Add missing SVN eol-style property to files where it was missing.
[pub/USBasp.git] / LUFA / CodeTemplates / makefile_template.uc3
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. <<
5 #
6 # Released to the Public Domain
7 #
8 # Additional material for this makefile was written by:
9 # Peter Fleury
10 # Tim Henigan
11 # Colin O'Flynn
12 # Reiner Patommel
13 # Markus Pfaff
14 # Sander Pool
15 # Frederik Rouleau
16 # Carlos Lamas
17 # Dean Camera
18 # Opendous Inc.
19 # Denver Gingerich
20 #
21 #----------------------------------------------------------------------------
22 # On command line:
23 #
24 # make all = Make software.
25 #
26 # make clean = Clean out built project files.
27 #
28 # make dfu = Download the hex file to the device, using dfu-programmer (must
29 # have dfu-programmer installed).
30 #
31 # make flip = Download the hex file to the device, using Atmel FLIP (must
32 # have Atmel FLIP installed).
33 #
34 # make doxygen = Generate DoxyGen documentation for the project (must have
35 # DoxyGen installed)
36 #
37 # make filename.s = Just compile filename.c into the assembler code only.
38 #
39 # make filename.i = Create a preprocessed source file for use in submitting
40 # bug reports to the GCC project.
41 #
42 # To rebuild project do "make clean" then "make all".
43 #----------------------------------------------------------------------------
44
45
46 # MCU name
47 MCU = ### INSERT NAME OF MICROCONTROLLER MODEL HERE ###
48
49
50 # Targeted chip architecture (see library "Architectures" documentation)
51 ARCH = UC3
52
53
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.
57 BOARD = ### INSERT NAME OF BOARD HERE, OR NONE IF NO BOARD DRIVERS USED ###
58
59
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.
65 #
66 # This should be the frequency the system core runs at, after the system clock
67 # has been set up correctly and started.
68 F_CPU = ### INSERT PRESCALED SYSTEM CLOCK SPEED HERE, IN HZ ###
69
70
71 # Input clock frequency.
72 # This will define a symbol, F_USB, in all source code files equal to the
73 # input clock frequency (before any prescaling is performed) in Hz. This value may
74 # differ from F_CPU, as the USB clock is often sourced from the same oscillator as
75 # the CPU clock, but run through multipliers and dividers to achieve the desired
76 # clock rate.
77 #
78 # For the UC3 chips, this should be equal to 48MHz or 96MHz.
79 F_USB = ### INSERT CLOCK TO USB MODULE HERE, IN HZ ###
80
81
82 # Output format. (can be srec, ihex, binary)
83 FORMAT = ihex
84
85
86 # Target file name (without extension).
87 TARGET = ### INSERT NAME OF MAIN FILENAME HERE, WITHOUT EXTENSION ###
88
89
90 # Object files directory
91 # To put object files in current directory, use a dot (.), do NOT make
92 # this an empty or blank macro!
93 OBJDIR = .
94
95
96 # Path to the LUFA library
97 LUFA_PATH = ### INSERT PATH TO LUFA LIBRARY RELATIVE TO PROJECT DIRECTORY HERE ###
98
99
100 # LUFA library compile-time options and predefined tokens (add '-D' before each token)
101 LUFA_OPTS = ### INSERT LUFA COMPILE TIME TOKES HERE ###
102
103
104 # Create the LUFA source path variables by including the LUFA root makefile
105 include $(LUFA_PATH)/LUFA/makefile
106
107
108 # List C source files here. (C dependencies are automatically generated.)
109 SRC = $(TARGET).c \
110 $(LUFA_SRC_USB) \
111 $(LUFA_SRC_USBCLASS)
112 ### INSERT ADDITIONAL PROJECT SOURCE FILENAMES OR LUFA MODULE NAMES HERE ###
113
114
115 # List C++ source files here. (C dependencies are automatically generated.)
116 CPPSRC =
117
118
119 # List Assembler source files here.
120 # Make them always end in a capital .S. Files ending in a lowercase .s
121 # will not be considered source files but generated files (assembler
122 # output from the compiler), and will be deleted upon "make clean"!
123 # Even though the DOS/Win* filesystem matches both .s and .S the same,
124 # it will preserve the spelling of the filenames, and gcc itself does
125 # care about how the name is spelled on its command-line.
126 ASRC =
127
128
129 # Optimization level, can be [0, 1, 2, 3, s].
130 # 0 = turn off optimization. s = optimize for size.
131 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
132 OPT = s
133
134
135 # List any extra directories to look for include files here.
136 # Each directory must be seperated by a space.
137 # Use forward slashes for directory separators.
138 # For a directory that has spaces, enclose it in quotes.
139 EXTRAINCDIRS = $(LUFA_PATH)/
140
141
142 # Compiler flag to set the C Standard level.
143 # c89 = "ANSI" C
144 # gnu89 = c89 plus GCC extensions
145 # c99 = ISO C99 standard (not yet fully implemented)
146 # gnu99 = c99 plus GCC extensions
147 CSTANDARD = -std=gnu99
148
149
150 # Place -D or -U options here for C sources
151 CDEFS = -DF_CPU=$(F_CPU)UL
152 CDEFS += -DF_USB=$(F_USB)UL
153 CDEFS += -DBOARD=BOARD_$(BOARD)
154 CDEFS += -DARCH=ARCH_$(ARCH)
155 CDEFS += $(LUFA_OPTS)
156
157
158 # Place -D or -U options here for ASM sources
159 ADEFS = -DF_CPU=$(F_CPU)
160 ADEFS += -DF_USB=$(F_USB)UL
161 ADEFS += -DBOARD=BOARD_$(BOARD)
162 ADEFS += -DARCH=ARCH_$(ARCH)
163 ADEFS += $(LUFA_OPTS)
164
165 # Place -D or -U options here for C++ sources
166 CPPDEFS = -DF_CPU=$(F_CPU)UL
167 CPPDEFS += -DF_USB=$(F_USB)UL
168 CPPDEFS += -DBOARD=BOARD_$(BOARD)
169 CPPDEFS += -DARCH=ARCH_$(ARCH)
170 CPPDEFS += $(LUFA_OPTS)
171
172
173 # Debugging level.
174 DEBUG = 3
175
176
177 #---------------- Compiler Options C ----------------
178 # -g*: generate debugging information
179 # -O*: optimization level
180 # -f...: tuning, see GCC manual and avr-libc documentation
181 # -Wall...: warning level
182 # -Wa,...: tell GCC to pass this to the assembler.
183 # -adhlns...: create assembler listing
184 CFLAGS = -g$(DEBUG)
185 CFLAGS += $(CDEFS)
186 CFLAGS += -O$(OPT)
187 CFLAGS += -funsigned-char
188 CFLAGS += -funsigned-bitfields
189 CFLAGS += -ffunction-sections
190 CFLAGS += -fno-strict-aliasing
191 CFLAGS += -Wall
192 CFLAGS += -Wstrict-prototypes
193 CFLAGS += -masm-addr-pseudos
194 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
195 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
196 CFLAGS += $(CSTANDARD)
197
198
199 #---------------- Compiler Options C++ ----------------
200 # -g*: generate debugging information
201 # -O*: optimization level
202 # -f...: tuning, see GCC manual and avr-libc documentation
203 # -Wall...: warning level
204 # -Wa,...: tell GCC to pass this to the assembler.
205 # -adhlns...: create assembler listing
206 CPPFLAGS = -g$(DEBUG)
207 CPPFLAGS += $(CPPDEFS)
208 CPPFLAGS += -O$(OPT)
209 CPPFLAGS += -funsigned-char
210 CPPFLAGS += -funsigned-bitfields
211 CPPFLAGS += -ffunction-sections
212 CPPFLAGS += -fno-strict-aliasing
213 CPPFLAGS += -fno-exceptions
214 CPPFLAGS += -masm-addr-pseudos
215 CPPFLAGS += -Wall
216 CPPFLAGS += -Wundef
217 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
218 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
219 #CPPFLAGS += $(CSTANDARD)
220
221
222 #---------------- Assembler Options ----------------
223 # -Wa,...: tell GCC to pass this to the assembler.
224 # -adhlns: create listing
225 # -gstabs: have the assembler create line number information; note that
226 # for use in COFF files, additional information about filenames
227 # and function names needs to be present in the assembler source
228 # files -- see avr-libc docs [FIXME: not yet described there]
229 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
230 # dump that will be displayed for a given single line of source input.
231 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
232
233
234 #---------------- Linker Options ----------------
235 # -Wl,...: tell GCC to pass this to linker.
236 # -Map: create map file
237 # --cref: add cross reference to map file
238 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
239 LDFLAGS += -Wl,--relax
240 LDFLAGS += -Wl,--gc-sections
241 LDFLAGS += -Wl,--rodata-writable
242 LDFLAGS += -Wl,--direct-data
243 #LDFLAGS += -T linker_script.x
244
245
246 #============================================================================
247
248
249 # Define programs and commands.
250 SHELL = sh
251 CC = avr32-gcc
252 OBJCOPY = avr32-objcopy
253 OBJDUMP = avr32-objdump
254 SIZE = avr32-size
255 AR = avr32-ar rcs
256 NM = avr32-nm
257 REMOVE = rm -f
258 REMOVEDIR = rm -rf
259 COPY = cp
260 WINSHELL = cmd
261
262
263 # Define Messages
264 # English
265 MSG_ERRORS_NONE = Errors: none
266 MSG_BEGIN = -------- begin --------
267 MSG_END = -------- end --------
268 MSG_SIZE_BEFORE = Size before:
269 MSG_SIZE_AFTER = Size after:
270 MSG_COFF = Converting to AVR COFF:
271 MSG_FLASH = Creating load file for Flash:
272 MSG_EEPROM = Creating load file for EEPROM:
273 MSG_EXTENDED_LISTING = Creating Extended Listing:
274 MSG_SYMBOL_TABLE = Creating Symbol Table:
275 MSG_LINKING = Linking:
276 MSG_COMPILING = Compiling C:
277 MSG_COMPILING_CPP = Compiling C++:
278 MSG_ASSEMBLING = Assembling:
279 MSG_CLEANING = Cleaning project:
280 MSG_CREATING_LIBRARY = Creating library:
281
282
283
284
285 # Define all object files.
286 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
287
288 # Define all listing files.
289 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
290
291
292 # Compiler flags to generate dependency files.
293 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
294
295
296 # Combine all necessary flags and optional flags.
297 # Add target processor to flags.
298 ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
299 ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
300 ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
301
302
303
304
305
306 # Default target.
307 all: begin gccversion sizebefore build sizeafter end
308
309 # Change the build target to build a HEX file or a library.
310 build: elf hex lss sym
311 #build: lib
312
313
314 elf: $(TARGET).elf
315 hex: $(TARGET).hex
316 lss: $(TARGET).lss
317 sym: $(TARGET).sym
318 LIBNAME=lib$(TARGET).a
319 lib: $(LIBNAME)
320
321
322
323 # Eye candy.
324 # AVR Studio 3.x does not check make's exit code but relies on
325 # the following magic strings to be generated by the compile job.
326 begin:
327 @echo
328 @echo $(MSG_BEGIN)
329
330 end:
331 @echo $(MSG_END)
332 @echo
333
334
335 # Display size of file.
336 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
337 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
338 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
339 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
340
341
342 sizebefore:
343 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
344 2>/dev/null; echo; fi
345
346 sizeafter:
347 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
348 2>/dev/null; echo; fi
349
350
351
352 # Display compiler version information.
353 gccversion :
354 @$(CC) --version
355
356
357 # Program the device.
358 flip: $(TARGET).hex
359 batchisp -hardware usb -device $(MCU) -operation erase f
360 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
361 batchisp -hardware usb -device $(MCU) -operation start reset 0
362
363 dfu: $(TARGET).hex
364 dfu-programmer $(MCU) erase
365 dfu-programmer $(MCU) flash $(TARGET).hex
366 dfu-programmer $(MCU) reset
367
368
369 # Create final output files (.hex, .eep) from ELF output file.
370 %.hex: %.elf
371 @echo
372 @echo $(MSG_FLASH) $@
373 $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
374
375 # Create extended listing file from ELF output file.
376 %.lss: %.elf
377 @echo
378 @echo $(MSG_EXTENDED_LISTING) $@
379 $(OBJDUMP) -h -S -z $< > $@
380
381 # Create a symbol table from ELF output file.
382 %.sym: %.elf
383 @echo
384 @echo $(MSG_SYMBOL_TABLE) $@
385 $(NM) -n $< > $@
386
387
388
389 # Create library from object files.
390 .SECONDARY : $(TARGET).a
391 .PRECIOUS : $(OBJ)
392 %.a: $(OBJ)
393 @echo
394 @echo $(MSG_CREATING_LIBRARY) $@
395 $(AR) $@ $(OBJ)
396
397
398 # Link: create ELF output file from object files.
399 .SECONDARY : $(TARGET).elf
400 .PRECIOUS : $(OBJ)
401 %.elf: $(OBJ)
402 @echo
403 @echo $(MSG_LINKING) $@
404 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
405
406
407 # Compile: create object files from C source files.
408 $(OBJDIR)/%.o : %.c
409 @echo
410 @echo $(MSG_COMPILING) $<
411 $(CC) -c $(ALL_CFLAGS) $< -o $@
412
413
414 # Compile: create object files from C++ source files.
415 $(OBJDIR)/%.o : %.cpp
416 @echo
417 @echo $(MSG_COMPILING_CPP) $<
418 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
419
420
421 # Compile: create assembler files from C source files.
422 %.s : %.c
423 $(CC) -S $(ALL_CFLAGS) $< -o $@
424
425
426 # Compile: create assembler files from C++ source files.
427 %.s : %.cpp
428 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
429
430
431 # Assemble: create object files from assembler source files.
432 $(OBJDIR)/%.o : %.S
433 @echo
434 @echo $(MSG_ASSEMBLING) $<
435 $(CC) -c $(ALL_ASFLAGS) $< -o $@
436
437
438 # Create preprocessed source for use in sending a bug report.
439 %.i : %.c
440 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
441
442
443 # Target: clean project.
444 clean: begin clean_list end
445
446 clean_list :
447 @echo
448 @echo $(MSG_CLEANING)
449 $(REMOVE) $(TARGET).hex
450 $(REMOVE) $(TARGET).cof
451 $(REMOVE) $(TARGET).elf
452 $(REMOVE) $(TARGET).map
453 $(REMOVE) $(TARGET).sym
454 $(REMOVE) $(TARGET).lss
455 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
456 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
457 $(REMOVE) $(SRC:.c=.s)
458 $(REMOVE) $(SRC:.c=.d)
459 $(REMOVE) $(SRC:.c=.i)
460 $(REMOVEDIR) .dep
461
462 doxygen:
463 @echo Generating Project Documentation...
464 @doxygen Doxygen.conf
465 @echo Documentation Generation Complete.
466
467 clean_doxygen:
468 rm -rf Documentation
469
470 # Create object files directory
471 $(shell mkdir $(OBJDIR) 2>/dev/null)
472
473
474 # Include the dependency files.
475 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
476
477
478 # Listing of phony targets.
479 .PHONY : all begin finish end sizebefore sizeafter gccversion \
480 build elf hex lss sym doxygen clean clean_list clean_doxygen \
481 dfu flip
482