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. <<
6 # Released to the Public Domain
8 # Additional material for this makefile was written by:
21 #----------------------------------------------------------------------------
24 # make all = Make software.
26 # make clean = Clean out built project files.
28 # make coff = Convert ELF to AVR COFF.
30 # make extcoff = Convert ELF to AVR Extended COFF.
32 # make program = Download the hex file to the device, using avrdude.
33 # Please customize the avrdude settings below first!
35 # make dfu = Download the hex file to the device, using dfu-programmer (must
36 # have dfu-programmer installed).
38 # make flip = Download the hex file to the device, using Atmel FLIP (must
39 # have Atmel FLIP installed).
41 # make dfu-ee = Download the eeprom file to the device, using dfu-programmer
42 # (must have dfu-programmer installed).
44 # make flip-ee = Download the eeprom file to the device, using Atmel FLIP
45 # (must have Atmel FLIP installed).
47 # make doxygen = Generate DoxyGen documentation for the project (must have
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.
53 # make filename.s = Just compile filename.c into the assembler code only.
55 # make filename.i = Create a preprocessed source file for use in submitting
56 # bug reports to the GCC project.
58 # To rebuild project do "make clean" then "make all".
59 #----------------------------------------------------------------------------
66 # Target board (see library BoardTypes.h documentation, USER or blank for projects not requiring
67 # LUFA board drivers). If USER is selected, put custom board drivers in a directory called
68 # "Board" inside the application directory.
72 # Processor frequency.
73 # This will define a symbol, F_CPU, in all source code files equal to the
74 # processor frequency. You can then use this symbol in your source code to
75 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
76 # automatically to create a 32-bit value in your source code.
93 # Output format. (can be srec, ihex, binary)
97 # Target file name (without extension).
101 # Object files directory
102 # To put object files in current directory, use a dot (.), do NOT make
103 # this an empty or blank macro!
107 # List C source files here. (C dependencies are automatically generated.)
110 ../../LUFA/Scheduler/Scheduler.c \
111 ../../LUFA/Drivers/USB/LowLevel/LowLevel.c \
112 ../../LUFA/Drivers/USB/LowLevel/Endpoint.c \
113 ../../LUFA/Drivers/USB/LowLevel/DevChapter9.c \
114 ../../LUFA/Drivers/USB/HighLevel/USBTask.c \
115 ../../LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
116 ../../LUFA/Drivers/USB/HighLevel/Events.c \
117 ../../LUFA/Drivers/USB/HighLevel/StdDescriptors.c \
119 # List C++ source files here. (C dependencies are automatically generated.)
123 # List Assembler source files here.
124 # Make them always end in a capital .S. Files ending in a lowercase .s
125 # will not be considered source files but generated files (assembler
126 # output from the compiler), and will be deleted upon "make clean"!
127 # Even though the DOS/Win* filesystem matches both .s and .S the same,
128 # it will preserve the spelling of the filenames, and gcc itself does
129 # care about how the name is spelled on its command-line.
133 # Optimization level, can be [0, 1, 2, 3, s].
134 # 0 = turn off optimization. s = optimize for size.
135 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
140 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
141 # AVR Studio 4.10 requires dwarf-2.
142 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
146 # List any extra directories to look for include files here.
147 # Each directory must be seperated by a space.
148 # Use forward slashes for directory separators.
149 # For a directory that has spaces, enclose it in quotes.
150 EXTRAINCDIRS = ../../
153 # Compiler flag to set the C Standard level.
155 # gnu89 = c89 plus GCC extensions
156 # c99 = ISO C99 standard (not yet fully implemented)
157 # gnu99 = c99 plus GCC extensions
158 CSTANDARD = -std=gnu99
161 # Place -D or -U options here for C sources
162 CDEFS = -DF_CPU=$(F_CPU)UL -DBOARD=BOARD_$(BOARD) -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DNO_STREAM_CALLBACKS
163 CDEFS += -DUSB_DEVICE_ONLY -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
166 # Place -D or -U options here for ASM sources
167 ADEFS = -DF_CPU=$(F_CPU)
170 # Place -D or -U options here for C++ sources
171 CPPDEFS = -DF_CPU=$(F_CPU)UL
172 #CPPDEFS += -D__STDC_LIMIT_MACROS
173 #CPPDEFS += -D__STDC_CONSTANT_MACROS
177 #---------------- Compiler Options C ----------------
178 # -g*: generate debugging information
179 # -O*: optimization level
180 # -f...: tuning, see GCC manual and avr-libc documentation
181 # -Wall...: warning level
182 # -Wa,...: tell GCC to pass this to the assembler.
183 # -adhlns...: create assembler listing
187 CFLAGS += -funsigned-char
188 CFLAGS += -funsigned-bitfields
189 CFLAGS += -ffunction-sections
190 CFLAGS += -fpack-struct
191 CFLAGS += -fshort-enums
192 CFLAGS += -finline-limit=20
194 CFLAGS += -Wstrict-prototypes
196 #CFLAGS += -fno-unit-at-a-time
197 #CFLAGS += -Wunreachable-code
198 #CFLAGS += -Wsign-compare
199 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
200 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
201 CFLAGS += $(CSTANDARD)
204 #---------------- Compiler Options C++ ----------------
205 # -g*: generate debugging information
206 # -O*: optimization level
207 # -f...: tuning, see GCC manual and avr-libc documentation
208 # -Wall...: warning level
209 # -Wa,...: tell GCC to pass this to the assembler.
210 # -adhlns...: create assembler listing
211 CPPFLAGS = -g$(DEBUG)
212 CPPFLAGS += $(CPPDEFS)
214 CPPFLAGS += -funsigned-char
215 CPPFLAGS += -funsigned-bitfields
216 CPPFLAGS += -fpack-struct
217 CPPFLAGS += -fshort-enums
218 CPPFLAGS += -fno-exceptions
221 #CPPFLAGS += -mshort-calls
222 #CPPFLAGS += -fno-unit-at-a-time
223 #CPPFLAGS += -Wstrict-prototypes
224 #CPPFLAGS += -Wunreachable-code
225 #CPPFLAGS += -Wsign-compare
226 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
227 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
228 #CPPFLAGS += $(CSTANDARD)
231 #---------------- Assembler Options ----------------
232 # -Wa,...: tell GCC to pass this to the assembler.
233 # -adhlns: create listing
234 # -gstabs: have the assembler create line number information; note that
235 # for use in COFF files, additional information about filenames
236 # and function names needs to be present in the assembler source
237 # files -- see avr-libc docs [FIXME: not yet described there]
238 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
239 # dump that will be displayed for a given single line of source input.
240 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
243 #---------------- Library Options ----------------
244 # Minimalistic printf version
245 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
247 # Floating point printf version (requires MATH_LIB = -lm below)
248 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
250 # If this is left blank, then it will use the Standard printf version.
252 #PRINTF_LIB = $(PRINTF_LIB_MIN)
253 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
256 # Minimalistic scanf version
257 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
259 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
260 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
262 # If this is left blank, then it will use the Standard scanf version.
264 #SCANF_LIB = $(SCANF_LIB_MIN)
265 #SCANF_LIB = $(SCANF_LIB_FLOAT)
271 # List any extra directories to look for libraries here.
272 # Each directory must be seperated by a space.
273 # Use forward slashes for directory separators.
274 # For a directory that has spaces, enclose it in quotes.
279 #---------------- External Memory Options ----------------
281 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
282 # used for variables (.data/.bss) and heap (malloc()).
283 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
285 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
286 # only used for heap (malloc()).
287 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
293 #---------------- Linker Options ----------------
294 # -Wl,...: tell GCC to pass this to linker.
295 # -Map: create map file
296 # --cref: add cross reference to map file
297 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
298 LDFLAGS += -Wl,--relax
299 LDFLAGS += -Wl,--gc-sections
300 LDFLAGS += $(EXTMEMOPTS)
301 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
302 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
303 #LDFLAGS += -T linker_script.x
307 #---------------- Programming Options (avrdude) ----------------
309 # Programming hardware: alf avr910 avrisp bascom bsd
310 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
313 # to get a full listing.
315 AVRDUDE_PROGRAMMER = jtagmkII
317 # com1 = serial port. Use lpt1 to connect to parallel port.
320 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
321 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
324 # Uncomment the following if you want avrdude's erase cycle counter.
325 # Note that this counter needs to be initialized first using -Yn,
326 # see avrdude manual.
327 #AVRDUDE_ERASE_COUNTER = -y
329 # Uncomment the following if you do /not/ wish a verification to be
330 # performed after programming the device.
331 #AVRDUDE_NO_VERIFY = -V
333 # Increase verbosity level. Please use this when submitting bug
334 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
335 # to submit bug reports.
336 #AVRDUDE_VERBOSE = -v -v
338 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
339 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
340 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
341 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
345 #---------------- Debugging Options ----------------
347 # For simulavr only - target MCU frequency.
348 DEBUG_MFREQ = $(F_CPU)
350 # Set the DEBUG_UI to either gdb or insight.
354 # Set the debugging back-end to either avarice, simulavr.
355 DEBUG_BACKEND = avarice
356 #DEBUG_BACKEND = simulavr
359 GDBINIT_FILE = __avr_gdbinit
361 # When using avarice settings for the JTAG
364 # Debugging port used to communicate between GDB / avarice / simulavr.
367 # Debugging host used to communicate between GDB / avarice / simulavr, normally
368 # just set to localhost unless doing some sort of crazy debugging when
369 # avarice is running on a different computer.
370 DEBUG_HOST = localhost
374 #============================================================================
377 # Define programs and commands.
380 OBJCOPY = avr-objcopy
381 OBJDUMP = avr-objdump
393 MSG_ERRORS_NONE = Errors: none
394 MSG_BEGIN = -------- begin --------
395 MSG_END = -------- end --------
396 MSG_SIZE_BEFORE = Size before:
397 MSG_SIZE_AFTER = Size after:
398 MSG_COFF = Converting to AVR COFF:
399 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
400 MSG_FLASH = Creating load file for Flash:
401 MSG_EEPROM = Creating load file for EEPROM:
402 MSG_EXTENDED_LISTING = Creating Extended Listing:
403 MSG_SYMBOL_TABLE = Creating Symbol Table:
404 MSG_LINKING = Linking:
405 MSG_COMPILING = Compiling C:
406 MSG_COMPILING_CPP = Compiling C++:
407 MSG_ASSEMBLING = Assembling:
408 MSG_CLEANING = Cleaning project:
409 MSG_CREATING_LIBRARY = Creating library:
414 # Define all object files.
415 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
417 # Define all listing files.
418 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
421 # Compiler flags to generate dependency files.
422 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
425 # Combine all necessary flags and optional flags.
426 # Add target processor to flags.
427 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
428 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
429 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
436 all: begin gccversion sizebefore build checkhooks checklibmode sizeafter end
438 # Change the build target to build a HEX file or a library.
439 build: elf hex eep lss sym
448 LIBNAME=lib$(TARGET).a
454 # AVR Studio 3.x does not check make's exit code but relies on
455 # the following magic strings to be generated by the compile job.
465 # Display size of file.
466 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
467 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
468 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
469 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
472 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
473 2>/dev/null; echo; fi
476 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
477 2>/dev/null; echo; fi
481 @echo ------- Unhooked LUFA Events -------
482 @$(shell) (grep -s '^Event.*LUFA/.*\\.o' $(TARGET).map | \
483 cut -d' ' -f1 | cut -d'_' -f2- | grep ".*") || \
485 @echo ----- End Unhooked LUFA Events -----
489 @echo ----------- Library Mode -----------
490 @$(shell) ($(CC) $(ALL_CFLAGS) -E -dM - < /dev/null \
491 | grep 'USB_\(DEVICE\|HOST\)_ONLY' | cut -d' ' -f2 | grep ".*") \
492 || echo "No specific mode (both device and host mode allowable)."
493 @echo ------------------------------------
495 # Display compiler version information.
501 # Program the device.
502 program: $(TARGET).hex $(TARGET).eep
503 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
506 batchisp -hardware usb -device $(MCU) -operation erase f
507 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
508 batchisp -hardware usb -device $(MCU) -operation start reset 0
511 dfu-programmer $(MCU) erase
512 dfu-programmer $(MCU) flash --debug 1 $(TARGET).hex
513 dfu-programmer $(MCU) reset
515 flip-ee: $(TARGET).hex $(TARGET).eep
516 copy $(TARGET).eep $(TARGET)eep.hex
517 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
518 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program
519 batchisp -hardware usb -device $(MCU) -operation start reset 0
521 dfu-ee: $(TARGET).hex $(TARGET).eep
522 dfu-programmer $(MCU) erase
523 dfu-programmer $(MCU) eeprom --debug 1 $(TARGET).eep
524 dfu-programmer $(MCU) reset
526 # Generate avr-gdb config/init file which does the following:
527 # define the reset signal, load the target file, connect to target, and set
528 # a breakpoint at main().
530 @$(REMOVE) $(GDBINIT_FILE)
531 @echo define reset >> $(GDBINIT_FILE)
532 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
533 @echo end >> $(GDBINIT_FILE)
534 @echo file $(TARGET).elf >> $(GDBINIT_FILE)
535 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
536 ifeq ($(DEBUG_BACKEND),simulavr)
537 @echo load >> $(GDBINIT_FILE)
539 @echo break main >> $(GDBINIT_FILE)
541 debug: gdb-config $(TARGET).elf
542 ifeq ($(DEBUG_BACKEND), avarice)
543 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
544 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
545 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
546 @$(WINSHELL) /c pause
549 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
550 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
552 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
557 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
558 COFFCONVERT = $(OBJCOPY) --debugging
559 COFFCONVERT += --change-section-address .data-0x800000
560 COFFCONVERT += --change-section-address .bss-0x800000
561 COFFCONVERT += --change-section-address .noinit-0x800000
562 COFFCONVERT += --change-section-address .eeprom-0x810000
568 @echo $(MSG_COFF) $(TARGET).cof
569 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
572 extcoff: $(TARGET).elf
574 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
575 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
579 # Create final output files (.hex, .eep) from ELF output file.
582 @echo $(MSG_FLASH) $@
583 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
587 @echo $(MSG_EEPROM) $@
588 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
589 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
591 # Create extended listing file from ELF output file.
594 @echo $(MSG_EXTENDED_LISTING) $@
595 $(OBJDUMP) -h -z -S $< > $@
597 # Create a symbol table from ELF output file.
600 @echo $(MSG_SYMBOL_TABLE) $@
605 # Create library from object files.
606 .SECONDARY : $(TARGET).a
610 @echo $(MSG_CREATING_LIBRARY) $@
614 # Link: create ELF output file from object files.
615 .SECONDARY : $(TARGET).elf
619 @echo $(MSG_LINKING) $@
620 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
623 # Compile: create object files from C source files.
626 @echo $(MSG_COMPILING) $<
627 $(CC) -c $(ALL_CFLAGS) $< -o $@
630 # Compile: create object files from C++ source files.
631 $(OBJDIR)/%.o : %.cpp
633 @echo $(MSG_COMPILING_CPP) $<
634 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
637 # Compile: create assembler files from C source files.
639 $(CC) -S $(ALL_CFLAGS) $< -o $@
642 # Compile: create assembler files from C++ source files.
644 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
647 # Assemble: create object files from assembler source files.
650 @echo $(MSG_ASSEMBLING) $<
651 $(CC) -c $(ALL_ASFLAGS) $< -o $@
654 # Create preprocessed source for use in sending a bug report.
656 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
659 # Target: clean project.
660 clean: begin clean_list clean_binary end
663 $(REMOVE) $(TARGET).hex
666 @echo $(MSG_CLEANING)
667 $(REMOVE) $(TARGET).eep
668 $(REMOVE) $(TARGET).cof
669 $(REMOVE) $(TARGET).elf
670 $(REMOVE) $(TARGET).map
671 $(REMOVE) $(TARGET).sym
672 $(REMOVE) $(TARGET).lss
673 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
674 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
675 $(REMOVE) $(SRC:.c=.s)
676 $(REMOVE) $(SRC:.c=.d)
677 $(REMOVE) $(SRC:.c=.i)
682 @echo Generating Project Documentation...
683 @doxygen Doxygen.conf
684 @echo Documentation Generation Complete.
689 # Create object files directory
690 $(shell mkdir $(OBJDIR) 2>/dev/null)
693 # Include the dependency files.
694 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
697 # Listing of phony targets.
698 .PHONY : all checkhooks checklibmode begin \
699 finish end sizebefore sizeafter gccversion \
700 build elf hex eep lss sym coff extcoff \
701 clean clean_list clean_binary program debug \
702 gdb-config doxygen dfu flip