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 # hex file.hex Create Intel HEX image from ELF output file.
17 # bin file.bin Create binary image from ELF output file.
18 # sizes Display target size information.
19 # isp Use ISP instead of JTAGICE mkII when programming.
20 # cpuinfo Get CPU information.
21 # halt Stop CPU execution.
22 # chiperase Perform a JTAG Chip Erase command.
23 # erase Perform a flash chip erase.
24 # program Program MCU memory from ELF output file.
25 # secureflash Protect chip by setting security bit.
27 # debug Open a debug connection with the MCU.
28 # run Start CPU execution.
29 # readregs Read CPU registers.
30 # doc Build the documentation.
31 # cleandoc Clean up the documentation.
32 # rebuilddoc Rebuild the documentation.
33 # verbose Display main executed commands.
35 # Copyright (c) 2007, Atmel Corporation All rights reserved.
37 # Redistribution and use in source and binary forms, with or without
38 # modification, are permitted provided that the following conditions are met:
40 # 1. Redistributions of source code must retain the above copyright notice, this
41 # list of conditions and the following disclaimer.
43 # 2. Redistributions in binary form must reproduce the above copyright notice,
44 # this list of conditions and the following disclaimer in the documentation and/
45 # or other materials provided with the distribution.
47 # 3. The name of ATMEL may not be used to endorse or promote products derived
48 # from this software without specific prior written permission.
50 # THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
51 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
52 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
53 # SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
54 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
55 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
57 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
58 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
59 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
63 # ENVIRONMENT SETTINGS
64 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
66 FirstWord = $(if $(1),$(word 1,$(1)))
67 LastWord = $(if $(1),$(word $(words $(1)),$(1)))
71 TGTTYPE = $(suffix $(TARGET))
79 CPPFLAGS = -march=$(ARCH) -mpart=$(PART) $(WARNINGS) $(DEFS) \
80 $(PLATFORM_INC_PATH:%=-I%) $(INC_PATH:%=-I%) $(CPP_EXTRA_FLAGS)
81 DPNDFILES = $(CSRCS:.c=.d) $(ASSRCS:.S=.d)
82 CPPFILES = $(CSRCS:.c=.i)
85 CFLAGS = $(DEBUG) $(OPTIMIZATION) $(C_EXTRA_FLAGS) \
86 $(PLATFORM_INC_PATH:%=-Wa,-I%) $(INC_PATH:%=-Wa,-I%) $(AS_EXTRA_FLAGS)
87 ASFILES = $(CSRCS:.c=.x) $(ASSRCS:.S=.x)
91 $(PLATFORM_INC_PATH:%=-Wa,-I%) $(INC_PATH:%=-Wa,-I%) $(AS_EXTRA_FLAGS)
92 OBJFILES = $(CSRCS:.c=.o) $(ASSRCS:.S=.o)
95 LDFLAGS = -march=$(ARCH) -mpart=$(PART) \
96 $(LIB_PATH:%=-L%) $(LINKER_SCRIPT:%=-T%) $(LD_EXTRA_FLAGS)
98 LDLIBS = $(LIBS:%=-l%)
100 OBJDUMP = avr32-objdump
101 LSS = $(TARGET:$(TGTTYPE)=.lss)
104 SYM = $(TARGET:$(TGTTYPE)=.sym)
106 OBJCOPY = avr32-objcopy
107 HEX = $(TARGET:$(TGTTYPE)=.hex)
108 BIN = $(TARGET:$(TGTTYPE)=.bin)
115 PROGRAM = avr32program
118 ISPFLAGS = -device at32$(PART) -hardware usb -operation
120 DBGPROXY = avr32gdbproxy
125 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
127 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
129 ERR_TARGET_TYPE = Target type not supported: `$(TGTTYPE)'
130 MSG_CLEANING = Cleaning project.
131 MSG_PREPROCESSING = Preprocessing \`$<\' to \`$@\'.
132 MSG_COMPILING = Compiling \`$<\' to \`$@\'.
133 MSG_ASSEMBLING = Assembling \`$<\' to \`$@\'.
134 MSG_ARCHIVING = Archiving to \`$@\'.
135 MSG_LINKING = Linking to \`$@\'.
136 MSG_EXTENDED_LISTING = Creating extended listing to \`$@\'.
137 MSG_SYMBOL_TABLE = Creating symbol table to \`$@\'.
138 MSG_IHEX_IMAGE = Creating Intel HEX image to \`$@\'.
139 MSG_BINARY_IMAGE = Creating binary image to \`$@\'.
140 MSG_GETTING_CPU_INFO = Getting CPU information.
141 MSG_HALTING = Stopping CPU execution.
142 MSG_ERASING_CHIP = Performing a JTAG Chip Erase command.
143 MSG_ERASING = Performing a flash chip erase.
144 MSG_PROGRAMMING = Programming MCU memory from \`$(TARGET)\'.
145 MSG_SECURING_FLASH = Protecting chip by setting security bit.
146 MSG_RESETTING = Resetting MCU.
147 MSG_DEBUGGING = Opening debug connection with MCU.
148 MSG_RUNNING = Starting CPU execution.
149 MSG_READING_CPU_REGS = Reading CPU registers.
150 MSG_CLEANING_DOC = Cleaning documentation.
151 MSG_GENERATING_DOC = Generating documentation to \`$(DOC_PATH)\'.
154 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
156 # ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
158 # Include the make configuration file.
161 # ** ** TOP-LEVEL RULES ** **
163 # Default goal: build the project.
166 all: ccversion a lss sym sizes
168 ifeq ($(TGTTYPE),.elf)
170 all: ccversion elf lss sym hex bin sizes
172 $(error $(ERR_TARGET_TYPE))
176 # Clean up the project.
179 @echo $(MSG_CLEANING)
180 -$(VERBOSE_CMD)$(RM) $(BIN)
181 -$(VERBOSE_CMD)$(RM) $(HEX)
182 -$(VERBOSE_CMD)$(RM) $(SYM)
183 -$(VERBOSE_CMD)$(RM) $(LSS)
184 -$(VERBOSE_CMD)$(RM) $(TARGET)
185 -$(VERBOSE_CMD)$(RM) $(OBJFILES)
186 -$(VERBOSE_CMD)$(RM) $(ASFILES)
187 -$(VERBOSE_CMD)$(RM) $(CPPFILES)
188 -$(VERBOSE_CMD)$(RM) $(DPNDFILES)
191 # Rebuild the project.
195 # Display CC version information.
202 # Generate preprocessed files from C source files.
204 cppfiles: $(CPPFILES)
206 # Generate preprocessed assembler files from C and assembler source files.
210 # Generate object files from C and assembler source files.
212 objfiles: $(OBJFILES)
215 # Archive: create A output file from object files.
219 ifeq ($(TGTTYPE),.elf)
220 # Link: create ELF output file from object files.
226 # Create extended listing from target output file.
230 # Create symbol table from target output file.
234 ifeq ($(TGTTYPE),.elf)
236 # Create Intel HEX image from ELF output file.
240 # Create binary image from ELF output file.
246 # Display target size information.
254 ifeq ($(TGTTYPE),.elf)
262 ifeq ($(TGTTYPE),.elf)
264 # Use ISP instead of JTAGICE mkII when programming.
266 ifeq ($(filter-out isp verbose,$(MAKECMDGOALS)),)
273 ifeq ($(findstring isp,$(MAKECMDGOALS)),)
275 # Get CPU information.
279 @echo $(MSG_GETTING_CPU_INFO)
280 $(VERBOSE_CMD)$(PROGRAM) cpuinfo
281 ifneq ($(call LastWord,$(filter cpuinfo chiperase erase program secureflash reset debug run readregs,$(MAKECMDGOALS))),cpuinfo)
282 @$(SLEEP) $(SLEEPUSB)
287 # Stop CPU execution.
290 ifeq ($(filter cpuinfo chiperase erase program secureflash reset run readregs,$(MAKECMDGOALS)),)
293 $(VERBOSE_CMD)$(PROGRAM) halt
294 ifneq ($(call LastWord,$(filter halt debug,$(MAKECMDGOALS))),halt)
295 @$(SLEEP) $(SLEEPUSB)
303 # Perform a JTAG Chip Erase command.
307 @echo $(MSG_ERASING_CHIP)
308 $(VERBOSE_CMD)$(PROGRAM) chiperase
309 ifneq ($(call LastWord,$(filter cpuinfo chiperase program secureflash reset debug run readregs,$(MAKECMDGOALS))),chiperase)
310 @$(SLEEP) $(SLEEPUSB)
315 # Perform a flash chip erase.
318 ifeq ($(filter chiperase program,$(MAKECMDGOALS)),)
321 $(VERBOSE_CMD)$(PROGRAM) erase $(FLASH:%=-f%)
322 ifneq ($(call LastWord,$(filter cpuinfo erase secureflash reset debug run readregs,$(MAKECMDGOALS))),erase)
323 @$(SLEEP) $(SLEEPUSB)
331 # Program MCU memory from ELF output file.
335 @echo $(MSG_PROGRAMMING)
336 $(VERBOSE_CMD)$(PROGRAM) program $(FLASH:%=-f%) $(PROG_CLOCK:%=-c%) -e -v -R $(if $(findstring run,$(MAKECMDGOALS)),-r) $(TARGET)
337 ifneq ($(call LastWord,$(filter cpuinfo chiperase program secureflash debug readregs,$(MAKECMDGOALS))),program)
338 @$(SLEEP) $(SLEEPUSB)
343 # Protect chip by setting security bit.
347 @echo $(MSG_SECURING_FLASH)
348 $(VERBOSE_CMD)$(PROGRAM) secureflash
349 ifneq ($(call LastWord,$(filter cpuinfo chiperase erase program secureflash reset debug run readregs,$(MAKECMDGOALS))),secureflash)
350 @$(SLEEP) $(SLEEPUSB)
358 ifeq ($(filter program run,$(MAKECMDGOALS)),)
360 @echo $(MSG_RESETTING)
361 $(VERBOSE_CMD)$(PROGRAM) reset
362 ifneq ($(call LastWord,$(filter cpuinfo chiperase erase secureflash reset debug readregs,$(MAKECMDGOALS))),reset)
363 @$(SLEEP) $(SLEEPUSB)
371 # Open a debug connection with the MCU.
375 @echo $(MSG_DEBUGGING)
376 $(VERBOSE_CMD)$(DBGPROXY) $(FLASH:%=-f%)
377 ifneq ($(call LastWord,$(filter cpuinfo halt chiperase erase program secureflash reset debug run readregs,$(MAKECMDGOALS))),debug)
378 @$(SLEEP) $(SLEEPUSB)
383 # Start CPU execution.
386 ifeq ($(findstring program,$(MAKECMDGOALS)),)
389 $(VERBOSE_CMD)$(PROGRAM) run $(if $(findstring reset,$(MAKECMDGOALS)),-R)
390 ifneq ($(call LastWord,$(filter cpuinfo chiperase erase secureflash debug run readregs,$(MAKECMDGOALS))),run)
391 @$(SLEEP) $(SLEEPUSB)
399 # Read CPU registers.
403 @echo $(MSG_READING_CPU_REGS)
404 $(VERBOSE_CMD)$(PROGRAM) readregs
405 ifneq ($(call LastWord,$(filter cpuinfo chiperase erase program secureflash reset debug run readregs,$(MAKECMDGOALS))),readregs)
406 @$(SLEEP) $(SLEEPUSB)
413 # Perform a flash chip erase.
416 ifeq ($(findstring program,$(MAKECMDGOALS)),)
419 $(VERBOSE_CMD)$(ISP) $(ISPFLAGS) erase f memory flash blankcheck
420 ifeq ($(call LastWord,$(filter erase secureflash debug run,$(MAKECMDGOALS))),erase)
427 # Program MCU memory from ELF output file.
431 @echo $(MSG_PROGRAMMING)
432 $(VERBOSE_CMD)$(ISP) $(ISPFLAGS) erase f memory flash blankcheck loadbuffer $(TARGET) program verify $(if $(findstring run,$(MAKECMDGOALS)),$(if $(findstring secureflash,$(MAKECMDGOALS)),,start $(if $(findstring reset,$(MAKECMDGOALS)),,no)reset 0))
433 ifeq ($(call LastWord,$(filter program secureflash debug,$(MAKECMDGOALS))),program)
437 # Protect chip by setting security bit.
441 @echo $(MSG_SECURING_FLASH)
442 $(VERBOSE_CMD)$(ISP) $(ISPFLAGS) memory security addrange 0x0 0x0 fillbuffer 0x01 program $(if $(findstring run,$(MAKECMDGOALS)),start $(if $(findstring reset,$(MAKECMDGOALS)),,no)reset 0)
443 ifeq ($(call LastWord,$(filter erase program secureflash debug,$(MAKECMDGOALS))),secureflash)
452 # Open a debug connection with the MCU.
456 @echo $(MSG_DEBUGGING)
457 $(VERBOSE_CMD)$(DBGPROXY) $(FLASH:%=-f%)
458 ifeq ($(call LastWord,$(filter erase program secureflash debug run,$(MAKECMDGOALS))),debug)
462 # Start CPU execution.
465 ifeq ($(filter program secureflash,$(MAKECMDGOALS)),)
468 $(VERBOSE_CMD)$(ISP) $(ISPFLAGS) start $(if $(findstring reset,$(MAKECMDGOALS)),,no)reset 0
469 ifeq ($(call LastWord,$(filter erase debug run,$(MAKECMDGOALS))),run)
480 # Build the documentation.
484 @echo $(MSG_GENERATING_DOC)
485 $(VERBOSE_CMD)cd $(dir $(DOC_CFG)) && $(DOCGEN) $(notdir $(DOC_CFG))
488 # Clean up the documentation.
491 @echo $(MSG_CLEANING_DOC)
492 -$(VERBOSE_CMD)$(RM) $(DOC_PATH)
495 # Rebuild the documentation.
497 rebuilddoc: cleandoc doc
499 # Display main executed commands.
501 ifeq ($(filter-out isp verbose,$(MAKECMDGOALS)),)
507 ifneq ($(findstring verbose,$(MAKECMDGOALS)),)
508 # Prefix displaying the following command if and only if verbose is a goal.
510 # New line displayed if and only if verbose is a goal.
517 # ** ** COMPILATION RULES ** **
519 # Include silently the dependency files.
520 -include $(DPNDFILES)
522 # The dependency files are not built alone but along with first generation files.
525 # First generation files depend on make files.
526 $(CPPFILES) $(ASFILES) $(OBJFILES): Makefile $(MAKECFG)
528 ifeq ($(TGTTYPE),.elf)
529 # Files resulting from linking depend on linker script.
530 $(TARGET): $(LINKER_SCRIPT)
533 # Preprocess: create preprocessed files from C source files.
535 @echo $(MSG_PREPROCESSING)
536 $(VERBOSE_CMD)$(CPP) $(CPPFLAGS) -MD -MP -MT '$*.i $*.x $*.o' -o $@ $<
541 # Preprocess & compile: create assembler files from C source files.
543 @echo $(MSG_COMPILING)
544 $(VERBOSE_CMD)$(CC) -S $(CPPFLAGS) -MD -MP -MT '$*.i $*.o' $(CFLAGS) -o $@ $<
549 # Preprocess: create preprocessed files from assembler source files.
551 @echo $(MSG_PREPROCESSING)
552 $(VERBOSE_CMD)$(CPP) $(CPPFLAGS) -MD -MP -MT '$*.x $*.o' -o $@ $<
557 # Preprocess, compile & assemble: create object files from C source files.
559 @echo $(MSG_COMPILING)
560 $(VERBOSE_CMD)$(CC) -c $(CPPFLAGS) -MD -MP -MT '$*.i $*.x' $(CFLAGS) -o $@ $<
565 # Preprocess & assemble: create object files from assembler source files.
567 @echo $(MSG_ASSEMBLING)
568 $(VERBOSE_CMD)$(CC) -c $(CPPFLAGS) -MD -MP -MT '$*.x' $(ASFLAGS) -o $@ $<
573 .PRECIOUS: $(OBJFILES)
575 # Archive: create A output file from object files.
576 .SECONDARY: $(TARGET)
577 $(TARGET): $(OBJFILES)
578 @echo $(MSG_ARCHIVING)
579 $(VERBOSE_CMD)$(AR) $(ARFLAGS) $@ $(filter %.o,$+)
582 ifeq ($(TGTTYPE),.elf)
583 # Link: create ELF output file from object files.
584 .SECONDARY: $(TARGET)
585 $(TARGET): $(OBJFILES)
587 $(VERBOSE_CMD)$(CC) $(LDFLAGS) $(filter %.o,$+) $(LOADLIBES) $(LDLIBS) -o $@
592 # Create extended listing from target output file.
594 @echo $(MSG_EXTENDED_LISTING)
595 $(VERBOSE_CMD)$(OBJDUMP) -h -S $< > $@
598 # Create symbol table from target output file.
600 @echo $(MSG_SYMBOL_TABLE)
601 $(VERBOSE_CMD)$(NM) -n $< > $@
604 ifeq ($(TGTTYPE),.elf)
606 # Create Intel HEX image from ELF output file.
608 @echo $(MSG_IHEX_IMAGE)
609 $(VERBOSE_CMD)$(OBJCOPY) -O ihex $< $@
612 # Create binary image from ELF output file.
614 @echo $(MSG_BINARY_IMAGE)
615 $(VERBOSE_CMD)$(OBJCOPY) -O binary $< $@