Statistics
| Branch: | Tag: | Revision:

root / LUFA / CodeTemplates / makefile_template.uc3 @ 978b99e5

History | View | Annotate | Download (13.9 KB)

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
# 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 = ### INSERT CLOCK TO USB MODULE HERE, IN HZ ###
77

    
78

    
79
# Output format. (can be srec, ihex, binary)
80
FORMAT = ihex
81

    
82

    
83
# Target file name (without extension).
84
TARGET = ### INSERT NAME OF MAIN FILENAME HERE, WITHOUT EXTENSION ###
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 = ### INSERT PATH TO LUFA LIBRARY RELATIVE TO PROJECT DIRECTORY HERE ###
95

    
96

    
97
# LUFA library compile-time options and predefined tokens (add '-D' before each token)
98
LUFA_OPTS = ### INSERT LUFA COMPILE TIME TOKES HERE ###
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 = $(TARGET).c                                                 \
107
	  $(LUFA_SRC_USB)                                             \
108
	  $(LUFA_SRC_USBCLASS)
109
      ### INSERT ADDITIONAL PROJECT SOURCE FILENAMES OR LUFA MODULE NAMES HERE ###
110

    
111

    
112
# List C++ source files here. (C dependencies are automatically generated.)
113
CPPSRC = 
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 =
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 += -Wall
189
CFLAGS += -Wstrict-prototypes
190
CFLAGS += -masm-addr-pseudos
191
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
192
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
193
CFLAGS += $(CSTANDARD)
194

    
195

    
196
#---------------- Compiler Options C++ ----------------
197
#  -g*:          generate debugging information
198
#  -O*:          optimization level
199
#  -f...:        tuning, see GCC manual and avr-libc documentation
200
#  -Wall...:     warning level
201
#  -Wa,...:      tell GCC to pass this to the assembler.
202
#    -adhlns...: create assembler listing
203
CPPFLAGS = -g$(DEBUG)
204
CPPFLAGS += $(CPPDEFS)
205
CPPFLAGS += -O$(OPT)
206
CPPFLAGS += -funsigned-char
207
CPPFLAGS += -funsigned-bitfields
208
CPPFLAGS += -ffunction-sections
209
CPPFLAGS += -fno-strict-aliasing
210
CPPFLAGS += -fno-exceptions
211
CPPFLAGS += -masm-addr-pseudos
212
CPPFLAGS += -Wall
213
CPPFLAGS += -Wundef
214
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
215
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
216
#CPPFLAGS += $(CSTANDARD)
217

    
218

    
219
#---------------- Assembler Options ----------------
220
#  -Wa,...:   tell GCC to pass this to the assembler.
221
#  -adhlns:   create listing
222
#  -gstabs:   have the assembler create line number information; note that
223
#             for use in COFF files, additional information about filenames
224
#             and function names needs to be present in the assembler source
225
#             files -- see avr-libc docs [FIXME: not yet described there]
226
#  -listing-cont-lines: Sets the maximum number of continuation lines of hex 
227
#       dump that will be displayed for a given single line of source input.
228
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
229

    
230

    
231
#---------------- Linker Options ----------------
232
#  -Wl,...:     tell GCC to pass this to linker.
233
#    -Map:      create map file
234
#    --cref:    add cross reference to  map file
235
LDFLAGS  = -Wl,-Map=$(TARGET).map,--cref
236
LDFLAGS += -Wl,--gc-sections --rodata-writable
237
LDFLAGS += -Wl,--direct-data
238
#LDFLAGS += -T linker_script.x
239

    
240

    
241
#============================================================================
242

    
243

    
244
# Define programs and commands.
245
SHELL = sh
246
CC = avr32-gcc
247
OBJCOPY = avr32-objcopy
248
OBJDUMP = avr32-objdump
249
SIZE = avr32-size
250
AR = avr32-ar rcs
251
NM = avr32-nm
252
REMOVE = rm -f
253
REMOVEDIR = rm -rf
254
COPY = cp
255
WINSHELL = cmd
256

    
257

    
258
# Define Messages
259
# English
260
MSG_ERRORS_NONE = Errors: none
261
MSG_BEGIN = -------- begin --------
262
MSG_END = --------  end  --------
263
MSG_SIZE_BEFORE = Size before: 
264
MSG_SIZE_AFTER = Size after:
265
MSG_COFF = Converting to AVR COFF:
266
MSG_FLASH = Creating load file for Flash:
267
MSG_EEPROM = Creating load file for EEPROM:
268
MSG_EXTENDED_LISTING = Creating Extended Listing:
269
MSG_SYMBOL_TABLE = Creating Symbol Table:
270
MSG_LINKING = Linking:
271
MSG_COMPILING = Compiling C:
272
MSG_COMPILING_CPP = Compiling C++:
273
MSG_ASSEMBLING = Assembling:
274
MSG_CLEANING = Cleaning project:
275
MSG_CREATING_LIBRARY = Creating library:
276

    
277

    
278

    
279

    
280
# Define all object files.
281
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o) 
282

    
283
# Define all listing files.
284
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst) 
285

    
286

    
287
# Compiler flags to generate dependency files.
288
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
289

    
290

    
291
# Combine all necessary flags and optional flags.
292
# Add target processor to flags.
293
ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
294
ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
295
ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
296

    
297

    
298

    
299

    
300

    
301
# Default target.
302
all: begin gccversion sizebefore build sizeafter end
303

    
304
# Change the build target to build a HEX file or a library.
305
build: elf hex lss sym
306
#build: lib
307

    
308

    
309
elf: $(TARGET).elf
310
hex: $(TARGET).hex
311
lss: $(TARGET).lss
312
sym: $(TARGET).sym
313
LIBNAME=lib$(TARGET).a
314
lib: $(LIBNAME)
315

    
316

    
317

    
318
# Eye candy.
319
# AVR Studio 3.x does not check make's exit code but relies on
320
# the following magic strings to be generated by the compile job.
321
begin:
322
	@echo
323
	@echo $(MSG_BEGIN)
324

    
325
end:
326
	@echo $(MSG_END)
327
	@echo
328

    
329

    
330
# Display size of file.
331
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
332
ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
333
MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
334
FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
335

    
336

    
337
sizebefore:
338
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
339
	2>/dev/null; echo; fi
340

    
341
sizeafter:
342
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
343
	2>/dev/null; echo; fi
344

    
345

    
346

    
347
# Display compiler version information.
348
gccversion : 
349
	@$(CC) --version
350

    
351

    
352
# Program the device.  
353
flip: $(TARGET).hex
354
	batchisp -hardware usb -device $(MCU) -operation erase f
355
	batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
356
	batchisp -hardware usb -device $(MCU) -operation start reset 0
357

    
358
dfu: $(TARGET).hex
359
	dfu-programmer $(MCU) erase
360
	dfu-programmer $(MCU) flash $(TARGET).hex
361
	dfu-programmer $(MCU) reset
362

    
363

    
364
# Create final output files (.hex, .eep) from ELF output file.
365
%.hex: %.elf
366
	@echo
367
	@echo $(MSG_FLASH) $@
368
	$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
369

    
370
# Create extended listing file from ELF output file.
371
%.lss: %.elf
372
	@echo
373
	@echo $(MSG_EXTENDED_LISTING) $@
374
	$(OBJDUMP) -h -S -z $< > $@
375

    
376
# Create a symbol table from ELF output file.
377
%.sym: %.elf
378
	@echo
379
	@echo $(MSG_SYMBOL_TABLE) $@
380
	$(NM) -n $< > $@
381

    
382

    
383

    
384
# Create library from object files.
385
.SECONDARY : $(TARGET).a
386
.PRECIOUS : $(OBJ)
387
%.a: $(OBJ)
388
	@echo
389
	@echo $(MSG_CREATING_LIBRARY) $@
390
	$(AR) $@ $(OBJ)
391

    
392

    
393
# Link: create ELF output file from object files.
394
.SECONDARY : $(TARGET).elf
395
.PRECIOUS : $(OBJ)
396
%.elf: $(OBJ)
397
	@echo
398
	@echo $(MSG_LINKING) $@
399
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
400

    
401

    
402
# Compile: create object files from C source files.
403
$(OBJDIR)/%.o : %.c
404
	@echo
405
	@echo $(MSG_COMPILING) $<
406
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
407

    
408

    
409
# Compile: create object files from C++ source files.
410
$(OBJDIR)/%.o : %.cpp
411
	@echo
412
	@echo $(MSG_COMPILING_CPP) $<
413
	$(CC) -c $(ALL_CPPFLAGS) $< -o $@ 
414

    
415

    
416
# Compile: create assembler files from C source files.
417
%.s : %.c
418
	$(CC) -S $(ALL_CFLAGS) $< -o $@
419

    
420

    
421
# Compile: create assembler files from C++ source files.
422
%.s : %.cpp
423
	$(CC) -S $(ALL_CPPFLAGS) $< -o $@
424

    
425

    
426
# Assemble: create object files from assembler source files.
427
$(OBJDIR)/%.o : %.S
428
	@echo
429
	@echo $(MSG_ASSEMBLING) $<
430
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
431

    
432

    
433
# Create preprocessed source for use in sending a bug report.
434
%.i : %.c
435
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 
436

    
437

    
438
# Target: clean project.
439
clean: begin clean_list end
440

    
441
clean_list :
442
	@echo
443
	@echo $(MSG_CLEANING)
444
	$(REMOVE) $(TARGET).hex
445
	$(REMOVE) $(TARGET).cof
446
	$(REMOVE) $(TARGET).elf
447
	$(REMOVE) $(TARGET).map
448
	$(REMOVE) $(TARGET).sym
449
	$(REMOVE) $(TARGET).lss
450
	$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
451
	$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
452
	$(REMOVE) $(SRC:.c=.s)
453
	$(REMOVE) $(SRC:.c=.d)
454
	$(REMOVE) $(SRC:.c=.i)
455
	$(REMOVEDIR) .dep
456

    
457
doxygen:
458
	@echo Generating Project Documentation \($(TARGET)\)...
459
	@doxygen Doxygen.conf
460
	@echo Documentation Generation Complete.
461

    
462
clean_doxygen:
463
	rm -rf Documentation
464

    
465
checksource:
466
	@for f in $(SRC) $(CPPSRC) $(ASRC); do \
467
		if [ -f $$f ]; then \
468
			echo "Found Source File: $$f" ; \
469
		else \
470
			echo "Source File Not Found: $$f" ; \
471
		fi; done 
472

    
473

    
474
# Create object files directory
475
$(shell mkdir $(OBJDIR) 2>/dev/null)
476

    
477

    
478
# Include the dependency files.
479
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
480

    
481

    
482
# Listing of phony targets.
483
.PHONY : all begin finish end sizebefore sizeafter gccversion \
484
build elf hex lss sym doxygen clean clean_list clean_doxygen  \
485
dfu flip checksource
486