config.mk 10.9 KB
Newer Older
wdenk's avatar
wdenk committed
1
#
2
# (C) Copyright 2000-2013
wdenk's avatar
wdenk committed
3 4
# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
#
5
# SPDX-License-Identifier:	GPL-2.0+
wdenk's avatar
wdenk committed
6 7 8
#
#########################################################################

9 10 11 12 13 14 15
# Set shell to bash if possible, otherwise fall back to sh
SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
	else if [ -x /bin/bash ]; then echo /bin/bash; \
	else echo sh; fi; fi)

export	SHELL

16
ifeq ($(CURDIR),$(SRCTREE))
Wolfgang Denk's avatar
Wolfgang Denk committed
17
dir :=
18 19 20 21
else
dir := $(subst $(SRCTREE)/,,$(CURDIR))
endif

22 23 24 25 26
ifneq ($(OBJTREE),$(SRCTREE))
# Create object files for SPL in a separate directory
ifeq ($(CONFIG_SPL_BUILD),y)
obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/)
else
27
obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/)
28
endif
29 30
src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/)

31 32 33 34 35 36
$(shell mkdir -p $(obj))
else
# Create object files for SPL in a separate directory
ifeq ($(CONFIG_SPL_BUILD),y)
obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/)

37 38 39
$(shell mkdir -p $(obj))
else
obj :=
40
endif
41 42 43
src :=
endif

wdenk's avatar
wdenk committed
44 45 46 47 48
# clean the slate ...
PLATFORM_RELFLAGS =
PLATFORM_CPPFLAGS =
PLATFORM_LDFLAGS =

wdenk's avatar
wdenk committed
49 50
#########################################################################

51 52 53 54 55 56 57
HOSTCFLAGS	= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \
		  $(HOSTCPPFLAGS)
HOSTSTRIP	= strip

#
# Mac OS X / Darwin's C preprocessor is Apple specific.  It
# generates numerous errors and warnings.  We want to bypass it
58
# and use GNU C's cpp.	To do this we pass the -traditional-cpp
59 60 61 62 63 64 65 66 67
# option to the compiler.  Note that the -traditional-cpp flag
# DOES NOT have the same semantics as GNU C's flag, all it does
# is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
#
# Apple's linker is similar, thanks to the new 2 stage linking
# multiple symbol definitions are treated as errors, hence the
# -multiply_defined suppress option to turn off this error.
#

68
ifeq ($(HOSTOS),darwin)
69 70 71 72
# get major and minor product version (e.g. '10' and '6' for Snow Leopard)
DARWIN_MAJOR_VERSION	= $(shell sw_vers -productVersion | cut -f 1 -d '.')
DARWIN_MINOR_VERSION	= $(shell sw_vers -productVersion | cut -f 2 -d '.')

73 74
os_x_before	= $(shell if [ $(DARWIN_MAJOR_VERSION) -le $(1) -a \
	$(DARWIN_MINOR_VERSION) -le $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;)
75 76

# Snow Leopards build environment has no longer restrictions as described above
77 78 79
HOSTCC		 = $(call os_x_before, 10, 5, "cc", "gcc")
HOSTCFLAGS	+= $(call os_x_before, 10, 4, "-traditional-cpp")
HOSTLDFLAGS	+= $(call os_x_before, 10, 5, "-multiply_defined suppress")
wdenk's avatar
wdenk committed
80 81 82
else
HOSTCC		= gcc
endif
83 84 85 86 87 88 89 90 91 92 93

ifeq ($(HOSTOS),cygwin)
HOSTCFLAGS	+= -ansi
endif

# We build some files with extra pedantic flags to try to minimize things
# that won't build on some weird host compiler -- though there are lots of
# exceptions for files that aren't complaint.

HOSTCFLAGS_NOPED = $(filter-out -pedantic,$(HOSTCFLAGS))
HOSTCFLAGS	+= -pedantic
wdenk's avatar
wdenk committed
94 95

#########################################################################
96
#
97
# Option checker, gcc version (courtesy linux kernel) to ensure
98 99
# only supported compiler options are used
#
100
CC_OPTIONS_CACHE_FILE := $(OBJTREE)/include/generated/cc_options.mk
101
CC_TEST_OFILE := $(OBJTREE)/include/generated/cc_test_file.o
102 103 104

-include $(CC_OPTIONS_CACHE_FILE)

105 106
cc-option-sys = $(shell mkdir -p $(dir $(CC_TEST_OFILE)); \
		if $(CC) $(CFLAGS) $(1) -S -xc /dev/null -o $(CC_TEST_OFILE) \
107 108 109 110 111 112 113 114 115 116
		> /dev/null 2>&1; then \
		echo 'CC_OPTIONS += $(strip $1)' >> $(CC_OPTIONS_CACHE_FILE); \
		echo "$(1)"; fi)

ifeq ($(CONFIG_CC_OPT_CACHE_DISABLE),y)
cc-option = $(strip $(if $(call cc-option-sys,$1),$1,$2))
else
cc-option = $(strip $(if $(findstring $1,$(CC_OPTIONS)),$1,\
		$(if $(call cc-option-sys,$1),$1,$2)))
endif
wdenk's avatar
wdenk committed
117

118 119 120
# cc-version
# Usage gcc-ver := $(call cc-version)
cc-version = $(shell $(SHELL) $(SRCTREE)/tools/gcc-version.sh $(CC))
121
binutils-version = $(shell $(SHELL) $(SRCTREE)/tools/binutils-version.sh $(AS))
122

wdenk's avatar
wdenk committed
123 124 125 126
#
# Include the make variables (CC, etc...)
#
AS	= $(CROSS_COMPILE)as
Khem Raj's avatar
Khem Raj committed
127 128 129 130 131

# Always use GNU ld
LD	= $(shell if $(CROSS_COMPILE)ld.bfd -v > /dev/null 2>&1; \
		then echo "$(CROSS_COMPILE)ld.bfd"; else echo "$(CROSS_COMPILE)ld"; fi;)

wdenk's avatar
wdenk committed
132 133 134 135
CC	= $(CROSS_COMPILE)gcc
CPP	= $(CC) -E
AR	= $(CROSS_COMPILE)ar
NM	= $(CROSS_COMPILE)nm
136
LDR	= $(CROSS_COMPILE)ldr
wdenk's avatar
wdenk committed
137 138 139 140
STRIP	= $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
RANLIB	= $(CROSS_COMPILE)RANLIB
141
DTC	= dtc
142
CHECK	= sparse
wdenk's avatar
wdenk committed
143

144 145 146 147
#########################################################################

# Load generated board configuration
sinclude $(OBJTREE)/include/autoconf.mk
148
sinclude $(OBJTREE)/include/config.mk
149

Peter Tyser's avatar
Peter Tyser committed
150 151
# Some architecture config.mk files need to know what CPUDIR is set to,
# so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
152 153 154 155 156 157
# Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
# CPU-specific code.
CPUDIR=arch/$(ARCH)/cpu/$(CPU)
ifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR)))
CPUDIR=arch/$(ARCH)/cpu
endif
Peter Tyser's avatar
Peter Tyser committed
158

159
sinclude $(TOPDIR)/arch/$(ARCH)/config.mk	# include architecture dependend rules
Peter Tyser's avatar
Peter Tyser committed
160 161
sinclude $(TOPDIR)/$(CPUDIR)/config.mk		# include  CPU	specific rules

162
ifdef	SOC
Peter Tyser's avatar
Peter Tyser committed
163
sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk	# include  SoC	specific rules
164 165 166 167 168 169 170 171 172 173 174 175
endif
ifdef	VENDOR
BOARDDIR = $(VENDOR)/$(BOARD)
else
BOARDDIR = $(BOARD)
endif
ifdef	BOARD
sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk	# include board specific rules
endif

#########################################################################

176 177 178
# We don't actually use $(ARFLAGS) anywhere anymore, so catch people
# who are porting old code to latest mainline but not updating $(AR).
ARFLAGS = $(error update your Makefile to use cmd_link_o_target and not AR)
wdenk's avatar
wdenk committed
179
RELFLAGS= $(PLATFORM_RELFLAGS)
180
DBGFLAGS= -g # -DDEBUG
wdenk's avatar
wdenk committed
181
OPTFLAGS= -Os #-fomit-frame-pointer
182

183
OBJCFLAGS += --gap-fill=0xff
wdenk's avatar
wdenk committed
184

wdenk's avatar
wdenk committed
185 186
gccincdir := $(shell $(CC) -print-file-name=include)

wdenk's avatar
wdenk committed
187
CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS)		\
188
	-D__KERNEL__
189 190 191 192 193 194 195

# Enable garbage collection of un-used sections for SPL
ifeq ($(CONFIG_SPL_BUILD),y)
CPPFLAGS += -ffunction-sections -fdata-sections
LDFLAGS_FINAL += --gc-sections
endif

196 197 198
# TODO(sjg@chromium.org): Is this correct on Mac OS?
ifdef CONFIG_FIT_SIGNATURE
HOSTLIBS	+= -lssl -lcrypto
199 200 201 202

# This affects include/image.h, but including the board config file
# is tricky, so manually define this options here.
HOSTCFLAGS	+= -DCONFIG_FIT_SIGNATURE
203 204
endif

205 206
ifneq ($(CONFIG_SYS_TEXT_BASE),)
CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE)
207
endif
208

209 210 211 212
ifneq ($(CONFIG_SPL_TEXT_BASE),)
CPPFLAGS += -DCONFIG_SPL_TEXT_BASE=$(CONFIG_SPL_TEXT_BASE)
endif

213 214 215 216
ifneq ($(CONFIG_SPL_PAD_TO),)
CPPFLAGS += -DCONFIG_SPL_PAD_TO=$(CONFIG_SPL_PAD_TO)
endif

217 218 219 220
ifneq ($(CONFIG_UBOOT_PAD_TO),)
CPPFLAGS += -DCONFIG_UBOOT_PAD_TO=$(CONFIG_UBOOT_PAD_TO)
endif

221 222 223 224
ifeq ($(CONFIG_SPL_BUILD),y)
CPPFLAGS += -DCONFIG_SPL_BUILD
endif

225 226 227
# Does this architecture support generic board init?
ifeq ($(__HAVE_ARCH_GENERIC_BOARD),)
ifneq ($(CONFIG_SYS_GENERIC_BOARD),)
228 229
CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \
Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file)
230 231 232
endif
endif

233 234 235 236
ifneq ($(RESET_VECTOR_ADDRESS),)
CPPFLAGS += -DRESET_VECTOR_ADDRESS=$(RESET_VECTOR_ADDRESS)
endif

237 238 239 240 241
ifneq ($(OBJTREE),$(SRCTREE))
CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include
endif

CPPFLAGS += -I$(TOPDIR)/include
Wolfgang Denk's avatar
Wolfgang Denk committed
242
CPPFLAGS += -fno-builtin -ffreestanding -nostdinc	\
243
	-isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
wdenk's avatar
wdenk committed
244 245

CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
246 247 248

ifdef BUILD_TAG
CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"'
wdenk's avatar
wdenk committed
249 250
endif

Wolfgang Denk's avatar
Wolfgang Denk committed
251 252
CFLAGS_SSP := $(call cc-option,-fno-stack-protector)
CFLAGS += $(CFLAGS_SSP)
253 254
# Some toolchains enable security related warning flags by default,
# but they don't make much sense in the u-boot world, so disable them.
Wolfgang Denk's avatar
Wolfgang Denk committed
255 256 257
CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \
	       $(call cc-option,-Wno-format-security)
CFLAGS += $(CFLAGS_WARN)
258

259 260 261 262
# Report stack usage if supported
CFLAGS_STACK := $(call cc-option,-fstack-usage)
CFLAGS += $(CFLAGS_STACK)

263 264 265 266 267 268 269 270 271 272
BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))

ifeq ($(findstring examples/,$(BCURDIR)),)
ifeq ($(CONFIG_SPL_BUILD),)
ifdef FTRACE
CFLAGS += -finstrument-functions -DFTRACE
endif
endif
endif

273 274 275
# $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
# option to the assembler.
AFLAGS_DEBUG :=
276

277 278 279 280 281 282
# turn jbsr into jsr for m68k
ifeq ($(ARCH),m68k)
ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
AFLAGS_DEBUG := -Wa,-gstabs,-S
endif
endif
283

wdenk's avatar
wdenk committed
284 285
AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)

286
LDFLAGS += $(PLATFORM_LDFLAGS)
287
LDFLAGS_FINAL += -Bstatic
288

289
LDFLAGS_u-boot += -T $(obj)u-boot.lds $(LDFLAGS_FINAL)
290
ifneq ($(CONFIG_SYS_TEXT_BASE),)
291
LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
292
endif
wdenk's avatar
wdenk committed
293

294 295 296 297 298
LDFLAGS_u-boot-spl += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL)
ifneq ($(CONFIG_SPL_TEXT_BASE),)
LDFLAGS_u-boot-spl += -Ttext $(CONFIG_SPL_TEXT_BASE)
endif

299 300 301 302
# Linus' kernel sanity checking tool
CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
                  -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF)

wdenk's avatar
wdenk committed
303 304 305 306 307 308 309 310 311 312
# Location of a usable BFD library, where we define "usable" as
# "built for ${HOST}, supports ${TARGET}".  Sensible values are
# - When cross-compiling: the root of the cross-environment
# - Linux/ppc (native): /usr
# - NetBSD/ppc (native): you lose ... (must extract these from the
#   binutils build directory, plus the native and U-Boot include
#   files don't like each other)
#
# So far, this is used only by tools/gdb/Makefile.

313
ifeq ($(HOSTOS),darwin)
wdenk's avatar
wdenk committed
314 315
BFD_ROOT_DIR =		/usr/local/tools
else
316 317 318 319
ifeq ($(HOSTARCH),$(ARCH))
# native
BFD_ROOT_DIR =		/usr
else
wdenk's avatar
wdenk committed
320 321 322 323
#BFD_ROOT_DIR =		/LinuxPPC/CDK		# Linux/i386
#BFD_ROOT_DIR =		/usr/pkg/cross		# NetBSD/i386
BFD_ROOT_DIR =		/opt/powerpc
endif
324
endif
wdenk's avatar
wdenk committed
325 326 327

#########################################################################

328
export	HOSTCC HOSTCFLAGS HOSTLDFLAGS PEDCFLAGS HOSTSTRIP CROSS_COMPILE \
329
	AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
330
export	CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
wdenk's avatar
wdenk committed
331 332 333

#########################################################################

334
# Allow boards to use custom optimize flags on a per dir/file basis
335 336
ALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR))
ALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR))
337 338 339 340 341 342 343
EXTRA_CPPFLAGS = $(CPPFLAGS_$(BCURDIR)/$(@F)) $(CPPFLAGS_$(BCURDIR))
ALL_CFLAGS += $(EXTRA_CPPFLAGS)

# The _DEP version uses the $< file target (for dependency generation)
# See rules.mk
EXTRA_CPPFLAGS_DEP = $(CPPFLAGS_$(BCURDIR)/$(addsuffix .o,$(basename $<))) \
		$(CPPFLAGS_$(BCURDIR))
344
$(obj)%.s:	%.S
345
	$(CPP) $(ALL_AFLAGS) -o $@ $<
346
$(obj)%.o:	%.S
347
	$(CC)  $(ALL_AFLAGS) -o $@ $< -c
348
$(obj)%.o:	%.c
349 350 351
ifneq ($(CHECKSRC),0)
	$(CHECK) $(CHECKFLAGS) $(ALL_CFLAGS) $<
endif
352
	$(CC)  $(ALL_CFLAGS) -o $@ $< -c
353
$(obj)%.i:	%.c
354
	$(CPP) $(ALL_CFLAGS) -o $@ $< -c
355
$(obj)%.s:	%.c
356
	$(CC)  $(ALL_CFLAGS) -o $@ $< -c -S
357

wdenk's avatar
wdenk committed
358
#########################################################################
359 360 361

# If the list of objects to link is empty, just create an empty built-in.o
cmd_link_o_target = $(if $(strip $1),\
362
		      $(LD) $(LDFLAGS) -r -o $@ $1,\
363
		      rm -f $@; $(AR) rcs $@ )
364 365

#########################################################################