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 dfu = Download the hex file to the device, using dfu-programmer (must
29 # have dfu-programmer installed).
31 # make flip = Download the hex file to the device, using Atmel FLIP (must
32 # have Atmel FLIP installed).
34 # make doxygen = Generate DoxyGen documentation for the project (must have
37 # make filename.s = Just compile filename.c into the assembler code only.
39 # make filename.i = Create a preprocessed source file for use in submitting
40 # bug reports to the GCC project.
42 # To rebuild project do "make clean" then "make all".
43 #----------------------------------------------------------------------------
50 # Targeted chip architecture (see library "Architectures" documentation)
54 # Target board (see library "Board Types" documentation, NONE for projects not requiring
55 # LUFA board drivers). If USER is selected, put custom board drivers in a directory called
56 # "Board" inside the application directory.
60 # Processor frequency.
61 # This will define a symbol, F_CPU, in all source code files equal to the
62 # processor frequency in Hz. You can then use this symbol in your source code to
63 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
64 # automatically to create a 32-bit value in your source code.
66 # This should be the frequency the system core runs at, after the system clock
67 # has been set up correctly and started.
71 # USB controller master clock frequency.
72 # This will define a symbol, F_USB, in all source code files equal to the
73 # input clock frequency of the USB controller's clock generator in Hz.
75 # For the UC3 chips, this should be equal to 48MHz or 96MHz.
79 # Output format. (can be srec, ihex, binary)
83 # Target file name (without extension).
87 # Object files directory
88 # To put object files in current directory, use a dot (.), do NOT make
89 # this an empty or blank macro!
93 # Path to the LUFA library
97 # LUFA library compile-time options and predefined tokens (add '-D' before each token)
101 # Create the LUFA source path variables by including the LUFA root makefile
102 include $(LUFA_PATH)/LUFA/makefile
105 # List C source files here. (C dependencies are automatically generated.)
108 $(LUFA_SRC_USBCLASS) \
109 $(LUFA_SRC_SCHEDULER)
112 # List C++ source files here. (C dependencies are automatically generated.)
113 CPPSRC = Test_CPP.cpp
116 # List Assembler source files here.
117 # Make them always end in a capital .S. Files ending in a lowercase .s
118 # will not be considered source files but generated files (assembler
119 # output from the compiler), and will be deleted upon "make clean"!
120 # Even though the DOS/Win* filesystem matches both .s and .S the same,
121 # it will preserve the spelling of the filenames, and gcc itself does
122 # care about how the name is spelled on its command-line.
124 $(LUFA_PATH)/LUFA/Platform/UC3/Exception.S
127 # Optimization level, can be [0, 1, 2, 3, s].
128 # 0 = turn off optimization. s = optimize for size.
129 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
133 # List any extra directories to look for include files here.
134 # Each directory must be seperated by a space.
135 # Use forward slashes for directory separators.
136 # For a directory that has spaces, enclose it in quotes.
137 EXTRAINCDIRS = $(LUFA_PATH)/
140 # Compiler flag to set the C Standard level.
142 # gnu89 = c89 plus GCC extensions
143 # c99 = ISO C99 standard (not yet fully implemented)
144 # gnu99 = c99 plus GCC extensions
145 CSTANDARD = -std=gnu99
148 # Place -D or -U options here for C sources
149 CDEFS = -DF_CPU=$(F_CPU)UL
150 CDEFS += -DF_USB=$(F_USB)UL
151 CDEFS += -DBOARD=BOARD_$(BOARD)
152 CDEFS += -DARCH=ARCH_$(ARCH)
153 CDEFS += $(LUFA_OPTS)
156 # Place -D or -U options here for ASM sources
157 ADEFS = -DF_CPU=$(F_CPU)
158 ADEFS += -DF_USB=$(F_USB)UL
159 ADEFS += -DBOARD=BOARD_$(BOARD)
160 ADEFS += -DARCH=ARCH_$(ARCH)
161 ADEFS += $(LUFA_OPTS)
163 # Place -D or -U options here for C++ sources
164 CPPDEFS = -DF_CPU=$(F_CPU)UL
165 CPPDEFS += -DF_USB=$(F_USB)UL
166 CPPDEFS += -DBOARD=BOARD_$(BOARD)
167 CPPDEFS += -DARCH=ARCH_$(ARCH)
168 CPPDEFS += $(LUFA_OPTS)
175 #---------------- Compiler Options C ----------------
176 # -g*: generate debugging information
177 # -O*: optimization level
178 # -f...: tuning, see GCC manual and avr-libc documentation
179 # -Wall...: warning level
180 # -Wa,...: tell GCC to pass this to the assembler.
181 # -adhlns...: create assembler listing
185 CFLAGS += -funsigned-char
186 CFLAGS += -funsigned-bitfields
187 CFLAGS += -ffunction-sections
188 CFLAGS += -fno-strict-aliasing
190 CFLAGS += -Wstrict-prototypes
191 CFLAGS += -masm-addr-pseudos
192 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
193 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
194 CFLAGS += $(CSTANDARD)
197 #---------------- Compiler Options C++ ----------------
198 # -g*: generate debugging information
199 # -O*: optimization level
200 # -f...: tuning, see GCC manual and avr-libc documentation
201 # -Wall...: warning level
202 # -Wa,...: tell GCC to pass this to the assembler.
203 # -adhlns...: create assembler listing
204 CPPFLAGS = -g$(DEBUG)
205 CPPFLAGS += $(CPPDEFS)
207 CPPFLAGS += -funsigned-char
208 CPPFLAGS += -funsigned-bitfields
209 CPPFLAGS += -ffunction-sections
210 CPPFLAGS += -fno-strict-aliasing
211 CPPFLAGS += -fno-exceptions
212 CPPFLAGS += -masm-addr-pseudos
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)
232 #---------------- Linker Options ----------------
233 # -Wl,...: tell GCC to pass this to linker.
234 # -Map: create map file
235 # --cref: add cross reference to map file
236 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
237 LDFLAGS += -Wl,--gc-sections --rodata-writable
238 LDFLAGS += -Wl,--direct-data
239 #LDFLAGS += -T linker_script.x
242 #============================================================================
245 # Define programs and commands.
248 OBJCOPY = avr32-objcopy
249 OBJDUMP = avr32-objdump
261 MSG_ERRORS_NONE = Errors: none
262 MSG_BEGIN = -------- begin --------
263 MSG_END = -------- end --------
264 MSG_SIZE_BEFORE = Size before:
265 MSG_SIZE_AFTER = Size after:
266 MSG_COFF = Converting to AVR COFF:
267 MSG_FLASH = Creating load file for Flash:
268 MSG_EEPROM = Creating load file for EEPROM:
269 MSG_EXTENDED_LISTING = Creating Extended Listing:
270 MSG_SYMBOL_TABLE = Creating Symbol Table:
271 MSG_LINKING = Linking:
272 MSG_COMPILING = Compiling C:
273 MSG_COMPILING_CPP = Compiling C++:
274 MSG_ASSEMBLING = Assembling:
275 MSG_CLEANING = Cleaning project:
276 MSG_CREATING_LIBRARY = Creating library:
281 # Define all object files.
282 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
284 # Define all listing files.
285 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
288 # Compiler flags to generate dependency files.
289 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
292 # Combine all necessary flags and optional flags.
293 # Add target processor to flags.
294 ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
295 ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
296 ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
303 all: begin gccversion sizebefore build sizeafter end
305 # Change the build target to build a HEX file or a library.
306 build: elf hex lss sym
314 LIBNAME=lib$(TARGET).a
320 # AVR Studio 3.x does not check make's exit code but relies on
321 # the following magic strings to be generated by the compile job.
331 # Display size of file.
332 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
333 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
334 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
335 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
339 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
340 2>/dev/null; echo; fi
343 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
344 2>/dev/null; echo; fi
348 # Display compiler version information.
353 # Program the device.
355 batchisp -hardware usb -device $(MCU) -operation erase f
356 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
357 batchisp -hardware usb -device $(MCU) -operation start reset 0
360 dfu-programmer $(MCU) erase
361 dfu-programmer $(MCU) flash $(TARGET).hex
362 dfu-programmer $(MCU) reset
365 # Create final output files (.hex, .eep) from ELF output file.
368 @echo $(MSG_FLASH) $@
369 $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
371 # Create extended listing file from ELF output file.
374 @echo $(MSG_EXTENDED_LISTING) $@
375 $(OBJDUMP) -h -S -z $< > $@
377 # Create a symbol table from ELF output file.
380 @echo $(MSG_SYMBOL_TABLE) $@
385 # Create library from object files.
386 .SECONDARY : $(TARGET).a
390 @echo $(MSG_CREATING_LIBRARY) $@
394 # Link: create ELF output file from object files.
395 .SECONDARY : $(TARGET).elf
399 @echo $(MSG_LINKING) $@
400 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
403 # Compile: create object files from C source files.
406 @echo $(MSG_COMPILING) $<
407 $(CC) -c $(ALL_CFLAGS) $< -o $@
410 # Compile: create object files from C++ source files.
411 $(OBJDIR)/%.o : %.cpp
413 @echo $(MSG_COMPILING_CPP) $<
414 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
417 # Compile: create assembler files from C source files.
419 $(CC) -S $(ALL_CFLAGS) $< -o $@
422 # Compile: create assembler files from C++ source files.
424 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
427 # Assemble: create object files from assembler source files.
430 @echo $(MSG_ASSEMBLING) $<
431 $(CC) -c $(ALL_ASFLAGS) $< -o $@
434 # Create preprocessed source for use in sending a bug report.
436 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
439 # Target: clean project.
440 clean: begin clean_list end
444 @echo $(MSG_CLEANING)
445 $(REMOVE) $(TARGET).hex
446 $(REMOVE) $(TARGET).cof
447 $(REMOVE) $(TARGET).elf
448 $(REMOVE) $(TARGET).map
449 $(REMOVE) $(TARGET).sym
450 $(REMOVE) $(TARGET).lss
451 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
452 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
453 $(REMOVE) $(SRC:.c=.s)
454 $(REMOVE) $(SRC:.c=.d)
455 $(REMOVE) $(SRC:.c=.i)
459 @echo Generating Project Documentation \($(TARGET)\)...
460 @doxygen Doxygen.conf
461 @echo Documentation Generation Complete.
467 @for f in $(SRC) $(CPPSRC) $(ASRC); do \
468 if [ -f $$f ]; then \
469 echo "Found Source File: $$f" ; \
471 echo "Source File Not Found: $$f" ; \
475 # Create object files directory
476 $(shell mkdir $(OBJDIR) 2>/dev/null)
479 # Include the dependency files.
480 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
483 # Listing of phony targets.
484 .PHONY : all begin finish end sizebefore sizeafter gccversion \
485 build elf hex lss sym doxygen clean clean_list clean_doxygen \