1 # Hey Emacs, this is a -*- makefile -*-
3 # Goals available on make command line:
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.
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.
30 # Copyright (c) 2007, Atmel Corporation All rights reserved.
32 # Redistribution and use in source and binary forms, with or without
33 # modification, are permitted provided that the following conditions are met:
35 # 1. Redistributions of source code must retain the above copyright notice, this
36 # list of conditions and the following disclaimer.
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.
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.
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.
57 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
58 # ENVIRONMENT SETTINGS
59 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
61 FirstWord = $(if $(1),$(word 1,$(1)))
62 LastWord = $(if $(1),$(word $(words $(1)),$(1)))
66 TGTTYPE = $(suffix $(TARGET))
67 TGTFILE = $(PART)-$(TARGET)
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)
81 CFLAGS = $(DEBUG) $(OPTIMIZATION) $(C_EXTRA_FLAGS)
82 ASFILES = $(CSRCS:.c=.x) $(ASSRCS:.S=.x)
85 ASFLAGS = $(DEBUG) $(AS_EXTRA_FLAGS)
86 OBJFILES = $(CSRCS:.c=.o) $(ASSRCS:.S=.o)
89 LDFLAGS = -march=$(ARCH) -mpart=$(PART) \
90 $(LIB_PATH:%=-L%) $(LINKER_SCRIPT:%=-T%) $(LD_EXTRA_FLAGS)
92 LDLIBS = $(LIBS:%=-l%)
94 OBJDUMP = avr32-objdump
95 LSS = $(TGTFILE:$(TGTTYPE)=.lss)
98 SYM = $(TGTFILE:$(TGTTYPE)=.sym)
100 OBJCOPY = avr32-objcopy
101 BIN = $(TGTFILE:$(TGTTYPE)=.bin)
105 SUDO = $(shell if [ -x /usr/bin/sudo ]; then echo sudo; fi)
110 PROGRAM = avr32program
112 DBGPROXY = avr32gdbproxy
117 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
119 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
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)\'.
142 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
144 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
146 # Include the make configuration file.
149 # ** ** TOP-LEVEL RULES ** **
151 # Default goal: build the project.
154 all: ccversion a lss sym
156 ifeq ($(TGTTYPE),.elf)
158 all: ccversion elf lss sym bin sizes
160 $(error $(ERR_TARGET_TYPE))
164 # Clean up the project.
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)
178 # Rebuild the project.
182 # Display CC version information.
189 # Generate preprocessed files from C source files.
191 cppfiles: $(CPPFILES)
193 # Generate preprocessed assembler files from C and assembler source files.
197 # Generate object files from C and assembler source files.
199 objfiles: $(OBJFILES)
202 # Archive: create A output file from object files.
206 ifeq ($(TGTTYPE),.elf)
207 # Link: create ELF output file from object files.
213 # Create extended listing from target output file.
217 # Create symbol table from target output file.
221 ifeq ($(TGTTYPE),.elf)
222 # Create binary image from ELF output file.
227 # Display target size information.
234 ifeq ($(TGTTYPE),.elf)
236 # Get CPU information.
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)
248 # Stop CPU execution.
251 ifeq ($(filter cpuinfo program reset run readregs,$(MAKECMDGOALS)),)
254 $(VERBOSE_CMD)$(SUDO) $(PROGRAM) -cUSB halt
255 ifneq ($(call LastWord,$(filter halt debug,$(MAKECMDGOALS))),halt)
256 @$(SLEEP) $(SLEEPUSB)
264 # Program MCU memory from ELF output file.
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)
279 ifeq ($(filter program run,$(MAKECMDGOALS)),)
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)
292 # Open a debug connection with the MCU.
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)
304 # Start CPU execution.
307 ifeq ($(findstring program,$(MAKECMDGOALS)),)
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)
320 # Read CPU registers.
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)
334 # Build the documentation.
338 @echo $(MSG_GENERATING_DOC)
339 $(VERBOSE_CMD)cd $(dir $(DOC_CFG)) && $(DOCGEN) $(notdir $(DOC_CFG))
342 # Clean up the documentation.
345 @echo $(MSG_CLEANING_DOC)
346 -$(VERBOSE_CMD)$(RM) $(DOC_PATH)
349 # Rebuild the documentation.
351 rebuilddoc: cleandoc doc
353 # Display main executed commands.
355 ifeq ($(MAKECMDGOALS),verbose)
361 ifneq ($(findstring verbose,$(MAKECMDGOALS)),)
362 # Prefix displaying the following command if and only if verbose is a goal.
364 # New line displayed if and only if verbose is a goal.
371 # ** ** COMPILATION RULES ** **
373 # Include silently the dependency files.
374 -include $(DPNDFILES)
376 # The dependency files are not built alone but along with first generation files.
379 # First generation files depend on make files.
380 $(CPPFILES) $(ASFILES) $(OBJFILES): Makefile $(MAKECFG)
382 ifeq ($(TGTTYPE),.elf)
383 # Files resulting from linking depend on linker script.
384 $(TGTFILE): $(LINKER_SCRIPT)
387 # Preprocess: create preprocessed files from C source files.
389 @echo $(MSG_PREPROCESSING)
390 $(VERBOSE_CMD)$(CPP) $(CPPFLAGS) -MD -MP -MT '$*.i $*.x $*.o' -o $@ $<
395 # Preprocess & compile: create assembler files from C source files.
397 @echo $(MSG_COMPILING)
398 $(VERBOSE_CMD)$(CC) -S $(CPPFLAGS) -MD -MP -MT '$*.i $*.o' $(CFLAGS) -o $@ $<
403 # Preprocess: create preprocessed files from assembler source files.
405 @echo $(MSG_PREPROCESSING)
406 $(VERBOSE_CMD)$(CPP) $(CPPFLAGS) -MD -MP -MT '$*.x $*.o' -o $@ $<
411 # Preprocess, compile & assemble: create object files from C source files.
413 @echo $(MSG_COMPILING)
414 $(VERBOSE_CMD)$(CC) -c $(CPPFLAGS) -MD -MP -MT '$*.i $*.x' $(CFLAGS) -o $@ $<
419 # Preprocess & assemble: create object files from assembler source files.
421 @echo $(MSG_ASSEMBLING)
422 $(VERBOSE_CMD)$(CC) -c $(CPPFLAGS) -MD -MP -MT '$*.x' $(ASFLAGS) -o $@ $<
427 .PRECIOUS: $(OBJFILES)
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,$+)
436 ifeq ($(TGTTYPE),.elf)
437 # Link: create ELF output file from object files.
438 .SECONDARY: $(TGTFILE)
439 $(TGTFILE): $(OBJFILES)
441 $(VERBOSE_CMD)$(CC) $(LDFLAGS) $(filter %.o,$+) $(LOADLIBES) $(LDLIBS) -o $@
446 # Create extended listing from target output file.
448 @echo $(MSG_EXTENDED_LISTING)
449 $(VERBOSE_CMD)$(OBJDUMP) -h -S $< > $@
452 # Create symbol table from target output file.
454 @echo $(MSG_SYMBOL_TABLE)
455 $(VERBOSE_CMD)$(NM) -n $< > $@
458 ifeq ($(TGTTYPE),.elf)
459 # Create binary image from ELF output file.
461 @echo $(MSG_BINARY_IMAGE)
462 $(VERBOSE_CMD)$(OBJCOPY) -O binary $< $@