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).
98 TARGET = KeyboardFullInt
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/Drivers/USB/LowLevel/LowLevel.c \
111 ../../LUFA/Drivers/USB/LowLevel/Endpoint.c \
112 ../../LUFA/Drivers/USB/LowLevel/DevChapter9.c \
113 ../../LUFA/Drivers/USB/HighLevel/USBTask.c \
114 ../../LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
115 ../../LUFA/Drivers/USB/HighLevel/Events.c \
116 ../../LUFA/Drivers/USB/HighLevel/StdDescriptors.c \
118 # List C++ source files here. (C dependencies are automatically generated.)
122 # List Assembler source files here.
123 # Make them always end in a capital .S. Files ending in a lowercase .s
124 # will not be considered source files but generated files (assembler
125 # output from the compiler), and will be deleted upon "make clean"!
126 # Even though the DOS/Win* filesystem matches both .s and .S the same,
127 # it will preserve the spelling of the filenames, and gcc itself does
128 # care about how the name is spelled on its command-line.
132 # Optimization level, can be [0, 1, 2, 3, s].
133 # 0 = turn off optimization. s = optimize for size.
134 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
139 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
140 # AVR Studio 4.10 requires dwarf-2.
141 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
145 # List any extra directories to look for include files here.
146 # Each directory must be seperated by a space.
147 # Use forward slashes for directory separators.
148 # For a directory that has spaces, enclose it in quotes.
149 EXTRAINCDIRS = ../../
152 # Compiler flag to set the C Standard level.
154 # gnu89 = c89 plus GCC extensions
155 # c99 = ISO C99 standard (not yet fully implemented)
156 # gnu99 = c99 plus GCC extensions
157 CSTANDARD = -std=gnu99
160 # Place -D or -U options here for C sources
161 CDEFS = -DF_CPU=$(F_CPU)UL -DBOARD=BOARD_$(BOARD) -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DNO_STREAM_CALLBACKS
162 CDEFS += -DUSB_DEVICE_ONLY -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED)"
165 # Place -D or -U options here for ASM sources
166 ADEFS = -DF_CPU=$(F_CPU)
169 # Place -D or -U options here for C++ sources
170 CPPDEFS = -DF_CPU=$(F_CPU)UL
171 #CPPDEFS += -D__STDC_LIMIT_MACROS
172 #CPPDEFS += -D__STDC_CONSTANT_MACROS
176 #---------------- Compiler Options C ----------------
177 # -g*: generate debugging information
178 # -O*: optimization level
179 # -f...: tuning, see GCC manual and avr-libc documentation
180 # -Wall...: warning level
181 # -Wa,...: tell GCC to pass this to the assembler.
182 # -adhlns...: create assembler listing
186 CFLAGS += -funsigned-char
187 CFLAGS += -funsigned-bitfields
188 CFLAGS += -ffunction-sections
189 CFLAGS += -fpack-struct
190 CFLAGS += -fshort-enums
191 CFLAGS += -finline-limit=20
193 CFLAGS += -Wstrict-prototypes
195 #CFLAGS += -fno-unit-at-a-time
196 #CFLAGS += -Wunreachable-code
197 #CFLAGS += -Wsign-compare
198 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
199 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
200 CFLAGS += $(CSTANDARD)
203 #---------------- Compiler Options C++ ----------------
204 # -g*: generate debugging information
205 # -O*: optimization level
206 # -f...: tuning, see GCC manual and avr-libc documentation
207 # -Wall...: warning level
208 # -Wa,...: tell GCC to pass this to the assembler.
209 # -adhlns...: create assembler listing
210 CPPFLAGS = -g$(DEBUG)
211 CPPFLAGS += $(CPPDEFS)
213 CPPFLAGS += -funsigned-char
214 CPPFLAGS += -funsigned-bitfields
215 CPPFLAGS += -fpack-struct
216 CPPFLAGS += -fshort-enums
217 CPPFLAGS += -fno-exceptions
220 #CPPFLAGS += -mshort-calls
221 #CPPFLAGS += -fno-unit-at-a-time
222 #CPPFLAGS += -Wstrict-prototypes
223 #CPPFLAGS += -Wunreachable-code
224 #CPPFLAGS += -Wsign-compare
225 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
226 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
227 #CPPFLAGS += $(CSTANDARD)
230 #---------------- Assembler Options ----------------
231 # -Wa,...: tell GCC to pass this to the assembler.
232 # -adhlns: create listing
233 # -gstabs: have the assembler create line number information; note that
234 # for use in COFF files, additional information about filenames
235 # and function names needs to be present in the assembler source
236 # files -- see avr-libc docs [FIXME: not yet described there]
237 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
238 # dump that will be displayed for a given single line of source input.
239 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
242 #---------------- Library Options ----------------
243 # Minimalistic printf version
244 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
246 # Floating point printf version (requires MATH_LIB = -lm below)
247 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
249 # If this is left blank, then it will use the Standard printf version.
251 #PRINTF_LIB = $(PRINTF_LIB_MIN)
252 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
255 # Minimalistic scanf version
256 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
258 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
259 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
261 # If this is left blank, then it will use the Standard scanf version.
263 #SCANF_LIB = $(SCANF_LIB_MIN)
264 #SCANF_LIB = $(SCANF_LIB_FLOAT)
270 # List any extra directories to look for libraries here.
271 # Each directory must be seperated by a space.
272 # Use forward slashes for directory separators.
273 # For a directory that has spaces, enclose it in quotes.
278 #---------------- External Memory Options ----------------
280 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
281 # used for variables (.data/.bss) and heap (malloc()).
282 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
284 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
285 # only used for heap (malloc()).
286 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
292 #---------------- Linker Options ----------------
293 # -Wl,...: tell GCC to pass this to linker.
294 # -Map: create map file
295 # --cref: add cross reference to map file
296 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
297 LDFLAGS += -Wl,--relax
298 LDFLAGS += -Wl,--gc-sections
299 LDFLAGS += $(EXTMEMOPTS)
300 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
301 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
302 #LDFLAGS += -T linker_script.x
306 #---------------- Programming Options (avrdude) ----------------
308 # Programming hardware: alf avr910 avrisp bascom bsd
309 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
312 # to get a full listing.
314 AVRDUDE_PROGRAMMER = jtagmkII
316 # com1 = serial port. Use lpt1 to connect to parallel port.
319 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
320 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
323 # Uncomment the following if you want avrdude's erase cycle counter.
324 # Note that this counter needs to be initialized first using -Yn,
325 # see avrdude manual.
326 #AVRDUDE_ERASE_COUNTER = -y
328 # Uncomment the following if you do /not/ wish a verification to be
329 # performed after programming the device.
330 #AVRDUDE_NO_VERIFY = -V
332 # Increase verbosity level. Please use this when submitting bug
333 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
334 # to submit bug reports.
335 #AVRDUDE_VERBOSE = -v -v
337 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
338 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
339 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
340 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
344 #---------------- Debugging Options ----------------
346 # For simulavr only - target MCU frequency.
347 DEBUG_MFREQ = $(F_CPU)
349 # Set the DEBUG_UI to either gdb or insight.
353 # Set the debugging back-end to either avarice, simulavr.
354 DEBUG_BACKEND = avarice
355 #DEBUG_BACKEND = simulavr
358 GDBINIT_FILE = __avr_gdbinit
360 # When using avarice settings for the JTAG
363 # Debugging port used to communicate between GDB / avarice / simulavr.
366 # Debugging host used to communicate between GDB / avarice / simulavr, normally
367 # just set to localhost unless doing some sort of crazy debugging when
368 # avarice is running on a different computer.
369 DEBUG_HOST = localhost
373 #============================================================================
376 # Define programs and commands.
379 OBJCOPY = avr-objcopy
380 OBJDUMP = avr-objdump
392 MSG_ERRORS_NONE = Errors: none
393 MSG_BEGIN = -------- begin --------
394 MSG_END = -------- end --------
395 MSG_SIZE_BEFORE = Size before:
396 MSG_SIZE_AFTER = Size after:
397 MSG_COFF = Converting to AVR COFF:
398 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
399 MSG_FLASH = Creating load file for Flash:
400 MSG_EEPROM = Creating load file for EEPROM:
401 MSG_EXTENDED_LISTING = Creating Extended Listing:
402 MSG_SYMBOL_TABLE = Creating Symbol Table:
403 MSG_LINKING = Linking:
404 MSG_COMPILING = Compiling C:
405 MSG_COMPILING_CPP = Compiling C++:
406 MSG_ASSEMBLING = Assembling:
407 MSG_CLEANING = Cleaning project:
408 MSG_CREATING_LIBRARY = Creating library:
413 # Define all object files.
414 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
416 # Define all listing files.
417 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
420 # Compiler flags to generate dependency files.
421 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
424 # Combine all necessary flags and optional flags.
425 # Add target processor to flags.
426 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
427 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
428 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
435 all: begin gccversion sizebefore build checkhooks checklibmode sizeafter end
437 # Change the build target to build a HEX file or a library.
438 build: elf hex eep lss sym
447 LIBNAME=lib$(TARGET).a
453 # AVR Studio 3.x does not check make's exit code but relies on
454 # the following magic strings to be generated by the compile job.
464 # Display size of file.
465 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
466 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
467 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
468 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
471 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
472 2>/dev/null; echo; fi
475 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
476 2>/dev/null; echo; fi
480 @echo ------- Unhooked LUFA Events -------
481 @$(shell) (grep -s '^Event.*LUFA/.*\\.o' $(TARGET).map | \
482 cut -d' ' -f1 | cut -d'_' -f2- | grep ".*") || \
484 @echo ----- End Unhooked LUFA Events -----
488 @echo ----------- Library Mode -----------
489 @$(shell) ($(CC) $(ALL_CFLAGS) -E -dM - < /dev/null \
490 | grep 'USB_\(DEVICE\|HOST\)_ONLY' | cut -d' ' -f2 | grep ".*") \
491 || echo "No specific mode (both device and host mode allowable)."
492 @echo ------------------------------------
494 # Display compiler version information.
500 # Program the device.
501 program: $(TARGET).hex $(TARGET).eep
502 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
505 batchisp -hardware usb -device $(MCU) -operation erase f
506 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
507 batchisp -hardware usb -device $(MCU) -operation start reset 0
510 dfu-programmer $(MCU) erase
511 dfu-programmer $(MCU) flash --debug 1 $(TARGET).hex
512 dfu-programmer $(MCU) reset
514 flip-ee: $(TARGET).hex $(TARGET).eep
515 copy $(TARGET).eep $(TARGET)eep.hex
516 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
517 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program
518 batchisp -hardware usb -device $(MCU) -operation start reset 0
520 dfu-ee: $(TARGET).hex $(TARGET).eep
521 dfu-programmer $(MCU) erase
522 dfu-programmer $(MCU) eeprom --debug 1 $(TARGET).eep
523 dfu-programmer $(MCU) reset
525 # Generate avr-gdb config/init file which does the following:
526 # define the reset signal, load the target file, connect to target, and set
527 # a breakpoint at main().
529 @$(REMOVE) $(GDBINIT_FILE)
530 @echo define reset >> $(GDBINIT_FILE)
531 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
532 @echo end >> $(GDBINIT_FILE)
533 @echo file $(TARGET).elf >> $(GDBINIT_FILE)
534 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
535 ifeq ($(DEBUG_BACKEND),simulavr)
536 @echo load >> $(GDBINIT_FILE)
538 @echo break main >> $(GDBINIT_FILE)
540 debug: gdb-config $(TARGET).elf
541 ifeq ($(DEBUG_BACKEND), avarice)
542 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
543 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
544 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
545 @$(WINSHELL) /c pause
548 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
549 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
551 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
556 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
557 COFFCONVERT = $(OBJCOPY) --debugging
558 COFFCONVERT += --change-section-address .data-0x800000
559 COFFCONVERT += --change-section-address .bss-0x800000
560 COFFCONVERT += --change-section-address .noinit-0x800000
561 COFFCONVERT += --change-section-address .eeprom-0x810000
567 @echo $(MSG_COFF) $(TARGET).cof
568 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
571 extcoff: $(TARGET).elf
573 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
574 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
578 # Create final output files (.hex, .eep) from ELF output file.
581 @echo $(MSG_FLASH) $@
582 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
586 @echo $(MSG_EEPROM) $@
587 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
588 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
590 # Create extended listing file from ELF output file.
593 @echo $(MSG_EXTENDED_LISTING) $@
594 $(OBJDUMP) -h -z -S $< > $@
596 # Create a symbol table from ELF output file.
599 @echo $(MSG_SYMBOL_TABLE) $@
604 # Create library from object files.
605 .SECONDARY : $(TARGET).a
609 @echo $(MSG_CREATING_LIBRARY) $@
613 # Link: create ELF output file from object files.
614 .SECONDARY : $(TARGET).elf
618 @echo $(MSG_LINKING) $@
619 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
622 # Compile: create object files from C source files.
625 @echo $(MSG_COMPILING) $<
626 $(CC) -c $(ALL_CFLAGS) $< -o $@
629 # Compile: create object files from C++ source files.
630 $(OBJDIR)/%.o : %.cpp
632 @echo $(MSG_COMPILING_CPP) $<
633 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
636 # Compile: create assembler files from C source files.
638 $(CC) -S $(ALL_CFLAGS) $< -o $@
641 # Compile: create assembler files from C++ source files.
643 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
646 # Assemble: create object files from assembler source files.
649 @echo $(MSG_ASSEMBLING) $<
650 $(CC) -c $(ALL_ASFLAGS) $< -o $@
653 # Create preprocessed source for use in sending a bug report.
655 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
658 # Target: clean project.
659 clean: begin clean_list clean_binary end
662 $(REMOVE) $(TARGET).hex
665 @echo $(MSG_CLEANING)
666 $(REMOVE) $(TARGET).eep
667 $(REMOVE) $(TARGET).cof
668 $(REMOVE) $(TARGET).elf
669 $(REMOVE) $(TARGET).map
670 $(REMOVE) $(TARGET).sym
671 $(REMOVE) $(TARGET).lss
672 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
673 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
674 $(REMOVE) $(SRC:.c=.s)
675 $(REMOVE) $(SRC:.c=.d)
676 $(REMOVE) $(SRC:.c=.i)
681 @echo Generating Project Documentation...
682 @doxygen Doxygen.conf
683 @echo Documentation Generation Complete.
688 # Create object files directory
689 $(shell mkdir $(OBJDIR) 2>/dev/null)
692 # Include the dependency files.
693 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
696 # Listing of phony targets.
697 .PHONY : all checkhooks checklibmode begin \
698 finish end sizebefore sizeafter gccversion \
699 build elf hex eep lss sym coff extcoff \
700 clean clean_list clean_binary program debug \
701 gdb-config doxygen dfu flip