parse_monitor: replace printf printf_P
[protos/xbee-avr.git] / makefile
1 \r
2 # Hey Emacs, this is a -*- makefile -*-\r
3 #----------------------------------------------------------------------------\r
4 # WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.\r
5 #  >> Modified for use with the LUFA project. <<\r
6 #\r
7 # Released to the Public Domain\r
8 #\r
9 # Additional material for this makefile was written by:\r
10 # Peter Fleury\r
11 # Tim Henigan\r
12 # Colin O'Flynn\r
13 # Reiner Patommel\r
14 # Markus Pfaff\r
15 # Sander Pool\r
16 # Frederik Rouleau\r
17 # Carlos Lamas\r
18 # Dean Camera\r
19 # Opendous Inc.\r
20 # Denver Gingerich\r
21 #\r
22 #----------------------------------------------------------------------------\r
23 # On command line:\r
24 #\r
25 # make all = Make software.\r
26 #\r
27 # make clean = Clean out built project files.\r
28 #\r
29 # make coff = Convert ELF to AVR COFF.\r
30 #\r
31 # make extcoff = Convert ELF to AVR Extended COFF.\r
32 #\r
33 # make program = Download the hex file to the device, using avrdude.\r
34 #                Please customize the avrdude settings below first!\r
35 #\r
36 # make dfu = Download the hex file to the device, using dfu-programmer (must\r
37 #            have dfu-programmer installed).\r
38 #\r
39 # make flip = Download the hex file to the device, using Atmel FLIP (must\r
40 #             have Atmel FLIP installed).\r
41 #\r
42 # make dfu-ee = Download the eeprom file to the device, using dfu-programmer\r
43 #               (must have dfu-programmer installed).\r
44 #\r
45 # make flip-ee = Download the eeprom file to the device, using Atmel FLIP\r
46 #                (must have Atmel FLIP installed).\r
47 #\r
48 # make doxygen = Generate DoxyGen documentation for the project (must have\r
49 #                DoxyGen installed)\r
50 #\r
51 # make debug = Start either simulavr or avarice as specified for debugging,\r
52 #              with avr-gdb or avr-insight as the front end for debugging.\r
53 #\r
54 # make filename.s = Just compile filename.c into the assembler code only.\r
55 #\r
56 # make filename.i = Create a preprocessed source file for use in submitting\r
57 #                   bug reports to the GCC project.\r
58 #\r
59 # To rebuild project do "make clean" then "make all".\r
60 #----------------------------------------------------------------------------\r
61 \r
62 \r
63 # MCU name\r
64 MCU = at90usb1287\r
65 \r
66 \r
67 # Target architecture (see library "Board Types" documentation).\r
68 ARCH = AVR8\r
69 \r
70 \r
71 # Target board (see library "Board Types" documentation, NONE for projects not requiring\r
72 # LUFA board drivers). If USER is selected, put custom board drivers in a directory called\r
73 # "Board" inside the application directory.\r
74 BOARD = USBKEY\r
75 \r
76 \r
77 # Processor frequency.\r
78 #     This will define a symbol, F_CPU, in all source code files equal to the\r
79 #     processor frequency in Hz. You can then use this symbol in your source code to\r
80 #     calculate timings. Do NOT tack on a 'UL' at the end, this will be done\r
81 #     automatically to create a 32-bit value in your source code.\r
82 #\r
83 #     This will be an integer division of F_USB below, as it is sourced by\r
84 #     F_USB after it has run through any CPU prescalers. Note that this value\r
85 #     does not *change* the processor frequency - it should merely be updated to\r
86 #     reflect the processor speed set externally so that the code can use accurate\r
87 #     software delays.\r
88 F_CPU = 8000000\r
89 \r
90 \r
91 # Input clock frequency.\r
92 #     This will define a symbol, F_USB, in all source code files equal to the\r
93 #     input clock frequency (before any prescaling is performed) in Hz. This value may\r
94 #     differ from F_CPU if prescaling is used on the latter, and is required as the\r
95 #     raw input clock is fed directly to the PLL sections of the AVR for high speed\r
96 #     clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'\r
97 #     at the end, this will be done automatically to create a 32-bit value in your\r
98 #     source code.\r
99 #\r
100 #     If no clock division is performed on the input clock inside the AVR (via the\r
101 #     CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.\r
102 F_USB = $(F_CPU)\r
103 \r
104 \r
105 # Output format. (can be srec, ihex, binary)\r
106 FORMAT = ihex\r
107 \r
108 \r
109 # Target file name (without extension).\r
110 TARGET = DualVirtualSerial\r
111 \r
112 \r
113 # Object files directory\r
114 #     To put object files in current directory, use a dot (.), do NOT make\r
115 #     this an empty or blank macro!\r
116 OBJDIR = .\r
117 \r
118 \r
119 # Path to the LUFA library\r
120 LUFA_PATH = ../../../..\r
121 \r
122 \r
123 # LUFA library compile-time options and predefined tokens\r
124 LUFA_OPTS  = -D USB_DEVICE_ONLY\r
125 LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8\r
126 LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1\r
127 LUFA_OPTS += -D USE_FLASH_DESCRIPTORS\r
128 LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"\r
129 \r
130 \r
131 # Create the LUFA source path variables by including the LUFA root makefile\r
132 include $(LUFA_PATH)/LUFA/makefile\r
133 \r
134 \r
135 # List C source files here. (C dependencies are automatically generated.)\r
136 SRC = \\r
137         $(TARGET).c \\r
138         Descriptors.c \\r
139         $(LUFA_SRC_USB) \\r
140         $(LUFA_SRC_USBCLASS) \\r
141         cirbuf_add_buf_head.c \\r
142         cirbuf_add_buf_tail.c \\r
143         cirbuf_add_head.c \\r
144         cirbuf_add_tail.c \\r
145         cirbuf_align.c \\r
146         cirbuf.c \\r
147         cirbuf_del_buf_head.c \\r
148         cirbuf_del_buf_tail.c \\r
149         cirbuf_del_head.c \\r
150         cirbuf_del_tail.c \\r
151         cirbuf_get_buf_head.c \\r
152         cirbuf_get_buf_tail.c \\r
153         cirbuf_get_head.c \\r
154         cirbuf_get_tail.c \\r
155         cmdline.c \\r
156         commands.c \\r
157         commands_gen.c \\r
158         Descriptors.c \\r
159         DualVirtualSerial.c \\r
160         main.c \\r
161         rc_proto.c \\r
162         parse.c \\r
163         parse_num.c \\r
164         parse_string.c \\r
165         rdline.c \\r
166         scheduler_add.c \\r
167         scheduler.c \\r
168         scheduler_del.c \\r
169         scheduler_dump.c \\r
170         scheduler_interrupt.c \\r
171         scheduler_stats.c \\r
172         uart.c \\r
173         uart_dev_io.c \\r
174         uart_events.c \\r
175         uart_getconf.c \\r
176         uart_recv.c \\r
177         uart_recv_nowait.c \\r
178         uart_send.c \\r
179         uart_send_nowait.c \\r
180         uart_setconf.c \\r
181         xbee_atcmd.c \\r
182         xbee.c \\r
183         xbee_neighbor.c \\r
184         xbee_proto.c \\r
185         xbee_stats.c \\r
186         vt100.c \\r
187         error.c \\r
188         int_show.c \\r
189         stackdump.c \\r
190         stack_space.c \\r
191         timer0_getset.c \\r
192         timer0_prescaler.c \\r
193         timer0_register_OC_at_tics.c \\r
194         timer0_register_OC_in_us.c \\r
195         timer0_register_OV.c \\r
196         timer0_startstop.c \\r
197         timer1_getset.c \\r
198         timer1_prescaler.c \\r
199         timer1_register_OC_at_tics.c \\r
200         timer1_register_OC_in_us.c \\r
201         timer1_register_OV.c \\r
202         timer1_startstop.c \\r
203         timer2_getset.c \\r
204         timer2_prescaler.c \\r
205         timer2_register_OC_at_tics.c \\r
206         timer2_register_OC_in_us.c \\r
207         timer2_register_OV.c \\r
208         timer2_startstop.c \\r
209         timer3_getset.c \\r
210         timer3_prescaler.c \\r
211         timer3_register_OC_at_tics.c \\r
212         timer3_register_OC_in_us.c \\r
213         timer3_register_OV.c \\r
214         timer3_startstop.c \\r
215         timer4_getset.c \\r
216         timer4_prescaler.c \\r
217         timer4_register_OC_at_tics.c \\r
218         timer4_register_OC_in_us.c \\r
219         timer4_register_OV.c \\r
220         timer4_startstop.c \\r
221         timer5_getset.c \\r
222         timer5_prescaler.c \\r
223         timer5_register_OC_at_tics.c \\r
224         timer5_register_OC_in_us.c \\r
225         timer5_register_OV.c \\r
226         timer5_startstop.c \\r
227         timer_conf_check.c \\r
228         timer_init.c \\r
229         timer_intr.c \\r
230         callout.c \\r
231         parse_neighbor.c \\r
232         parse_atcmd.c \\r
233         parse_monitor.c \\r
234         time.c\r
235 \r
236 # List C++ source files here. (C dependencies are automatically generated.)\r
237 CPPSRC =\r
238 \r
239 \r
240 # List Assembler source files here.\r
241 #     Make them always end in a capital .S.  Files ending in a lowercase .s\r
242 #     will not be considered source files but generated files (assembler\r
243 #     output from the compiler), and will be deleted upon "make clean"!\r
244 #     Even though the DOS/Win* filesystem matches both .s and .S the same,\r
245 #     it will preserve the spelling of the filenames, and gcc itself does\r
246 #     care about how the name is spelled on its command-line.\r
247 ASRC =\r
248 \r
249 \r
250 # Optimization level, can be [0, 1, 2, 3, s].\r
251 #     0 = turn off optimization. s = optimize for size.\r
252 #     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)\r
253 OPT = s\r
254 \r
255 \r
256 # Debugging format.\r
257 #     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.\r
258 #     AVR Studio 4.10 requires dwarf-2.\r
259 #     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.\r
260 DEBUG = dwarf-2\r
261 \r
262 \r
263 # List any extra directories to look for include files here.\r
264 #     Each directory must be seperated by a space.\r
265 #     Use forward slashes for directory separators.\r
266 #     For a directory that has spaces, enclose it in quotes.\r
267 EXTRAINCDIRS = $(LUFA_PATH)/\r
268 \r
269 \r
270 # Compiler flag to set the C Standard level.\r
271 #     c89   = "ANSI" C\r
272 #     gnu89 = c89 plus GCC extensions\r
273 #     c99   = ISO C99 standard (not yet fully implemented)\r
274 #     gnu99 = c99 plus GCC extensions\r
275 CSTANDARD = -std=c99\r
276 \r
277 \r
278 # Place -D or -U options here for C sources\r
279 CDEFS  = -DF_CPU=$(F_CPU)UL\r
280 CDEFS += -DF_USB=$(F_USB)UL\r
281 CDEFS += -DBOARD=BOARD_$(BOARD) -DARCH=ARCH_$(ARCH)\r
282 CDEFS += $(LUFA_OPTS)\r
283 \r
284 \r
285 # Place -D or -U options here for ASM sources\r
286 ADEFS  = -DF_CPU=$(F_CPU)\r
287 ADEFS += -DF_USB=$(F_USB)UL\r
288 ADEFS += -DBOARD=BOARD_$(BOARD) -DARCH=ARCH_$(ARCH)\r
289 ADEFS += $(LUFA_OPTS)\r
290 \r
291 # Place -D or -U options here for C++ sources\r
292 CPPDEFS  = -DF_CPU=$(F_CPU)UL\r
293 CPPDEFS += -DF_USB=$(F_USB)UL\r
294 CPPDEFS += -DBOARD=BOARD_$(BOARD) -DARCH=ARCH_$(ARCH)\r
295 CPPDEFS += $(LUFA_OPTS)\r
296 #CPPDEFS += -D__STDC_LIMIT_MACROS\r
297 #CPPDEFS += -D__STDC_CONSTANT_MACROS\r
298 \r
299 \r
300 \r
301 #---------------- Compiler Options C ----------------\r
302 #  -g*:          generate debugging information\r
303 #  -O*:          optimization level\r
304 #  -f...:        tuning, see GCC manual and avr-libc documentation\r
305 #  -Wall...:     warning level\r
306 #  -Wa,...:      tell GCC to pass this to the assembler.\r
307 #    -adhlns...: create assembler listing\r
308 CFLAGS = -g$(DEBUG)\r
309 CFLAGS += $(CDEFS)\r
310 CFLAGS += -O$(OPT)\r
311 CFLAGS += -funsigned-char\r
312 CFLAGS += -funsigned-bitfields\r
313 CFLAGS += -ffunction-sections\r
314 CFLAGS += -fno-inline-small-functions\r
315 CFLAGS += -fpack-struct\r
316 CFLAGS += -fshort-enums\r
317 CFLAGS += -fno-strict-aliasing\r
318 CFLAGS += -Wall -Werror\r
319 CFLAGS += -Wstrict-prototypes\r
320 CFLAGS += -ffreestanding\r
321 #CFLAGS += -mshort-calls\r
322 #CFLAGS += -fno-unit-at-a-time\r
323 #CFLAGS += -Wundef\r
324 #CFLAGS += -Wunreachable-code\r
325 #CFLAGS += -Wsign-compare\r
326 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)\r
327 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))\r
328 CFLAGS += $(CSTANDARD)\r
329 CFLAGS += -std=gnu99\r
330 \r
331 \r
332 #---------------- Compiler Options C++ ----------------\r
333 #  -g*:          generate debugging information\r
334 #  -O*:          optimization level\r
335 #  -f...:        tuning, see GCC manual and avr-libc documentation\r
336 #  -Wall...:     warning level\r
337 #  -Wa,...:      tell GCC to pass this to the assembler.\r
338 #    -adhlns...: create assembler listing\r
339 CPPFLAGS = -g$(DEBUG)\r
340 CPPFLAGS += $(CPPDEFS)\r
341 CPPFLAGS += -O$(OPT)\r
342 CPPFLAGS += -funsigned-char\r
343 CPPFLAGS += -funsigned-bitfields\r
344 CPPFLAGS += -fpack-struct\r
345 CPPFLAGS += -fshort-enums\r
346 CPPFLAGS += -fno-exceptions\r
347 CPPFLAGS += -Wall\r
348 CPPFLAGS += -Wundef\r
349 #CPPFLAGS += -mshort-calls\r
350 #CPPFLAGS += -fno-unit-at-a-time\r
351 #CPPFLAGS += -Wstrict-prototypes\r
352 #CPPFLAGS += -Wunreachable-code\r
353 #CPPFLAGS += -Wsign-compare\r
354 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)\r
355 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))\r
356 #CPPFLAGS += $(CSTANDARD)\r
357 \r
358 \r
359 #---------------- Assembler Options ----------------\r
360 #  -Wa,...:   tell GCC to pass this to the assembler.\r
361 #  -adhlns:   create listing\r
362 #  -gstabs:   have the assembler create line number information; note that\r
363 #             for use in COFF files, additional information about filenames\r
364 #             and function names needs to be present in the assembler source\r
365 #             files -- see avr-libc docs [FIXME: not yet described there]\r
366 #  -listing-cont-lines: Sets the maximum number of continuation lines of hex\r
367 #       dump that will be displayed for a given single line of source input.\r
368 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100\r
369 \r
370 \r
371 #---------------- Library Options ----------------\r
372 # Minimalistic printf version\r
373 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min\r
374 \r
375 # Floating point printf version (requires MATH_LIB = -lm below)\r
376 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt\r
377 \r
378 # If this is left blank, then it will use the Standard printf version.\r
379 PRINTF_LIB =\r
380 #PRINTF_LIB = $(PRINTF_LIB_MIN)\r
381 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)\r
382 \r
383 \r
384 # Minimalistic scanf version\r
385 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min\r
386 \r
387 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)\r
388 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt\r
389 \r
390 # If this is left blank, then it will use the Standard scanf version.\r
391 SCANF_LIB =\r
392 #SCANF_LIB = $(SCANF_LIB_MIN)\r
393 #SCANF_LIB = $(SCANF_LIB_FLOAT)\r
394 \r
395 \r
396 MATH_LIB = -lm\r
397 \r
398 \r
399 # List any extra directories to look for libraries here.\r
400 #     Each directory must be seperated by a space.\r
401 #     Use forward slashes for directory separators.\r
402 #     For a directory that has spaces, enclose it in quotes.\r
403 EXTRALIBDIRS =\r
404 \r
405 \r
406 \r
407 #---------------- External Memory Options ----------------\r
408 \r
409 # 64 KB of external RAM, starting after internal RAM (ATmega128!),\r
410 # used for variables (.data/.bss) and heap (malloc()).\r
411 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff\r
412 \r
413 # 64 KB of external RAM, starting after internal RAM (ATmega128!),\r
414 # only used for heap (malloc()).\r
415 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff\r
416 \r
417 EXTMEMOPTS =\r
418 \r
419 \r
420 \r
421 #---------------- Linker Options ----------------\r
422 #  -Wl,...:     tell GCC to pass this to linker.\r
423 #    -Map:      create map file\r
424 #    --cref:    add cross reference to  map file\r
425 LDFLAGS  = -Wl,-Map=$(TARGET).map,--cref\r
426 LDFLAGS += -Wl,--relax\r
427 LDFLAGS += -Wl,--gc-sections\r
428 LDFLAGS += $(EXTMEMOPTS)\r
429 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))\r
430 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)\r
431 #LDFLAGS += -T linker_script.x\r
432 \r
433 \r
434 \r
435 #---------------- Programming Options (avrdude) ----------------\r
436 \r
437 # Programming hardware\r
438 # Type: avrdude -c ?\r
439 # to get a full listing.\r
440 #\r
441 AVRDUDE_PROGRAMMER = jtagmkII\r
442 \r
443 # com1 = serial port. Use lpt1 to connect to parallel port.\r
444 AVRDUDE_PORT = usb\r
445 \r
446 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex\r
447 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep\r
448 \r
449 \r
450 # Uncomment the following if you want avrdude's erase cycle counter.\r
451 # Note that this counter needs to be initialized first using -Yn,\r
452 # see avrdude manual.\r
453 #AVRDUDE_ERASE_COUNTER = -y\r
454 \r
455 # Uncomment the following if you do /not/ wish a verification to be\r
456 # performed after programming the device.\r
457 #AVRDUDE_NO_VERIFY = -V\r
458 \r
459 # Increase verbosity level.  Please use this when submitting bug\r
460 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>\r
461 # to submit bug reports.\r
462 #AVRDUDE_VERBOSE = -v -v\r
463 \r
464 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)\r
465 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)\r
466 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)\r
467 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)\r
468 \r
469 \r
470 \r
471 #---------------- Debugging Options ----------------\r
472 \r
473 # For simulavr only - target MCU frequency.\r
474 DEBUG_MFREQ = $(F_CPU)\r
475 \r
476 # Set the DEBUG_UI to either gdb or insight.\r
477 # DEBUG_UI = gdb\r
478 DEBUG_UI = insight\r
479 \r
480 # Set the debugging back-end to either avarice, simulavr.\r
481 DEBUG_BACKEND = avarice\r
482 #DEBUG_BACKEND = simulavr\r
483 \r
484 # GDB Init Filename.\r
485 GDBINIT_FILE = __avr_gdbinit\r
486 \r
487 # When using avarice settings for the JTAG\r
488 JTAG_DEV = /dev/com1\r
489 \r
490 # Debugging port used to communicate between GDB / avarice / simulavr.\r
491 DEBUG_PORT = 4242\r
492 \r
493 # Debugging host used to communicate between GDB / avarice / simulavr, normally\r
494 #     just set to localhost unless doing some sort of crazy debugging when\r
495 #     avarice is running on a different computer.\r
496 DEBUG_HOST = localhost\r
497 \r
498 \r
499 \r
500 #============================================================================\r
501 \r
502 \r
503 # Define programs and commands.\r
504 SHELL = sh\r
505 CC = avr-gcc\r
506 OBJCOPY = avr-objcopy\r
507 OBJDUMP = avr-objdump\r
508 SIZE = avr-size\r
509 AR = avr-ar rcs\r
510 NM = avr-nm\r
511 AVRDUDE = avrdude\r
512 REMOVE = rm -f\r
513 REMOVEDIR = rm -rf\r
514 COPY = cp\r
515 WINSHELL = cmd\r
516 \r
517 \r
518 # Define Messages\r
519 # English\r
520 MSG_ERRORS_NONE = Errors: none\r
521 MSG_BEGIN = -------- begin --------\r
522 MSG_END = --------  end  --------\r
523 MSG_SIZE_BEFORE = Size before:\r
524 MSG_SIZE_AFTER = Size after:\r
525 MSG_COFF = Converting to AVR COFF:\r
526 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:\r
527 MSG_FLASH = Creating load file for Flash:\r
528 MSG_EEPROM = Creating load file for EEPROM:\r
529 MSG_EXTENDED_LISTING = Creating Extended Listing:\r
530 MSG_SYMBOL_TABLE = Creating Symbol Table:\r
531 MSG_LINKING = Linking:\r
532 MSG_COMPILING = Compiling C:\r
533 MSG_COMPILING_CPP = Compiling C++:\r
534 MSG_ASSEMBLING = Assembling:\r
535 MSG_CLEANING = Cleaning project:\r
536 MSG_CREATING_LIBRARY = Creating library:\r
537 \r
538 \r
539 \r
540 \r
541 # Define all object files.\r
542 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)\r
543 \r
544 # Define all listing files.\r
545 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)\r
546 \r
547 \r
548 # Compiler flags to generate dependency files.\r
549 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d\r
550 \r
551 \r
552 # Combine all necessary flags and optional flags.\r
553 # Add target processor to flags.\r
554 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)\r
555 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)\r
556 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)\r
557 \r
558 \r
559 \r
560 \r
561 \r
562 # Default target.\r
563 all: begin gccversion sizebefore build sizeafter end\r
564 \r
565 # Change the build target to build a HEX file or a library.\r
566 build: elf hex eep lss sym\r
567 #build: lib\r
568 \r
569 \r
570 elf: $(TARGET).elf\r
571 hex: $(TARGET).hex\r
572 eep: $(TARGET).eep\r
573 lss: $(TARGET).lss\r
574 sym: $(TARGET).sym\r
575 LIBNAME=lib$(TARGET).a\r
576 lib: $(LIBNAME)\r
577 \r
578 \r
579 \r
580 # Eye candy.\r
581 # AVR Studio 3.x does not check make's exit code but relies on\r
582 # the following magic strings to be generated by the compile job.\r
583 begin:\r
584         @echo\r
585         @echo $(MSG_BEGIN)\r
586 \r
587 end:\r
588         @echo $(MSG_END)\r
589         @echo\r
590 \r
591 \r
592 # Display size of file.\r
593 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex\r
594 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf\r
595 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )\r
596 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )\r
597 \r
598 \r
599 sizebefore:\r
600         @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \\r
601         2>/dev/null; echo; fi\r
602 \r
603 sizeafter:\r
604         @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \\r
605         2>/dev/null; echo; fi\r
606 \r
607 \r
608 \r
609 # Display compiler version information.\r
610 gccversion :\r
611         @$(CC) --version\r
612 \r
613 \r
614 # Program the device.\r
615 program: $(TARGET).hex $(TARGET).eep\r
616         $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)\r
617 \r
618 flip: $(TARGET).hex\r
619         batchisp -hardware usb -device $(MCU) -operation erase f\r
620         batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program\r
621         batchisp -hardware usb -device $(MCU) -operation start reset 0\r
622 \r
623 dfu: $(TARGET).hex\r
624         dfu-programmer $(MCU) erase\r
625         dfu-programmer $(MCU) flash $(TARGET).hex\r
626         dfu-programmer $(MCU) reset\r
627 \r
628 flip-ee: $(TARGET).hex $(TARGET).eep\r
629         $(COPY) $(TARGET).eep $(TARGET)eep.hex\r
630         batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase\r
631         batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program\r
632         batchisp -hardware usb -device $(MCU) -operation start reset 0\r
633         $(REMOVE) $(TARGET)eep.hex\r
634 \r
635 dfu-ee: $(TARGET).hex $(TARGET).eep\r
636         dfu-programmer $(MCU) eeprom-flash $(TARGET).eep\r
637         dfu-programmer $(MCU) reset\r
638 \r
639 \r
640 # Generate avr-gdb config/init file which does the following:\r
641 #     define the reset signal, load the target file, connect to target, and set\r
642 #     a breakpoint at main().\r
643 gdb-config:\r
644         @$(REMOVE) $(GDBINIT_FILE)\r
645         @echo define reset >> $(GDBINIT_FILE)\r
646         @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)\r
647         @echo end >> $(GDBINIT_FILE)\r
648         @echo file $(TARGET).elf >> $(GDBINIT_FILE)\r
649         @echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)\r
650 ifeq ($(DEBUG_BACKEND),simulavr)\r
651         @echo load  >> $(GDBINIT_FILE)\r
652 endif\r
653         @echo break main >> $(GDBINIT_FILE)\r
654 \r
655 debug: gdb-config $(TARGET).elf\r
656 ifeq ($(DEBUG_BACKEND), avarice)\r
657         @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.\r
658         @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \\r
659         $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)\r
660         @$(WINSHELL) /c pause\r
661 \r
662 else\r
663         @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \\r
664         $(DEBUG_MFREQ) --port $(DEBUG_PORT)\r
665 endif\r
666         @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)\r
667 \r
668 \r
669 \r
670 \r
671 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.\r
672 COFFCONVERT = $(OBJCOPY) --debugging\r
673 COFFCONVERT += --change-section-address .data-0x800000\r
674 COFFCONVERT += --change-section-address .bss-0x800000\r
675 COFFCONVERT += --change-section-address .noinit-0x800000\r
676 COFFCONVERT += --change-section-address .eeprom-0x810000\r
677 \r
678 \r
679 \r
680 coff: $(TARGET).elf\r
681         @echo\r
682         @echo $(MSG_COFF) $(TARGET).cof\r
683         $(COFFCONVERT) -O coff-avr $< $(TARGET).cof\r
684 \r
685 \r
686 extcoff: $(TARGET).elf\r
687         @echo\r
688         @echo $(MSG_EXTENDED_COFF) $(TARGET).cof\r
689         $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof\r
690 \r
691 \r
692 \r
693 # Create final output files (.hex, .eep) from ELF output file.\r
694 %.hex: %.elf\r
695         @echo\r
696         @echo $(MSG_FLASH) $@\r
697         $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@\r
698 \r
699 %.eep: %.elf\r
700         @echo\r
701         @echo $(MSG_EEPROM) $@\r
702         -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \\r
703         --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0\r
704 \r
705 # Create extended listing file from ELF output file.\r
706 %.lss: %.elf\r
707         @echo\r
708         @echo $(MSG_EXTENDED_LISTING) $@\r
709         $(OBJDUMP) -h -S -z $< > $@\r
710 \r
711 # Create a symbol table from ELF output file.\r
712 %.sym: %.elf\r
713         @echo\r
714         @echo $(MSG_SYMBOL_TABLE) $@\r
715         $(NM) -n $< > $@\r
716 \r
717 \r
718 \r
719 # Create library from object files.\r
720 .SECONDARY : $(TARGET).a\r
721 .PRECIOUS : $(OBJ)\r
722 %.a: $(OBJ)\r
723         @echo\r
724         @echo $(MSG_CREATING_LIBRARY) $@\r
725         $(AR) $@ $(OBJ)\r
726 \r
727 \r
728 # Link: create ELF output file from object files.\r
729 .SECONDARY : $(TARGET).elf\r
730 .PRECIOUS : $(OBJ)\r
731 %.elf: $(OBJ)\r
732         @echo\r
733         @echo $(MSG_LINKING) $@\r
734         $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)\r
735 \r
736 \r
737 # Compile: create object files from C source files.\r
738 $(OBJDIR)/%.o : %.c\r
739         @echo\r
740         @echo $(MSG_COMPILING) $<\r
741         $(CC) -c $(ALL_CFLAGS) $< -o $@\r
742 \r
743 \r
744 # Compile: create object files from C++ source files.\r
745 $(OBJDIR)/%.o : %.cpp\r
746         @echo\r
747         @echo $(MSG_COMPILING_CPP) $<\r
748         $(CC) -c $(ALL_CPPFLAGS) $< -o $@\r
749 \r
750 \r
751 # Compile: create assembler files from C source files.\r
752 %.s : %.c\r
753         $(CC) -S $(ALL_CFLAGS) $< -o $@\r
754 \r
755 \r
756 # Compile: create assembler files from C++ source files.\r
757 %.s : %.cpp\r
758         $(CC) -S $(ALL_CPPFLAGS) $< -o $@\r
759 \r
760 \r
761 # Assemble: create object files from assembler source files.\r
762 $(OBJDIR)/%.o : %.S\r
763         @echo\r
764         @echo $(MSG_ASSEMBLING) $<\r
765         $(CC) -c $(ALL_ASFLAGS) $< -o $@\r
766 \r
767 \r
768 # Create preprocessed source for use in sending a bug report.\r
769 %.i : %.c\r
770         $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@\r
771 \r
772 \r
773 # Target: clean project.\r
774 clean: begin clean_list end\r
775 \r
776 clean_list :\r
777         @echo\r
778         @echo $(MSG_CLEANING)\r
779         $(REMOVE) $(TARGET).hex\r
780         $(REMOVE) $(TARGET).eep\r
781         $(REMOVE) $(TARGET).cof\r
782         $(REMOVE) $(TARGET).elf\r
783         $(REMOVE) $(TARGET).map\r
784         $(REMOVE) $(TARGET).sym\r
785         $(REMOVE) $(TARGET).lss\r
786         $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)\r
787         $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)\r
788         $(REMOVE) $(SRC:.c=.s)\r
789         $(REMOVE) $(SRC:.c=.d)\r
790         $(REMOVE) $(SRC:.c=.i)\r
791         $(REMOVEDIR) .dep\r
792 \r
793 doxygen:\r
794         @echo Generating Project Documentation \($(TARGET)\)...\r
795         @doxygen Doxygen.conf\r
796         @echo Documentation Generation Complete.\r
797 \r
798 clean_doxygen:\r
799         rm -rf Documentation\r
800 \r
801 checksource:\r
802         @for f in $(SRC) $(CPPSRC) $(ASRC); do \\r
803                 if [ -f $$f ]; then \\r
804                         echo "Found Source File: $$f" ; \\r
805                 else \\r
806                         echo "Source File Not Found: $$f" ; \\r
807                 fi; done \r
808 \r
809 \r
810 # Create object files directory\r
811 $(shell mkdir $(OBJDIR) 2>/dev/null)\r
812 \r
813 \r
814 # Include the dependency files.\r
815 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)\r
816 \r
817 \r
818 # Listing of phony targets.\r
819 .PHONY : all begin finish end sizebefore sizeafter gccversion \\r
820 build elf hex eep lss sym coff extcoff doxygen clean          \\r
821 clean_list clean_doxygen program dfu flip flip-ee dfu-ee      \\r
822 debug gdb-config checksource\r
823 \r