Subversion Repositories HomeAutomation

Rev

Rev 859 | Rev 1883 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
63 jimmy 1
# Hey Emacs, this is a -*- makefile -*-
2
#
356 andfri 3
# WinAVR makefile written by Eric B. Weddington, J�rg Wunsch, et al.
63 jimmy 4
# Released to the Public Domain
5
# Please read the make user manual!
6
#
7
# Additional material for this makefile was submitted by:
8
#  Tim Henigan
9
#  Peter Fleury
10
#  Reiner Patommel
11
#  Sander Pool
12
#  Frederik Rouleau
13
#  Markus Pfaff
14
#
15
# On command line:
16
#
17
# make all = Make software.
18
#
19
# make clean = Clean out built project files.
20
#
21
# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
22
#
23
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
24
#                4.07 or greater).
25
#
26
# make program = Download the hex file to the device, using avrdude.  Please
27
#                customize the avrdude settings below first!
28
#
29
# make filename.s = Just compile filename.c into the assembler code only
30
#
31
# To rebuild project do "make clean" then "make all".
32
#
33
 
34
########
35
# Differences from WinAVR 20040720 sample:
36
# - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum)
37
# - F_OSC Define in CFLAGS and AFLAGS
38
 
859 arune 39
## HomeAutomation-users! Make sure you have a system.inc in your EmbeddedSoftware/AVR/personal folder ##
63 jimmy 40
 
859 arune 41
## FUSES, will automatically be programmed ##
380 eqlazer 42
#MCU = atmega8
63 jimmy 43
 
859 arune 44
#MCU = atmega88
45
#HIGHFUSE=0xdc
46
#LOWFUSE=0xe2
47
#EXTFUSE=0x01
63 jimmy 48
 
859 arune 49
MCU = atmega168
50
HIGHFUSE=0xdc
51
LOWFUSE=0xe2
52
EXTFUSE=0x01
53
 
1645 arune 54
#MCU = atmega328p
55
#HIGHFUSE=0xdc
56
#LOWFUSE=0xe2
57
#EXTFUSE=0x01
859 arune 58
 
1645 arune 59
 
859 arune 60
# for using the same system.inc we use BIOSDIR and BIOSTARGET for setting the correct file to flash
61
# flash:w:$(BIOSDIR)/$(BIOSTARGET).hex
62
BIOSDIR = .
63
BIOSTARGET = main
64
include ../../personal/system.inc
65
 
66
 
63 jimmy 67
# Output format. (can be srec, ihex, binary)
68
FORMAT = ihex
69
 
70
 
71
# Target file name (without extension).
72
TARGET = main
73
 
665 arune 74
LIBDIR = ../../avr-lib/
63 jimmy 75
 
76
# List C source files here. (C dependencies are automatically generated.)
77
SRC =	$(TARGET).c\
665 arune 78
		$(LIBDIR)drivers/uart/serial.c\
79
		$(LIBDIR)drivers/uart/uart.c\
80
		$(LIBDIR)drivers/timer/timebase.c\
81
		$(LIBDIR)drivers/mcu/mcu.c\
693 arune 82
		$(LIBDIR)drivers/can/stdcan.c\
83
		$(LIBDIR)drivers/can/mcp2515/mcp2515.c\
665 arune 84
 
63 jimmy 85
# List Assembler source files here.
86
# Make them always end in a capital .S.  Files ending in a lowercase .s
87
# will not be considered source files but generated files (assembler
88
# output from the compiler), and will be deleted upon "make clean"!
89
# Even though the DOS/Win* filesystem matches both .s and .S the same,
90
# it will preserve the spelling of the filenames, and gcc itself does
91
# care about how the name is spelled on its command-line.
92
ASRC = 
93
 
94
 
95
# Optimization level, can be [0, 1, 2, 3, s]. 
96
# 0 = turn off optimization. s = optimize for size.
97
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
98
OPT = s
99
#OPT = 3
100
 
101
# Debugging format.
102
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
103
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
104
#DEBUG = stabs
105
DEBUG = dwarf-2
106
 
107
# List any extra directories to look for include files here.
108
#     Each directory must be seperated by a space.
693 arune 109
EXTRAINCDIRS = $(LIBDIR)drivers/uart $(LIBDIR)drivers/timer $(LIBDIR)drivers/mcu $(LIBDIR)drivers/can/mcp2515/ $(LIBDIR)drivers/can/ $(LIBDIR) 
63 jimmy 110
 
111
# Compiler flag to set the C Standard level.
112
# c89   - "ANSI" C
113
# gnu89 - c89 plus GCC extensions
114
# c99   - ISO C99 standard (not yet fully implemented)
115
# gnu99 - c99 plus GCC extensions
116
CSTANDARD = -std=gnu99
117
 
118
# Place -D or -U options here
119
CDEFS =
120
 
121
# Place -I options here
122
CINCS =
123
 
124
 
125
# Compiler flags.
126
#  -g*:          generate debugging information
127
#  -O*:          optimization level
128
#  -f...:        tuning, see GCC manual and avr-libc documentation
129
#  -Wall...:     warning level
130
#  -Wa,...:      tell GCC to pass this to the assembler.
131
#    -adhlns...: create assembler listing
142 jimmy 132
CFLAGS = 
133
#CFLAGS += -g$(DEBUG)
63 jimmy 134
CFLAGS += $(CDEFS) $(CINCS)
135
CFLAGS += -O$(OPT)
136
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
137
CFLAGS += -Wall -Wstrict-prototypes
138
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
139
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
140
CFLAGS += $(CSTANDARD)
665 arune 141
#CFLAGS += -DF_CPU=$(F_CPU)
63 jimmy 142
 
143
 
144
 
145
# Assembler flags.
146
#  -Wa,...:   tell GCC to pass this to the assembler.
147
#  -ahlms:    create listing
148
#  -gstabs:   have the assembler create line number information; note that
149
#             for use in COFF files, additional information about filenames
150
#             and function names needs to be present in the assembler source
151
#             files -- see avr-libc docs [FIXME: not yet described there]
152
##ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
153
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-g$(DEBUG)
665 arune 154
#ASFLAGS += -DF_OSC=$(F_OSC)
63 jimmy 155
 
156
 
157
#Additional libraries.
158
 
159
# Minimalistic printf version
160
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
161
 
162
# Floating point printf version (requires MATH_LIB = -lm below)
163
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
164
 
165
PRINTF_LIB = 
166
 
167
# Minimalistic scanf version
168
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
169
 
170
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
171
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
172
 
173
SCANF_LIB = 
174
 
175
MATH_LIB = -lm
176
 
177
# External memory options
178
 
179
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
180
# used for variables (.data/.bss) and heap (malloc()).
181
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
182
 
183
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
184
# only used for heap (malloc()).
185
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
186
 
187
EXTMEMOPTS =
188
 
189
# Linker flags.
190
#  -Wl,...:     tell GCC to pass this to linker.
191
#    -Map:      create map file
192
#    --cref:    add cross reference to  map file
193
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
194
LDFLAGS += $(EXTMEMOPTS)
195
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
196
 
197
 
859 arune 198
## HomeAutomation-users: settings are moved to system.inc ##
63 jimmy 199
 
200
# Programming support using avrdude. Settings and variables.
201
 
202
# Programming hardware: alf avr910 avrisp bascom bsd 
203
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
204
#
205
# Type: avrdude -c ?
206
# to get a full listing.
207
#
859 arune 208
#AVRDUDE_PROGRAMMER = avrispmkII
63 jimmy 209
 
210
# com1 = serial port. Use lpt1 to connect to parallel port.
859 arune 211
#AVRDUDE_PORT = usb    # programmer connected to serial device
212
#AVRDUDE_BAUD = 115200
63 jimmy 213
 
859 arune 214
#AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
63 jimmy 215
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
216
 
217
 
218
# Uncomment the following if you want avrdude's erase cycle counter.
219
# Note that this counter needs to be initialized first using -Yn,
220
# see avrdude manual.
221
#AVRDUDE_ERASE_COUNTER = -y
222
 
223
# Uncomment the following if you do /not/ wish a verification to be
224
# performed after programming the device.
225
#AVRDUDE_NO_VERIFY = -V
226
 
227
# Increase verbosity level.  Please use this when submitting bug
228
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
229
# to submit bug reports.
230
#AVRDUDE_VERBOSE = -v -v
231
 
859 arune 232
#AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -b $(AVRDUDE_BAUD)
233
#AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
234
#AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
235
#AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
63 jimmy 236
 
237
 
238
 
239
# ---------------------------------------------------------------------------
240
 
241
# Define directories, if needed.
242
DIRAVR = c:/progra~1/winavr
243
DIRAVRBIN = $(DIRAVR)/bin
244
DIRAVRUTILS = $(DIRAVR)/utils/bin
245
DIRINC = .
246
DIRLIB = $(DIRAVR)/avr/lib
247
 
248
 
249
# Define programs and commands.
250
SHELL = sh
251
CC = avr-gcc
252
OBJCOPY = avr-objcopy
253
OBJDUMP = avr-objdump
254
SIZE = avr-size
255
NM = avr-nm
859 arune 256
#AVRDUDE = avrdude
63 jimmy 257
REMOVE = rm -f
258
COPY = cp
259
 
260
 
261
 
262
 
263
# Define Messages
264
# English
265
MSG_ERRORS_NONE = Errors: none
266
MSG_BEGIN = -------- begin --------
267
MSG_END = --------  end  --------
268
MSG_SIZE_BEFORE = Size before: 
269
MSG_SIZE_AFTER = Size after:
270
MSG_COFF = Converting to AVR COFF:
271
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
272
MSG_FLASH = Creating load file for Flash:
273
MSG_EEPROM = Creating load file for EEPROM:
274
MSG_EXTENDED_LISTING = Creating Extended Listing:
275
MSG_SYMBOL_TABLE = Creating Symbol Table:
276
MSG_LINKING = Linking:
277
MSG_COMPILING = Compiling:
278
MSG_ASSEMBLING = Assembling:
279
MSG_CLEANING = Cleaning project:
280
 
281
 
282
 
283
 
284
# Define all object files.
285
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
286
 
287
# Define all listing files.
288
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
289
 
290
 
291
# Compiler flags to generate dependency files.
292
### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
293
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
294
 
295
# Combine all necessary flags and optional flags.
296
# Add target processor to flags.
297
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
298
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
299
 
300
 
301
 
302
 
303
 
304
# Default target.
305
all: begin gccversion sizebefore build sizeafter finished end
306
 
307
build: elf hex eep lss sym
308
 
309
elf: $(TARGET).elf
310
hex: $(TARGET).hex
311
eep: $(TARGET).eep
312
lss: $(TARGET).lss 
313
sym: $(TARGET).sym
314
 
315
 
316
 
317
# Eye candy.
318
# AVR Studio 3.x does not check make's exit code but relies on
319
# the following magic strings to be generated by the compile job.
320
begin:
321
	@echo
322
	@echo $(MSG_BEGIN)
323
 
324
finished:
325
	@echo $(MSG_ERRORS_NONE)
326
 
327
end:
328
	@echo $(MSG_END)
329
	@echo
330
 
331
 
332
# Display size of file.
333
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
334
ELFSIZE = $(SIZE) -A $(TARGET).elf
335
sizebefore:
336
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
337
 
338
sizeafter:
339
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
340
 
341
 
342
 
343
# Display compiler version information.
344
gccversion : 
345
	@$(CC) --version
346
 
347
 
859 arune 348
# Program the device.  
349
install: $(TARGET).hex $(TARGET).eep
350
	$(UPLOAD) $(ULFLAGS)
63 jimmy 351
 
352
# Program the device.  
353
program: $(TARGET).hex $(TARGET).eep
859 arune 354
	$(UPLOAD) $(ULFLAGS)
355
#	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
63 jimmy 356
 
357
#programlock: 
358
#	$(AVRDUDE) $(AVRDUDE_FLAGS) -U lock:w:0x00:m
359
 
360
#programinit: 
361
#	$(AVRDUDE) $(AVRDUDE_FLAGS) -U hfuse:w:0xd9:m -U lfuse:w:0xe4:m
362
 
363
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
364
COFFCONVERT=$(OBJCOPY) --debugging \
365
--change-section-address .data-0x800000 \
366
--change-section-address .bss-0x800000 \
367
--change-section-address .noinit-0x800000 \
368
--change-section-address .eeprom-0x810000 
369
 
370
 
371
coff: $(TARGET).elf
372
	@echo
373
	@echo $(MSG_COFF) $(TARGET).cof
374
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
375
 
376
 
377
extcoff: $(TARGET).elf
378
	@echo
379
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
380
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
381
 
382
 
383
 
384
# Create final output files (.hex, .eep) from ELF output file.
385
%.hex: %.elf
386
	@echo
387
	@echo $(MSG_FLASH) $@
388
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
389
 
390
%.eep: %.elf
391
	@echo
392
	@echo $(MSG_EEPROM) $@
393
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
394
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
395
 
396
# Create extended listing file from ELF output file.
397
%.lss: %.elf
398
	@echo
399
	@echo $(MSG_EXTENDED_LISTING) $@
400
	$(OBJDUMP) -h -S $< > $@
401
 
402
# Create a symbol table from ELF output file.
403
%.sym: %.elf
404
	@echo
405
	@echo $(MSG_SYMBOL_TABLE) $@
406
	$(NM) -n $< > $@
407
 
408
 
409
 
410
# Link: create ELF output file from object files.
411
.SECONDARY : $(TARGET).elf
412
.PRECIOUS : $(OBJ)
413
%.elf: $(OBJ)
414
	@echo
415
	@echo $(MSG_LINKING) $@
416
	$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
417
 
418
 
419
# Compile: create object files from C source files.
420
%.o : %.c
421
	@echo
422
	@echo $(MSG_COMPILING) $<
423
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
424
 
425
 
426
# Compile: create assembler files from C source files.
427
%.s : %.c
428
	$(CC) -S $(ALL_CFLAGS) $< -o $@
429
 
430
 
431
# Assemble: create object files from assembler source files.
432
%.o : %.S
433
	@echo
434
	@echo $(MSG_ASSEMBLING) $<
435
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
436
 
437
 
438
 
439
# Target: clean project.
440
clean: begin clean_list finished end
441
 
442
clean_list :
443
	@echo
444
	@echo $(MSG_CLEANING)
445
	$(REMOVE) $(TARGET).hex
446
	$(REMOVE) $(TARGET).eep
447
	$(REMOVE) $(TARGET).obj
448
	$(REMOVE) $(TARGET).cof
449
	$(REMOVE) $(TARGET).elf
450
	$(REMOVE) $(TARGET).map
451
	$(REMOVE) $(TARGET).obj
452
	$(REMOVE) $(TARGET).a90
453
	$(REMOVE) $(TARGET).sym
454
	$(REMOVE) $(TARGET).lnk
455
	$(REMOVE) $(TARGET).lss
456
	$(REMOVE) $(OBJ)
457
	$(REMOVE) $(LST)
458
	$(REMOVE) $(SRC:.c=.s)
459
	$(REMOVE) $(SRC:.c=.d)
460
	$(REMOVE) .dep/*
461
 
462
 
463
 
464
# Include the dependency files.
465
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
466
 
467
 
468
# Listing of phony targets.
469
.PHONY : all begin finish end sizebefore sizeafter gccversion \
470
build elf hex eep lss sym coff extcoff \
471
clean clean_list program programlock programinit
472