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