Fix incorrect macro guard in the UC3 EndpointStream header file.
[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,--gc-sections --rodata-writable
240 LDFLAGS += -Wl,--direct-data
241 #LDFLAGS += -T linker_script.x
242
243
244 #============================================================================
245
246
247 # Define programs and commands.
248 SHELL = sh
249 CC = avr32-gcc
250 OBJCOPY = avr32-objcopy
251 OBJDUMP = avr32-objdump
252 SIZE = avr32-size
253 AR = avr32-ar rcs
254 NM = avr32-nm
255 REMOVE = rm -f
256 REMOVEDIR = rm -rf
257 COPY = cp
258 WINSHELL = cmd
259
260
261 # Define Messages
262 # English
263 MSG_ERRORS_NONE = Errors: none
264 MSG_BEGIN = -------- begin --------
265 MSG_END = -------- end --------
266 MSG_SIZE_BEFORE = Size before:
267 MSG_SIZE_AFTER = Size after:
268 MSG_COFF = Converting to AVR COFF:
269 MSG_FLASH = Creating load file for Flash:
270 MSG_EEPROM = Creating load file for EEPROM:
271 MSG_EXTENDED_LISTING = Creating Extended Listing:
272 MSG_SYMBOL_TABLE = Creating Symbol Table:
273 MSG_LINKING = Linking:
274 MSG_COMPILING = Compiling C:
275 MSG_COMPILING_CPP = Compiling C++:
276 MSG_ASSEMBLING = Assembling:
277 MSG_CLEANING = Cleaning project:
278 MSG_CREATING_LIBRARY = Creating library:
279
280
281
282
283 # Define all object files.
284 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
285
286 # Define all listing files.
287 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
288
289
290 # Compiler flags to generate dependency files.
291 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
292
293
294 # Combine all necessary flags and optional flags.
295 # Add target processor to flags.
296 ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
297 ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
298 ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
299
300
301
302
303
304 # Default target.
305 all: begin gccversion sizebefore build sizeafter end
306
307 # Change the build target to build a HEX file or a library.
308 build: elf hex lss sym
309 #build: lib
310
311
312 elf: $(TARGET).elf
313 hex: $(TARGET).hex
314 lss: $(TARGET).lss
315 sym: $(TARGET).sym
316 LIBNAME=lib$(TARGET).a
317 lib: $(LIBNAME)
318
319
320
321 # Eye candy.
322 # AVR Studio 3.x does not check make's exit code but relies on
323 # the following magic strings to be generated by the compile job.
324 begin:
325 @echo
326 @echo $(MSG_BEGIN)
327
328 end:
329 @echo $(MSG_END)
330 @echo
331
332
333 # Display size of file.
334 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
335 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
336 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
337 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
338
339
340 sizebefore:
341 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
342 2>/dev/null; echo; fi
343
344 sizeafter:
345 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
346 2>/dev/null; echo; fi
347
348
349
350 # Display compiler version information.
351 gccversion :
352 @$(CC) --version
353
354
355 # Program the device.
356 flip: $(TARGET).hex
357 batchisp -hardware usb -device $(MCU) -operation erase f
358 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
359 batchisp -hardware usb -device $(MCU) -operation start reset 0
360
361 dfu: $(TARGET).hex
362 dfu-programmer $(MCU) erase
363 dfu-programmer $(MCU) flash $(TARGET).hex
364 dfu-programmer $(MCU) reset
365
366
367 # Create final output files (.hex, .eep) from ELF output file.
368 %.hex: %.elf
369 @echo
370 @echo $(MSG_FLASH) $@
371 $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
372
373 # Create extended listing file from ELF output file.
374 %.lss: %.elf
375 @echo
376 @echo $(MSG_EXTENDED_LISTING) $@
377 $(OBJDUMP) -h -S -z $< > $@
378
379 # Create a symbol table from ELF output file.
380 %.sym: %.elf
381 @echo
382 @echo $(MSG_SYMBOL_TABLE) $@
383 $(NM) -n $< > $@
384
385
386
387 # Create library from object files.
388 .SECONDARY : $(TARGET).a
389 .PRECIOUS : $(OBJ)
390 %.a: $(OBJ)
391 @echo
392 @echo $(MSG_CREATING_LIBRARY) $@
393 $(AR) $@ $(OBJ)
394
395
396 # Link: create ELF output file from object files.
397 .SECONDARY : $(TARGET).elf
398 .PRECIOUS : $(OBJ)
399 %.elf: $(OBJ)
400 @echo
401 @echo $(MSG_LINKING) $@
402 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
403
404
405 # Compile: create object files from C source files.
406 $(OBJDIR)/%.o : %.c
407 @echo
408 @echo $(MSG_COMPILING) $<
409 $(CC) -c $(ALL_CFLAGS) $< -o $@
410
411
412 # Compile: create object files from C++ source files.
413 $(OBJDIR)/%.o : %.cpp
414 @echo
415 @echo $(MSG_COMPILING_CPP) $<
416 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
417
418
419 # Compile: create assembler files from C source files.
420 %.s : %.c
421 $(CC) -S $(ALL_CFLAGS) $< -o $@
422
423
424 # Compile: create assembler files from C++ source files.
425 %.s : %.cpp
426 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
427
428
429 # Assemble: create object files from assembler source files.
430 $(OBJDIR)/%.o : %.S
431 @echo
432 @echo $(MSG_ASSEMBLING) $<
433 $(CC) -c $(ALL_ASFLAGS) $< -o $@
434
435
436 # Create preprocessed source for use in sending a bug report.
437 %.i : %.c
438 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
439
440
441 # Target: clean project.
442 clean: begin clean_list end
443
444 clean_list :
445 @echo
446 @echo $(MSG_CLEANING)
447 $(REMOVE) $(TARGET).hex
448 $(REMOVE) $(TARGET).cof
449 $(REMOVE) $(TARGET).elf
450 $(REMOVE) $(TARGET).map
451 $(REMOVE) $(TARGET).sym
452 $(REMOVE) $(TARGET).lss
453 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
454 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
455 $(REMOVE) $(SRC:.c=.s)
456 $(REMOVE) $(SRC:.c=.d)
457 $(REMOVE) $(SRC:.c=.i)
458 $(REMOVEDIR) .dep
459
460 doxygen:
461 @echo Generating Project Documentation...
462 @doxygen Doxygen.conf
463 @echo Documentation Generation Complete.
464
465 clean_doxygen:
466 rm -rf Documentation
467
468 # Create object files directory
469 $(shell mkdir $(OBJDIR) 2>/dev/null)
470
471
472 # Include the dependency files.
473 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
474
475
476 # Listing of phony targets.
477 .PHONY : all begin finish end sizebefore sizeafter gccversion \
478 build elf hex lss sym doxygen clean clean_list clean_doxygen \
479 dfu flip
480