]> git.sur5r.net Git - freertos/blob - Demo/lwIP_AVR32_UC3/AT32UC3A/GCC/Makefile
Add AVR32 port and demo files.
[freertos] / Demo / lwIP_AVR32_UC3 / AT32UC3A / GCC / Makefile
1 # Hey Emacs, this is a -*- makefile -*-
2
3 # Goals available on make command line:
4 #
5 # [all]                   Default goal: build the project.
6 # clean                   Clean up the project.
7 # rebuild                 Rebuild the project.
8 # ccversion               Display CC version information.
9 # cppfiles  file.i        Generate preprocessed files from C source files.
10 # asfiles   file.x        Generate preprocessed assembler files from C and assembler source files.
11 # objfiles  file.o        Generate object files from C and assembler source files.
12 # a         file.a        Archive: create A output file from object files.
13 # elf       file.elf      Link: create ELF output file from object files.
14 # lss       file.lss      Create extended listing from target output file.
15 # sym       file.sym      Create symbol table from target output file.
16 # bin       file.bin      Create binary image from ELF output file.
17 # sizes                   Display target size information.
18 # cpuinfo                 Get CPU information.
19 # halt                    Stop CPU execution.
20 # program                 Program MCU memory from ELF output file.
21 # reset                   Reset CPU.
22 # debug                   Open a debug connection with the MCU.
23 # run                     Start CPU execution.
24 # readregs                Read CPU registers.
25 # doc                     Build the documentation.
26 # cleandoc                Clean up the documentation.
27 # rebuilddoc              Rebuild the documentation.
28 # verbose                 Display main executed commands.
29
30 # Copyright (c) 2007, Atmel Corporation All rights reserved.
31 #
32 # Redistribution and use in source and binary forms, with or without
33 # modification, are permitted provided that the following conditions are met:
34 #
35 # 1. Redistributions of source code must retain the above copyright notice, this
36 # list of conditions and the following disclaimer.
37 #
38 # 2. Redistributions in binary form must reproduce the above copyright notice,
39 # this list of conditions and the following disclaimer in the documentation and/
40 # or other materials provided with the distribution.
41 #
42 # 3. The name of ATMEL may not be used to endorse or promote products derived
43 # from this software without specific prior written permission.
44 #
45 # THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
46 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
47 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
48 # SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
49 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
50 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
51 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
52 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
53 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
54 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55
56
57 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
58 # ENVIRONMENT SETTINGS
59 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
60
61 FirstWord = $(if $(1),$(word 1,$(1)))
62 LastWord  = $(if $(1),$(word $(words $(1)),$(1)))
63
64 MAKE      = make
65 MAKECFG   = config.mk
66 TGTTYPE   = $(suffix $(TARGET))
67 TGTFILE   = $(PART)-$(TARGET)
68
69 RM        = rm -Rf
70
71 AR        = avr32-ar
72 ARFLAGS   = rcs
73
74 CPP       = $(CC) -E
75 CPPFLAGS  = -march=$(ARCH) -mpart=$(PART) $(WARNINGS) $(DEFS) \
76             $(PLATFORM_INC_PATH:%=-I%) $(INC_PATH:%=-I%) $(CPP_EXTRA_FLAGS)
77 DPNDFILES = $(CSRCS:.c=.d) $(ASSRCS:.S=.d)
78 CPPFILES  = $(CSRCS:.c=.i)
79
80 CC        = avr32-gcc
81 CFLAGS    = $(DEBUG) $(OPTIMIZATION) $(C_EXTRA_FLAGS)
82 ASFILES   = $(CSRCS:.c=.x) $(ASSRCS:.S=.x)
83
84 AS        = avr32-as
85 ASFLAGS   = $(DEBUG) $(AS_EXTRA_FLAGS)
86 OBJFILES  = $(CSRCS:.c=.o) $(ASSRCS:.S=.o)
87
88 LD        = avr32-ld
89 LDFLAGS   = -march=$(ARCH) -mpart=$(PART) \
90             $(LIB_PATH:%=-L%) $(LINKER_SCRIPT:%=-T%) $(LD_EXTRA_FLAGS)
91 LOADLIBES =
92 LDLIBS    = $(LIBS:%=-l%)
93
94 OBJDUMP   = avr32-objdump
95 LSS       = $(TGTFILE:$(TGTTYPE)=.lss)
96
97 NM        = avr32-nm
98 SYM       = $(TGTFILE:$(TGTTYPE)=.sym)
99
100 OBJCOPY   = avr32-objcopy
101 BIN       = $(TGTFILE:$(TGTTYPE)=.bin)
102
103 SIZE      = avr32-size
104
105 SUDO      = $(shell if [ -x /usr/bin/sudo ]; then echo sudo; fi)
106
107 SLEEP     = sleep
108 SLEEPUSB  = 9
109
110 PROGRAM   = avr32program
111
112 DBGPROXY  = avr32gdbproxy 
113
114 DOCGEN    = doxygen
115
116
117 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
118 # MESSAGES
119 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
120
121 ERR_TARGET_TYPE       = Target type not supported: `$(TGTTYPE)'
122 MSG_CLEANING          = Cleaning project.
123 MSG_PREPROCESSING     = Preprocessing \`$<\' to \`$@\'.
124 MSG_COMPILING         = Compiling \`$<\' to \`$@\'.
125 MSG_ASSEMBLING        = Assembling \`$<\' to \`$@\'.
126 MSG_ARCHIVING         = Archiving to \`$@\'.
127 MSG_LINKING           = Linking to \`$@\'.
128 MSG_EXTENDED_LISTING  = Creating extended listing to \`$@\'.
129 MSG_SYMBOL_TABLE      = Creating symbol table to \`$@\'.
130 MSG_BINARY_IMAGE      = Creating binary image to \`$@\'.
131 MSG_GETTING_CPU_INFO  = Getting CPU information.
132 MSG_HALTING           = Stopping CPU execution.
133 MSG_PROGRAMMING       = Programming MCU memory from \`$<\'.
134 MSG_RESETTING         = Resetting CPU.
135 MSG_DEBUGGING         = Opening debug connection with MCU.
136 MSG_RUNNING           = Starting CPU execution.
137 MSG_READING_CPU_REGS  = Reading CPU registers.
138 MSG_CLEANING_DOC      = Cleaning documentation.
139 MSG_GENERATING_DOC    = Generating documentation to \`$(DOC_PATH)\'.
140
141
142 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
143 # MAKE RULES
144 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
145
146 # Include the make configuration file.
147 include $(MAKECFG)
148
149 # ** ** TOP-LEVEL RULES ** **
150
151 # Default goal: build the project.
152 ifeq ($(TGTTYPE),.a)
153 .PHONY: all
154 all: ccversion a lss sym
155 else
156 ifeq ($(TGTTYPE),.elf)
157 .PHONY: all
158 all: ccversion elf lss sym bin sizes
159 else
160 $(error $(ERR_TARGET_TYPE))
161 endif
162 endif
163
164 # Clean up the project.
165 .PHONY: clean
166 clean:
167         @echo $(MSG_CLEANING)
168         -$(VERBOSE_CMD)$(RM) $(BIN)
169         -$(VERBOSE_CMD)$(RM) $(SYM)
170         -$(VERBOSE_CMD)$(RM) $(LSS)
171         -$(VERBOSE_CMD)$(RM) $(TGTFILE)
172         -$(VERBOSE_CMD)$(RM) $(OBJFILES)
173         -$(VERBOSE_CMD)$(RM) $(ASFILES)
174         -$(VERBOSE_CMD)$(RM) $(CPPFILES)
175         -$(VERBOSE_CMD)$(RM) $(DPNDFILES)
176         $(VERBOSE_NL)
177
178 # Rebuild the project.
179 .PHONY: rebuild
180 rebuild: clean all
181
182 # Display CC version information.
183 .PHONY: ccversion
184 ccversion:
185         @echo
186         @echo
187         @$(CC) --version
188
189 # Generate preprocessed files from C source files.
190 .PHONY: cppfiles
191 cppfiles: $(CPPFILES)
192
193 # Generate preprocessed assembler files from C and assembler source files.
194 .PHONY: asfiles
195 asfiles: $(ASFILES)
196
197 # Generate object files from C and assembler source files.
198 .PHONY: objfiles
199 objfiles: $(OBJFILES)
200
201 ifeq ($(TGTTYPE),.a)
202 # Archive: create A output file from object files.
203 .PHONY: a
204 a: $(TGTFILE)
205 else
206 ifeq ($(TGTTYPE),.elf)
207 # Link: create ELF output file from object files.
208 .PHONY: elf
209 elf: $(TGTFILE)
210 endif
211 endif
212
213 # Create extended listing from target output file.
214 .PHONY: lss
215 lss: $(LSS)
216
217 # Create symbol table from target output file.
218 .PHONY: sym
219 sym: $(SYM)
220
221 ifeq ($(TGTTYPE),.elf)
222 # Create binary image from ELF output file.
223 .PHONY: bin
224 bin: $(BIN)
225 endif
226
227 # Display target size information.
228 .PHONY: sizes
229 sizes: $(TGTFILE)
230         @echo
231         @echo
232         @$(SIZE) -Ax $<
233
234 ifeq ($(TGTTYPE),.elf)
235
236 # Get CPU information.
237 .PHONY: cpuinfo
238 cpuinfo:
239         @echo
240         @echo $(MSG_GETTING_CPU_INFO)
241         $(VERBOSE_CMD)$(SUDO) $(PROGRAM) -cUSB cpuinfo
242 ifneq ($(call LastWord,$(filter cpuinfo program reset debug run readregs,$(MAKECMDGOALS))),cpuinfo)
243         @$(SLEEP) $(SLEEPUSB)
244 else
245         @echo
246 endif
247
248 # Stop CPU execution.
249 .PHONY: halt
250 halt:
251 ifeq ($(filter cpuinfo program reset run readregs,$(MAKECMDGOALS)),)
252         @echo
253         @echo $(MSG_HALTING)
254         $(VERBOSE_CMD)$(SUDO) $(PROGRAM) -cUSB halt
255 ifneq ($(call LastWord,$(filter halt debug,$(MAKECMDGOALS))),halt)
256         @$(SLEEP) $(SLEEPUSB)
257 else
258         @echo
259 endif
260 else
261         @echo > /dev/null
262 endif
263
264 # Program MCU memory from ELF output file.
265 .PHONY: program
266 program: $(TGTFILE)
267         @echo
268         @echo $(MSG_PROGRAMMING)
269         $(VERBOSE_CMD)$(SUDO) $(PROGRAM) -cUSB program $(FLASH:%=-f%) -e -v -R $(if $(findstring run,$(MAKECMDGOALS)),-r) $<
270 ifneq ($(call LastWord,$(filter cpuinfo program debug readregs,$(MAKECMDGOALS))),program)
271         @$(SLEEP) $(SLEEPUSB)
272 else
273         @echo
274 endif
275
276 # Reset CPU.
277 .PHONY: reset
278 reset:
279 ifeq ($(filter program run,$(MAKECMDGOALS)),)
280         @echo
281         @echo $(MSG_RESETTING)
282         $(VERBOSE_CMD)$(SUDO) $(PROGRAM) -cUSB reset
283 ifneq ($(call LastWord,$(filter cpuinfo reset debug readregs,$(MAKECMDGOALS))),reset)
284         @$(SLEEP) $(SLEEPUSB)
285 else
286         @echo
287 endif
288 else
289         @echo > /dev/null
290 endif
291
292 # Open a debug connection with the MCU.
293 .PHONY: debug
294 debug:
295         @echo
296         @echo $(MSG_DEBUGGING)
297         $(VERBOSE_CMD)$(SUDO) $(DBGPROXY) -cUSB $(patsubst cfi@%,-f%,$(FLASH:internal@%=-f%))
298 ifneq ($(call LastWord,$(filter cpuinfo halt program reset debug run readregs,$(MAKECMDGOALS))),debug)
299         @$(SLEEP) $(SLEEPUSB)
300 else
301         @echo
302 endif
303
304 # Start CPU execution.
305 .PHONY: run
306 run:
307 ifeq ($(findstring program,$(MAKECMDGOALS)),)
308         @echo
309         @echo $(MSG_RUNNING)
310         $(VERBOSE_CMD)$(SUDO) $(PROGRAM) -cUSB run $(if $(findstring reset,$(MAKECMDGOALS)),-R)
311 ifneq ($(call LastWord,$(filter cpuinfo debug run readregs,$(MAKECMDGOALS))),run)
312         @$(SLEEP) $(SLEEPUSB)
313 else
314         @echo
315 endif
316 else
317         @echo > /dev/null
318 endif
319
320 # Read CPU registers.
321 .PHONY: readregs
322 readregs:
323         @echo
324         @echo $(MSG_READING_CPU_REGS)
325         $(VERBOSE_CMD)$(SUDO) $(PROGRAM) -cUSB readregs
326 ifneq ($(call LastWord,$(filter cpuinfo program reset debug run readregs,$(MAKECMDGOALS))),readregs)
327         @$(SLEEP) $(SLEEPUSB)
328 else
329         @echo
330 endif
331
332 endif
333
334 # Build the documentation.
335 .PHONY: doc
336 doc:
337         @echo
338         @echo $(MSG_GENERATING_DOC)
339         $(VERBOSE_CMD)cd $(dir $(DOC_CFG)) && $(DOCGEN) $(notdir $(DOC_CFG))
340         @echo
341
342 # Clean up the documentation.
343 .PHONY: cleandoc
344 cleandoc:
345         @echo $(MSG_CLEANING_DOC)
346         -$(VERBOSE_CMD)$(RM) $(DOC_PATH)
347         $(VERBOSE_NL)
348
349 # Rebuild the documentation.
350 .PHONY: rebuilddoc
351 rebuilddoc: cleandoc doc
352
353 # Display main executed commands.
354 .PHONY: verbose
355 ifeq ($(MAKECMDGOALS),verbose)
356 verbose: all
357 else
358 verbose:
359         @echo > /dev/null
360 endif
361 ifneq ($(findstring verbose,$(MAKECMDGOALS)),)
362 # Prefix displaying the following command if and only if verbose is a goal.
363 VERBOSE_CMD =
364 # New line displayed if and only if verbose is a goal.
365 VERBOSE_NL  = @echo
366 else
367 VERBOSE_CMD = @
368 VERBOSE_NL  =
369 endif
370
371 # ** ** COMPILATION RULES ** **
372
373 # Include silently the dependency files.
374 -include $(DPNDFILES)
375
376 # The dependency files are not built alone but along with first generation files.
377 $(DPNDFILES):
378
379 # First generation files depend on make files.
380 $(CPPFILES) $(ASFILES) $(OBJFILES): Makefile $(MAKECFG)
381
382 ifeq ($(TGTTYPE),.elf)
383 # Files resulting from linking depend on linker script.
384 $(TGTFILE): $(LINKER_SCRIPT)
385 endif
386
387 # Preprocess: create preprocessed files from C source files.
388 %.i: %.c %.d
389         @echo $(MSG_PREPROCESSING)
390         $(VERBOSE_CMD)$(CPP) $(CPPFLAGS) -MD -MP -MT '$*.i $*.x $*.o' -o $@ $<
391         @touch $*.d
392         @touch $@
393         $(VERBOSE_NL)
394
395 # Preprocess & compile: create assembler files from C source files.
396 %.x: %.c %.d
397         @echo $(MSG_COMPILING)
398         $(VERBOSE_CMD)$(CC) -S $(CPPFLAGS) -MD -MP -MT '$*.i $*.o' $(CFLAGS) -o $@ $<
399         @touch $*.d
400         @touch $@
401         $(VERBOSE_NL)
402
403 # Preprocess: create preprocessed files from assembler source files.
404 %.x: %.S %.d
405         @echo $(MSG_PREPROCESSING)
406         $(VERBOSE_CMD)$(CPP) $(CPPFLAGS) -MD -MP -MT '$*.x $*.o' -o $@ $<
407         @touch $*.d
408         @touch $@
409         $(VERBOSE_NL)
410
411 # Preprocess, compile & assemble: create object files from C source files.
412 %.o: %.c %.d
413         @echo $(MSG_COMPILING)
414         $(VERBOSE_CMD)$(CC) -c $(CPPFLAGS) -MD -MP -MT '$*.i $*.x' $(CFLAGS) -o $@ $<
415         @touch $*.d
416         @touch $@
417         $(VERBOSE_NL)
418
419 # Preprocess & assemble: create object files from assembler source files.
420 %.o: %.S %.d
421         @echo $(MSG_ASSEMBLING)
422         $(VERBOSE_CMD)$(CC) -c $(CPPFLAGS) -MD -MP -MT '$*.x' $(ASFLAGS) -o $@ $<
423         @touch $*.d
424         @touch $@
425         $(VERBOSE_NL)
426
427 .PRECIOUS: $(OBJFILES)
428 ifeq ($(TGTTYPE),.a)
429 # Archive: create A output file from object files.
430 .SECONDARY: $(TGTFILE)
431 $(TGTFILE): $(OBJFILES)
432         @echo $(MSG_ARCHIVING)
433         $(VERBOSE_CMD)$(AR) $(ARFLAGS) $@ $(filter %.o,$+)
434         $(VERBOSE_NL)
435 else
436 ifeq ($(TGTTYPE),.elf)
437 # Link: create ELF output file from object files.
438 .SECONDARY: $(TGTFILE)
439 $(TGTFILE): $(OBJFILES)
440         @echo $(MSG_LINKING)
441         $(VERBOSE_CMD)$(CC) $(LDFLAGS) $(filter %.o,$+) $(LOADLIBES) $(LDLIBS) -o $@
442         $(VERBOSE_NL)
443 endif
444 endif
445
446 # Create extended listing from target output file.
447 $(LSS): $(TGTFILE)
448         @echo $(MSG_EXTENDED_LISTING)
449         $(VERBOSE_CMD)$(OBJDUMP) -h -S $< > $@
450         $(VERBOSE_NL)
451
452 # Create symbol table from target output file.
453 $(SYM): $(TGTFILE)
454         @echo $(MSG_SYMBOL_TABLE)
455         $(VERBOSE_CMD)$(NM) -n $< > $@
456         $(VERBOSE_NL)
457
458 ifeq ($(TGTTYPE),.elf)
459 # Create binary image from ELF output file.
460 $(BIN): $(TGTFILE)
461         @echo $(MSG_BINARY_IMAGE)
462         $(VERBOSE_CMD)$(OBJCOPY) -O binary $< $@
463         $(VERBOSE_NL)
464 endif