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