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