1 # List of available make goals:
\r
3 # all Default target, builds the project
\r
4 # clean Clean up the project
\r
5 # rebuild Rebuild the project
\r
6 # debug_flash Builds the project and debug in flash
\r
7 # debug_sram Builds the project and debug in sram
\r
9 # doc Build the documentation
\r
10 # cleandoc Clean up the documentation
\r
11 # rebuilddoc Rebuild the documentation
\r
15 # Copyright (c) 2011 - 2013 Atmel Corporation. All rights reserved.
\r
17 # \asf_license_start
\r
21 # Redistribution and use in source and binary forms, with or without
\r
22 # modification, are permitted provided that the following conditions are met:
\r
24 # 1. Redistributions of source code must retain the above copyright notice,
\r
25 # this list of conditions and the following disclaimer.
\r
27 # 2. Redistributions in binary form must reproduce the above copyright notice,
\r
28 # this list of conditions and the following disclaimer in the documentation
\r
29 # and/or other materials provided with the distribution.
\r
31 # 3. The name of Atmel may not be used to endorse or promote products derived
\r
32 # from this software without specific prior written permission.
\r
34 # 4. This software may only be redistributed and used in connection with an
\r
35 # Atmel microcontroller product.
\r
37 # THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
\r
38 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
39 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
40 # EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
\r
41 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
42 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\r
43 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
44 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
\r
45 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
46 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
47 # POSSIBILITY OF SUCH DAMAGE.
\r
52 # Include the config.mk file from the current working path, e.g., where the
\r
56 # Tool to use to generate documentation from the source code
\r
59 # Look for source files relative to the top-level source directory
\r
60 VPATH := $(PRJ_PATH)
\r
62 # Output target file
\r
63 project_type := $(PROJECT_TYPE)
\r
65 # Output target file
\r
66 ifeq ($(project_type),flash)
\r
67 target := $(TARGET_FLASH)
\r
68 linker_script := $(PRJ_PATH)/$(LINKER_SCRIPT_FLASH)
\r
69 debug_script := $(PRJ_PATH)/$(DEBUG_SCRIPT_FLASH)
\r
71 target := $(TARGET_SRAM)
\r
72 linker_script := $(PRJ_PATH)/$(LINKER_SCRIPT_SRAM)
\r
73 debug_script := $(PRJ_PATH)/$(DEBUG_SCRIPT_SRAM)
\r
76 # Output project name (target name minus suffix)
\r
77 project := $(basename $(target))
\r
79 # Output target file (typically ELF or static library)
\r
80 ifeq ($(suffix $(target)),.a)
\r
83 ifeq ($(suffix $(target)),.elf)
\r
86 $(error "Target type $(target_type) is not supported")
\r
90 # Allow override of operating system detection. The user can add OS=Linux or
\r
91 # OS=Windows on the command line to explicit set the host OS.
\r
93 # This allows to work around broken uname utility on certain systems.
\r
95 ifeq ($(strip $(OS)), Linux)
\r
98 ifeq ($(strip $(OS)), Windows)
\r
99 os_type := windows32_64
\r
103 os_type ?= $(strip $(shell uname))
\r
105 ifeq ($(os_type),windows32)
\r
108 ifeq ($(os_type),windows64)
\r
111 ifeq ($(os_type),windows32_64)
\r
117 # Default to Linux style operating system. Both Cygwin and mingw are fully
\r
118 # compatible (for this Makefile) with Linux.
\r
125 # Output documentation directory and configuration file.
\r
126 docdir := ../doxygen/html
\r
127 doccfg := ../doxygen/doxyfile.doxygen
\r
129 CROSS ?= arm-none-eabi-
\r
133 CPP := $(CROSS)gcc -E
\r
137 OBJCOPY := $(CROSS)objcopy
\r
138 OBJDUMP := $(CROSS)objdump
\r
139 SIZE := $(CROSS)size
\r
143 ifeq ($(os),Windows)
\r
144 RMDIR := rmdir /S /Q
\r
146 RMDIR := rmdir -p --ignore-fail-on-non-empty
\r
149 # On Windows, we need to override the shell to force the use of cmd.exe
\r
150 ifeq ($(os),Windows)
\r
154 # Strings for beautifying output
\r
155 MSG_CLEAN_FILES = "RM *.o *.d"
\r
156 MSG_CLEAN_DIRS = "RMDIR $(strip $(clean-dirs))"
\r
157 MSG_CLEAN_DOC = "RMDIR $(docdir)"
\r
158 MSG_MKDIR = "MKDIR $(dir $@)"
\r
162 MSG_ARCHIVING = "AR $@"
\r
163 MSG_ASSEMBLING = "AS $@"
\r
164 MSG_BINARY_IMAGE = "OBJCOPY $@"
\r
165 MSG_COMPILING = "CC $@"
\r
166 MSG_COMPILING_CXX = "CXX $@"
\r
167 MSG_EXTENDED_LISTING = "OBJDUMP $@"
\r
168 MSG_IHEX_IMAGE = "OBJCOPY $@"
\r
169 MSG_LINKING = "LN $@"
\r
170 MSG_PREPROCESSING = "CPP $@"
\r
171 MSG_SIZE = "SIZE $@"
\r
172 MSG_SYMBOL_TABLE = "NM $@"
\r
174 MSG_GENERATING_DOC = "DOXYGEN $(docdir)"
\r
176 # Don't use make's built-in rules and variables
\r
179 # Don't print 'Entering directory ...'
\r
180 MAKEFLAGS += --no-print-directory
\r
182 # Function for reversing the order of a list
\r
183 reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
\r
185 # Hide command output by default, but allow the user to override this
\r
186 # by adding V=1 on the command line.
\r
188 # This is inspired by the Kbuild system used by the Linux kernel.
\r
190 ifeq ("$(origin V)", "command line")
\r
198 ifeq ($(VERBOSE), 1)
\r
204 arflags-gnu-y := $(ARFLAGS)
\r
205 asflags-gnu-y := $(ASFLAGS)
\r
206 cflags-gnu-y := $(CFLAGS)
\r
207 cxxflags-gnu-y := $(CXXFLAGS)
\r
208 cppflags-gnu-y := $(CPPFLAGS)
\r
210 dbgflags-gnu-y := $(DBGFLAGS)
\r
211 libflags-gnu-y := $(foreach LIB,$(LIBS),-l$(LIB))
\r
212 ldflags-gnu-y := $(LDFLAGS)
\r
213 flashflags-gnu-y :=
\r
217 clean-files += $(wildcard $(target) $(project).map)
\r
218 clean-files += $(wildcard $(project).hex $(project).bin)
\r
219 clean-files += $(wildcard $(project).lss $(project).sym)
\r
220 clean-files += $(wildcard $(build))
\r
222 # Use pipes instead of temporary files for communication between processes
\r
223 cflags-gnu-y += -pipe
\r
224 asflags-gnu-y += -pipe
\r
225 ldflags-gnu-y += -pipe
\r
228 arflags-gnu-y += rcs
\r
230 # Always enable warnings. And be very careful about implicit
\r
232 cflags-gnu-y += -Wall -Wstrict-prototypes -Wmissing-prototypes
\r
233 cflags-gnu-y += -Werror-implicit-function-declaration
\r
234 cxxflags-gnu-y += -Wall
\r
235 # IAR doesn't allow arithmetic on void pointers, so warn about that.
\r
236 cflags-gnu-y += -Wpointer-arith
\r
237 cxxflags-gnu-y += -Wpointer-arith
\r
239 # Preprocessor flags.
\r
240 cppflags-gnu-y += $(foreach INC,$(addprefix $(PRJ_PATH)/,$(INC_PATH)),-I$(INC))
\r
241 asflags-gnu-y += $(foreach INC,$(addprefix $(PRJ_PATH)/,$(INC_PATH)),'-Wa,-I$(INC)')
\r
243 # CPU specific flags.
\r
244 cpuflags-gnu-y += -mcpu=$(ARCH) -mthumb -D=__$(PART)__
\r
246 # Dependency file flags.
\r
247 depflags = -MD -MP -MQ $@
\r
249 # Debug specific flags.
\r
250 ifdef BUILD_DEBUG_LEVEL
\r
251 dbgflags-gnu-y += -g$(BUILD_DEBUG_LEVEL)
\r
253 dbgflags-gnu-y += -g3
\r
256 # Optimization specific flags.
\r
257 ifdef BUILD_OPTIMIZATION
\r
258 optflags-gnu-y = -O$(BUILD_OPTIMIZATION)
\r
260 optflags-gnu-y = $(OPTIMIZATION)
\r
263 # Always preprocess assembler files.
\r
264 asflags-gnu-y += -x assembler-with-cpp
\r
265 # Compile C files using the GNU99 standard.
\r
266 cflags-gnu-y += -std=gnu99
\r
267 # Compile C++ files using the GNU++98 standard.
\r
268 cxxflags-gnu-y += -std=gnu++98
\r
270 # Don't use strict aliasing (very common in embedded applications).
\r
271 cflags-gnu-y += -fno-strict-aliasing
\r
272 cxxflags-gnu-y += -fno-strict-aliasing
\r
274 # Separate each function and data into its own separate section to allow
\r
275 # garbage collection of unused sections.
\r
276 cflags-gnu-y += -ffunction-sections -fdata-sections
\r
277 cxxflags-gnu-y += -ffunction-sections -fdata-sections
\r
280 cflags-gnu-y += -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int
\r
281 cflags-gnu-y += -Wmain -Wparentheses
\r
282 cflags-gnu-y += -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused
\r
283 cflags-gnu-y += -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef
\r
284 cflags-gnu-y += -Wshadow -Wbad-function-cast -Wwrite-strings
\r
285 cflags-gnu-y += -Wsign-compare -Waggregate-return
\r
286 cflags-gnu-y += -Wmissing-declarations
\r
287 cflags-gnu-y += -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations
\r
288 cflags-gnu-y += -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long
\r
289 cflags-gnu-y += -Wunreachable-code
\r
290 cflags-gnu-y += -Wcast-align
\r
291 cflags-gnu-y += --param max-inline-insns-single=500
\r
293 # To reduce application size use only integer printf function.
\r
294 cflags-gnu-y += -Dprintf=iprintf
\r
296 # Garbage collect unreferred sections when linking.
\r
297 ldflags-gnu-y += -Wl,--gc-sections
\r
299 # Use the linker script if provided by the project.
\r
300 ifneq ($(strip $(linker_script)),)
\r
301 ldflags-gnu-y += -Wl,-T $(linker_script)
\r
304 # Output a link map file and a cross reference table
\r
305 ldflags-gnu-y += -Wl,-Map=$(project).map,--cref
\r
307 # Add library search paths relative to the top level directory.
\r
308 ldflags-gnu-y += $(foreach _LIB_PATH,$(addprefix $(PRJ_PATH)/,$(LIB_PATH)),-L$(_LIB_PATH))
\r
310 a_flags = $(cpuflags-gnu-y) $(depflags) $(cppflags-gnu-y) $(asflags-gnu-y) -D__ASSEMBLY__
\r
311 c_flags = $(cpuflags-gnu-y) $(dbgflags-gnu-y) $(depflags) $(optflags-gnu-y) $(cppflags-gnu-y) $(cflags-gnu-y)
\r
312 cxx_flags= $(cpuflags-gnu-y) $(dbgflags-gnu-y) $(depflags) $(optflags-gnu-y) $(cppflags-gnu-y) $(cxxflags-gnu-y)
\r
313 l_flags = -Wl,--entry=Reset_Handler -Wl,--cref $(cpuflags-gnu-y) $(optflags-gnu-y) $(ldflags-gnu-y)
\r
314 ar_flags = $(arflags-gnu-y)
\r
316 # Source files list and part informations must already be included before
\r
317 # running this makefile
\r
319 # If a custom build directory is specified, use it -- force trailing / in directory name.
\r
321 build-dir := $(dir $(BUILD_DIR))$(if $(notdir $(BUILD_DIR)),$(notdir $(BUILD_DIR))/)
\r
326 # Create object files list from source files list.
\r
327 obj-y := $(addprefix $(build-dir), $(addsuffix .o,$(basename $(CSRCS) $(ASSRCS))))
\r
328 # Create dependency files list from source files list.
\r
329 dep-files := $(wildcard $(foreach f,$(obj-y),$(basename $(f)).d))
\r
331 clean-files += $(wildcard $(obj-y))
\r
332 clean-files += $(dep-files)
\r
334 clean-dirs += $(call reverse,$(sort $(wildcard $(dir $(obj-y)))))
\r
338 ifeq ($(project_type),all)
\r
340 $(MAKE) all PROJECT_TYPE=flash
\r
341 $(MAKE) all PROJECT_TYPE=sram
\r
343 ifeq ($(target_type),lib)
\r
344 all: $(target) $(project).lss $(project).sym
\r
346 ifeq ($(target_type),elf)
\r
347 all: $(target) $(project).lss $(project).sym $(project).hex $(project).bin
\r
352 # Clean up the project.
\r
355 @$(if $(strip $(clean-files)),echo $(MSG_CLEAN_FILES))
\r
356 $(if $(strip $(clean-files)),$(Q)$(RM) $(clean-files),)
\r
357 @$(if $(strip $(clean-dirs)),echo $(MSG_CLEAN_DIRS))
\r
358 # Remove created directories, and make sure we only remove existing
\r
359 # directories, since recursive rmdir might help us a bit on the way.
\r
360 ifeq ($(os),Windows)
\r
361 $(Q)$(if $(strip $(clean-dirs)), \
\r
362 $(RMDIR) $(strip $(subst /,\,$(clean-dirs))))
\r
364 $(Q)$(if $(strip $(clean-dirs)), \
\r
365 for directory in $(strip $(clean-dirs)); do \
\r
366 if [ -d "$$directory" ]; then \
\r
367 $(RMDIR) $$directory; \
\r
373 # Rebuild the project.
\r
377 # Debug the project in flash.
\r
378 .PHONY: debug_flash
\r
380 $(GDB) -x "$(PRJ_PATH)/$(DEBUG_SCRIPT_FLASH)" -ex "reset" -readnow -se $(TARGET_FLASH)
\r
382 # Debug the project in sram.
\r
385 $(GDB) -x "$(PRJ_PATH)/$(DEBUG_SCRIPT_SRAM)" -ex "reset" -readnow -se $(TARGET_SRAM)
\r
390 # Create object files from C source files.
\r
391 $(build-dir)%.o: %.c $(MAKEFILE_PATH) config.mk
\r
392 $(Q)test -d $(dir $@) || echo $(MSG_MKDIR)
\r
393 ifeq ($(os),Windows)
\r
394 $(Q)test -d $(patsubst %/,%,$(dir $@)) || mkdir $(subst /,\,$(dir $@))
\r
396 $(Q)test -d $(dir $@) || mkdir -p $(dir $@)
\r
398 @echo $(MSG_COMPILING)
\r
399 $(Q)$(CC) $(c_flags) -c $< -o $@
\r
401 # Create object files from C++ source files.
\r
402 $(build-dir)%.o: %.cpp $(MAKEFILE_PATH) config.mk
\r
403 $(Q)test -d $(dir $@) || echo $(MSG_MKDIR)
\r
404 ifeq ($(os),Windows)
\r
405 $(Q)test -d $(patsubst %/,%,$(dir $@)) || mkdir $(subst /,\,$(dir $@))
\r
407 $(Q)test -d $(dir $@) || mkdir -p $(dir $@)
\r
409 @echo $(MSG_COMPILING_CXX)
\r
410 $(Q)$(CXX) $(cxx_flags) -c $< -o $@
\r
412 # Preprocess and assemble: create object files from assembler source files.
\r
413 $(build-dir)%.o: %.S $(MAKEFILE_PATH) config.mk
\r
414 $(Q)test -d $(dir $@) || echo $(MSG_MKDIR)
\r
415 ifeq ($(os),Windows)
\r
416 $(Q)test -d $(patsubst %/,%,$(dir $@)) || mkdir $(subst /,\,$(dir $@))
\r
418 $(Q)test -d $(dir $@) || mkdir -p $(dir $@)
\r
420 @echo $(MSG_ASSEMBLING)
\r
421 $(Q)$(CC) $(a_flags) -c $< -o $@
\r
423 # Include all dependency files to add depedency to all header files in use.
\r
424 include $(dep-files)
\r
426 ifeq ($(target_type),lib)
\r
427 # Archive object files into an archive
\r
428 $(target): $(MAKEFILE_PATH) config.mk $(obj-y)
\r
429 @echo $(MSG_ARCHIVING)
\r
430 $(Q)$(AR) $(ar_flags) $@ $(obj-y)
\r
432 $(Q)$(SIZE) -Bxt $@
\r
434 ifeq ($(target_type),elf)
\r
435 # Link the object files into an ELF file. Also make sure the target is rebuilt
\r
436 # if the common Makefile.sam.in or project config.mk is changed.
\r
437 $(target): $(linker_script) $(MAKEFILE_PATH) config.mk $(obj-y)
\r
438 @echo $(MSG_LINKING)
\r
439 $(Q)$(LD) $(l_flags) $(obj-y) $(libflags-gnu-y) -o $@
\r
446 # Create extended function listing from target output file.
\r
448 @echo $(MSG_EXTENDED_LISTING)
\r
449 $(Q)$(OBJDUMP) -h -S $< > $@
\r
451 # Create symbol table from target output file.
\r
453 @echo $(MSG_SYMBOL_TABLE)
\r
454 $(Q)$(NM) -n $< > $@
\r
456 # Create Intel HEX image from ELF output file.
\r
458 @echo $(MSG_IHEX_IMAGE)
\r
459 $(Q)$(OBJCOPY) -O ihex $(flashflags-gnu-y) $< $@
\r
461 # Create binary image from ELF output file.
\r
463 @echo $(MSG_BINARY_IMAGE)
\r
464 $(Q)$(OBJCOPY) -O binary $< $@
\r
466 # Provide information about the detected host operating system.
\r
467 .SECONDARY: info-os
\r
469 @echo $(MSG_INFO)$(os) build host detected
\r
471 # Build Doxygen generated documentation.
\r
474 @echo $(MSG_GENERATING_DOC)
\r
475 $(Q)cd $(dir $(doccfg)) && $(DOCGEN) $(notdir $(doccfg))
\r
477 # Clean Doxygen generated documentation.
\r
480 @$(if $(wildcard $(docdir)),echo $(MSG_CLEAN_DOC))
\r
481 $(Q)$(if $(wildcard $(docdir)),$(RM) --recursive $(docdir))
\r
483 # Rebuild the Doxygen generated documentation.
\r
485 rebuilddoc: cleandoc doc
\r