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 = BluetoothHost
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.)
112 BluetoothHCICommands.c \
113 BluetoothACLPackets.c \
114 ../../LUFA/Scheduler/Scheduler.c \
115 ../../LUFA/Drivers/AT90USBXXX/Serial_Stream.c \
116 ../../LUFA/Drivers/AT90USBXXX/Serial.c \
117 ../../LUFA/Drivers/USB/Class/ConfigDescriptor.c \
118 ../../LUFA/Drivers/USB/LowLevel/LowLevel.c \
119 ../../LUFA/Drivers/USB/LowLevel/Pipe.c \
120 ../../LUFA/Drivers/USB/LowLevel/Host.c \
121 ../../LUFA/Drivers/USB/LowLevel/HostChapter9.c \
122 ../../LUFA/Drivers/USB/HighLevel/USBTask.c \
123 ../../LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
124 ../../LUFA/Drivers/USB/HighLevel/Events.c \
126 # List C++ source files here. (C dependencies are automatically generated.)
130 # List Assembler source files here.
131 # Make them always end in a capital .S. Files ending in a lowercase .s
132 # will not be considered source files but generated files (assembler
133 # output from the compiler), and will be deleted upon "make clean"!
134 # Even though the DOS/Win* filesystem matches both .s and .S the same,
135 # it will preserve the spelling of the filenames, and gcc itself does
136 # care about how the name is spelled on its command-line.
140 # Optimization level, can be [0, 1, 2, 3, s].
141 # 0 = turn off optimization. s = optimize for size.
142 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
147 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
148 # AVR Studio 4.10 requires dwarf-2.
149 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
153 # List any extra directories to look for include files here.
154 # Each directory must be seperated by a space.
155 # Use forward slashes for directory separators.
156 # For a directory that has spaces, enclose it in quotes.
157 EXTRAINCDIRS = ../../
160 # Compiler flag to set the C Standard level.
162 # gnu89 = c89 plus GCC extensions
163 # c99 = ISO C99 standard (not yet fully implemented)
164 # gnu99 = c99 plus GCC extensions
165 CSTANDARD = -std=gnu99
168 # Place -D or -U options here for C sources
169 CDEFS = -DF_CPU=$(F_CPU)UL -DBOARD=BOARD_$(BOARD) -DUSE_NONSTANDARD_DESCRIPTOR_NAMES
170 CDEFS += -DUSB_HOST_ONLY -DUSE_STATIC_OPTIONS="(USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
171 CDEFS += -DNO_STREAM_CALLBACKS
173 # Place -D or -U options here for ASM sources
174 ADEFS = -DF_CPU=$(F_CPU)
177 # Place -D or -U options here for C++ sources
178 CPPDEFS = -DF_CPU=$(F_CPU)UL
179 #CPPDEFS += -D__STDC_LIMIT_MACROS
180 #CPPDEFS += -D__STDC_CONSTANT_MACROS
184 #---------------- Compiler Options C ----------------
185 # -g*: generate debugging information
186 # -O*: optimization level
187 # -f...: tuning, see GCC manual and avr-libc documentation
188 # -Wall...: warning level
189 # -Wa,...: tell GCC to pass this to the assembler.
190 # -adhlns...: create assembler listing
194 CFLAGS += -funsigned-char
195 CFLAGS += -funsigned-bitfields
196 CFLAGS += -ffunction-sections
197 CFLAGS += -fpack-struct
198 CFLAGS += -fshort-enums
199 CFLAGS += -finline-limit=20
201 CFLAGS += -Wstrict-prototypes
203 #CFLAGS += -fno-unit-at-a-time
204 #CFLAGS += -Wunreachable-code
205 #CFLAGS += -Wsign-compare
206 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
207 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
208 CFLAGS += $(CSTANDARD)
211 #---------------- Compiler Options C++ ----------------
212 # -g*: generate debugging information
213 # -O*: optimization level
214 # -f...: tuning, see GCC manual and avr-libc documentation
215 # -Wall...: warning level
216 # -Wa,...: tell GCC to pass this to the assembler.
217 # -adhlns...: create assembler listing
218 CPPFLAGS = -g$(DEBUG)
219 CPPFLAGS += $(CPPDEFS)
221 CPPFLAGS += -funsigned-char
222 CPPFLAGS += -funsigned-bitfields
223 CPPFLAGS += -fpack-struct
224 CPPFLAGS += -fshort-enums
225 CPPFLAGS += -fno-exceptions
228 #CPPFLAGS += -mshort-calls
229 #CPPFLAGS += -fno-unit-at-a-time
230 #CPPFLAGS += -Wstrict-prototypes
231 #CPPFLAGS += -Wunreachable-code
232 #CPPFLAGS += -Wsign-compare
233 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
234 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
235 #CPPFLAGS += $(CSTANDARD)
238 #---------------- Assembler Options ----------------
239 # -Wa,...: tell GCC to pass this to the assembler.
240 # -adhlns: create listing
241 # -gstabs: have the assembler create line number information; note that
242 # for use in COFF files, additional information about filenames
243 # and function names needs to be present in the assembler source
244 # files -- see avr-libc docs [FIXME: not yet described there]
245 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
246 # dump that will be displayed for a given single line of source input.
247 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
250 #---------------- Library Options ----------------
251 # Minimalistic printf version
252 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
254 # Floating point printf version (requires MATH_LIB = -lm below)
255 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
257 # If this is left blank, then it will use the Standard printf version.
259 #PRINTF_LIB = $(PRINTF_LIB_MIN)
260 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
263 # Minimalistic scanf version
264 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
266 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
267 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
269 # If this is left blank, then it will use the Standard scanf version.
271 #SCANF_LIB = $(SCANF_LIB_MIN)
272 #SCANF_LIB = $(SCANF_LIB_FLOAT)
278 # List any extra directories to look for libraries here.
279 # Each directory must be seperated by a space.
280 # Use forward slashes for directory separators.
281 # For a directory that has spaces, enclose it in quotes.
286 #---------------- External Memory Options ----------------
288 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
289 # used for variables (.data/.bss) and heap (malloc()).
290 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
292 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
293 # only used for heap (malloc()).
294 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
300 #---------------- Linker Options ----------------
301 # -Wl,...: tell GCC to pass this to linker.
302 # -Map: create map file
303 # --cref: add cross reference to map file
304 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
305 LDFLAGS += -Wl,--relax
306 LDFLAGS += -Wl,--gc-sections
307 LDFLAGS += $(EXTMEMOPTS)
308 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
309 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
310 #LDFLAGS += -T linker_script.x
314 #---------------- Programming Options (avrdude) ----------------
316 # Programming hardware: alf avr910 avrisp bascom bsd
317 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
320 # to get a full listing.
322 AVRDUDE_PROGRAMMER = jtagmkII
324 # com1 = serial port. Use lpt1 to connect to parallel port.
327 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
328 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
331 # Uncomment the following if you want avrdude's erase cycle counter.
332 # Note that this counter needs to be initialized first using -Yn,
333 # see avrdude manual.
334 #AVRDUDE_ERASE_COUNTER = -y
336 # Uncomment the following if you do /not/ wish a verification to be
337 # performed after programming the device.
338 #AVRDUDE_NO_VERIFY = -V
340 # Increase verbosity level. Please use this when submitting bug
341 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
342 # to submit bug reports.
343 #AVRDUDE_VERBOSE = -v -v
345 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
346 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
347 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
348 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
352 #---------------- Debugging Options ----------------
354 # For simulavr only - target MCU frequency.
355 DEBUG_MFREQ = $(F_CPU)
357 # Set the DEBUG_UI to either gdb or insight.
361 # Set the debugging back-end to either avarice, simulavr.
362 DEBUG_BACKEND = avarice
363 #DEBUG_BACKEND = simulavr
366 GDBINIT_FILE = __avr_gdbinit
368 # When using avarice settings for the JTAG
371 # Debugging port used to communicate between GDB / avarice / simulavr.
374 # Debugging host used to communicate between GDB / avarice / simulavr, normally
375 # just set to localhost unless doing some sort of crazy debugging when
376 # avarice is running on a different computer.
377 DEBUG_HOST = localhost
381 #============================================================================
384 # Define programs and commands.
387 OBJCOPY = avr-objcopy
388 OBJDUMP = avr-objdump
400 MSG_ERRORS_NONE = Errors: none
401 MSG_BEGIN = -------- begin --------
402 MSG_END = -------- end --------
403 MSG_SIZE_BEFORE = Size before:
404 MSG_SIZE_AFTER = Size after:
405 MSG_COFF = Converting to AVR COFF:
406 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
407 MSG_FLASH = Creating load file for Flash:
408 MSG_EEPROM = Creating load file for EEPROM:
409 MSG_EXTENDED_LISTING = Creating Extended Listing:
410 MSG_SYMBOL_TABLE = Creating Symbol Table:
411 MSG_LINKING = Linking:
412 MSG_COMPILING = Compiling C:
413 MSG_COMPILING_CPP = Compiling C++:
414 MSG_ASSEMBLING = Assembling:
415 MSG_CLEANING = Cleaning project:
416 MSG_CREATING_LIBRARY = Creating library:
421 # Define all object files.
422 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
424 # Define all listing files.
425 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
428 # Compiler flags to generate dependency files.
429 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
432 # Combine all necessary flags and optional flags.
433 # Add target processor to flags.
434 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
435 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
436 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
443 all: begin gccversion sizebefore build checkhooks checklibmode sizeafter end
445 # Change the build target to build a HEX file or a library.
446 build: elf hex eep lss sym
455 LIBNAME=lib$(TARGET).a
461 # AVR Studio 3.x does not check make's exit code but relies on
462 # the following magic strings to be generated by the compile job.
472 # Display size of file.
473 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
474 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
475 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
476 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
479 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
480 2>/dev/null; echo; fi
483 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
484 2>/dev/null; echo; fi
488 @echo ------- Unhooked LUFA Events -------
489 @$(shell) (grep -s '^Event.*LUFA/.*\\.o' $(TARGET).map | \
490 cut -d' ' -f1 | cut -d'_' -f2- | grep ".*") || \
492 @echo ----- End Unhooked LUFA Events -----
496 @echo ----------- Library Mode -----------
497 @$(shell) ($(CC) $(ALL_CFLAGS) -E -dM - < /dev/null \
498 | grep 'USB_\(DEVICE\|HOST\)_ONLY' | cut -d' ' -f2 | grep ".*") \
499 || echo "No specific mode (both device and host mode allowable)."
500 @echo ------------------------------------
502 # Display compiler version information.
508 # Program the device.
509 program: $(TARGET).hex $(TARGET).eep
510 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
513 batchisp -hardware usb -device $(MCU) -operation erase f
514 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
515 batchisp -hardware usb -device $(MCU) -operation start reset 0
518 dfu-programmer $(MCU) erase
519 dfu-programmer $(MCU) flash --debug 1 $(TARGET).hex
520 dfu-programmer $(MCU) reset
522 flip-ee: $(TARGET).hex $(TARGET).eep
523 copy $(TARGET).eep $(TARGET)eep.hex
524 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
525 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program
526 batchisp -hardware usb -device $(MCU) -operation start reset 0
528 dfu-ee: $(TARGET).hex $(TARGET).eep
529 dfu-programmer $(MCU) erase
530 dfu-programmer $(MCU) eeprom --debug 1 $(TARGET).eep
531 dfu-programmer $(MCU) reset
533 # Generate avr-gdb config/init file which does the following:
534 # define the reset signal, load the target file, connect to target, and set
535 # a breakpoint at main().
537 @$(REMOVE) $(GDBINIT_FILE)
538 @echo define reset >> $(GDBINIT_FILE)
539 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
540 @echo end >> $(GDBINIT_FILE)
541 @echo file $(TARGET).elf >> $(GDBINIT_FILE)
542 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
543 ifeq ($(DEBUG_BACKEND),simulavr)
544 @echo load >> $(GDBINIT_FILE)
546 @echo break main >> $(GDBINIT_FILE)
548 debug: gdb-config $(TARGET).elf
549 ifeq ($(DEBUG_BACKEND), avarice)
550 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
551 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
552 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
553 @$(WINSHELL) /c pause
556 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
557 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
559 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
564 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
565 COFFCONVERT = $(OBJCOPY) --debugging
566 COFFCONVERT += --change-section-address .data-0x800000
567 COFFCONVERT += --change-section-address .bss-0x800000
568 COFFCONVERT += --change-section-address .noinit-0x800000
569 COFFCONVERT += --change-section-address .eeprom-0x810000
575 @echo $(MSG_COFF) $(TARGET).cof
576 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
579 extcoff: $(TARGET).elf
581 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
582 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
586 # Create final output files (.hex, .eep) from ELF output file.
589 @echo $(MSG_FLASH) $@
590 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
594 @echo $(MSG_EEPROM) $@
595 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
596 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
598 # Create extended listing file from ELF output file.
601 @echo $(MSG_EXTENDED_LISTING) $@
602 $(OBJDUMP) -h -z -S $< > $@
604 # Create a symbol table from ELF output file.
607 @echo $(MSG_SYMBOL_TABLE) $@
612 # Create library from object files.
613 .SECONDARY : $(TARGET).a
617 @echo $(MSG_CREATING_LIBRARY) $@
621 # Link: create ELF output file from object files.
622 .SECONDARY : $(TARGET).elf
626 @echo $(MSG_LINKING) $@
627 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
630 # Compile: create object files from C source files.
633 @echo $(MSG_COMPILING) $<
634 $(CC) -c $(ALL_CFLAGS) $< -o $@
637 # Compile: create object files from C++ source files.
638 $(OBJDIR)/%.o : %.cpp
640 @echo $(MSG_COMPILING_CPP) $<
641 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
644 # Compile: create assembler files from C source files.
646 $(CC) -S $(ALL_CFLAGS) $< -o $@
649 # Compile: create assembler files from C++ source files.
651 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
654 # Assemble: create object files from assembler source files.
657 @echo $(MSG_ASSEMBLING) $<
658 $(CC) -c $(ALL_ASFLAGS) $< -o $@
661 # Create preprocessed source for use in sending a bug report.
663 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
666 ## Target: clean project.
667 clean: begin clean_list clean_binary end
670 $(REMOVE) $(TARGET).hex
673 @echo $(MSG_CLEANING)
674 $(REMOVE) $(TARGET).eep
675 $(REMOVE) $(TARGET).cof
676 $(REMOVE) $(TARGET).elf
677 $(REMOVE) $(TARGET).map
678 $(REMOVE) $(TARGET).sym
679 $(REMOVE) $(TARGET).lss
680 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
681 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
682 $(REMOVE) $(SRC:.c=.s)
683 $(REMOVE) $(SRC:.c=.d)
684 $(REMOVE) $(SRC:.c=.i)
688 @echo Generating Project Documentation...
689 @doxygen Doxygen.conf
690 @echo Documentation Generation Complete.
692 # Create object files directory
693 $(shell mkdir $(OBJDIR) 2>/dev/null)
696 # Include the dependency files.
697 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
700 # Listing of phony targets.
701 .PHONY : all checkhooks checklibmode begin \
702 finish end sizebefore sizeafter gccversion \
703 build elf hex eep lss sym coff extcoff \
704 clean clean_list clean_binary program debug \