Add tag for the 120219 release.
[pub/USBasp.git] / BuildTests / ModuleTest / makefile.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 = uc3a3256
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 = NONE
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 = 12000000
69
70
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.
74 #
75 # For the UC3 chips, this should be equal to 48MHz or 96MHz.
76 F_USB = 48000000
77
78
79 # Output format. (can be srec, ihex, binary)
80 FORMAT = ihex
81
82
83 # Target file name (without extension).
84 TARGET = Test
85
86
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!
90 OBJDIR = .
91
92
93 # Path to the LUFA library
94 LUFA_PATH = ../..
95
96
97 # LUFA library compile-time options and predefined tokens (add '-D' before each token)
98 LUFA_OPTS =
99
100
101 # Create the LUFA source path variables by including the LUFA root makefile
102 include $(LUFA_PATH)/LUFA/makefile
103
104
105 # List C source files here. (C dependencies are automatically generated.)
106 SRC = Test_C.c \
107 $(LUFA_SRC_USB) \
108 $(LUFA_SRC_USBCLASS) \
109 $(LUFA_SRC_SCHEDULER)
110
111
112 # List C++ source files here. (C dependencies are automatically generated.)
113 CPPSRC = Test_CPP.cpp
114
115
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.
123 ASRC = Dummy.S \
124 $(LUFA_PATH)/LUFA/Platform/UC3/Exception.S
125
126
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.)
130 OPT = s
131
132
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)/
138
139
140 # Compiler flag to set the C Standard level.
141 # c89 = "ANSI" C
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
146
147
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)
154
155
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)
162
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)
169
170
171 # Debugging level.
172 DEBUG = 3
173
174
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
182 CFLAGS = -g$(DEBUG)
183 CFLAGS += $(CDEFS)
184 CFLAGS += -O$(OPT)
185 CFLAGS += -funsigned-char
186 CFLAGS += -funsigned-bitfields
187 CFLAGS += -ffunction-sections
188 CFLAGS += -fno-strict-aliasing
189 CFLAGS += -masm-addr-pseudos
190 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
191 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
192 CFLAGS += $(CSTANDARD)
193 CFLAGS += -Werror
194 CFLAGS += -Wall
195 CFLAGS += -Wextra
196 CFLAGS += -Wstrict-prototypes
197 CFLAGS += -Wformat=2
198 CFLAGS += -Winit-self
199 CFLAGS += -Wswitch-enum
200 CFLAGS += -Wunused
201 CFLAGS += -Wundef
202 CFLAGS += -Wpointer-arith
203 #CFLAGS += -Wcast-align
204 CFLAGS += -Wwrite-strings
205 CFLAGS += -Wlogical-op
206 CFLAGS += -Wmissing-parameter-type
207 CFLAGS += -Wmissing-declarations
208 CFLAGS += -Wmissing-field-initializers
209 CFLAGS += -Wmissing-format-attribute
210 #CFLAGS += -Wredundant-decls
211 CFLAGS += -Wnested-externs
212 CFLAGS += -Woverlength-strings
213 #CFLAGS += -Wswitch-default
214 #CFLAGS += -Wc++-compat
215 #CFLAGS += -Wcast-qual
216 #CFLAGS += -Wconversion
217 #CFLAGS += -Wjump-misses-init
218 #CFLAGS += -pedantic
219
220
221 #---------------- Compiler Options C++ ----------------
222 # -g*: generate debugging information
223 # -O*: optimization level
224 # -f...: tuning, see GCC manual and avr-libc documentation
225 # -Wall...: warning level
226 # -Wa,...: tell GCC to pass this to the assembler.
227 # -adhlns...: create assembler listing
228 CPPFLAGS = -g$(DEBUG)
229 CPPFLAGS += $(CPPDEFS)
230 CPPFLAGS += -O$(OPT)
231 CPPFLAGS += -funsigned-char
232 CPPFLAGS += -funsigned-bitfields
233 CPPFLAGS += -ffunction-sections
234 CPPFLAGS += -fno-strict-aliasing
235 CPPFLAGS += -fno-exceptions
236 CPPFLAGS += -masm-addr-pseudos
237 CPPFLAGS += -Wall
238 CPPFLAGS += -Wundef
239 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
240 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
241 #CPPFLAGS += $(CSTANDARD)
242
243
244 #---------------- Assembler Options ----------------
245 # -Wa,...: tell GCC to pass this to the assembler.
246 # -adhlns: create listing
247 # -gstabs: have the assembler create line number information; note that
248 # for use in COFF files, additional information about filenames
249 # and function names needs to be present in the assembler source
250 # files -- see avr-libc docs [FIXME: not yet described there]
251 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
252 # dump that will be displayed for a given single line of source input.
253 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst)
254
255
256 #---------------- Linker Options ----------------
257 # -Wl,...: tell GCC to pass this to linker.
258 # -Map: create map file
259 # --cref: add cross reference to map file
260 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
261 LDFLAGS += -Wl,--gc-sections --rodata-writable
262 LDFLAGS += -Wl,--direct-data
263 #LDFLAGS += -T linker_script.x
264
265
266 #============================================================================
267
268
269 # Define programs and commands.
270 SHELL = sh
271 CC = avr32-gcc
272 OBJCOPY = avr32-objcopy
273 OBJDUMP = avr32-objdump
274 SIZE = avr32-size
275 AR = avr32-ar rcs
276 NM = avr32-nm
277 REMOVE = rm -f
278 REMOVEDIR = rm -rf
279 COPY = cp
280 WINSHELL = cmd
281
282
283 # Define Messages
284 # English
285 MSG_ERRORS_NONE = Errors: none
286 MSG_BEGIN = -------- begin --------
287 MSG_END = -------- end --------
288 MSG_SIZE_BEFORE = Size before:
289 MSG_SIZE_AFTER = Size after:
290 MSG_COFF = Converting to AVR COFF:
291 MSG_FLASH = Creating load file for Flash:
292 MSG_EEPROM = Creating load file for EEPROM:
293 MSG_EXTENDED_LISTING = Creating Extended Listing:
294 MSG_SYMBOL_TABLE = Creating Symbol Table:
295 MSG_LINKING = Linking:
296 MSG_COMPILING = Compiling C:
297 MSG_COMPILING_CPP = Compiling C++:
298 MSG_ASSEMBLING = Assembling:
299 MSG_CLEANING = Cleaning project:
300 MSG_CREATING_LIBRARY = Creating library:
301
302
303
304
305 # Define all object files.
306 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
307
308 # Define all listing files.
309 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
310
311
312 # Compiler flags to generate dependency files.
313 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
314
315
316 # Combine all necessary flags and optional flags.
317 # Add target processor to flags.
318 ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
319 ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
320 ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
321
322
323
324
325
326 # Default target.
327 all: begin gccversion sizebefore build sizeafter end
328
329 # Change the build target to build a HEX file or a library.
330 build: elf hex lss sym
331 #build: lib
332
333
334 elf: $(TARGET).elf
335 hex: $(TARGET).hex
336 lss: $(TARGET).lss
337 sym: $(TARGET).sym
338 LIBNAME=lib$(TARGET).a
339 lib: $(LIBNAME)
340
341
342
343 # Eye candy.
344 # AVR Studio 3.x does not check make's exit code but relies on
345 # the following magic strings to be generated by the compile job.
346 begin:
347 @echo
348 @echo $(MSG_BEGIN)
349
350 end:
351 @echo $(MSG_END)
352 @echo
353
354
355 # Display size of file.
356 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
357 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
358 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
359 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
360
361
362 sizebefore:
363 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
364 2>/dev/null; echo; fi
365
366 sizeafter:
367 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
368 2>/dev/null; echo; fi
369
370
371
372 # Display compiler version information.
373 gccversion :
374 @$(CC) --version
375
376
377 # Program the device.
378 flip: $(TARGET).hex
379 batchisp -hardware usb -device $(MCU) -operation erase f
380 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
381 batchisp -hardware usb -device $(MCU) -operation start reset 0
382
383 dfu: $(TARGET).hex
384 dfu-programmer $(MCU) erase
385 dfu-programmer $(MCU) flash $(TARGET).hex
386 dfu-programmer $(MCU) reset
387
388
389 # Create final output files (.hex, .eep) from ELF output file.
390 %.hex: %.elf
391 @echo
392 @echo $(MSG_FLASH) $@
393 $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
394
395 # Create extended listing file from ELF output file.
396 %.lss: %.elf
397 @echo
398 @echo $(MSG_EXTENDED_LISTING) $@
399 $(OBJDUMP) -h -S -z $< > $@
400
401 # Create a symbol table from ELF output file.
402 %.sym: %.elf
403 @echo
404 @echo $(MSG_SYMBOL_TABLE) $@
405 $(NM) -n $< > $@
406
407
408
409 # Create library from object files.
410 .SECONDARY : $(TARGET).a
411 .PRECIOUS : $(OBJ)
412 %.a: $(OBJ)
413 @echo
414 @echo $(MSG_CREATING_LIBRARY) $@
415 $(AR) $@ $(OBJ)
416
417
418 # Link: create ELF output file from object files.
419 .SECONDARY : $(TARGET).elf
420 .PRECIOUS : $(OBJ)
421 %.elf: $(OBJ)
422 @echo
423 @echo $(MSG_LINKING) $@
424 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
425
426
427 # Compile: create object files from C source files.
428 $(OBJDIR)/%.o : %.c
429 @echo
430 @echo $(MSG_COMPILING) $<
431 $(CC) -c $(ALL_CFLAGS) $< -o $@
432
433
434 # Compile: create object files from C++ source files.
435 $(OBJDIR)/%.o : %.cpp
436 @echo
437 @echo $(MSG_COMPILING_CPP) $<
438 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
439
440
441 # Compile: create assembler files from C source files.
442 %.s : %.c
443 $(CC) -S $(ALL_CFLAGS) $< -o $@
444
445
446 # Compile: create assembler files from C++ source files.
447 %.s : %.cpp
448 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
449
450
451 # Assemble: create object files from assembler source files.
452 $(OBJDIR)/%.o : %.S
453 @echo
454 @echo $(MSG_ASSEMBLING) $<
455 $(CC) -c $(ALL_ASFLAGS) $< -o $@
456
457
458 # Create preprocessed source for use in sending a bug report.
459 %.i : %.c
460 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
461
462
463 # Target: clean project.
464 clean: begin clean_list end
465
466 clean_list :
467 @echo
468 @echo $(MSG_CLEANING)
469 $(REMOVE) $(TARGET).hex
470 $(REMOVE) $(TARGET).cof
471 $(REMOVE) $(TARGET).elf
472 $(REMOVE) $(TARGET).map
473 $(REMOVE) $(TARGET).sym
474 $(REMOVE) $(TARGET).lss
475 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
476 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
477 $(REMOVE) $(SRC:.c=.s)
478 $(REMOVE) $(SRC:.c=.d)
479 $(REMOVE) $(SRC:.c=.i)
480 $(REMOVEDIR) .dep
481
482 doxygen:
483 @echo Generating Project Documentation \($(TARGET)\)...
484 @doxygen Doxygen.conf
485 @echo Documentation Generation Complete.
486
487 clean_doxygen:
488 rm -rf Documentation
489
490 checksource:
491 @for f in $(SRC) $(CPPSRC) $(ASRC); do \
492 if [ -f $$f ]; then \
493 echo "Found Source File: $$f" ; \
494 else \
495 echo "Source File Not Found: $$f" ; \
496 fi; done
497
498
499 # Create object files directory
500 $(shell mkdir $(OBJDIR) 2>/dev/null)
501
502
503 # Include the dependency files.
504 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
505
506
507 # Listing of phony targets.
508 .PHONY : all begin finish end sizebefore sizeafter gccversion \
509 build elf hex lss sym doxygen clean clean_list clean_doxygen \
510 dfu flip checksource
511