1 # Hey Emacs, this is a -*- makefile -*-
2 #----------------------------------------------------------------------------
3 # WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
5 # Released to the Public Domain
7 # Additional material for this makefile was written by:
17 #----------------------------------------------------------------------------
20 # make all = Make software.
22 # make clean = Clean out built project files.
24 # make coff = Convert ELF to AVR COFF.
26 # make extcoff = Convert ELF to AVR Extended COFF.
28 # make program = Download the hex file to the device, using avrdude.
29 # Please customize the avrdude settings below first!
31 # make debug = Start either simulavr or avarice as specified for debugging,
32 # with avr-gdb or avr-insight as the front end for debugging.
34 # make filename.s = Just compile filename.c into the assembler code only.
36 # make filename.i = Create a preprocessed source file for use in submitting
37 # bug reports to the GCC project.
39 # To rebuild project do "make clean" then "make all".
40 #----------------------------------------------------------------------------
47 # Target board (see library BoardTypes.h documentation, USER or blank for projects not requiring
48 # LUFA board drivers). If USER is selected, put custom board drivers in a directory called
49 # "Board" inside the application directory.
53 # Processor frequency.
54 # This will define a symbol, F_CPU, in all source code files equal to the
55 # processor frequency. You can then use this symbol in your source code to
56 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
57 # automatically to create a 32-bit value in your source code.
74 # Output format. (can be srec, ihex, binary)
78 # Target file name (without extension).
82 # Object files directory
83 # To put object files in current directory, use a dot (.), do NOT make
84 # this an empty or blank macro!
88 # List C source files here. (C dependencies are automatically generated.)
93 SideshowApplications.c \
95 ../../LUFA/Scheduler/Scheduler.c \
96 ../../LUFA/Drivers/USB/LowLevel/LowLevel.c \
97 ../../LUFA/Drivers/USB/LowLevel/Endpoint.c \
98 ../../LUFA/Drivers/USB/LowLevel/DevChapter9.c \
99 ../../LUFA/Drivers/USB/HighLevel/USBTask.c \
100 ../../LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
101 ../../LUFA/Drivers/USB/HighLevel/Events.c \
102 ../../LUFA/Drivers/USB/HighLevel/StdDescriptors.c \
103 ../../LUFA/Drivers/AT90USBXXX/Serial_Stream.c \
104 ../../LUFA/Drivers/AT90USBXXX/Serial.c \
107 # List C++ source files here. (C dependencies are automatically generated.)
111 # List Assembler source files here.
112 # Make them always end in a capital .S. Files ending in a lowercase .s
113 # will not be considered source files but generated files (assembler
114 # output from the compiler), and will be deleted upon "make clean"!
115 # Even though the DOS/Win* filesystem matches both .s and .S the same,
116 # it will preserve the spelling of the filenames, and gcc itself does
117 # care about how the name is spelled on its command-line.
121 # Optimization level, can be [0, 1, 2, 3, s].
122 # 0 = turn off optimization. s = optimize for size.
123 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
128 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
129 # AVR Studio 4.10 requires dwarf-2.
130 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
134 # List any extra directories to look for include files here.
135 # Each directory must be seperated by a space.
136 # Use forward slashes for directory separators.
137 # For a directory that has spaces, enclose it in quotes.
138 EXTRAINCDIRS = ../../
141 # Compiler flag to set the C Standard level.
143 # gnu89 = c89 plus GCC extensions
144 # c99 = ISO C99 standard (not yet fully implemented)
145 # gnu99 = c99 plus GCC extensions
146 CSTANDARD = -std=gnu99
149 # Place -D or -U options here for C sources
150 CDEFS = -DF_CPU=$(F_CPU)UL -DBOARD=BOARD_$(BOARD) -DUSE_NONSTANDARD_DESCRIPTOR_NAMES
151 CDEFS += -DUSB_DEVICE_ONLY -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
152 CDEFS += -DNO_STREAM_CALLBACKS
155 # Place -D or -U options here for ASM sources
156 ADEFS = -DF_CPU=$(F_CPU)
159 # Place -D or -U options here for C++ sources
160 CPPDEFS = -DF_CPU=$(F_CPU)UL
161 #CPPDEFS += -D__STDC_LIMIT_MACROS
162 #CPPDEFS += -D__STDC_CONSTANT_MACROS
166 #---------------- Compiler Options C ----------------
167 # -g*: generate debugging information
168 # -O*: optimization level
169 # -f...: tuning, see GCC manual and avr-libc documentation
170 # -Wall...: warning level
171 # -Wa,...: tell GCC to pass this to the assembler.
172 # -adhlns...: create assembler listing
176 CFLAGS += -funsigned-char
177 CFLAGS += -funsigned-bitfields
178 CFLAGS += -ffunction-sections
179 CFLAGS += -fpack-struct
180 CFLAGS += -fshort-enums
181 CFLAGS += -finline-limit=20
183 CFLAGS += -Wstrict-prototypes
185 #CFLAGS += -fno-unit-at-a-time
186 #CFLAGS += -Wunreachable-code
187 #CFLAGS += -Wsign-compare
188 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
189 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
190 CFLAGS += $(CSTANDARD)
193 #---------------- Compiler Options C++ ----------------
194 # -g*: generate debugging information
195 # -O*: optimization level
196 # -f...: tuning, see GCC manual and avr-libc documentation
197 # -Wall...: warning level
198 # -Wa,...: tell GCC to pass this to the assembler.
199 # -adhlns...: create assembler listing
200 CPPFLAGS = -g$(DEBUG)
201 CPPFLAGS += $(CPPDEFS)
203 CPPFLAGS += -funsigned-char
204 CPPFLAGS += -funsigned-bitfields
205 CPPFLAGS += -fpack-struct
206 CPPFLAGS += -fshort-enums
207 CPPFLAGS += -fno-exceptions
210 #CPPFLAGS += -mshort-calls
211 #CPPFLAGS += -fno-unit-at-a-time
212 #CPPFLAGS += -Wstrict-prototypes
213 #CPPFLAGS += -Wunreachable-code
214 #CPPFLAGS += -Wsign-compare
215 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
216 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
217 #CPPFLAGS += $(CSTANDARD)
220 #---------------- Assembler Options ----------------
221 # -Wa,...: tell GCC to pass this to the assembler.
222 # -adhlns: create listing
223 # -gstabs: have the assembler create line number information; note that
224 # for use in COFF files, additional information about filenames
225 # and function names needs to be present in the assembler source
226 # files -- see avr-libc docs [FIXME: not yet described there]
227 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
228 # dump that will be displayed for a given single line of source input.
229 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
232 #---------------- Library Options ----------------
233 # Minimalistic printf version
234 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
236 # Floating point printf version (requires MATH_LIB = -lm below)
237 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
239 # If this is left blank, then it will use the Standard printf version.
241 #PRINTF_LIB = $(PRINTF_LIB_MIN)
242 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
245 # Minimalistic scanf version
246 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
248 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
249 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
251 # If this is left blank, then it will use the Standard scanf version.
253 #SCANF_LIB = $(SCANF_LIB_MIN)
254 #SCANF_LIB = $(SCANF_LIB_FLOAT)
260 # List any extra directories to look for libraries here.
261 # Each directory must be seperated by a space.
262 # Use forward slashes for directory separators.
263 # For a directory that has spaces, enclose it in quotes.
268 #---------------- External Memory Options ----------------
270 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
271 # used for variables (.data/.bss) and heap (malloc()).
272 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
274 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
275 # only used for heap (malloc()).
276 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
282 #---------------- Linker Options ----------------
283 # -Wl,...: tell GCC to pass this to linker.
284 # -Map: create map file
285 # --cref: add cross reference to map file
286 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
287 LDFLAGS += -Wl,--relax
288 LDFLAGS += -Wl,--gc-sections
289 LDFLAGS += $(EXTMEMOPTS)
290 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
291 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
292 #LDFLAGS += -T linker_script.x
296 #---------------- Programming Options (avrdude) ----------------
298 # Programming hardware: alf avr910 avrisp bascom bsd
299 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
302 # to get a full listing.
304 AVRDUDE_PROGRAMMER = jtagmkII
306 # com1 = serial port. Use lpt1 to connect to parallel port.
309 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
310 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
313 # Uncomment the following if you want avrdude's erase cycle counter.
314 # Note that this counter needs to be initialized first using -Yn,
315 # see avrdude manual.
316 #AVRDUDE_ERASE_COUNTER = -y
318 # Uncomment the following if you do /not/ wish a verification to be
319 # performed after programming the device.
320 #AVRDUDE_NO_VERIFY = -V
322 # Increase verbosity level. Please use this when submitting bug
323 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
324 # to submit bug reports.
325 #AVRDUDE_VERBOSE = -v -v
327 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
328 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
329 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
330 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
334 #---------------- Debugging Options ----------------
336 # For simulavr only - target MCU frequency.
337 DEBUG_MFREQ = $(F_CPU)
339 # Set the DEBUG_UI to either gdb or insight.
343 # Set the debugging back-end to either avarice, simulavr.
344 DEBUG_BACKEND = avarice
345 #DEBUG_BACKEND = simulavr
348 GDBINIT_FILE = __avr_gdbinit
350 # When using avarice settings for the JTAG
353 # Debugging port used to communicate between GDB / avarice / simulavr.
356 # Debugging host used to communicate between GDB / avarice / simulavr, normally
357 # just set to localhost unless doing some sort of crazy debugging when
358 # avarice is running on a different computer.
359 DEBUG_HOST = localhost
363 #============================================================================
366 # Define programs and commands.
369 OBJCOPY = avr-objcopy
370 OBJDUMP = avr-objdump
382 MSG_ERRORS_NONE = Errors: none
383 MSG_BEGIN = -------- begin --------
384 MSG_END = -------- end --------
385 MSG_SIZE_BEFORE = Size before:
386 MSG_SIZE_AFTER = Size after:
387 MSG_COFF = Converting to AVR COFF:
388 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
389 MSG_FLASH = Creating load file for Flash:
390 MSG_EEPROM = Creating load file for EEPROM:
391 MSG_EXTENDED_LISTING = Creating Extended Listing:
392 MSG_SYMBOL_TABLE = Creating Symbol Table:
393 MSG_LINKING = Linking:
394 MSG_COMPILING = Compiling C:
395 MSG_COMPILING_CPP = Compiling C++:
396 MSG_ASSEMBLING = Assembling:
397 MSG_CLEANING = Cleaning project:
398 MSG_CREATING_LIBRARY = Creating library:
403 # Define all object files.
404 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
406 # Define all listing files.
407 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
410 # Compiler flags to generate dependency files.
411 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
414 # Combine all necessary flags and optional flags.
415 # Add target processor to flags.
416 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
417 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
418 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
425 all: begin gccversion sizebefore build checkhooks checklibmode sizeafter end
427 # Change the build target to build a HEX file or a library.
428 build: elf hex eep lss sym
437 LIBNAME=lib$(TARGET).a
443 # AVR Studio 3.x does not check make's exit code but relies on
444 # the following magic strings to be generated by the compile job.
454 # Display size of file.
455 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
456 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
457 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
458 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
461 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
462 2>/dev/null; echo; fi
465 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
466 2>/dev/null; echo; fi
470 @echo ------- Unhooked LUFA Events -------
471 @$(shell) (grep -s '^Event.*LUFA/.*\\.o' $(TARGET).map | \
472 cut -d' ' -f1 | cut -d'_' -f2- | grep ".*") || \
474 @echo ----- End Unhooked LUFA Events -----
478 @echo ----------- Library Mode -----------
479 @$(shell) ($(CC) $(ALL_CFLAGS) -E -dM - < /dev/null \
480 | grep 'USB_\(DEVICE\|HOST\)_ONLY' | cut -d' ' -f2 | grep ".*") \
481 || echo "No specific mode (both device and host mode allowable)."
482 @echo ------------------------------------
484 # Display compiler version information.
490 # Program the device.
491 program: $(TARGET).hex $(TARGET).eep
492 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
495 # Generate avr-gdb config/init file which does the following:
496 # define the reset signal, load the target file, connect to target, and set
497 # a breakpoint at main().
499 @$(REMOVE) $(GDBINIT_FILE)
500 @echo define reset >> $(GDBINIT_FILE)
501 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
502 @echo end >> $(GDBINIT_FILE)
503 @echo file $(TARGET).elf >> $(GDBINIT_FILE)
504 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
505 ifeq ($(DEBUG_BACKEND),simulavr)
506 @echo load >> $(GDBINIT_FILE)
508 @echo break main >> $(GDBINIT_FILE)
510 debug: gdb-config $(TARGET).elf
511 ifeq ($(DEBUG_BACKEND), avarice)
512 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
513 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
514 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
515 @$(WINSHELL) /c pause
518 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
519 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
521 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
526 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
527 COFFCONVERT = $(OBJCOPY) --debugging
528 COFFCONVERT += --change-section-address .data-0x800000
529 COFFCONVERT += --change-section-address .bss-0x800000
530 COFFCONVERT += --change-section-address .noinit-0x800000
531 COFFCONVERT += --change-section-address .eeprom-0x810000
537 @echo $(MSG_COFF) $(TARGET).cof
538 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
541 extcoff: $(TARGET).elf
543 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
544 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
548 # Create final output files (.hex, .eep) from ELF output file.
551 @echo $(MSG_FLASH) $@
552 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
556 @echo $(MSG_EEPROM) $@
557 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
558 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
560 # Create extended listing file from ELF output file.
563 @echo $(MSG_EXTENDED_LISTING) $@
564 $(OBJDUMP) -h -z -S $< > $@
566 # Create a symbol table from ELF output file.
569 @echo $(MSG_SYMBOL_TABLE) $@
574 # Create library from object files.
575 .SECONDARY : $(TARGET).a
579 @echo $(MSG_CREATING_LIBRARY) $@
583 # Link: create ELF output file from object files.
584 .SECONDARY : $(TARGET).elf
588 @echo $(MSG_LINKING) $@
589 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
592 # Compile: create object files from C source files.
595 @echo $(MSG_COMPILING) $<
596 $(CC) -c $(ALL_CFLAGS) $< -o $@
599 # Compile: create object files from C++ source files.
600 $(OBJDIR)/%.o : %.cpp
602 @echo $(MSG_COMPILING_CPP) $<
603 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
606 # Compile: create assembler files from C source files.
608 $(CC) -S $(ALL_CFLAGS) $< -o $@
611 # Compile: create assembler files from C++ source files.
613 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
616 # Assemble: create object files from assembler source files.
619 @echo $(MSG_ASSEMBLING) $<
620 $(CC) -c $(ALL_ASFLAGS) $< -o $@
623 # Create preprocessed source for use in sending a bug report.
625 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
628 # Target: clean project.
629 clean: begin clean_list clean_binary end
632 $(REMOVE) $(TARGET).hex
635 @echo $(MSG_CLEANING)
636 $(REMOVE) $(TARGET).eep
637 $(REMOVE) $(TARGET).cof
638 $(REMOVE) $(TARGET).elf
639 $(REMOVE) $(TARGET).map
640 $(REMOVE) $(TARGET).sym
641 $(REMOVE) $(TARGET).lss
642 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
643 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
644 $(REMOVE) $(SRC:.c=.s)
645 $(REMOVE) $(SRC:.c=.d)
646 $(REMOVE) $(SRC:.c=.i)
651 @echo Generating Project Documentation...
652 @doxygen Doxygen.conf
653 @echo Documentation Generation Complete.
655 # Create object files directory
656 $(shell mkdir $(OBJDIR) 2>/dev/null)
659 # Include the dependency files.
660 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
663 # Listing of phony targets.
664 .PHONY : all checkhooks checklibmode begin \
665 finish end sizebefore sizeafter gccversion \
666 build elf hex eep lss sym coff extcoff \
667 clean clean_list clean_binary program debug \