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 - 2012 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 (Windows,$(findstring Windows,$(OS)))
\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),)
\r
114 ## Default to Linux style operating system. Both Cygwin and mingw are fully
\r
115 ## compatible (for this Makefile) with Linux.
\r
121 ifeq ($(os_type),windows32_64)
\r
124 ifeq ($(os_type),Linux)
\r
131 # Output documentation directory and configuration file.
\r
132 docdir := ../doxygen/html
\r
133 doccfg := ../doxygen/doxyfile.doxygen
\r
135 CROSS ?= arm-none-eabi-
\r
139 CPP := $(CROSS)gcc -E
\r
143 OBJCOPY := $(CROSS)objcopy
\r
144 OBJDUMP := $(CROSS)objdump
\r
145 SIZE := $(CROSS)size
\r
149 ifeq ($(os),Windows)
\r
150 #RMDIR := rmdir /S /Q
\r
153 RMDIR := rmdir -p --ignore-fail-on-non-empty
\r
156 # Strings for beautifying output
\r
157 MSG_CLEAN_FILES = "RM *.o *.d"
\r
158 MSG_CLEAN_DIRS = "RMDIR $(strip $(clean-dirs))"
\r
159 MSG_CLEAN_DOC = "RMDIR $(docdir)"
\r
160 MSG_MKDIR = "MKDIR $(dir $@)"
\r
164 MSG_ARCHIVING = "AR $@"
\r
165 MSG_ASSEMBLING = "AS $@"
\r
166 MSG_BINARY_IMAGE = "OBJCOPY $@"
\r
167 MSG_COMPILING = "CC $@"
\r
168 MSG_COMPILING_CXX = "CXX $@"
\r
169 MSG_EXTENDED_LISTING = "OBJDUMP $@"
\r
170 MSG_IHEX_IMAGE = "OBJCOPY $@"
\r
171 MSG_LINKING = "LN $@"
\r
172 MSG_PREPROCESSING = "CPP $@"
\r
173 MSG_SIZE = "SIZE $@"
\r
174 MSG_SYMBOL_TABLE = "NM $@"
\r
176 MSG_GENERATING_DOC = "DOXYGEN $(docdir)"
\r
178 # Don't use make's built-in rules and variables
\r
181 # Don't print 'Entering directory ...'
\r
182 MAKEFLAGS += --no-print-directory
\r
184 # Function for reversing the order of a list
\r
185 reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
\r
187 # Hide command output by default, but allow the user to override this
\r
188 # by adding V=1 on the command line.
\r
190 # This is inspired by the Kbuild system used by the Linux kernel.
\r
192 ifeq ("$(origin V)", "command line")
\r
200 ifeq ($(VERBOSE), 1)
\r
207 arflags-gnu-y := $(ARFLAGS)
\r
208 asflags-gnu-y := $(ASFLAGS)
\r
209 cflags-gnu-y := $(CFLAGS)
\r
210 cxxflags-gnu-y := $(CXXFLAGS)
\r
211 cppflags-gnu-y := $(CPPFLAGS)
\r
213 dbgflags-gnu-y := $(DBGFLAGS)
\r
214 libflags-gnu-y := $(foreach LIB,$(LIBS),-l$(LIB))
\r
215 ldflags-gnu-y := $(LDFLAGS)
\r
216 flashflags-gnu-y :=
\r
220 clean-files += $(wildcard $(target) $(project).map)
\r
221 clean-files += $(wildcard $(project).hex $(project).bin)
\r
222 clean-files += $(wildcard $(project).lss $(project).sym)
\r
223 clean-files += $(wildcard $(build))
\r
225 # Use pipes instead of temporary files for communication between processes
\r
226 cflags-gnu-y += -pipe
\r
227 asflags-gnu-y += -pipe
\r
228 ldflags-gnu-y += -pipe
\r
231 arflags-gnu-y += rcs
\r
233 # Always enable warnings. And be very careful about implicit
\r
235 cflags-gnu-y += -Wall -Wstrict-prototypes -Wmissing-prototypes
\r
236 cflags-gnu-y += -Werror-implicit-function-declaration
\r
237 cxxflags-gnu-y += -Wall
\r
238 # IAR doesn't allow arithmetic on void pointers, so warn about that.
\r
239 cflags-gnu-y += -Wpointer-arith
\r
240 cxxflags-gnu-y += -Wpointer-arith
\r
242 # Preprocessor flags.
\r
243 cppflags-gnu-y += $(foreach INC,$(addprefix $(PRJ_PATH)/,$(INC_PATH)),-I$(INC))
\r
244 asflags-gnu-y += $(foreach INC,$(addprefix $(PRJ_PATH)/,$(INC_PATH)),'-Wa,-I$(INC)')
\r
246 # CPU specific flags.
\r
247 cpuflags-gnu-y += -mcpu=$(ARCH) -mthumb -D=__$(PART)__
\r
249 # Dependency file flags.
\r
250 depflags = -MD -MP -MQ $@
\r
252 # Debug specific flags.
\r
253 ifdef BUILD_DEBUG_LEVEL
\r
254 dbgflags-gnu-y += -g$(BUILD_DEBUG_LEVEL)
\r
256 dbgflags-gnu-y += -g3
\r
259 # Optimization specific flags.
\r
260 ifdef BUILD_OPTIMIZATION
\r
261 optflags-gnu-y = -O$(BUILD_OPTIMIZATION)
\r
263 optflags-gnu-y = $(OPTIMIZATION)
\r
266 # Always preprocess assembler files.
\r
267 asflags-gnu-y += -x assembler-with-cpp
\r
268 # Compile C files using the GNU99 standard.
\r
269 cflags-gnu-y += -std=gnu99
\r
270 # Compile C++ files using the GNU++98 standard.
\r
271 cxxflags-gnu-y += -std=gnu++98
\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 -Winline -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
340 ifeq ($(project_type),all)
\r
342 $(MAKE) all PROJECT_TYPE=flash
\r
343 $(MAKE) all PROJECT_TYPE=sram
\r
345 ifeq ($(target_type),lib)
\r
346 all: $(target) $(project).lss $(project).sym
\r
348 ifeq ($(target_type),elf)
\r
349 all: $(target) $(project).lss $(project).sym $(project).hex $(project).bin
\r
358 @echo os type '$(os_type)'
\r
360 @echo '$(findstring Windows,$(OS))'
\r
362 # Clean up the project.
\r
365 @$(if $(strip $(clean-files)),echo $(MSG_CLEAN_FILES))
\r
366 $(if $(strip $(clean-files)),$(Q)$(RM) $(clean-files),)
\r
367 @$(if $(strip $(clean-dirs)),echo $(MSG_CLEAN_DIRS))
\r
368 # Remove created directories, and make sure we only remove existing
\r
369 # directories, since recursive rmdir might help us a bit on the way.
\r
370 ifeq ($(os),Windows)
\r
371 $(Q)$(if $(strip $(clean-dirs)), \
\r
372 $(RMDIR) $(strip $(subst /,\,$(clean-dirs))))
\r
374 $(Q)$(if $(strip $(clean-dirs)), \
\r
375 for directory in $(strip $(clean-dirs)); do \
\r
376 if [ -d "$$directory" ]; then \
\r
377 $(RMDIR) $$directory; \
\r
383 # Rebuild the project.
\r
387 # Debug the project in flash.
\r
388 .PHONY: debug_flash
\r
390 $(GDB) -x "$(PRJ_PATH)/$(DEBUG_SCRIPT_FLASH)" -ex "reset" -readnow -se $(TARGET_FLASH)
\r
392 # Debug the project in sram.
\r
395 $(GDB) -x "$(PRJ_PATH)/$(DEBUG_SCRIPT_SRAM)" -ex "reset" -readnow -se $(TARGET_SRAM)
\r
400 # Create object files from C source files.
\r
401 $(build-dir)%.o: %.c $(PRJ_PATH)/sam/utils/make/Makefile.in config.mk
\r
403 ifeq ($(os),Windows)
\r
404 -mkdir $(subst /,\,$(dir $@))
\r
406 -mkdir -p $(dir $@)
\r
408 @echo $(MSG_COMPILING)
\r
409 $(Q)$(CC) $(c_flags) -c $< -o $@
\r
411 # Create object files from C++ source files.
\r
412 $(build-dir)%.o: %.cpp $(PRJ_PATH)/sam/utils/make/Makefile.in config.mk
\r
414 ifeq ($(os),Windows)
\r
415 -mkdir $(subst /,\,$(dir $@))
\r
417 -mkdir -p $(dir $@)
\r
419 @echo $(MSG_COMPILING_CXX)
\r
420 $(Q)$(CXX) $(cxx_flags) -c $< -o $@
\r
422 # Preprocess and assemble: create object files from assembler source files.
\r
423 $(build-dir)%.o: %.S $(PRJ_PATH)/sam/utils/make/Makefile.in config.mk
\r
425 ifeq ($(os),Windows)
\r
426 -mkdir $(subst /,\,$(dir $@))
\r
428 -mkdir -p $(dir $@)
\r
430 @echo $(MSG_ASSEMBLING)
\r
431 $(Q)$(CC) $(a_flags) -c $< -o $@
\r
433 # Include all dependency files to add depedency to all header files in use.
\r
434 include $(dep-files)
\r
436 ifeq ($(target_type),lib)
\r
437 # Archive object files into an archive
\r
438 $(target): $(PRJ_PATH)/sam/utils/make/Makefile.in config.mk $(obj-y)
\r
439 @echo $(MSG_ARCHIVING)
\r
440 $(Q)$(AR) $(ar_flags) $@ $(obj-y)
\r
442 $(Q)$(SIZE) -Bxt $@
\r
444 ifeq ($(target_type),elf)
\r
445 # Link the object files into an ELF file. Also make sure the target is rebuilt
\r
446 # if the common Makefile.in or project config.mk is changed.
\r
447 $(target): $(linker_script) $(PRJ_PATH)/sam/utils/make/Makefile.in config.mk $(obj-y)
\r
448 @echo $(MSG_LINKING)
\r
449 @echo $(Q)$(LD) $(l_flags) $(obj-y) $(libflags-gnu-y) -o $@
\r
450 $(Q)$(LD) $(l_flags) $(obj-y) $(libflags-gnu-y) -o $@
\r
457 # Create extended function listing from target output file.
\r
459 @echo $(MSG_EXTENDED_LISTING)
\r
460 $(Q)$(OBJDUMP) -h -S $< > $@
\r
462 # Create symbol table from target output file.
\r
464 @echo $(MSG_SYMBOL_TABLE)
\r
465 $(Q)$(NM) -n $< > $@
\r
467 # Create Intel HEX image from ELF output file.
\r
469 @echo $(MSG_IHEX_IMAGE)
\r
470 $(Q)$(OBJCOPY) -O ihex $(flashflags-gnu-y) $< $@
\r
472 # Create binary image from ELF output file.
\r
474 @echo $(MSG_BINARY_IMAGE)
\r
475 $(Q)$(OBJCOPY) -O binary $< $@
\r
477 # Provide information about the detected host operating system.
\r
478 .SECONDARY: info-os
\r
480 @echo $(MSG_INFO)$(os) build host detected
\r
482 # Build Doxygen generated documentation.
\r
485 @echo $(MSG_GENERATING_DOC)
\r
486 $(Q)cd $(dir $(doccfg)) && $(DOCGEN) $(notdir $(doccfg))
\r
488 # Clean Doxygen generated documentation.
\r
491 @$(if $(wildcard $(docdir)),echo $(MSG_CLEAN_DOC))
\r
492 $(Q)$(if $(wildcard $(docdir)),$(RM) --recursive $(docdir))
\r
494 # Rebuild the Doxygen generated documentation.
\r
496 rebuilddoc: cleandoc doc
\r