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 = RNDISEthernet
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.)
120 ../../LUFA/Scheduler/Scheduler.c \
121 ../../LUFA/Drivers/USB/LowLevel/LowLevel.c \
122 ../../LUFA/Drivers/USB/LowLevel/Endpoint.c \
123 ../../LUFA/Drivers/USB/LowLevel/DevChapter9.c \
124 ../../LUFA/Drivers/USB/HighLevel/USBTask.c \
125 ../../LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
126 ../../LUFA/Drivers/USB/HighLevel/Events.c \
127 ../../LUFA/Drivers/USB/HighLevel/StdDescriptors.c \
128 ../../LUFA/Drivers/AT90USBXXX/Serial_Stream.c \
129 ../../LUFA/Drivers/AT90USBXXX/Serial.c \
131 # List C++ source files here. (C dependencies are automatically generated.)
135 # List Assembler source files here.
136 # Make them always end in a capital .S. Files ending in a lowercase .s
137 # will not be considered source files but generated files (assembler
138 # output from the compiler), and will be deleted upon "make clean"!
139 # Even though the DOS/Win* filesystem matches both .s and .S the same,
140 # it will preserve the spelling of the filenames, and gcc itself does
141 # care about how the name is spelled on its command-line.
145 # Optimization level, can be [0, 1, 2, 3, s].
146 # 0 = turn off optimization. s = optimize for size.
147 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
152 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
153 # AVR Studio 4.10 requires dwarf-2.
154 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
158 # List any extra directories to look for include files here.
159 # Each directory must be seperated by a space.
160 # Use forward slashes for directory separators.
161 # For a directory that has spaces, enclose it in quotes.
162 EXTRAINCDIRS = ../../
165 # Compiler flag to set the C Standard level.
167 # gnu89 = c89 plus GCC extensions
168 # c99 = ISO C99 standard (not yet fully implemented)
169 # gnu99 = c99 plus GCC extensions
170 CSTANDARD = -std=gnu99
173 # Place -D or -U options here for C sources
174 CDEFS = -DF_CPU=$(F_CPU)UL -DBOARD=BOARD_$(BOARD) -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DNO_STREAM_CALLBACKS
175 CDEFS += -DUSB_DEVICE_ONLY -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
176 CDEFS += -DNO_DECODE_ETHERNET -DNO_DECODE_ARP -DNO_DECODE_ICMP -DNO_DECODE_IP -DNO_DECODE_TCP -DNO_DECODE_UDP -DNO_DECODE_DHCP
179 # Place -D or -U options here for ASM sources
180 ADEFS = -DF_CPU=$(F_CPU)
183 # Place -D or -U options here for C++ sources
184 CPPDEFS = -DF_CPU=$(F_CPU)UL
185 #CPPDEFS += -D__STDC_LIMIT_MACROS
186 #CPPDEFS += -D__STDC_CONSTANT_MACROS
190 #---------------- Compiler Options C ----------------
191 # -g*: generate debugging information
192 # -O*: optimization level
193 # -f...: tuning, see GCC manual and avr-libc documentation
194 # -Wall...: warning level
195 # -Wa,...: tell GCC to pass this to the assembler.
196 # -adhlns...: create assembler listing
200 CFLAGS += -funsigned-char
201 CFLAGS += -funsigned-bitfields
202 CFLAGS += -ffunction-sections
203 CFLAGS += -fpack-struct
204 CFLAGS += -fshort-enums
205 CFLAGS += -finline-limit=20
207 CFLAGS += -Wstrict-prototypes
209 #CFLAGS += -fno-unit-at-a-time
210 #CFLAGS += -Wunreachable-code
211 #CFLAGS += -Wsign-compare
212 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
213 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
214 CFLAGS += $(CSTANDARD)
217 #---------------- Compiler Options C++ ----------------
218 # -g*: generate debugging information
219 # -O*: optimization level
220 # -f...: tuning, see GCC manual and avr-libc documentation
221 # -Wall...: warning level
222 # -Wa,...: tell GCC to pass this to the assembler.
223 # -adhlns...: create assembler listing
224 CPPFLAGS = -g$(DEBUG)
225 CPPFLAGS += $(CPPDEFS)
227 CPPFLAGS += -funsigned-char
228 CPPFLAGS += -funsigned-bitfields
229 CPPFLAGS += -fpack-struct
230 CPPFLAGS += -fshort-enums
231 CPPFLAGS += -fno-exceptions
234 #CPPFLAGS += -mshort-calls
235 #CPPFLAGS += -fno-unit-at-a-time
236 #CPPFLAGS += -Wstrict-prototypes
237 #CPPFLAGS += -Wunreachable-code
238 #CPPFLAGS += -Wsign-compare
239 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
240 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
241 #CPPFLAGS += $(CSTANDARD)
244 #---------------- Assembler Options ----------------
245 # -Wa,...: tell GCC to pass this to the assembler.
246 # -adhlns: create listing
247 # -gstabs: have the assembler create line number information; note that
248 # for use in COFF files, additional information about filenames
249 # and function names needs to be present in the assembler source
250 # files -- see avr-libc docs [FIXME: not yet described there]
251 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
252 # dump that will be displayed for a given single line of source input.
253 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
256 #---------------- Library Options ----------------
257 # Minimalistic printf version
258 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
260 # Floating point printf version (requires MATH_LIB = -lm below)
261 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
263 # If this is left blank, then it will use the Standard printf version.
265 #PRINTF_LIB = $(PRINTF_LIB_MIN)
266 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
269 # Minimalistic scanf version
270 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
272 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
273 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
275 # If this is left blank, then it will use the Standard scanf version.
277 #SCANF_LIB = $(SCANF_LIB_MIN)
278 #SCANF_LIB = $(SCANF_LIB_FLOAT)
284 # List any extra directories to look for libraries here.
285 # Each directory must be seperated by a space.
286 # Use forward slashes for directory separators.
287 # For a directory that has spaces, enclose it in quotes.
292 #---------------- External Memory Options ----------------
294 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
295 # used for variables (.data/.bss) and heap (malloc()).
296 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
298 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
299 # only used for heap (malloc()).
300 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
306 #---------------- Linker Options ----------------
307 # -Wl,...: tell GCC to pass this to linker.
308 # -Map: create map file
309 # --cref: add cross reference to map file
310 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
311 LDFLAGS += -Wl,--relax
312 LDFLAGS += -Wl,--gc-sections
313 LDFLAGS += $(EXTMEMOPTS)
314 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
315 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
316 #LDFLAGS += -T linker_script.x
320 #---------------- Programming Options (avrdude) ----------------
322 # Programming hardware: alf avr910 avrisp bascom bsd
323 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
326 # to get a full listing.
328 AVRDUDE_PROGRAMMER = jtagmkII
330 # com1 = serial port. Use lpt1 to connect to parallel port.
333 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
334 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
337 # Uncomment the following if you want avrdude's erase cycle counter.
338 # Note that this counter needs to be initialized first using -Yn,
339 # see avrdude manual.
340 #AVRDUDE_ERASE_COUNTER = -y
342 # Uncomment the following if you do /not/ wish a verification to be
343 # performed after programming the device.
344 #AVRDUDE_NO_VERIFY = -V
346 # Increase verbosity level. Please use this when submitting bug
347 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
348 # to submit bug reports.
349 #AVRDUDE_VERBOSE = -v -v
351 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
352 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
353 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
354 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
358 #---------------- Debugging Options ----------------
360 # For simulavr only - target MCU frequency.
361 DEBUG_MFREQ = $(F_CPU)
363 # Set the DEBUG_UI to either gdb or insight.
367 # Set the debugging back-end to either avarice, simulavr.
368 DEBUG_BACKEND = avarice
369 #DEBUG_BACKEND = simulavr
372 GDBINIT_FILE = __avr_gdbinit
374 # When using avarice settings for the JTAG
377 # Debugging port used to communicate between GDB / avarice / simulavr.
380 # Debugging host used to communicate between GDB / avarice / simulavr, normally
381 # just set to localhost unless doing some sort of crazy debugging when
382 # avarice is running on a different computer.
383 DEBUG_HOST = localhost
387 #============================================================================
390 # Define programs and commands.
393 OBJCOPY = avr-objcopy
394 OBJDUMP = avr-objdump
406 MSG_ERRORS_NONE = Errors: none
407 MSG_BEGIN = -------- begin --------
408 MSG_END = -------- end --------
409 MSG_SIZE_BEFORE = Size before:
410 MSG_SIZE_AFTER = Size after:
411 MSG_COFF = Converting to AVR COFF:
412 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
413 MSG_FLASH = Creating load file for Flash:
414 MSG_EEPROM = Creating load file for EEPROM:
415 MSG_EXTENDED_LISTING = Creating Extended Listing:
416 MSG_SYMBOL_TABLE = Creating Symbol Table:
417 MSG_LINKING = Linking:
418 MSG_COMPILING = Compiling C:
419 MSG_COMPILING_CPP = Compiling C++:
420 MSG_ASSEMBLING = Assembling:
421 MSG_CLEANING = Cleaning project:
422 MSG_CREATING_LIBRARY = Creating library:
427 # Define all object files.
428 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
430 # Define all listing files.
431 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
434 # Compiler flags to generate dependency files.
435 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
438 # Combine all necessary flags and optional flags.
439 # Add target processor to flags.
440 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
441 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
442 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
449 all: begin gccversion sizebefore build checkhooks checklibmode sizeafter end
451 # Change the build target to build a HEX file or a library.
452 build: elf hex eep lss sym
461 LIBNAME=lib$(TARGET).a
467 # AVR Studio 3.x does not check make's exit code but relies on
468 # the following magic strings to be generated by the compile job.
478 # Display size of file.
479 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
480 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
481 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
482 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
485 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
486 2>/dev/null; echo; fi
489 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
490 2>/dev/null; echo; fi
494 @echo ------- Unhooked LUFA Events -------
495 @$(shell) (grep -s '^Event.*LUFA/.*\\.o' $(TARGET).map | \
496 cut -d' ' -f1 | cut -d'_' -f2- | grep ".*") || \
498 @echo ----- End Unhooked LUFA Events -----
502 @echo ----------- Library Mode -----------
503 @$(shell) ($(CC) $(ALL_CFLAGS) -E -dM - < /dev/null \
504 | grep 'USB_\(DEVICE\|HOST\)_ONLY' | cut -d' ' -f2 | grep ".*") \
505 || echo "No specific mode (both device and host mode allowable)."
506 @echo ------------------------------------
508 # Display compiler version information.
514 # Program the device.
515 program: $(TARGET).hex $(TARGET).eep
516 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
519 batchisp -hardware usb -device $(MCU) -operation erase f
520 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
521 batchisp -hardware usb -device $(MCU) -operation start reset 0
524 dfu-programmer $(MCU) erase
525 dfu-programmer $(MCU) flash --debug 1 $(TARGET).hex
526 dfu-programmer $(MCU) reset
528 flip-ee: $(TARGET).hex $(TARGET).eep
529 copy $(TARGET).eep $(TARGET)eep.hex
530 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
531 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program
532 batchisp -hardware usb -device $(MCU) -operation start reset 0
534 dfu-ee: $(TARGET).hex $(TARGET).eep
535 dfu-programmer $(MCU) erase
536 dfu-programmer $(MCU) eeprom --debug 1 $(TARGET).eep
537 dfu-programmer $(MCU) reset
539 # Generate avr-gdb config/init file which does the following:
540 # define the reset signal, load the target file, connect to target, and set
541 # a breakpoint at main().
543 @$(REMOVE) $(GDBINIT_FILE)
544 @echo define reset >> $(GDBINIT_FILE)
545 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
546 @echo end >> $(GDBINIT_FILE)
547 @echo file $(TARGET).elf >> $(GDBINIT_FILE)
548 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
549 ifeq ($(DEBUG_BACKEND),simulavr)
550 @echo load >> $(GDBINIT_FILE)
552 @echo break main >> $(GDBINIT_FILE)
554 debug: gdb-config $(TARGET).elf
555 ifeq ($(DEBUG_BACKEND), avarice)
556 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
557 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
558 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
559 @$(WINSHELL) /c pause
562 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
563 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
565 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
570 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
571 COFFCONVERT = $(OBJCOPY) --debugging
572 COFFCONVERT += --change-section-address .data-0x800000
573 COFFCONVERT += --change-section-address .bss-0x800000
574 COFFCONVERT += --change-section-address .noinit-0x800000
575 COFFCONVERT += --change-section-address .eeprom-0x810000
581 @echo $(MSG_COFF) $(TARGET).cof
582 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
585 extcoff: $(TARGET).elf
587 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
588 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
592 # Create final output files (.hex, .eep) from ELF output file.
595 @echo $(MSG_FLASH) $@
596 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
600 @echo $(MSG_EEPROM) $@
601 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
602 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
604 # Create extended listing file from ELF output file.
607 @echo $(MSG_EXTENDED_LISTING) $@
608 $(OBJDUMP) -h -z -S $< > $@
610 # Create a symbol table from ELF output file.
613 @echo $(MSG_SYMBOL_TABLE) $@
618 # Create library from object files.
619 .SECONDARY : $(TARGET).a
623 @echo $(MSG_CREATING_LIBRARY) $@
627 # Link: create ELF output file from object files.
628 .SECONDARY : $(TARGET).elf
632 @echo $(MSG_LINKING) $@
633 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
636 # Compile: create object files from C source files.
639 @echo $(MSG_COMPILING) $<
640 $(CC) -c $(ALL_CFLAGS) $< -o $@
643 # Compile: create object files from C++ source files.
644 $(OBJDIR)/%.o : %.cpp
646 @echo $(MSG_COMPILING_CPP) $<
647 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
650 # Compile: create assembler files from C source files.
652 $(CC) -S $(ALL_CFLAGS) $< -o $@
655 # Compile: create assembler files from C++ source files.
657 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
660 # Assemble: create object files from assembler source files.
663 @echo $(MSG_ASSEMBLING) $<
664 $(CC) -c $(ALL_ASFLAGS) $< -o $@
667 # Create preprocessed source for use in sending a bug report.
669 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
672 # Target: clean project.
673 clean: begin clean_list clean_binary end
676 $(REMOVE) $(TARGET).hex
679 @echo $(MSG_CLEANING)
680 $(REMOVE) $(TARGET).eep
681 $(REMOVE) $(TARGET).cof
682 $(REMOVE) $(TARGET).elf
683 $(REMOVE) $(TARGET).map
684 $(REMOVE) $(TARGET).sym
685 $(REMOVE) $(TARGET).lss
686 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
687 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
688 $(REMOVE) $(SRC:.c=.s)
689 $(REMOVE) $(SRC:.c=.d)
690 $(REMOVE) $(SRC:.c=.i)
695 @echo Generating Project Documentation...
696 @doxygen Doxygen.conf
697 @echo Documentation Generation Complete.
702 # Create object files directory
703 $(shell mkdir $(OBJDIR) 2>/dev/null)
706 # Include the dependency files.
707 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
710 # Listing of phony targets.
711 .PHONY : all checkhooks checklibmode begin \
712 finish end sizebefore sizeafter gccversion \
713 build elf hex eep lss sym coff extcoff \
714 clean clean_list clean_binary program debug \
715 gdb-config doxygen dfu flip