]>
Commit | Line | Data |
---|---|---|
1 | # Hey Emacs, this is a -*- makefile -*- | |
2 | #---------------------------------------------------------------------------- | |
3 | # WinAVR Makefile Template written by Eric B. Weddington, Jg Wunsch, et al. | |
4 | # | |
5 | # Released to the Public Domain | |
6 | # | |
7 | # Additional material for this makefile was written by: | |
8 | # Peter Fleury | |
9 | # Tim Henigan | |
10 | # Colin O'Flynn | |
11 | # Reiner Patommel | |
12 | # Markus Pfaff | |
13 | # Sander Pool | |
14 | # Frederik Rouleau | |
15 | # Carlos Lamas | |
16 | # | |
17 | #---------------------------------------------------------------------------- | |
18 | # On command line: | |
19 | # | |
20 | # make all = Make software. | |
21 | # | |
22 | # make clean = Clean out built project files. | |
23 | # | |
24 | # make coff = Convert ELF to AVR COFF. | |
25 | # | |
26 | # make extcoff = Convert ELF to AVR Extended COFF. | |
27 | # | |
28 | # make program = Download the hex file to the device. | |
29 | # Please customize your programmer settings(PROGRAM_CMD) | |
30 | # | |
31 | # make teensy = Download the hex file to the device, using teensy_loader_cli. | |
32 | # (must have teensy_loader_cli installed). | |
33 | # | |
34 | # make dfu = Download the hex file to the device, using dfu-programmer (must | |
35 | # have dfu-programmer installed). | |
36 | # | |
37 | # make flip = Download the hex file to the device, using Atmel FLIP (must | |
38 | # have Atmel FLIP installed). | |
39 | # | |
40 | # make dfu-ee = Download the eeprom file to the device, using dfu-programmer | |
41 | # (must have dfu-programmer installed). | |
42 | # | |
43 | # make flip-ee = Download the eeprom file to the device, using Atmel FLIP | |
44 | # (must have Atmel FLIP installed). | |
45 | # | |
46 | # make debug = Start either simulavr or avarice as specified for debugging, | |
47 | # with avr-gdb or avr-insight as the front end for debugging. | |
48 | # | |
49 | # make filename.s = Just compile filename.c into the assembler code only. | |
50 | # | |
51 | # make filename.i = Create a preprocessed source file for use in submitting | |
52 | # bug reports to the GCC project. | |
53 | # | |
54 | # To rebuild project do "make clean" then "make all". | |
55 | #---------------------------------------------------------------------------- | |
56 | ||
57 | ||
58 | # Output format. (can be srec, ihex, binary) | |
59 | FORMAT = ihex | |
60 | ||
61 | ||
62 | # Object files directory | |
63 | # To put object files in current directory, use a dot (.), do NOT make | |
64 | # this an empty or blank macro! | |
65 | OBJDIR = obj_$(TARGET) | |
66 | ||
67 | ||
68 | # Optimization level, can be [0, 1, 2, 3, s]. | |
69 | # 0 = turn off optimization. s = optimize for size. | |
70 | # (Note: 3 is not always the best optimization level. See avr-libc FAQ.) | |
71 | OPT = s | |
72 | ||
73 | ||
74 | # Debugging format. | |
75 | # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. | |
76 | # AVR Studio 4.10 requires dwarf-2. | |
77 | # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. | |
78 | DEBUG = dwarf-2 | |
79 | ||
80 | ||
81 | # List any extra directories to look for include files here. | |
82 | # Each directory must be seperated by a space. | |
83 | # Use forward slashes for directory separators. | |
84 | # For a directory that has spaces, enclose it in quotes. | |
85 | EXTRAINCDIRS = $(subst :, ,$(VPATH)) | |
86 | ||
87 | ||
88 | # Compiler flag to set the C Standard level. | |
89 | # c89 = "ANSI" C | |
90 | # gnu89 = c89 plus GCC extensions | |
91 | # c99 = ISO C99 standard (not yet fully implemented) | |
92 | # gnu99 = c99 plus GCC extensions | |
93 | CSTANDARD = -std=gnu99 | |
94 | ||
95 | ||
96 | # Place -D or -U options here for C sources | |
97 | CDEFS = -DF_CPU=$(F_CPU)UL | |
98 | CDEFS += $(OPT_DEFS) | |
99 | ||
100 | ||
101 | # Place -D or -U options here for ASM sources | |
102 | ADEFS = -DF_CPU=$(F_CPU) | |
103 | ADEFS += $(OPT_DEFS) | |
104 | ||
105 | ||
106 | # Place -D or -U options here for C++ sources | |
107 | CPPDEFS = -DF_CPU=$(F_CPU)UL | |
108 | #CPPDEFS += -D__STDC_LIMIT_MACROS | |
109 | #CPPDEFS += -D__STDC_CONSTANT_MACROS | |
110 | CPPDEFS += $(OPT_DEFS) | |
111 | ||
112 | ||
113 | ||
114 | #---------------- Compiler Options C ---------------- | |
115 | # -g*: generate debugging information | |
116 | # -O*: optimization level | |
117 | # -f...: tuning, see GCC manual and avr-libc documentation | |
118 | # -Wall...: warning level | |
119 | # -Wa,...: tell GCC to pass this to the assembler. | |
120 | # -adhlns...: create assembler listing | |
121 | CFLAGS = -g$(DEBUG) | |
122 | CFLAGS += $(CDEFS) | |
123 | CFLAGS += -O$(OPT) | |
124 | CFLAGS += -funsigned-char | |
125 | CFLAGS += -funsigned-bitfields | |
126 | CFLAGS += -ffunction-sections | |
127 | CFLAGS += -fdata-sections | |
128 | CFLAGS += -fno-inline-small-functions | |
129 | CFLAGS += -fpack-struct | |
130 | CFLAGS += -fshort-enums | |
131 | CFLAGS += -fno-strict-aliasing | |
132 | CFLAGS += -Wall | |
133 | CFLAGS += -Wstrict-prototypes | |
134 | #CFLAGS += -mshort-calls | |
135 | #CFLAGS += -fno-unit-at-a-time | |
136 | #CFLAGS += -Wundef | |
137 | #CFLAGS += -Wunreachable-code | |
138 | #CFLAGS += -Wsign-compare | |
139 | CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst) | |
140 | CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) | |
141 | CFLAGS += $(CSTANDARD) | |
142 | ifdef CONFIG_H | |
143 | CFLAGS += -include $(CONFIG_H) | |
144 | endif | |
145 | ||
146 | ||
147 | #---------------- Compiler Options C++ ---------------- | |
148 | # -g*: generate debugging information | |
149 | # -O*: optimization level | |
150 | # -f...: tuning, see GCC manual and avr-libc documentation | |
151 | # -Wall...: warning level | |
152 | # -Wa,...: tell GCC to pass this to the assembler. | |
153 | # -adhlns...: create assembler listing | |
154 | CPPFLAGS = -g$(DEBUG) | |
155 | CPPFLAGS += $(CPPDEFS) | |
156 | CPPFLAGS += -O$(OPT) | |
157 | CPPFLAGS += -funsigned-char | |
158 | CPPFLAGS += -funsigned-bitfields | |
159 | CPPFLAGS += -fpack-struct | |
160 | CPPFLAGS += -fshort-enums | |
161 | CPPFLAGS += -fno-exceptions | |
162 | CPPFLAGS += -ffunction-sections | |
163 | CPPFLAGS += -fdata-sections | |
164 | # to supress "warning: only initialized variables can be placed into program memory area" | |
165 | CPPFLAGS += -w | |
166 | CPPFLAGS += -Wall | |
167 | CPPFLAGS += -Wundef | |
168 | #CPPFLAGS += -mshort-calls | |
169 | #CPPFLAGS += -fno-unit-at-a-time | |
170 | #CPPFLAGS += -Wstrict-prototypes | |
171 | #CPPFLAGS += -Wunreachable-code | |
172 | #CPPFLAGS += -Wsign-compare | |
173 | CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst) | |
174 | CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) | |
175 | #CPPFLAGS += $(CSTANDARD) | |
176 | ifdef CONFIG_H | |
177 | CPPFLAGS += -include $(CONFIG_H) | |
178 | endif | |
179 | ||
180 | ||
181 | #---------------- Assembler Options ---------------- | |
182 | # -Wa,...: tell GCC to pass this to the assembler. | |
183 | # -adhlns: create listing | |
184 | # -gstabs: have the assembler create line number information; note that | |
185 | # for use in COFF files, additional information about filenames | |
186 | # and function names needs to be present in the assembler source | |
187 | # files -- see avr-libc docs [FIXME: not yet described there] | |
188 | # -listing-cont-lines: Sets the maximum number of continuation lines of hex | |
189 | # dump that will be displayed for a given single line of source input. | |
190 | ASFLAGS = $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100 | |
191 | ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) | |
192 | ifdef CONFIG_H | |
193 | ASFLAGS += -include $(CONFIG_H) | |
194 | endif | |
195 | ||
196 | ||
197 | #---------------- Library Options ---------------- | |
198 | # Minimalistic printf version | |
199 | PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min | |
200 | ||
201 | # Floating point printf version (requires MATH_LIB = -lm below) | |
202 | PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt | |
203 | ||
204 | # If this is left blank, then it will use the Standard printf version. | |
205 | PRINTF_LIB = | |
206 | #PRINTF_LIB = $(PRINTF_LIB_MIN) | |
207 | #PRINTF_LIB = $(PRINTF_LIB_FLOAT) | |
208 | ||
209 | ||
210 | # Minimalistic scanf version | |
211 | SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min | |
212 | ||
213 | # Floating point + %[ scanf version (requires MATH_LIB = -lm below) | |
214 | SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt | |
215 | ||
216 | # If this is left blank, then it will use the Standard scanf version. | |
217 | SCANF_LIB = | |
218 | #SCANF_LIB = $(SCANF_LIB_MIN) | |
219 | #SCANF_LIB = $(SCANF_LIB_FLOAT) | |
220 | ||
221 | ||
222 | MATH_LIB = -lm | |
223 | ||
224 | ||
225 | # List any extra directories to look for libraries here. | |
226 | # Each directory must be seperated by a space. | |
227 | # Use forward slashes for directory separators. | |
228 | # For a directory that has spaces, enclose it in quotes. | |
229 | EXTRALIBDIRS = | |
230 | ||
231 | ||
232 | ||
233 | #---------------- External Memory Options ---------------- | |
234 | ||
235 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), | |
236 | # used for variables (.data/.bss) and heap (malloc()). | |
237 | #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff | |
238 | ||
239 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), | |
240 | # only used for heap (malloc()). | |
241 | #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff | |
242 | ||
243 | EXTMEMOPTS = | |
244 | ||
245 | ||
246 | ||
247 | #---------------- Linker Options ---------------- | |
248 | # -Wl,...: tell GCC to pass this to linker. | |
249 | # -Map: create map file | |
250 | # --cref: add cross reference to map file | |
251 | # | |
252 | # Comennt out "--relax" option to avoid a error such: | |
253 | # (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12' | |
254 | # | |
255 | LDFLAGS = -Wl,-Map=$(TARGET).map,--cref | |
256 | #LDFLAGS += -Wl,--relax | |
257 | LDFLAGS += -Wl,--gc-sections | |
258 | LDFLAGS += $(EXTMEMOPTS) | |
259 | LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS)) | |
260 | LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) | |
261 | #LDFLAGS += -T linker_script.x | |
262 | # You can give EXTRALDFLAGS at 'make' command line. | |
263 | LDFLAGS += $(EXTRALDFLAGS) | |
264 | ||
265 | ||
266 | ||
267 | #---------------- Debugging Options ---------------- | |
268 | ||
269 | # For simulavr only - target MCU frequency. | |
270 | DEBUG_MFREQ = $(F_CPU) | |
271 | ||
272 | # Set the DEBUG_UI to either gdb or insight. | |
273 | # DEBUG_UI = gdb | |
274 | DEBUG_UI = insight | |
275 | ||
276 | # Set the debugging back-end to either avarice, simulavr. | |
277 | DEBUG_BACKEND = avarice | |
278 | #DEBUG_BACKEND = simulavr | |
279 | ||
280 | # GDB Init Filename. | |
281 | GDBINIT_FILE = __avr_gdbinit | |
282 | ||
283 | # When using avarice settings for the JTAG | |
284 | JTAG_DEV = /dev/com1 | |
285 | ||
286 | # Debugging port used to communicate between GDB / avarice / simulavr. | |
287 | DEBUG_PORT = 4242 | |
288 | ||
289 | # Debugging host used to communicate between GDB / avarice / simulavr, normally | |
290 | # just set to localhost unless doing some sort of crazy debugging when | |
291 | # avarice is running on a different computer. | |
292 | DEBUG_HOST = localhost | |
293 | ||
294 | ||
295 | ||
296 | #============================================================================ | |
297 | ||
298 | ||
299 | # Define programs and commands. | |
300 | SHELL = sh | |
301 | CC = avr-gcc | |
302 | OBJCOPY = avr-objcopy | |
303 | OBJDUMP = avr-objdump | |
304 | SIZE = avr-size | |
305 | AR = avr-ar rcs | |
306 | NM = avr-nm | |
307 | REMOVE = rm -f | |
308 | REMOVEDIR = rmdir | |
309 | COPY = cp | |
310 | WINSHELL = cmd | |
311 | ||
312 | ||
313 | # Define Messages | |
314 | # English | |
315 | MSG_ERRORS_NONE = Errors: none | |
316 | MSG_BEGIN = -------- begin -------- | |
317 | MSG_END = -------- end -------- | |
318 | MSG_SIZE_BEFORE = Size before: | |
319 | MSG_SIZE_AFTER = Size after: | |
320 | MSG_COFF = Converting to AVR COFF: | |
321 | MSG_EXTENDED_COFF = Converting to AVR Extended COFF: | |
322 | MSG_FLASH = Creating load file for Flash: | |
323 | MSG_EEPROM = Creating load file for EEPROM: | |
324 | MSG_EXTENDED_LISTING = Creating Extended Listing: | |
325 | MSG_SYMBOL_TABLE = Creating Symbol Table: | |
326 | MSG_LINKING = Linking: | |
327 | MSG_COMPILING = Compiling C: | |
328 | MSG_COMPILING_CPP = Compiling C++: | |
329 | MSG_ASSEMBLING = Assembling: | |
330 | MSG_CLEANING = Cleaning project: | |
331 | MSG_CREATING_LIBRARY = Creating library: | |
332 | ||
333 | ||
334 | ||
335 | ||
336 | # Define all object files. | |
337 | OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC)))) | |
338 | ||
339 | # Define all listing files. | |
340 | LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst %.S,$(OBJDIR)/%.lst,$(SRC)))) | |
341 | ||
342 | ||
343 | # Compiler flags to generate dependency files. | |
344 | #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d | |
345 | GENDEPFLAGS = -MMD -MP -MF .dep/$(subst /,_,$@).d | |
346 | ||
347 | ||
348 | # Combine all necessary flags and optional flags. | |
349 | # Add target processor to flags. | |
350 | # You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar | |
351 | ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS) | |
352 | ALL_CPPFLAGS = -mmcu=$(MCU) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS) | |
353 | ALL_ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS) | |
354 | ||
355 | ||
356 | ||
357 | ||
358 | ||
359 | # Default target. | |
360 | all: begin gccversion sizebefore build sizeafter end | |
361 | ||
362 | # Change the build target to build a HEX file or a library. | |
363 | build: elf hex eep lss sym | |
364 | #build: lib | |
365 | ||
366 | ||
367 | elf: $(TARGET).elf | |
368 | hex: $(TARGET).hex | |
369 | eep: $(TARGET).eep | |
370 | lss: $(TARGET).lss | |
371 | sym: $(TARGET).sym | |
372 | LIBNAME=lib$(TARGET).a | |
373 | lib: $(LIBNAME) | |
374 | ||
375 | ||
376 | ||
377 | # Eye candy. | |
378 | # AVR Studio 3.x does not check make's exit code but relies on | |
379 | # the following magic strings to be generated by the compile job. | |
380 | begin: | |
381 | @echo | |
382 | @echo $(MSG_BEGIN) | |
383 | ||
384 | end: | |
385 | @echo $(MSG_END) | |
386 | @echo | |
387 | ||
388 | ||
389 | # Display size of file. | |
390 | HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex | |
391 | #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf | |
392 | ELFSIZE = $(SIZE) $(TARGET).elf | |
393 | ||
394 | sizebefore: | |
395 | @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \ | |
396 | 2>/dev/null; echo; fi | |
397 | ||
398 | sizeafter: | |
399 | @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \ | |
400 | 2>/dev/null; echo; fi | |
401 | ||
402 | ||
403 | ||
404 | # Display compiler version information. | |
405 | gccversion : | |
406 | @$(CC) --version | |
407 | ||
408 | ||
409 | ||
410 | # Program the device. | |
411 | program: $(TARGET).hex $(TARGET).eep | |
412 | $(PROGRAM_CMD) | |
413 | ||
414 | teensy: $(TARGET).hex | |
415 | teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex | |
416 | ||
417 | flip: $(TARGET).hex | |
418 | batchisp -hardware usb -device $(MCU) -operation erase f | |
419 | batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program | |
420 | batchisp -hardware usb -device $(MCU) -operation start reset 0 | |
421 | ||
422 | dfu: $(TARGET).hex | |
423 | @echo -n dfu-programmer: waiting | |
424 | @until dfu-programmer $(MCU) get bootloader-version > /dev/null 2>&1; do \ | |
425 | echo -n "."; \ | |
426 | sleep 1; \ | |
427 | done | |
428 | @echo | |
429 | ||
430 | ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1))) | |
431 | dfu-programmer $(MCU) erase --force | |
432 | else | |
433 | dfu-programmer $(MCU) erase | |
434 | endif | |
435 | dfu-programmer $(MCU) flash $(TARGET).hex | |
436 | dfu-programmer $(MCU) reset | |
437 | ||
438 | dfu-start: | |
439 | dfu-programmer $(MCU) reset | |
440 | dfu-programmer $(MCU) start | |
441 | ||
442 | flip-ee: $(TARGET).hex $(TARGET).eep | |
443 | $(COPY) $(TARGET).eep $(TARGET)eep.hex | |
444 | batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase | |
445 | batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program | |
446 | batchisp -hardware usb -device $(MCU) -operation start reset 0 | |
447 | $(REMOVE) $(TARGET)eep.hex | |
448 | ||
449 | dfu-ee: $(TARGET).hex $(TARGET).eep | |
450 | ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1))) | |
451 | dfu-programmer $(MCU) flash --eeprom $(TARGET).eep | |
452 | else | |
453 | dfu-programmer $(MCU) flash-eeprom $(TARGET).eep | |
454 | endif | |
455 | dfu-programmer $(MCU) reset | |
456 | ||
457 | ||
458 | # Generate avr-gdb config/init file which does the following: | |
459 | # define the reset signal, load the target file, connect to target, and set | |
460 | # a breakpoint at main(). | |
461 | gdb-config: | |
462 | @$(REMOVE) $(GDBINIT_FILE) | |
463 | @echo define reset >> $(GDBINIT_FILE) | |
464 | @echo SIGNAL SIGHUP >> $(GDBINIT_FILE) | |
465 | @echo end >> $(GDBINIT_FILE) | |
466 | @echo file $(TARGET).elf >> $(GDBINIT_FILE) | |
467 | @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE) | |
468 | ifeq ($(DEBUG_BACKEND),simulavr) | |
469 | @echo load >> $(GDBINIT_FILE) | |
470 | endif | |
471 | @echo break main >> $(GDBINIT_FILE) | |
472 | ||
473 | debug: gdb-config $(TARGET).elf | |
474 | ifeq ($(DEBUG_BACKEND), avarice) | |
475 | @echo Starting AVaRICE - Press enter when "waiting to connect" message displays. | |
476 | @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \ | |
477 | $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT) | |
478 | @$(WINSHELL) /c pause | |
479 | ||
480 | else | |
481 | @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \ | |
482 | $(DEBUG_MFREQ) --port $(DEBUG_PORT) | |
483 | endif | |
484 | @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE) | |
485 | ||
486 | ||
487 | ||
488 | ||
489 | # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. | |
490 | COFFCONVERT = $(OBJCOPY) --debugging | |
491 | COFFCONVERT += --change-section-address .data-0x800000 | |
492 | COFFCONVERT += --change-section-address .bss-0x800000 | |
493 | COFFCONVERT += --change-section-address .noinit-0x800000 | |
494 | COFFCONVERT += --change-section-address .eeprom-0x810000 | |
495 | ||
496 | ||
497 | ||
498 | coff: $(TARGET).elf | |
499 | @echo | |
500 | @echo $(MSG_COFF) $(TARGET).cof | |
501 | $(COFFCONVERT) -O coff-avr $< $(TARGET).cof | |
502 | ||
503 | ||
504 | extcoff: $(TARGET).elf | |
505 | @echo | |
506 | @echo $(MSG_EXTENDED_COFF) $(TARGET).cof | |
507 | $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof | |
508 | ||
509 | ||
510 | ||
511 | # Create final output files (.hex, .eep) from ELF output file. | |
512 | %.hex: %.elf | |
513 | @echo | |
514 | @echo $(MSG_FLASH) $@ | |
515 | $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@ | |
516 | ||
517 | %.eep: %.elf | |
518 | @echo | |
519 | @echo $(MSG_EEPROM) $@ | |
520 | -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ | |
521 | --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0 | |
522 | ||
523 | # Create extended listing file from ELF output file. | |
524 | %.lss: %.elf | |
525 | @echo | |
526 | @echo $(MSG_EXTENDED_LISTING) $@ | |
527 | $(OBJDUMP) -h -S -z $< > $@ | |
528 | ||
529 | # Create a symbol table from ELF output file. | |
530 | %.sym: %.elf | |
531 | @echo | |
532 | @echo $(MSG_SYMBOL_TABLE) $@ | |
533 | $(NM) -n $< > $@ | |
534 | ||
535 | ||
536 | ||
537 | # Create library from object files. | |
538 | .SECONDARY : $(TARGET).a | |
539 | .PRECIOUS : $(OBJ) | |
540 | %.a: $(OBJ) | |
541 | @echo | |
542 | @echo $(MSG_CREATING_LIBRARY) $@ | |
543 | $(AR) $@ $(OBJ) | |
544 | ||
545 | ||
546 | # Link: create ELF output file from object files. | |
547 | .SECONDARY : $(TARGET).elf | |
548 | .PRECIOUS : $(OBJ) | |
549 | %.elf: $(OBJ) | |
550 | @echo | |
551 | @echo $(MSG_LINKING) $@ | |
552 | $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) | |
553 | ||
554 | ||
555 | # Compile: create object files from C source files. | |
556 | $(OBJDIR)/%.o : %.c | |
557 | @echo | |
558 | mkdir -p $(@D) | |
559 | @echo $(MSG_COMPILING) $< | |
560 | $(CC) -c $(ALL_CFLAGS) $< -o $@ | |
561 | ||
562 | ||
563 | # Compile: create object files from C++ source files. | |
564 | $(OBJDIR)/%.o : %.cpp | |
565 | @echo | |
566 | mkdir -p $(@D) | |
567 | @echo $(MSG_COMPILING_CPP) $< | |
568 | $(CC) -c $(ALL_CPPFLAGS) $< -o $@ | |
569 | ||
570 | ||
571 | # Compile: create assembler files from C source files. | |
572 | %.s : %.c | |
573 | $(CC) -S $(ALL_CFLAGS) $< -o $@ | |
574 | ||
575 | ||
576 | # Compile: create assembler files from C++ source files. | |
577 | %.s : %.cpp | |
578 | $(CC) -S $(ALL_CPPFLAGS) $< -o $@ | |
579 | ||
580 | ||
581 | # Assemble: create object files from assembler source files. | |
582 | $(OBJDIR)/%.o : %.S | |
583 | @echo | |
584 | mkdir -p $(@D) | |
585 | @echo $(MSG_ASSEMBLING) $< | |
586 | $(CC) -c $(ALL_ASFLAGS) $< -o $@ | |
587 | ||
588 | ||
589 | # Create preprocessed source for use in sending a bug report. | |
590 | %.i : %.c | |
591 | $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@ | |
592 | ||
593 | ||
594 | # Target: clean project. | |
595 | clean: begin clean_list end | |
596 | ||
597 | clean_list : | |
598 | @echo | |
599 | $(REMOVE) $(TARGET).hex | |
600 | $(REMOVE) $(TARGET).eep | |
601 | $(REMOVE) $(TARGET).cof | |
602 | $(REMOVE) $(TARGET).elf | |
603 | $(REMOVE) $(TARGET).map | |
604 | $(REMOVE) $(TARGET).sym | |
605 | $(REMOVE) $(TARGET).lss | |
606 | $(REMOVE) $(OBJ) | |
607 | $(REMOVE) $(LST) | |
608 | $(REMOVE) $(OBJ:.o=.s) | |
609 | $(REMOVE) $(OBJ:.o=.i) | |
610 | $(REMOVE) -r .dep | |
611 | $(REMOVE) -r $(OBJDIR) | |
612 | ||
613 | show_path: | |
614 | @echo VPATH=$(VPATH) | |
615 | @echo SRC=$(SRC) | |
616 | ||
617 | ||
618 | # Create object files directory | |
619 | $(shell mkdir $(OBJDIR) 2>/dev/null) | |
620 | ||
621 | ||
622 | # Include the dependency files. | |
623 | -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) | |
624 | ||
625 | ||
626 | # Listing of phony targets. | |
627 | .PHONY : all begin finish end sizebefore sizeafter gccversion \ | |
628 | build elf hex eep lss sym coff extcoff \ | |
629 | clean clean_list debug gdb-config show_path \ | |
630 | program teensy dfu flip dfu-ee flip-ee dfu-start |