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.)
109 # List C++ source files here. (C dependencies are automatically generated.)
113 # List Assembler source files here.
114 # Make them always end in a capital .S. Files ending in a lowercase .s
115 # will not be considered source files but generated files (assembler
116 # output from the compiler), and will be deleted upon "make clean"!
117 # Even though the DOS/Win* filesystem matches both .s and .S the same,
118 # it will preserve the spelling of the filenames, and gcc itself does
119 # care about how the name is spelled on its command-line.
123 # Optimization level, can be [0, 1, 2, 3, s].
124 # 0 = turn off optimization. s = optimize for size.
125 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
129 # List any extra directories to look for include files here.
130 # Each directory must be seperated by a space.
131 # Use forward slashes for directory separators.
132 # For a directory that has spaces, enclose it in quotes.
133 EXTRAINCDIRS = $(LUFA_PATH)/
136 # Compiler flag to set the C Standard level.
138 # gnu89 = c89 plus GCC extensions
139 # c99 = ISO C99 standard (not yet fully implemented)
140 # gnu99 = c99 plus GCC extensions
141 CSTANDARD = -std=gnu99
144 # Place -D or -U options here for C sources
145 CDEFS = -DF_CPU=$(F_CPU)UL
146 CDEFS += -DF_USB=$(F_USB)UL
147 CDEFS += -DBOARD=BOARD_$(BOARD)
148 CDEFS += -DARCH=ARCH_$(ARCH)
149 CDEFS += $(LUFA_OPTS)
152 # Place -D or -U options here for ASM sources
153 ADEFS = -DF_CPU=$(F_CPU)
154 ADEFS += -DF_USB=$(F_USB)UL
155 ADEFS += -DBOARD=BOARD_$(BOARD)
156 ADEFS += -DARCH=ARCH_$(ARCH)
157 ADEFS += $(LUFA_OPTS)
159 # Place -D or -U options here for C++ sources
160 CPPDEFS = -DF_CPU=$(F_CPU)UL
161 CPPDEFS += -DF_USB=$(F_USB)UL
162 CPPDEFS += -DBOARD=BOARD_$(BOARD)
163 CPPDEFS += -DARCH=ARCH_$(ARCH)
164 CPPDEFS += $(LUFA_OPTS)
171 #---------------- Compiler Options C ----------------
172 # -g*: generate debugging information
173 # -O*: optimization level
174 # -f...: tuning, see GCC manual and avr-libc documentation
175 # -Wall...: warning level
176 # -Wa,...: tell GCC to pass this to the assembler.
177 # -adhlns...: create assembler listing
181 CFLAGS += -funsigned-char
182 CFLAGS += -funsigned-bitfields
183 CFLAGS += -ffunction-sections
184 CFLAGS += -fno-strict-aliasing
186 CFLAGS += -Wstrict-prototypes
187 CFLAGS += -masm-addr-pseudos
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 += -ffunction-sections
206 CPPFLAGS += -fno-strict-aliasing
207 CPPFLAGS += -fno-exceptions
208 CPPFLAGS += -masm-addr-pseudos
211 #CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
212 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
213 #CPPFLAGS += $(CSTANDARD)
216 #---------------- Assembler Options ----------------
217 # -Wa,...: tell GCC to pass this to the assembler.
218 # -adhlns: create listing
219 # -gstabs: have the assembler create line number information; note that
220 # for use in COFF files, additional information about filenames
221 # and function names needs to be present in the assembler source
222 # files -- see avr-libc docs [FIXME: not yet described there]
223 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
224 # dump that will be displayed for a given single line of source input.
226 #ASFLAGS += -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
229 #---------------- Linker Options ----------------
230 # -Wl,...: tell GCC to pass this to linker.
231 # -Map: create map file
232 # --cref: add cross reference to map file
233 #LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
234 LDFLAGS += -Wl,--gc-sections --rodata-writable
235 LDFLAGS += -Wl,--direct-data
236 #LDFLAGS += -T linker_script.x
239 #============================================================================
242 # Define programs and commands.
245 OBJCOPY = avr32-objcopy
246 OBJDUMP = avr32-objdump
258 MSG_ERRORS_NONE = Errors: none
259 MSG_BEGIN = -------- begin --------
260 MSG_END = -------- end --------
261 MSG_SIZE_BEFORE = Size before:
262 MSG_SIZE_AFTER = Size after:
263 MSG_COFF = Converting to AVR COFF:
264 MSG_FLASH = Creating load file for Flash:
265 MSG_EEPROM = Creating load file for EEPROM:
266 MSG_EXTENDED_LISTING = Creating Extended Listing:
267 MSG_SYMBOL_TABLE = Creating Symbol Table:
268 MSG_LINKING = Linking:
269 MSG_COMPILING = Compiling C:
270 MSG_COMPILING_CPP = Compiling C++:
271 MSG_ASSEMBLING = Assembling:
272 MSG_CLEANING = Cleaning project:
273 MSG_CREATING_LIBRARY = Creating library:
278 # Define all object files.
279 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
281 # Define all listing files.
282 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
285 # Compiler flags to generate dependency files.
286 #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
289 # Combine all necessary flags and optional flags.
290 # Add target processor to flags.
291 ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
292 ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
293 ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
300 all: begin gccversion sizebefore build sizeafter end
302 # Change the build target to build a HEX file or a library.
303 build: elf hex lss sym
311 LIBNAME=lib$(TARGET).a
317 # AVR Studio 3.x does not check make's exit code but relies on
318 # the following magic strings to be generated by the compile job.
328 # Display size of file.
329 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
330 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
331 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
332 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
336 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
337 2>/dev/null; echo; fi
340 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
341 2>/dev/null; echo; fi
345 # Display compiler version information.
350 # Program the device.
352 batchisp -hardware usb -device $(MCU) -operation erase f
353 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
354 batchisp -hardware usb -device $(MCU) -operation start reset 0
357 dfu-programmer $(MCU) erase
358 dfu-programmer $(MCU) flash $(TARGET).hex
359 dfu-programmer $(MCU) reset
362 # Create final output files (.hex, .eep) from ELF output file.
365 @echo $(MSG_FLASH) $@
366 $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
368 # Create extended listing file from ELF output file.
371 @echo $(MSG_EXTENDED_LISTING) $@
372 $(OBJDUMP) -h -S -z $< > $@
374 # Create a symbol table from ELF output file.
377 @echo $(MSG_SYMBOL_TABLE) $@
382 # Create library from object files.
383 .SECONDARY : $(TARGET).a
387 @echo $(MSG_CREATING_LIBRARY) $@
391 # Link: create ELF output file from object files.
392 .SECONDARY : $(TARGET).elf
396 @echo $(MSG_LINKING) $@
397 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
400 # Compile: create object files from C source files.
403 @echo $(MSG_COMPILING) $<
404 $(CC) -c $(ALL_CFLAGS) $< -o $@
407 # Compile: create object files from C++ source files.
408 $(OBJDIR)/%.o : %.cpp
410 @echo $(MSG_COMPILING_CPP) $<
411 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
414 # Compile: create assembler files from C source files.
416 $(CC) -S $(ALL_CFLAGS) $< -o $@
419 # Compile: create assembler files from C++ source files.
421 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
424 # Assemble: create object files from assembler source files.
427 @echo $(MSG_ASSEMBLING) $<
428 $(CC) -c $(ALL_ASFLAGS) $< -o $@
431 # Create preprocessed source for use in sending a bug report.
433 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
436 # Target: clean project.
437 clean: begin clean_list end
441 @echo $(MSG_CLEANING)
442 $(REMOVE) $(TARGET).hex
443 $(REMOVE) $(TARGET).cof
444 $(REMOVE) $(TARGET).elf
445 $(REMOVE) $(TARGET).map
446 $(REMOVE) $(TARGET).sym
447 $(REMOVE) $(TARGET).lss
448 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
449 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
450 $(REMOVE) $(SRC:.c=.s)
451 $(REMOVE) $(SRC:.c=.d)
452 $(REMOVE) $(SRC:.c=.i)
456 @echo Generating Project Documentation \($(TARGET)\)...
457 @if ( ( cat Doxygen.conf ; echo "HTML_STYLESHEET=$(LUFA_PATH)/LUFA/DoxygenPages/Style/Style.css" ) | doxygen - 2>&1 | grep -v "warning: ignoring unsupported tag" ;); then \
460 @echo Documentation Generation Complete.
466 @for f in $(SRC) $(CPPSRC) $(ASRC); do \
467 if [ -f $$f ]; then \
468 echo "Found Source File: $$f" ; \
470 echo "Source File Not Found: $$f" ; \
474 # Create object files directory
475 $(shell mkdir $(OBJDIR) 2>/dev/null)
478 # Include the dependency files.
479 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
482 # Listing of phony targets.
483 .PHONY : all begin finish end sizebefore sizeafter gccversion \
484 build elf hex lss sym doxygen clean clean_list clean_doxygen \