xref: /btstack/port/samv71-xplained-atwilc3000/ASF/sam/utils/make/Makefile.sam.in (revision 1b2596b5303dd8caeea8565532c93cca8dab8cc4)
1*1b2596b5SMatthias Ringwald# List of available make goals:
2*1b2596b5SMatthias Ringwald#
3*1b2596b5SMatthias Ringwald# all                     Default target, builds the project
4*1b2596b5SMatthias Ringwald# clean                   Clean up the project
5*1b2596b5SMatthias Ringwald# rebuild                 Rebuild the project
6*1b2596b5SMatthias Ringwald# debug_flash             Builds the project and debug in flash
7*1b2596b5SMatthias Ringwald# debug_sram              Builds the project and debug in sram
8*1b2596b5SMatthias Ringwald#
9*1b2596b5SMatthias Ringwald# doc                     Build the documentation
10*1b2596b5SMatthias Ringwald# cleandoc                Clean up the documentation
11*1b2596b5SMatthias Ringwald# rebuilddoc              Rebuild the documentation
12*1b2596b5SMatthias Ringwald#
13*1b2596b5SMatthias Ringwald# \file
14*1b2596b5SMatthias Ringwald#
15*1b2596b5SMatthias Ringwald# Copyright (c) 2011 - 2013 Atmel Corporation. All rights reserved.
16*1b2596b5SMatthias Ringwald#
17*1b2596b5SMatthias Ringwald# \asf_license_start
18*1b2596b5SMatthias Ringwald#
19*1b2596b5SMatthias Ringwald# \page License
20*1b2596b5SMatthias Ringwald#
21*1b2596b5SMatthias Ringwald# Redistribution and use in source and binary forms, with or without
22*1b2596b5SMatthias Ringwald# modification, are permitted provided that the following conditions are met:
23*1b2596b5SMatthias Ringwald#
24*1b2596b5SMatthias Ringwald# 1. Redistributions of source code must retain the above copyright notice,
25*1b2596b5SMatthias Ringwald#    this list of conditions and the following disclaimer.
26*1b2596b5SMatthias Ringwald#
27*1b2596b5SMatthias Ringwald# 2. Redistributions in binary form must reproduce the above copyright notice,
28*1b2596b5SMatthias Ringwald#    this list of conditions and the following disclaimer in the documentation
29*1b2596b5SMatthias Ringwald#    and/or other materials provided with the distribution.
30*1b2596b5SMatthias Ringwald#
31*1b2596b5SMatthias Ringwald# 3. The name of Atmel may not be used to endorse or promote products derived
32*1b2596b5SMatthias Ringwald#    from this software without specific prior written permission.
33*1b2596b5SMatthias Ringwald#
34*1b2596b5SMatthias Ringwald# 4. This software may only be redistributed and used in connection with an
35*1b2596b5SMatthias Ringwald#    Atmel microcontroller product.
36*1b2596b5SMatthias Ringwald#
37*1b2596b5SMatthias Ringwald# THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
38*1b2596b5SMatthias Ringwald# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
39*1b2596b5SMatthias Ringwald# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
40*1b2596b5SMatthias Ringwald# EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
41*1b2596b5SMatthias Ringwald# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42*1b2596b5SMatthias Ringwald# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43*1b2596b5SMatthias Ringwald# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44*1b2596b5SMatthias Ringwald# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45*1b2596b5SMatthias Ringwald# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
46*1b2596b5SMatthias Ringwald# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
47*1b2596b5SMatthias Ringwald# POSSIBILITY OF SUCH DAMAGE.
48*1b2596b5SMatthias Ringwald#
49*1b2596b5SMatthias Ringwald# \asf_license_stop
50*1b2596b5SMatthias Ringwald#
51*1b2596b5SMatthias Ringwald
52*1b2596b5SMatthias Ringwald# Include the config.mk file from the current working path, e.g., where the
53*1b2596b5SMatthias Ringwald# user called make.
54*1b2596b5SMatthias Ringwaldinclude config.mk
55*1b2596b5SMatthias Ringwald
56*1b2596b5SMatthias Ringwald# Tool to use to generate documentation from the source code
57*1b2596b5SMatthias RingwaldDOCGEN          ?= doxygen
58*1b2596b5SMatthias Ringwald
59*1b2596b5SMatthias Ringwald# Look for source files relative to the top-level source directory
60*1b2596b5SMatthias RingwaldVPATH           := $(PRJ_PATH)
61*1b2596b5SMatthias Ringwald
62*1b2596b5SMatthias Ringwald# Output target file
63*1b2596b5SMatthias Ringwaldproject_type    := $(PROJECT_TYPE)
64*1b2596b5SMatthias Ringwald
65*1b2596b5SMatthias Ringwald# Output target file
66*1b2596b5SMatthias Ringwaldifeq ($(project_type),flash)
67*1b2596b5SMatthias Ringwaldtarget          := $(TARGET_FLASH)
68*1b2596b5SMatthias Ringwaldlinker_script   := $(PRJ_PATH)/$(LINKER_SCRIPT_FLASH)
69*1b2596b5SMatthias Ringwalddebug_script    := $(PRJ_PATH)/$(DEBUG_SCRIPT_FLASH)
70*1b2596b5SMatthias Ringwaldelse
71*1b2596b5SMatthias Ringwaldtarget          := $(TARGET_SRAM)
72*1b2596b5SMatthias Ringwaldlinker_script   := $(PRJ_PATH)/$(LINKER_SCRIPT_SRAM)
73*1b2596b5SMatthias Ringwalddebug_script    := $(PRJ_PATH)/$(DEBUG_SCRIPT_SRAM)
74*1b2596b5SMatthias Ringwaldendif
75*1b2596b5SMatthias Ringwald
76*1b2596b5SMatthias Ringwald# Output project name (target name minus suffix)
77*1b2596b5SMatthias Ringwaldproject         := $(basename $(target))
78*1b2596b5SMatthias Ringwald
79*1b2596b5SMatthias Ringwald# Output target file (typically ELF or static library)
80*1b2596b5SMatthias Ringwaldifeq ($(suffix $(target)),.a)
81*1b2596b5SMatthias Ringwaldtarget_type     := lib
82*1b2596b5SMatthias Ringwaldelse
83*1b2596b5SMatthias Ringwaldifeq ($(suffix $(target)),.elf)
84*1b2596b5SMatthias Ringwaldtarget_type     := elf
85*1b2596b5SMatthias Ringwaldelse
86*1b2596b5SMatthias Ringwald$(error "Target type $(target_type) is not supported")
87*1b2596b5SMatthias Ringwaldendif
88*1b2596b5SMatthias Ringwaldendif
89*1b2596b5SMatthias Ringwald
90*1b2596b5SMatthias Ringwald# Allow override of operating system detection. The user can add OS=Linux or
91*1b2596b5SMatthias Ringwald# OS=Windows on the command line to explicit set the host OS.
92*1b2596b5SMatthias Ringwald#
93*1b2596b5SMatthias Ringwald# This allows to work around broken uname utility on certain systems.
94*1b2596b5SMatthias Ringwaldifdef OS
95*1b2596b5SMatthias Ringwald  ifeq ($(strip $(OS)), Linux)
96*1b2596b5SMatthias Ringwald    os_type     := Linux
97*1b2596b5SMatthias Ringwald  endif
98*1b2596b5SMatthias Ringwald  ifeq ($(strip $(OS)), Windows)
99*1b2596b5SMatthias Ringwald    os_type     := windows32_64
100*1b2596b5SMatthias Ringwald  endif
101*1b2596b5SMatthias Ringwaldendif
102*1b2596b5SMatthias Ringwald
103*1b2596b5SMatthias Ringwaldos_type         ?= $(strip $(shell uname))
104*1b2596b5SMatthias Ringwald
105*1b2596b5SMatthias Ringwaldifeq ($(os_type),windows32)
106*1b2596b5SMatthias Ringwaldos              := Windows
107*1b2596b5SMatthias Ringwaldelse
108*1b2596b5SMatthias Ringwaldifeq ($(os_type),windows64)
109*1b2596b5SMatthias Ringwaldos              := Windows
110*1b2596b5SMatthias Ringwaldelse
111*1b2596b5SMatthias Ringwaldifeq ($(os_type),windows32_64)
112*1b2596b5SMatthias Ringwaldos              ?= Windows
113*1b2596b5SMatthias Ringwaldelse
114*1b2596b5SMatthias Ringwaldifeq ($(os_type),)
115*1b2596b5SMatthias Ringwaldos              := Windows
116*1b2596b5SMatthias Ringwaldelse
117*1b2596b5SMatthias Ringwald# Default to Linux style operating system. Both Cygwin and mingw are fully
118*1b2596b5SMatthias Ringwald# compatible (for this Makefile) with Linux.
119*1b2596b5SMatthias Ringwaldos              := Linux
120*1b2596b5SMatthias Ringwaldendif
121*1b2596b5SMatthias Ringwaldendif
122*1b2596b5SMatthias Ringwaldendif
123*1b2596b5SMatthias Ringwaldendif
124*1b2596b5SMatthias Ringwald
125*1b2596b5SMatthias Ringwald# Output documentation directory and configuration file.
126*1b2596b5SMatthias Ringwalddocdir          := ../doxygen/html
127*1b2596b5SMatthias Ringwalddoccfg          := ../doxygen/doxyfile.doxygen
128*1b2596b5SMatthias Ringwald
129*1b2596b5SMatthias RingwaldCROSS           ?= arm-none-eabi-
130*1b2596b5SMatthias RingwaldAR              := $(CROSS)ar
131*1b2596b5SMatthias RingwaldAS              := $(CROSS)as
132*1b2596b5SMatthias RingwaldCC              := $(CROSS)gcc
133*1b2596b5SMatthias RingwaldCPP             := $(CROSS)gcc -E
134*1b2596b5SMatthias RingwaldCXX             := $(CROSS)g++
135*1b2596b5SMatthias RingwaldLD              := $(CROSS)g++
136*1b2596b5SMatthias RingwaldNM              := $(CROSS)nm
137*1b2596b5SMatthias RingwaldOBJCOPY         := $(CROSS)objcopy
138*1b2596b5SMatthias RingwaldOBJDUMP         := $(CROSS)objdump
139*1b2596b5SMatthias RingwaldSIZE            := $(CROSS)size
140*1b2596b5SMatthias RingwaldGDB             := $(CROSS)gdb
141*1b2596b5SMatthias Ringwald
142*1b2596b5SMatthias RingwaldRM              := rm
143*1b2596b5SMatthias Ringwaldifeq ($(os),Windows)
144*1b2596b5SMatthias RingwaldRMDIR           := rmdir /S /Q
145*1b2596b5SMatthias Ringwaldelse
146*1b2596b5SMatthias RingwaldRMDIR           := rmdir -p --ignore-fail-on-non-empty
147*1b2596b5SMatthias Ringwaldendif
148*1b2596b5SMatthias Ringwald
149*1b2596b5SMatthias Ringwald# On Windows, we need to override the shell to force the use of cmd.exe
150*1b2596b5SMatthias Ringwaldifeq ($(os),Windows)
151*1b2596b5SMatthias RingwaldSHELL           := cmd
152*1b2596b5SMatthias Ringwaldendif
153*1b2596b5SMatthias Ringwald
154*1b2596b5SMatthias Ringwald# Strings for beautifying output
155*1b2596b5SMatthias RingwaldMSG_CLEAN_FILES         = "RM      *.o *.d"
156*1b2596b5SMatthias RingwaldMSG_CLEAN_DIRS          = "RMDIR   $(strip $(clean-dirs))"
157*1b2596b5SMatthias RingwaldMSG_CLEAN_DOC           = "RMDIR   $(docdir)"
158*1b2596b5SMatthias RingwaldMSG_MKDIR               = "MKDIR   $(dir $@)"
159*1b2596b5SMatthias Ringwald
160*1b2596b5SMatthias RingwaldMSG_INFO                = "INFO    "
161*1b2596b5SMatthias RingwaldMSG_PREBUILD            = "PREBUILD  $(PREBUILD_CMD)"
162*1b2596b5SMatthias RingwaldMSG_POSTBUILD           = "POSTBUILD $(POSTBUILD_CMD)"
163*1b2596b5SMatthias Ringwald
164*1b2596b5SMatthias RingwaldMSG_ARCHIVING           = "AR      $@"
165*1b2596b5SMatthias RingwaldMSG_ASSEMBLING          = "AS      $@"
166*1b2596b5SMatthias RingwaldMSG_BINARY_IMAGE        = "OBJCOPY $@"
167*1b2596b5SMatthias RingwaldMSG_COMPILING           = "CC      $@"
168*1b2596b5SMatthias RingwaldMSG_COMPILING_CXX       = "CXX     $@"
169*1b2596b5SMatthias RingwaldMSG_EXTENDED_LISTING    = "OBJDUMP $@"
170*1b2596b5SMatthias RingwaldMSG_IHEX_IMAGE          = "OBJCOPY $@"
171*1b2596b5SMatthias RingwaldMSG_LINKING             = "LN      $@"
172*1b2596b5SMatthias RingwaldMSG_PREPROCESSING       = "CPP     $@"
173*1b2596b5SMatthias RingwaldMSG_SIZE                = "SIZE    $@"
174*1b2596b5SMatthias RingwaldMSG_SYMBOL_TABLE        = "NM      $@"
175*1b2596b5SMatthias Ringwald
176*1b2596b5SMatthias RingwaldMSG_GENERATING_DOC      = "DOXYGEN $(docdir)"
177*1b2596b5SMatthias Ringwald
178*1b2596b5SMatthias Ringwald# Don't use make's built-in rules and variables
179*1b2596b5SMatthias RingwaldMAKEFLAGS       += -rR
180*1b2596b5SMatthias Ringwald
181*1b2596b5SMatthias Ringwald# Don't print 'Entering directory ...'
182*1b2596b5SMatthias RingwaldMAKEFLAGS       += --no-print-directory
183*1b2596b5SMatthias Ringwald
184*1b2596b5SMatthias Ringwald# Function for reversing the order of a list
185*1b2596b5SMatthias Ringwaldreverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
186*1b2596b5SMatthias Ringwald
187*1b2596b5SMatthias Ringwald# Hide command output by default, but allow the user to override this
188*1b2596b5SMatthias Ringwald# by adding V=1 on the command line.
189*1b2596b5SMatthias Ringwald#
190*1b2596b5SMatthias Ringwald# This is inspired by the Kbuild system used by the Linux kernel.
191*1b2596b5SMatthias Ringwaldifdef V
192*1b2596b5SMatthias Ringwald  ifeq ("$(origin V)", "command line")
193*1b2596b5SMatthias Ringwald    VERBOSE = $(V)
194*1b2596b5SMatthias Ringwald  endif
195*1b2596b5SMatthias Ringwaldendif
196*1b2596b5SMatthias Ringwaldifndef VERBOSE
197*1b2596b5SMatthias Ringwald  VERBOSE = 0
198*1b2596b5SMatthias Ringwaldendif
199*1b2596b5SMatthias Ringwald
200*1b2596b5SMatthias Ringwaldifeq ($(VERBOSE), 1)
201*1b2596b5SMatthias Ringwald  Q =
202*1b2596b5SMatthias Ringwaldelse
203*1b2596b5SMatthias Ringwald  Q = @
204*1b2596b5SMatthias Ringwaldendif
205*1b2596b5SMatthias Ringwald
206*1b2596b5SMatthias Ringwaldarflags-gnu-y           := $(ARFLAGS)
207*1b2596b5SMatthias Ringwaldasflags-gnu-y           := $(ASFLAGS)
208*1b2596b5SMatthias Ringwaldcflags-gnu-y            := $(CFLAGS)
209*1b2596b5SMatthias Ringwaldcxxflags-gnu-y          := $(CXXFLAGS)
210*1b2596b5SMatthias Ringwaldcppflags-gnu-y          := $(CPPFLAGS)
211*1b2596b5SMatthias Ringwaldcpuflags-gnu-y          :=
212*1b2596b5SMatthias Ringwalddbgflags-gnu-y          := $(DBGFLAGS)
213*1b2596b5SMatthias Ringwaldlibflags-gnu-y          := $(foreach LIB,$(LIBS),-l$(LIB))
214*1b2596b5SMatthias Ringwaldldflags-gnu-y           := $(LDFLAGS)
215*1b2596b5SMatthias Ringwaldflashflags-gnu-y        :=
216*1b2596b5SMatthias Ringwaldclean-files             :=
217*1b2596b5SMatthias Ringwaldclean-dirs              :=
218*1b2596b5SMatthias Ringwald
219*1b2596b5SMatthias Ringwaldclean-files             += $(wildcard $(target) $(project).map)
220*1b2596b5SMatthias Ringwaldclean-files             += $(wildcard $(project).hex $(project).bin)
221*1b2596b5SMatthias Ringwaldclean-files             += $(wildcard $(project).lss $(project).sym)
222*1b2596b5SMatthias Ringwaldclean-files             += $(wildcard $(build))
223*1b2596b5SMatthias Ringwald
224*1b2596b5SMatthias Ringwald# Use pipes instead of temporary files for communication between processes
225*1b2596b5SMatthias Ringwaldcflags-gnu-y    += -pipe
226*1b2596b5SMatthias Ringwaldasflags-gnu-y   += -pipe
227*1b2596b5SMatthias Ringwaldldflags-gnu-y   += -pipe
228*1b2596b5SMatthias Ringwald
229*1b2596b5SMatthias Ringwald# Archiver flags.
230*1b2596b5SMatthias Ringwaldarflags-gnu-y   += rcs
231*1b2596b5SMatthias Ringwald
232*1b2596b5SMatthias Ringwald# Always enable warnings. And be very careful about implicit
233*1b2596b5SMatthias Ringwald# declarations.
234*1b2596b5SMatthias Ringwaldcflags-gnu-y    += -Wall -Wstrict-prototypes -Wmissing-prototypes
235*1b2596b5SMatthias Ringwaldcflags-gnu-y    += -Werror-implicit-function-declaration
236*1b2596b5SMatthias Ringwaldcxxflags-gnu-y  += -Wall
237*1b2596b5SMatthias Ringwald# IAR doesn't allow arithmetic on void pointers, so warn about that.
238*1b2596b5SMatthias Ringwaldcflags-gnu-y    += -Wpointer-arith
239*1b2596b5SMatthias Ringwaldcxxflags-gnu-y  += -Wpointer-arith
240*1b2596b5SMatthias Ringwald
241*1b2596b5SMatthias Ringwald# Preprocessor flags.
242*1b2596b5SMatthias Ringwaldcppflags-gnu-y  += $(foreach INC,$(addprefix $(PRJ_PATH)/,$(INC_PATH)),-I$(INC))
243*1b2596b5SMatthias Ringwaldasflags-gnu-y   += $(foreach INC,$(addprefix $(PRJ_PATH)/,$(INC_PATH)),'-Wa,-I$(INC)')
244*1b2596b5SMatthias Ringwald
245*1b2596b5SMatthias Ringwald# CPU specific flags.
246*1b2596b5SMatthias Ringwaldcpuflags-gnu-y  += -mcpu=$(ARCH) -mthumb -D=__$(PART)__
247*1b2596b5SMatthias Ringwald
248*1b2596b5SMatthias Ringwald# Dependency file flags.
249*1b2596b5SMatthias Ringwalddepflags        = -MD -MP -MQ $@
250*1b2596b5SMatthias Ringwald
251*1b2596b5SMatthias Ringwald# Debug specific flags.
252*1b2596b5SMatthias Ringwaldifdef BUILD_DEBUG_LEVEL
253*1b2596b5SMatthias Ringwalddbgflags-gnu-y  += -g$(BUILD_DEBUG_LEVEL)
254*1b2596b5SMatthias Ringwaldelse
255*1b2596b5SMatthias Ringwalddbgflags-gnu-y  += -g3
256*1b2596b5SMatthias Ringwaldendif
257*1b2596b5SMatthias Ringwald
258*1b2596b5SMatthias Ringwald# Optimization specific flags.
259*1b2596b5SMatthias Ringwaldifdef BUILD_OPTIMIZATION
260*1b2596b5SMatthias Ringwaldoptflags-gnu-y  = -O$(BUILD_OPTIMIZATION)
261*1b2596b5SMatthias Ringwaldelse
262*1b2596b5SMatthias Ringwaldoptflags-gnu-y  = $(OPTIMIZATION)
263*1b2596b5SMatthias Ringwaldendif
264*1b2596b5SMatthias Ringwald
265*1b2596b5SMatthias Ringwald# Always preprocess assembler files.
266*1b2596b5SMatthias Ringwaldasflags-gnu-y   += -x assembler-with-cpp
267*1b2596b5SMatthias Ringwald# Compile C files using the GNU99 standard.
268*1b2596b5SMatthias Ringwaldcflags-gnu-y    += -std=gnu99
269*1b2596b5SMatthias Ringwald# Compile C++ files using the GNU++98 standard.
270*1b2596b5SMatthias Ringwaldcxxflags-gnu-y  += -std=gnu++98
271*1b2596b5SMatthias Ringwald
272*1b2596b5SMatthias Ringwald# Don't use strict aliasing (very common in embedded applications).
273*1b2596b5SMatthias Ringwaldcflags-gnu-y    += -fno-strict-aliasing
274*1b2596b5SMatthias Ringwaldcxxflags-gnu-y  += -fno-strict-aliasing
275*1b2596b5SMatthias Ringwald
276*1b2596b5SMatthias Ringwald# Separate each function and data into its own separate section to allow
277*1b2596b5SMatthias Ringwald# garbage collection of unused sections.
278*1b2596b5SMatthias Ringwaldcflags-gnu-y    += -ffunction-sections -fdata-sections
279*1b2596b5SMatthias Ringwaldcxxflags-gnu-y  += -ffunction-sections -fdata-sections
280*1b2596b5SMatthias Ringwald
281*1b2596b5SMatthias Ringwald# Various cflags.
282*1b2596b5SMatthias Ringwaldcflags-gnu-y += -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int
283*1b2596b5SMatthias Ringwaldcflags-gnu-y += -Wmain -Wparentheses
284*1b2596b5SMatthias Ringwaldcflags-gnu-y += -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused
285*1b2596b5SMatthias Ringwaldcflags-gnu-y += -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef
286*1b2596b5SMatthias Ringwaldcflags-gnu-y += -Wshadow -Wbad-function-cast -Wwrite-strings
287*1b2596b5SMatthias Ringwaldcflags-gnu-y += -Wsign-compare -Waggregate-return
288*1b2596b5SMatthias Ringwaldcflags-gnu-y += -Wmissing-declarations
289*1b2596b5SMatthias Ringwaldcflags-gnu-y += -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations
290*1b2596b5SMatthias Ringwaldcflags-gnu-y += -Wpacked -Wredundant-decls -Wnested-externs -Winline -Wlong-long
291*1b2596b5SMatthias Ringwaldcflags-gnu-y += -Wunreachable-code
292*1b2596b5SMatthias Ringwaldcflags-gnu-y += -Wcast-align
293*1b2596b5SMatthias Ringwaldcflags-gnu-y += --param max-inline-insns-single=500
294*1b2596b5SMatthias Ringwald
295*1b2596b5SMatthias Ringwald# Garbage collect unreferred sections when linking.
296*1b2596b5SMatthias Ringwaldldflags-gnu-y   += -Wl,--gc-sections
297*1b2596b5SMatthias Ringwald
298*1b2596b5SMatthias Ringwald# Use the linker script if provided by the project.
299*1b2596b5SMatthias Ringwaldifneq ($(strip $(linker_script)),)
300*1b2596b5SMatthias Ringwaldldflags-gnu-y   += -Wl,-T $(linker_script)
301*1b2596b5SMatthias Ringwaldendif
302*1b2596b5SMatthias Ringwald
303*1b2596b5SMatthias Ringwald# Output a link map file and a cross reference table
304*1b2596b5SMatthias Ringwaldldflags-gnu-y   += -Wl,-Map=$(project).map,--cref
305*1b2596b5SMatthias Ringwald
306*1b2596b5SMatthias Ringwald# Add library search paths relative to the top level directory.
307*1b2596b5SMatthias Ringwaldldflags-gnu-y   += $(foreach _LIB_PATH,$(addprefix $(PRJ_PATH)/,$(LIB_PATH)),-L$(_LIB_PATH))
308*1b2596b5SMatthias Ringwald
309*1b2596b5SMatthias Ringwalda_flags  = $(cpuflags-gnu-y) $(depflags) $(cppflags-gnu-y) $(asflags-gnu-y) -D__ASSEMBLY__
310*1b2596b5SMatthias Ringwaldc_flags  = $(cpuflags-gnu-y) $(dbgflags-gnu-y) $(depflags) $(optflags-gnu-y) $(cppflags-gnu-y) $(cflags-gnu-y)
311*1b2596b5SMatthias Ringwaldcxx_flags= $(cpuflags-gnu-y) $(dbgflags-gnu-y) $(depflags) $(optflags-gnu-y) $(cppflags-gnu-y) $(cxxflags-gnu-y)
312*1b2596b5SMatthias Ringwaldl_flags  = -Wl,--entry=Reset_Handler -Wl,--cref $(cpuflags-gnu-y) $(optflags-gnu-y) $(ldflags-gnu-y)
313*1b2596b5SMatthias Ringwaldar_flags = $(arflags-gnu-y)
314*1b2596b5SMatthias Ringwald
315*1b2596b5SMatthias Ringwald# Source files list and part informations must already be included before
316*1b2596b5SMatthias Ringwald# running this makefile
317*1b2596b5SMatthias Ringwald
318*1b2596b5SMatthias Ringwald# If a custom build directory is specified, use it -- force trailing / in directory name.
319*1b2596b5SMatthias Ringwaldifdef BUILD_DIR
320*1b2596b5SMatthias Ringwald	build-dir       := $(dir $(BUILD_DIR))$(if $(notdir $(BUILD_DIR)),$(notdir $(BUILD_DIR))/)
321*1b2596b5SMatthias Ringwaldelse
322*1b2596b5SMatthias Ringwald	build-dir        =
323*1b2596b5SMatthias Ringwaldendif
324*1b2596b5SMatthias Ringwald
325*1b2596b5SMatthias Ringwald# Create object files list from source files list.
326*1b2596b5SMatthias Ringwaldobj-y                   := $(addprefix $(build-dir), $(addsuffix .o,$(basename $(CSRCS) $(ASSRCS))))
327*1b2596b5SMatthias Ringwald# Create dependency files list from source files list.
328*1b2596b5SMatthias Ringwalddep-files               := $(wildcard $(foreach f,$(obj-y),$(basename $(f)).d))
329*1b2596b5SMatthias Ringwald
330*1b2596b5SMatthias Ringwaldclean-files             += $(wildcard $(obj-y))
331*1b2596b5SMatthias Ringwaldclean-files             += $(dep-files)
332*1b2596b5SMatthias Ringwald
333*1b2596b5SMatthias Ringwaldclean-dirs              += $(call reverse,$(sort $(wildcard $(dir $(obj-y)))))
334*1b2596b5SMatthias Ringwald
335*1b2596b5SMatthias Ringwald# Default target.
336*1b2596b5SMatthias Ringwald.PHONY: all
337*1b2596b5SMatthias Ringwaldifeq ($(project_type),all)
338*1b2596b5SMatthias Ringwaldall:
339*1b2596b5SMatthias Ringwald	$(MAKE) all PROJECT_TYPE=flash
340*1b2596b5SMatthias Ringwald	$(MAKE) all PROJECT_TYPE=sram
341*1b2596b5SMatthias Ringwaldelse
342*1b2596b5SMatthias Ringwaldifeq ($(target_type),lib)
343*1b2596b5SMatthias Ringwaldall: $(target) $(project).lss $(project).sym
344*1b2596b5SMatthias Ringwaldelse
345*1b2596b5SMatthias Ringwaldifeq ($(target_type),elf)
346*1b2596b5SMatthias Ringwaldall: prebuild $(target) $(project).lss $(project).sym $(project).hex $(project).bin postbuild
347*1b2596b5SMatthias Ringwaldendif
348*1b2596b5SMatthias Ringwaldendif
349*1b2596b5SMatthias Ringwaldendif
350*1b2596b5SMatthias Ringwald
351*1b2596b5SMatthias Ringwaldprebuild:
352*1b2596b5SMatthias Ringwaldifneq ($(strip $(PREBUILD_CMD)),)
353*1b2596b5SMatthias Ringwald	@echo $(MSG_PREBUILD)
354*1b2596b5SMatthias Ringwald	$(Q)$(PREBUILD_CMD)
355*1b2596b5SMatthias Ringwaldendif
356*1b2596b5SMatthias Ringwald
357*1b2596b5SMatthias Ringwaldpostbuild:
358*1b2596b5SMatthias Ringwaldifneq ($(strip $(POSTBUILD_CMD)),)
359*1b2596b5SMatthias Ringwald	@echo $(MSG_POSTBUILD)
360*1b2596b5SMatthias Ringwald	$(Q)$(POSTBUILD_CMD)
361*1b2596b5SMatthias Ringwaldendif
362*1b2596b5SMatthias Ringwald
363*1b2596b5SMatthias Ringwald# Clean up the project.
364*1b2596b5SMatthias Ringwald.PHONY: clean
365*1b2596b5SMatthias Ringwaldclean:
366*1b2596b5SMatthias Ringwald	@$(if $(strip $(clean-files)),echo $(MSG_CLEAN_FILES))
367*1b2596b5SMatthias Ringwald	$(if $(strip $(clean-files)),$(Q)$(RM) $(clean-files),)
368*1b2596b5SMatthias Ringwald	@$(if $(strip $(clean-dirs)),echo $(MSG_CLEAN_DIRS))
369*1b2596b5SMatthias Ringwald# Remove created directories, and make sure we only remove existing
370*1b2596b5SMatthias Ringwald# directories, since recursive rmdir might help us a bit on the way.
371*1b2596b5SMatthias Ringwaldifeq ($(os),Windows)
372*1b2596b5SMatthias Ringwald	$(Q)$(if $(strip $(clean-dirs)),                        \
373*1b2596b5SMatthias Ringwald			$(RMDIR) $(strip $(subst /,\,$(clean-dirs))))
374*1b2596b5SMatthias Ringwaldelse
375*1b2596b5SMatthias Ringwald	$(Q)$(if $(strip $(clean-dirs)),                        \
376*1b2596b5SMatthias Ringwald		for directory in $(strip $(clean-dirs)); do     \
377*1b2596b5SMatthias Ringwald			if [ -d "$$directory" ]; then           \
378*1b2596b5SMatthias Ringwald				$(RMDIR) $$directory;           \
379*1b2596b5SMatthias Ringwald			fi                                      \
380*1b2596b5SMatthias Ringwald		done                                            \
381*1b2596b5SMatthias Ringwald	)
382*1b2596b5SMatthias Ringwaldendif
383*1b2596b5SMatthias Ringwald
384*1b2596b5SMatthias Ringwald# Rebuild the project.
385*1b2596b5SMatthias Ringwald.PHONY: rebuild
386*1b2596b5SMatthias Ringwaldrebuild: clean all
387*1b2596b5SMatthias Ringwald
388*1b2596b5SMatthias Ringwald# Debug the project in flash.
389*1b2596b5SMatthias Ringwald.PHONY: debug_flash
390*1b2596b5SMatthias Ringwalddebug_flash: all
391*1b2596b5SMatthias Ringwald	$(GDB) -x "$(PRJ_PATH)/$(DEBUG_SCRIPT_FLASH)" -ex "reset" -readnow -se $(TARGET_FLASH)
392*1b2596b5SMatthias Ringwald
393*1b2596b5SMatthias Ringwald# Debug the project in sram.
394*1b2596b5SMatthias Ringwald.PHONY: debug_sram
395*1b2596b5SMatthias Ringwalddebug_sram: all
396*1b2596b5SMatthias Ringwald	$(GDB) -x "$(PRJ_PATH)/$(DEBUG_SCRIPT_SRAM)" -ex "reset" -readnow -se $(TARGET_SRAM)
397*1b2596b5SMatthias Ringwald
398*1b2596b5SMatthias Ringwald.PHONY: objfiles
399*1b2596b5SMatthias Ringwaldobjfiles: $(obj-y)
400*1b2596b5SMatthias Ringwald
401*1b2596b5SMatthias Ringwald# Create object files from C source files.
402*1b2596b5SMatthias Ringwald$(build-dir)%.o: %.c $(MAKEFILE_PATH) config.mk
403*1b2596b5SMatthias Ringwald	$(Q)test -d $(dir $@) || echo $(MSG_MKDIR)
404*1b2596b5SMatthias Ringwaldifeq ($(os),Windows)
405*1b2596b5SMatthias Ringwald	$(Q)test -d $(patsubst %/,%,$(dir $@)) || mkdir $(subst /,\,$(dir $@))
406*1b2596b5SMatthias Ringwaldelse
407*1b2596b5SMatthias Ringwald	$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
408*1b2596b5SMatthias Ringwaldendif
409*1b2596b5SMatthias Ringwald	@echo $(MSG_COMPILING)
410*1b2596b5SMatthias Ringwald	$(Q)$(CC) $(c_flags) -c $< -o $@
411*1b2596b5SMatthias Ringwald
412*1b2596b5SMatthias Ringwald# Create object files from C++ source files.
413*1b2596b5SMatthias Ringwald$(build-dir)%.o: %.cpp $(MAKEFILE_PATH) config.mk
414*1b2596b5SMatthias Ringwald	$(Q)test -d $(dir $@) || echo $(MSG_MKDIR)
415*1b2596b5SMatthias Ringwaldifeq ($(os),Windows)
416*1b2596b5SMatthias Ringwald	$(Q)test -d $(patsubst %/,%,$(dir $@)) || mkdir $(subst /,\,$(dir $@))
417*1b2596b5SMatthias Ringwaldelse
418*1b2596b5SMatthias Ringwald	$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
419*1b2596b5SMatthias Ringwaldendif
420*1b2596b5SMatthias Ringwald	@echo $(MSG_COMPILING_CXX)
421*1b2596b5SMatthias Ringwald	$(Q)$(CXX) $(cxx_flags) -c $< -o $@
422*1b2596b5SMatthias Ringwald
423*1b2596b5SMatthias Ringwald# Preprocess and assemble: create object files from assembler source files.
424*1b2596b5SMatthias Ringwald$(build-dir)%.o: %.S $(MAKEFILE_PATH) config.mk
425*1b2596b5SMatthias Ringwald	$(Q)test -d $(dir $@) || echo $(MSG_MKDIR)
426*1b2596b5SMatthias Ringwaldifeq ($(os),Windows)
427*1b2596b5SMatthias Ringwald	$(Q)test -d $(patsubst %/,%,$(dir $@)) || mkdir $(subst /,\,$(dir $@))
428*1b2596b5SMatthias Ringwaldelse
429*1b2596b5SMatthias Ringwald	$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
430*1b2596b5SMatthias Ringwaldendif
431*1b2596b5SMatthias Ringwald	@echo $(MSG_ASSEMBLING)
432*1b2596b5SMatthias Ringwald	$(Q)$(CC) $(a_flags) -c $< -o $@
433*1b2596b5SMatthias Ringwald
434*1b2596b5SMatthias Ringwald# Include all dependency files to add depedency to all header files in use.
435*1b2596b5SMatthias Ringwaldinclude $(dep-files)
436*1b2596b5SMatthias Ringwald
437*1b2596b5SMatthias Ringwaldifeq ($(target_type),lib)
438*1b2596b5SMatthias Ringwald# Archive object files into an archive
439*1b2596b5SMatthias Ringwald$(target): $(MAKEFILE_PATH) config.mk $(obj-y)
440*1b2596b5SMatthias Ringwald	@echo $(MSG_ARCHIVING)
441*1b2596b5SMatthias Ringwald	$(Q)$(AR) $(ar_flags) $@ $(obj-y)
442*1b2596b5SMatthias Ringwald	@echo $(MSG_SIZE)
443*1b2596b5SMatthias Ringwald	$(Q)$(SIZE) -Bxt $@
444*1b2596b5SMatthias Ringwaldelse
445*1b2596b5SMatthias Ringwaldifeq ($(target_type),elf)
446*1b2596b5SMatthias Ringwald# Link the object files into an ELF file. Also make sure the target is rebuilt
447*1b2596b5SMatthias Ringwald# if the common Makefile.sam.in or project config.mk is changed.
448*1b2596b5SMatthias Ringwald$(target): $(linker_script) $(MAKEFILE_PATH) config.mk $(obj-y)
449*1b2596b5SMatthias Ringwald	@echo $(MSG_LINKING)
450*1b2596b5SMatthias Ringwald	$(Q)$(LD) $(l_flags) $(obj-y) $(libflags-gnu-y) -o $@
451*1b2596b5SMatthias Ringwald	@echo $(MSG_SIZE)
452*1b2596b5SMatthias Ringwald	$(Q)$(SIZE) -Ax $@
453*1b2596b5SMatthias Ringwald	$(Q)$(SIZE) -Bx $@
454*1b2596b5SMatthias Ringwaldendif
455*1b2596b5SMatthias Ringwaldendif
456*1b2596b5SMatthias Ringwald
457*1b2596b5SMatthias Ringwald# Create extended function listing from target output file.
458*1b2596b5SMatthias Ringwald%.lss: $(target)
459*1b2596b5SMatthias Ringwald	@echo $(MSG_EXTENDED_LISTING)
460*1b2596b5SMatthias Ringwald	$(Q)$(OBJDUMP) -h -S $< > $@
461*1b2596b5SMatthias Ringwald
462*1b2596b5SMatthias Ringwald# Create symbol table from target output file.
463*1b2596b5SMatthias Ringwald%.sym: $(target)
464*1b2596b5SMatthias Ringwald	@echo $(MSG_SYMBOL_TABLE)
465*1b2596b5SMatthias Ringwald	$(Q)$(NM) -n $< > $@
466*1b2596b5SMatthias Ringwald
467*1b2596b5SMatthias Ringwald# Create Intel HEX image from ELF output file.
468*1b2596b5SMatthias Ringwald%.hex: $(target)
469*1b2596b5SMatthias Ringwald	@echo $(MSG_IHEX_IMAGE)
470*1b2596b5SMatthias Ringwald	$(Q)$(OBJCOPY) -O ihex $(flashflags-gnu-y)  $< $@
471*1b2596b5SMatthias Ringwald
472*1b2596b5SMatthias Ringwald# Create binary image from ELF output file.
473*1b2596b5SMatthias Ringwald%.bin: $(target)
474*1b2596b5SMatthias Ringwald	@echo $(MSG_BINARY_IMAGE)
475*1b2596b5SMatthias Ringwald	$(Q)$(OBJCOPY) -O binary $< $@
476*1b2596b5SMatthias Ringwald
477*1b2596b5SMatthias Ringwald# Provide information about the detected host operating system.
478*1b2596b5SMatthias Ringwald.SECONDARY: info-os
479*1b2596b5SMatthias Ringwaldinfo-os:
480*1b2596b5SMatthias Ringwald	@echo $(MSG_INFO)$(os) build host detected
481*1b2596b5SMatthias Ringwald
482*1b2596b5SMatthias Ringwald# Build Doxygen generated documentation.
483*1b2596b5SMatthias Ringwald.PHONY: doc
484*1b2596b5SMatthias Ringwalddoc:
485*1b2596b5SMatthias Ringwald	@echo $(MSG_GENERATING_DOC)
486*1b2596b5SMatthias Ringwald	$(Q)cd $(dir $(doccfg)) && $(DOCGEN) $(notdir $(doccfg))
487*1b2596b5SMatthias Ringwald
488*1b2596b5SMatthias Ringwald# Clean Doxygen generated documentation.
489*1b2596b5SMatthias Ringwald.PHONY: cleandoc
490*1b2596b5SMatthias Ringwaldcleandoc:
491*1b2596b5SMatthias Ringwald	@$(if $(wildcard $(docdir)),echo $(MSG_CLEAN_DOC))
492*1b2596b5SMatthias Ringwald	$(Q)$(if $(wildcard $(docdir)),$(RM) --recursive $(docdir))
493*1b2596b5SMatthias Ringwald
494*1b2596b5SMatthias Ringwald# Rebuild the Doxygen generated documentation.
495*1b2596b5SMatthias Ringwald.PHONY: rebuilddoc
496*1b2596b5SMatthias Ringwaldrebuilddoc: cleandoc doc
497