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