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 # Target board (see library "Board Types" documentation, NONE for projects not requiring
51 # LUFA board drivers). If USER is selected, put custom board drivers in a directory called
52 # "Board" inside the application directory.
56 # Targeted chip architecture (see library "Architectures" documentation)
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 will be an integer division of F_USB below, as it is sourced by
67 # F_USB after it has run through any CPU prescalers. Note that this value
68 # does not *change* the processor frequency - it should merely be updated to
69 # reflect the processor speed set externally so that the code can use accurate
74 # Input clock frequency.
75 # This will define a symbol, F_USB, in all source code files equal to the
76 # input clock frequency (before any prescaling is performed) in Hz. This value may
77 # differ from F_CPU if prescaling is used on the latter, and is required as the
78 # raw input clock is fed directly to the PLL sections of the AVR for high speed
79 # clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
80 # at the end, this will be done automatically to create a 32-bit value in your
83 # If no clock division is performed on the input clock inside the AVR (via the
84 # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
88 # Output format. (can be srec, ihex, binary)
92 # Target file name (without extension).
96 # Object files directory
97 # To put object files in current directory, use a dot (.), do NOT make
98 # this an empty or blank macro!
102 # Path to the LUFA library
103 LUFA_PATH = ../../../../
106 # LUFA library compile-time options and predefined tokens
107 LUFA_OPTS = -D USB_DEVICE_ONLY
108 LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=32
109 LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
110 LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_GCLK_SRC_PLL | USB_OPT_GCLK_CHANNEL_1)"
113 # Create the LUFA source path variables by including the LUFA root makefile
114 include $(LUFA_PATH)/LUFA/makefile
117 # List C source files here. (C dependencies are automatically generated.)
120 $(LUFA_PATH)/LUFA/Platform/UC3/INTC.c \
125 # List C++ source files here. (C dependencies are automatically generated.)
129 # List Assembler source files here.
130 # Make them always end in a capital .S. Files ending in a lowercase .s
131 # will not be considered source files but generated files (assembler
132 # output from the compiler), and will be deleted upon "make clean"!
133 # Even though the DOS/Win* filesystem matches both .s and .S the same,
134 # it will preserve the spelling of the filenames, and gcc itself does
135 # care about how the name is spelled on its command-line.
136 ASRC = $(LUFA_PATH)/LUFA/Platform/UC3/Exception.S
139 # Optimization level, can be [0, 1, 2, 3, s].
140 # 0 = turn off optimization. s = optimize for size.
141 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
149 # List any extra directories to look for include files here.
150 # Each directory must be seperated by a space.
151 # Use forward slashes for directory separators.
152 # For a directory that has spaces, enclose it in quotes.
153 EXTRAINCDIRS = $(LUFA_PATH)/
156 # Compiler flag to set the C Standard level.
158 # gnu89 = c89 plus GCC extensions
159 # c99 = ISO C99 standard (not yet fully implemented)
160 # gnu99 = c99 plus GCC extensions
161 CSTANDARD = -std=gnu99
164 # Place -D or -U options here for C sources
165 CDEFS = -DF_CPU=$(F_CPU)UL
166 CDEFS += -DF_USB=$(F_USB)UL
167 CDEFS += -DBOARD=BOARD_$(BOARD)
168 CDEFS += -DARCH=ARCH_$(ARCH)
169 CDEFS += $(LUFA_OPTS)
172 # Place -D or -U options here for ASM sources
173 ADEFS = -DF_CPU=$(F_CPU)
174 ADEFS += -DF_USB=$(F_USB)UL
175 ADEFS += -DBOARD=BOARD_$(BOARD)
176 ADEFS += -DARCH=ARCH_$(ARCH)
177 ADEFS += $(LUFA_OPTS)
179 # Place -D or -U options here for C++ sources
180 CPPDEFS = -DF_CPU=$(F_CPU)UL
181 CPPDEFS += -DF_USB=$(F_USB)UL
182 CPPDEFS += -DBOARD=BOARD_$(BOARD)
183 CPPDEFS += -DARCH=ARCH_$(ARCH)
184 CPPDEFS += $(LUFA_OPTS)
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 += -fno-strict-aliasing
204 CFLAGS += -masm-addr-pseudos
206 CFLAGS += -Wstrict-prototypes
207 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
208 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
209 CFLAGS += $(CSTANDARD)
212 #---------------- Compiler Options C++ ----------------
213 # -g*: generate debugging information
214 # -O*: optimization level
215 # -f...: tuning, see GCC manual and avr-libc documentation
216 # -Wall...: warning level
217 # -Wa,...: tell GCC to pass this to the assembler.
218 # -adhlns...: create assembler listing
219 CPPFLAGS = -g$(DEBUG)
220 CPPFLAGS += $(CPPDEFS)
222 CPPFLAGS += -funsigned-char
223 CPPFLAGS += -funsigned-bitfields
224 CPPFLAGS += -ffunction-sections
225 CPPFLAGS += -fno-strict-aliasing
226 CPPFLAGS += -fno-exceptions
227 CPPFLAGS += -masm-addr-pseudos
230 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
231 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
232 #CPPFLAGS += $(CSTANDARD)
235 #---------------- Assembler Options ----------------
236 # -Wa,...: tell GCC to pass this to the assembler.
237 # -adhlns: create listing
238 # -gstabs: have the assembler create line number information; note that
239 # for use in COFF files, additional information about filenames
240 # and function names needs to be present in the assembler source
241 # files -- see avr-libc docs [FIXME: not yet described there]
242 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
243 # dump that will be displayed for a given single line of source input.
244 ASFLAGS = -g3 $(ADEFS)
247 #---------------- Linker Options ----------------
248 # -Wl,...: tell GCC to pass this to linker.
249 # -Map: create map file
250 # --cref: add cross reference to map file
251 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
252 LDFLAGS += -Wl,--gc-sections --rodata-writable
253 LDFLAGS += -Wl,--direct-data
254 #LDFLAGS += -T avr32elf_uc3b0256.x
257 #============================================================================
260 # Define programs and commands.
263 OBJCOPY = avr32-objcopy
264 OBJDUMP = avr32-objdump
276 MSG_ERRORS_NONE = Errors: none
277 MSG_BEGIN = -------- begin --------
278 MSG_END = -------- end --------
279 MSG_SIZE_BEFORE = Size before:
280 MSG_SIZE_AFTER = Size after:
281 MSG_COFF = Converting to AVR COFF:
282 MSG_FLASH = Creating load file for Flash:
283 MSG_EEPROM = Creating load file for EEPROM:
284 MSG_EXTENDED_LISTING = Creating Extended Listing:
285 MSG_SYMBOL_TABLE = Creating Symbol Table:
286 MSG_LINKING = Linking:
287 MSG_COMPILING = Compiling C:
288 MSG_COMPILING_CPP = Compiling C++:
289 MSG_ASSEMBLING = Assembling:
290 MSG_CLEANING = Cleaning project:
291 MSG_CREATING_LIBRARY = Creating library:
296 # Define all object files.
297 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
299 # Define all listing files.
300 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
303 # Compiler flags to generate dependency files.
304 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
307 # Combine all necessary flags and optional flags.
308 # Add target processor to flags.
309 ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
310 ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
311 ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
318 all: begin gccversion sizebefore build sizeafter end
320 # Change the build target to build a HEX file or a library.
321 build: elf hex lss sym
329 LIBNAME=lib$(TARGET).a
335 # AVR Studio 3.x does not check make's exit code but relies on
336 # the following magic strings to be generated by the compile job.
346 # Display size of file.
347 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
348 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
349 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
350 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
354 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
355 2>/dev/null; echo; fi
358 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
359 2>/dev/null; echo; fi
363 # Display compiler version information.
368 # Program the device.
370 batchisp -hardware usb -device $(MCU) -operation erase f
371 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
372 batchisp -hardware usb -device $(MCU) -operation start reset 0
375 dfu-programmer $(MCU) erase
376 dfu-programmer $(MCU) flash $(TARGET).hex
377 dfu-programmer $(MCU) reset
380 # Create final output files (.hex, .eep) from ELF output file.
383 @echo $(MSG_FLASH) $@
384 $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
386 # Create extended listing file from ELF output file.
389 @echo $(MSG_EXTENDED_LISTING) $@
390 $(OBJDUMP) -h -S $< > $@
392 # Create a symbol table from ELF output file.
395 @echo $(MSG_SYMBOL_TABLE) $@
400 # Create library from object files.
401 .SECONDARY : $(TARGET).a
405 @echo $(MSG_CREATING_LIBRARY) $@
409 # Link: create ELF output file from object files.
410 .SECONDARY : $(TARGET).elf
414 @echo $(MSG_LINKING) $@
415 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
418 # Compile: create object files from C source files.
421 @echo $(MSG_COMPILING) $<
422 $(CC) -c $(ALL_CFLAGS) $< -o $@
425 # Compile: create object files from C++ source files.
426 $(OBJDIR)/%.o : %.cpp
428 @echo $(MSG_COMPILING_CPP) $<
429 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
432 # Compile: create assembler files from C source files.
434 $(CC) -S $(ALL_CFLAGS) $< -o $@
437 # Compile: create assembler files from C++ source files.
439 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
442 # Assemble: create object files from assembler source files.
445 @echo $(MSG_ASSEMBLING) $<
446 $(CC) -c $(ALL_ASFLAGS) $< -o $@
449 # Create preprocessed source for use in sending a bug report.
451 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
454 # Target: clean project.
455 clean: begin clean_list end
459 @echo $(MSG_CLEANING)
460 $(REMOVE) $(TARGET).hex
461 $(REMOVE) $(TARGET).cof
462 $(REMOVE) $(TARGET).elf
463 $(REMOVE) $(TARGET).map
464 $(REMOVE) $(TARGET).sym
465 $(REMOVE) $(TARGET).lss
466 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
467 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
468 $(REMOVE) $(SRC:.c=.s)
469 $(REMOVE) $(SRC:.c=.d)
470 $(REMOVE) $(SRC:.c=.i)
474 @echo Generating Project Documentation...
475 @doxygen Doxygen.conf
476 @echo Documentation Generation Complete.
481 # Create object files directory
482 $(shell mkdir $(OBJDIR) 2>/dev/null)
485 # Include the dependency files.
486 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
489 # Listing of phony targets.
490 .PHONY : all begin finish end sizebefore sizeafter gccversion \
491 build elf hex lss sym doxygen clean clean_list clean_doxygen \