Add makefile template for the AVR32 UC3 architecture.
[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 = 48000000
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
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 = Exception.S
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 = 0
133
134
135 # Debugging level.
136 DEBUG = 3
137
138
139 # List any extra directories to look for include files here.
140 # Each directory must be seperated by a space.
141 # Use forward slashes for directory separators.
142 # For a directory that has spaces, enclose it in quotes.
143 EXTRAINCDIRS = $(LUFA_PATH)/
144
145
146 # Compiler flag to set the C Standard level.
147 # c89 = "ANSI" C
148 # gnu89 = c89 plus GCC extensions
149 # c99 = ISO C99 standard (not yet fully implemented)
150 # gnu99 = c99 plus GCC extensions
151 CSTANDARD = -std=gnu99
152
153
154 # Place -D or -U options here for C sources
155 CDEFS = -DF_CPU=$(F_CPU)UL
156 CDEFS += -DF_USB=$(F_USB)UL
157 CDEFS += -DBOARD=BOARD_$(BOARD)
158 CDEFS += -DARCH=ARCH_$(ARCH)
159 CDEFS += $(LUFA_OPTS)
160
161
162 # Place -D or -U options here for ASM sources
163 ADEFS = -DF_CPU=$(F_CPU)
164 ADEFS += -DF_USB=$(F_USB)UL
165 ADEFS += -DBOARD=BOARD_$(BOARD)
166 ADEFS += -DARCH=ARCH_$(ARCH)
167 ADEFS += $(LUFA_OPTS)
168
169 # Place -D or -U options here for C++ sources
170 CPPDEFS = -DF_CPU=$(F_CPU)UL
171 CPPDEFS += -DF_USB=$(F_USB)UL
172 CPPDEFS += -DBOARD=BOARD_$(BOARD)
173 CPPDEFS += -DARCH=ARCH_$(ARCH)
174 CPPDEFS += $(LUFA_OPTS)
175 #CPPDEFS += -D__STDC_LIMIT_MACROS
176 #CPPDEFS += -D__STDC_CONSTANT_MACROS
177
178
179
180 #---------------- Compiler Options C ----------------
181 # -g*: generate debugging information
182 # -O*: optimization level
183 # -f...: tuning, see GCC manual and avr-libc documentation
184 # -Wall...: warning level
185 # -Wa,...: tell GCC to pass this to the assembler.
186 # -adhlns...: create assembler listing
187 CFLAGS = -g$(DEBUG)
188 CFLAGS += $(CDEFS)
189 CFLAGS += -O$(OPT)
190 CFLAGS += -funsigned-char
191 CFLAGS += -funsigned-bitfields
192 CFLAGS += -ffunction-sections
193 CFLAGS += -fno-strict-aliasing
194 CFLAGS += -masm-addr-pseudos
195 CFLAGS += -Wall
196 CFLAGS += -Wstrict-prototypes
197 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
198 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
199 CFLAGS += $(CSTANDARD)
200
201
202 #---------------- Compiler Options C++ ----------------
203 # -g*: generate debugging information
204 # -O*: optimization level
205 # -f...: tuning, see GCC manual and avr-libc documentation
206 # -Wall...: warning level
207 # -Wa,...: tell GCC to pass this to the assembler.
208 # -adhlns...: create assembler listing
209 CPPFLAGS = -g$(DEBUG)
210 CPPFLAGS += $(CPPDEFS)
211 CPPFLAGS += -O$(OPT)
212 CPPFLAGS += -funsigned-char
213 CPPFLAGS += -funsigned-bitfields
214 CPPFLAGS += -ffunction-sections
215 CPPFLAGS += -fno-strict-aliasing
216 CPPFLAGS += -fno-exceptions
217 CPPFLAGS += -masm-addr-pseudos
218 CPPFLAGS += -Wall
219 CPPFLAGS += -Wundef
220 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
221 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
222 #CPPFLAGS += $(CSTANDARD)
223
224
225 #---------------- Assembler Options ----------------
226 # -Wa,...: tell GCC to pass this to the assembler.
227 # -adhlns: create listing
228 # -gstabs: have the assembler create line number information; note that
229 # for use in COFF files, additional information about filenames
230 # and function names needs to be present in the assembler source
231 # files -- see avr-libc docs [FIXME: not yet described there]
232 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
233 # dump that will be displayed for a given single line of source input.
234 ASFLAGS = -g3 $(ADEFS)
235
236
237 #---------------- Linker Options ----------------
238 # -Wl,...: tell GCC to pass this to linker.
239 # -Map: create map file
240 # --cref: add cross reference to map file
241 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
242 LDFLAGS += -Wl,--gc-sections --rodata-writable
243 LDFLAGS += -Wl,--direct-data
244 #LDFLAGS += -T avr32elf_uc3b0256.x
245
246
247 #============================================================================
248
249
250 # Define programs and commands.
251 SHELL = sh
252 CC = avr32-gcc
253 OBJCOPY = avr32-objcopy
254 OBJDUMP = avr32-objdump
255 SIZE = avr32-size
256 AR = avr32-ar rcs
257 NM = avr32-nm
258 REMOVE = rm -f
259 REMOVEDIR = rm -rf
260 COPY = cp
261 WINSHELL = cmd
262
263
264 # Define Messages
265 # English
266 MSG_ERRORS_NONE = Errors: none
267 MSG_BEGIN = -------- begin --------
268 MSG_END = -------- end --------
269 MSG_SIZE_BEFORE = Size before:
270 MSG_SIZE_AFTER = Size after:
271 MSG_COFF = Converting to AVR COFF:
272 MSG_FLASH = Creating load file for Flash:
273 MSG_EEPROM = Creating load file for EEPROM:
274 MSG_EXTENDED_LISTING = Creating Extended Listing:
275 MSG_SYMBOL_TABLE = Creating Symbol Table:
276 MSG_LINKING = Linking:
277 MSG_COMPILING = Compiling C:
278 MSG_COMPILING_CPP = Compiling C++:
279 MSG_ASSEMBLING = Assembling:
280 MSG_CLEANING = Cleaning project:
281 MSG_CREATING_LIBRARY = Creating library:
282
283
284
285
286 # Define all object files.
287 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
288
289 # Define all listing files.
290 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
291
292
293 # Compiler flags to generate dependency files.
294 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
295
296
297 # Combine all necessary flags and optional flags.
298 # Add target processor to flags.
299 ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
300 ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
301 ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
302
303
304
305
306
307 # Default target.
308 all: begin gccversion sizebefore build sizeafter end
309
310 # Change the build target to build a HEX file or a library.
311 build: elf hex lss sym
312 #build: lib
313
314
315 elf: $(TARGET).elf
316 hex: $(TARGET).hex
317 lss: $(TARGET).lss
318 sym: $(TARGET).sym
319 LIBNAME=lib$(TARGET).a
320 lib: $(LIBNAME)
321
322
323
324 # Eye candy.
325 # AVR Studio 3.x does not check make's exit code but relies on
326 # the following magic strings to be generated by the compile job.
327 begin:
328 @echo
329 @echo $(MSG_BEGIN)
330
331 end:
332 @echo $(MSG_END)
333 @echo
334
335
336 # Display size of file.
337 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
338 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
339 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
340 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
341
342
343 sizebefore:
344 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
345 2>/dev/null; echo; fi
346
347 sizeafter:
348 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
349 2>/dev/null; echo; fi
350
351
352
353 # Display compiler version information.
354 gccversion :
355 @$(CC) --version
356
357
358 # Program the device.
359 flip: $(TARGET).hex
360 batchisp -hardware usb -device $(MCU) -operation erase f
361 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
362 batchisp -hardware usb -device $(MCU) -operation start reset 0
363
364 dfu: $(TARGET).hex
365 dfu-programmer $(MCU) erase
366 dfu-programmer $(MCU) flash $(TARGET).hex
367 dfu-programmer $(MCU) reset
368
369
370 # Create final output files (.hex, .eep) from ELF output file.
371 %.hex: %.elf
372 @echo
373 @echo $(MSG_FLASH) $@
374 $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
375
376 # Create extended listing file from ELF output file.
377 %.lss: %.elf
378 @echo
379 @echo $(MSG_EXTENDED_LISTING) $@
380 $(OBJDUMP) -h -S $< > $@
381
382 # Create a symbol table from ELF output file.
383 %.sym: %.elf
384 @echo
385 @echo $(MSG_SYMBOL_TABLE) $@
386 $(NM) -n $< > $@
387
388
389
390 # Create library from object files.
391 .SECONDARY : $(TARGET).a
392 .PRECIOUS : $(OBJ)
393 %.a: $(OBJ)
394 @echo
395 @echo $(MSG_CREATING_LIBRARY) $@
396 $(AR) $@ $(OBJ)
397
398
399 # Link: create ELF output file from object files.
400 .SECONDARY : $(TARGET).elf
401 .PRECIOUS : $(OBJ)
402 %.elf: $(OBJ)
403 @echo
404 @echo $(MSG_LINKING) $@
405 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
406
407
408 # Compile: create object files from C source files.
409 $(OBJDIR)/%.o : %.c
410 @echo
411 @echo $(MSG_COMPILING) $<
412 $(CC) -c $(ALL_CFLAGS) $< -o $@
413
414
415 # Compile: create object files from C++ source files.
416 $(OBJDIR)/%.o : %.cpp
417 @echo
418 @echo $(MSG_COMPILING_CPP) $<
419 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
420
421
422 # Compile: create assembler files from C source files.
423 %.s : %.c
424 $(CC) -S $(ALL_CFLAGS) $< -o $@
425
426
427 # Compile: create assembler files from C++ source files.
428 %.s : %.cpp
429 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
430
431
432 # Assemble: create object files from assembler source files.
433 $(OBJDIR)/%.o : %.S
434 @echo
435 @echo $(MSG_ASSEMBLING) $<
436 $(CC) -c $(ALL_ASFLAGS) $< -o $@
437
438
439 # Create preprocessed source for use in sending a bug report.
440 %.i : %.c
441 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
442
443
444 # Target: clean project.
445 clean: begin clean_list end
446
447 clean_list :
448 @echo
449 @echo $(MSG_CLEANING)
450 $(REMOVE) $(TARGET).hex
451 $(REMOVE) $(TARGET).cof
452 $(REMOVE) $(TARGET).elf
453 $(REMOVE) $(TARGET).map
454 $(REMOVE) $(TARGET).sym
455 $(REMOVE) $(TARGET).lss
456 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
457 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
458 $(REMOVE) $(SRC:.c=.s)
459 $(REMOVE) $(SRC:.c=.d)
460 $(REMOVE) $(SRC:.c=.i)
461 $(REMOVEDIR) .dep
462
463 doxygen:
464 @echo Generating Project Documentation...
465 @doxygen Doxygen.conf
466 @echo Documentation Generation Complete.
467
468 clean_doxygen:
469 rm -rf Documentation
470
471 # Create object files directory
472 $(shell mkdir $(OBJDIR) 2>/dev/null)
473
474
475 # Include the dependency files.
476 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
477
478
479 # Listing of phony targets.
480 .PHONY : all begin finish end sizebefore sizeafter gccversion \
481 build elf hex lss sym doxygen clean clean_list clean_doxygen \
482 dfu flip
483