Makefile: move BFD_ROOT_DIR to tools/gdb/Makefile
[oweals/u-boot.git] / config.mk
1 #
2 # (C) Copyright 2000-2013
3 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 #
5 # SPDX-License-Identifier:      GPL-2.0+
6 #
7 #########################################################################
8
9 ifeq ($(CURDIR),$(SRCTREE))
10 dir :=
11 else
12 dir := $(subst $(SRCTREE)/,,$(CURDIR))
13 endif
14
15 ifneq ($(OBJTREE),$(SRCTREE))
16 # Create object files for SPL in a separate directory
17 ifeq ($(CONFIG_SPL_BUILD),y)
18 ifeq ($(CONFIG_TPL_BUILD),y)
19 obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/)
20 else
21 obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/)
22 endif
23 else
24 obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/)
25 endif
26 src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/)
27
28 $(shell mkdir -p $(obj))
29 else
30 # Create object files for SPL in a separate directory
31 ifeq ($(CONFIG_SPL_BUILD),y)
32 ifeq ($(CONFIG_TPL_BUILD),y)
33 obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/)
34 else
35 obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/)
36
37 endif
38 $(shell mkdir -p $(obj))
39 else
40 obj :=
41 endif
42 src :=
43 endif
44
45 # clean the slate ...
46 PLATFORM_RELFLAGS =
47 PLATFORM_CPPFLAGS =
48 PLATFORM_LDFLAGS =
49
50 #########################################################################
51 #
52 # Option checker, gcc version (courtesy linux kernel) to ensure
53 # only supported compiler options are used
54 #
55 CC_OPTIONS_CACHE_FILE := $(OBJTREE)/include/generated/cc_options.mk
56 CC_TEST_OFILE := $(OBJTREE)/include/generated/cc_test_file.o
57
58 -include $(CC_OPTIONS_CACHE_FILE)
59
60 cc-option-sys = $(shell mkdir -p $(dir $(CC_TEST_OFILE)); \
61                 if $(CC) $(CFLAGS) $(1) -S -xc /dev/null -o $(CC_TEST_OFILE) \
62                 > /dev/null 2>&1; then \
63                 echo 'CC_OPTIONS += $(strip $1)' >> $(CC_OPTIONS_CACHE_FILE); \
64                 echo "$(1)"; fi)
65
66 ifeq ($(CONFIG_CC_OPT_CACHE_DISABLE),y)
67 cc-option = $(strip $(if $(call cc-option-sys,$1),$1,$2))
68 else
69 cc-option = $(strip $(if $(findstring $1,$(CC_OPTIONS)),$1,\
70                 $(if $(call cc-option-sys,$1),$1,$2)))
71 endif
72
73 # cc-version
74 # Usage gcc-ver := $(call cc-version)
75 cc-version = $(shell $(CONFIG_SHELL) $(SRCTREE)/scripts/gcc-version.sh $(CC))
76 binutils-version = $(shell $(CONFIG_SHELL) $(SRCTREE)/scripts/binutils-version.sh $(AS))
77 dtc-version = $(shell $(CONFIG_SHELL) $(SRCTREE)/scripts/dtc-version.sh $(DTC))
78
79 #########################################################################
80
81 # Load generated board configuration
82 ifeq ($(CONFIG_TPL_BUILD),y)
83 # Include TPL autoconf
84 sinclude $(OBJTREE)/include/tpl-autoconf.mk
85 else
86 ifeq ($(CONFIG_SPL_BUILD),y)
87 # Include SPL autoconf
88 sinclude $(OBJTREE)/include/spl-autoconf.mk
89 else
90 # Include normal autoconf
91 sinclude $(OBJTREE)/include/autoconf.mk
92 endif
93 endif
94 sinclude $(OBJTREE)/include/config.mk
95
96 # Some architecture config.mk files need to know what CPUDIR is set to,
97 # so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
98 # Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
99 # CPU-specific code.
100 CPUDIR=arch/$(ARCH)/cpu/$(CPU)
101 ifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR)))
102 CPUDIR=arch/$(ARCH)/cpu
103 endif
104
105 sinclude $(TOPDIR)/arch/$(ARCH)/config.mk       # include architecture dependend rules
106 sinclude $(TOPDIR)/$(CPUDIR)/config.mk          # include  CPU  specific rules
107
108 ifdef   SOC
109 sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk   # include  SoC  specific rules
110 endif
111 ifdef   VENDOR
112 BOARDDIR = $(VENDOR)/$(BOARD)
113 else
114 BOARDDIR = $(BOARD)
115 endif
116 ifdef   BOARD
117 sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk  # include board specific rules
118 endif
119
120 #########################################################################
121
122 # We don't actually use $(ARFLAGS) anywhere anymore, so catch people
123 # who are porting old code to latest mainline but not updating $(AR).
124 ARFLAGS = $(error update your Makefile to use cmd_link_o_target and not AR)
125 RELFLAGS= $(PLATFORM_RELFLAGS)
126 DBGFLAGS= -g # -DDEBUG
127 OPTFLAGS= -Os #-fomit-frame-pointer
128
129 OBJCFLAGS += --gap-fill=0xff
130
131 gccincdir := $(shell $(CC) -print-file-name=include)
132
133 CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS)         \
134         -D__KERNEL__
135
136 # Enable garbage collection of un-used sections for SPL
137 ifeq ($(CONFIG_SPL_BUILD),y)
138 CPPFLAGS += -ffunction-sections -fdata-sections
139 LDFLAGS_FINAL += --gc-sections
140 endif
141
142 ifneq ($(CONFIG_SYS_TEXT_BASE),)
143 CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE)
144 endif
145
146 ifeq ($(CONFIG_SPL_BUILD),y)
147 CPPFLAGS += -DCONFIG_SPL_BUILD
148 ifeq ($(CONFIG_TPL_BUILD),y)
149 CPPFLAGS += -DCONFIG_TPL_BUILD
150 endif
151 endif
152
153 # Does this architecture support generic board init?
154 ifeq ($(__HAVE_ARCH_GENERIC_BOARD),)
155 ifneq ($(CONFIG_SYS_GENERIC_BOARD),)
156 CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \
157 Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file)
158 endif
159 endif
160
161 ifneq ($(OBJTREE),$(SRCTREE))
162 CPPFLAGS += -I$(OBJTREE)/include
163 endif
164
165 CPPFLAGS += -I$(TOPDIR)/include -I$(SRCTREE)/arch/$(ARCH)/include
166 CPPFLAGS += -fno-builtin -ffreestanding -nostdinc       \
167         -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
168
169 CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
170
171 ifdef BUILD_TAG
172 CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"'
173 endif
174
175 CFLAGS_SSP := $(call cc-option,-fno-stack-protector)
176 CFLAGS += $(CFLAGS_SSP)
177 # Some toolchains enable security related warning flags by default,
178 # but they don't make much sense in the u-boot world, so disable them.
179 CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \
180                $(call cc-option,-Wno-format-security)
181 CFLAGS += $(CFLAGS_WARN)
182
183 # Report stack usage if supported
184 CFLAGS_STACK := $(call cc-option,-fstack-usage)
185 CFLAGS += $(CFLAGS_STACK)
186
187 BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))
188
189 ifeq ($(findstring examples/,$(BCURDIR)),)
190 ifeq ($(CONFIG_SPL_BUILD),)
191 ifdef FTRACE
192 CFLAGS += -finstrument-functions -DFTRACE
193 endif
194 endif
195 endif
196
197 # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
198 # option to the assembler.
199 AFLAGS_DEBUG :=
200
201 # turn jbsr into jsr for m68k
202 ifeq ($(ARCH),m68k)
203 ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
204 AFLAGS_DEBUG := -Wa,-gstabs,-S
205 endif
206 endif
207
208 AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
209
210 LDFLAGS += $(PLATFORM_LDFLAGS)
211 LDFLAGS_FINAL += -Bstatic
212
213 LDFLAGS_u-boot += -T $(obj)u-boot.lds $(LDFLAGS_FINAL)
214 ifneq ($(CONFIG_SYS_TEXT_BASE),)
215 LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
216 endif
217
218 LDFLAGS_$(SPL_BIN) += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL)
219 ifneq ($(CONFIG_SPL_TEXT_BASE),)
220 LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
221 endif
222
223 #########################################################################
224
225 export  CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS