]>
Commit | Line | Data |
---|---|---|
e2211743 | 1 | # |
eca3aeb3 | 2 | # (C) Copyright 2000-2013 |
e2211743 WD |
3 | # Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
4 | # | |
eca3aeb3 | 5 | # SPDX-License-Identifier: GPL-2.0+ |
e2211743 | 6 | # |
e2211743 WD |
7 | ######################################################################### |
8 | ||
f9328639 | 9 | ifeq ($(CURDIR),$(SRCTREE)) |
511d0c72 | 10 | dir := |
f9328639 MB |
11 | else |
12 | dir := $(subst $(SRCTREE)/,,$(CURDIR)) | |
13 | endif | |
14 | ||
c8f9c302 DS |
15 | ifneq ($(OBJTREE),$(SRCTREE)) |
16 | # Create object files for SPL in a separate directory | |
17 | ifeq ($(CONFIG_SPL_BUILD),y) | |
3aa29de0 YZ |
18 | ifeq ($(CONFIG_TPL_BUILD),y) |
19 | obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/) | |
20 | else | |
c8f9c302 | 21 | obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/) |
3aa29de0 | 22 | endif |
c8f9c302 | 23 | else |
f9328639 | 24 | obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/) |
c8f9c302 | 25 | endif |
f9328639 MB |
26 | src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/) |
27 | ||
c8f9c302 DS |
28 | $(shell mkdir -p $(obj)) |
29 | else | |
30 | # Create object files for SPL in a separate directory | |
31 | ifeq ($(CONFIG_SPL_BUILD),y) | |
3aa29de0 YZ |
32 | ifeq ($(CONFIG_TPL_BUILD),y) |
33 | obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/) | |
34 | else | |
c8f9c302 DS |
35 | obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/) |
36 | ||
3aa29de0 | 37 | endif |
f9328639 MB |
38 | $(shell mkdir -p $(obj)) |
39 | else | |
40 | obj := | |
c8f9c302 | 41 | endif |
f9328639 MB |
42 | src := |
43 | endif | |
44 | ||
592c5cab WD |
45 | # clean the slate ... |
46 | PLATFORM_RELFLAGS = | |
47 | PLATFORM_CPPFLAGS = | |
48 | PLATFORM_LDFLAGS = | |
49 | ||
e2211743 | 50 | ######################################################################### |
1820d4c7 | 51 | # |
19a695f8 | 52 | # Option checker, gcc version (courtesy linux kernel) to ensure |
1820d4c7 WD |
53 | # only supported compiler options are used |
54 | # | |
b6a467d7 | 55 | CC_OPTIONS_CACHE_FILE := $(OBJTREE)/include/generated/cc_options.mk |
6f4acc17 | 56 | CC_TEST_OFILE := $(OBJTREE)/include/generated/cc_test_file.o |
b6a467d7 DS |
57 | |
58 | -include $(CC_OPTIONS_CACHE_FILE) | |
59 | ||
6f4acc17 TR |
60 | cc-option-sys = $(shell mkdir -p $(dir $(CC_TEST_OFILE)); \ |
61 | if $(CC) $(CFLAGS) $(1) -S -xc /dev/null -o $(CC_TEST_OFILE) \ | |
b6a467d7 DS |
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 | |
e2211743 | 72 | |
19a695f8 TR |
73 | # cc-version |
74 | # Usage gcc-ver := $(call cc-version) | |
f6322eb7 MY |
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)) | |
e2211743 | 78 | |
c4e5f52a WD |
79 | ######################################################################### |
80 | ||
81 | # Load generated board configuration | |
3aa29de0 YZ |
82 | ifeq ($(CONFIG_TPL_BUILD),y) |
83 | # Include TPL autoconf | |
84 | sinclude $(OBJTREE)/include/tpl-autoconf.mk | |
85 | else | |
39bc12dd JF |
86 | ifeq ($(CONFIG_SPL_BUILD),y) |
87 | # Include SPL autoconf | |
88 | sinclude $(OBJTREE)/include/spl-autoconf.mk | |
89 | else | |
90 | # Include normal autoconf | |
c4e5f52a | 91 | sinclude $(OBJTREE)/include/autoconf.mk |
39bc12dd | 92 | endif |
3aa29de0 | 93 | endif |
5e987ddf | 94 | sinclude $(OBJTREE)/include/config.mk |
c4e5f52a | 95 | |
03b7004d PT |
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. | |
8d1f2682 PT |
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 | |
03b7004d | 104 | |
ea0364f1 | 105 | sinclude $(TOPDIR)/arch/$(ARCH)/config.mk # include architecture dependend rules |
03b7004d PT |
106 | sinclude $(TOPDIR)/$(CPUDIR)/config.mk # include CPU specific rules |
107 | ||
c4e5f52a | 108 | ifdef SOC |
03b7004d | 109 | sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules |
c4e5f52a WD |
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 | ||
5968adc4 MF |
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) | |
e2211743 | 125 | RELFLAGS= $(PLATFORM_RELFLAGS) |
9acb626f | 126 | DBGFLAGS= -g # -DDEBUG |
e2211743 | 127 | OPTFLAGS= -Os #-fomit-frame-pointer |
83b7e2a7 | 128 | |
6dd652fa | 129 | OBJCFLAGS += --gap-fill=0xff |
e2211743 | 130 | |
b783edae WD |
131 | gccincdir := $(shell $(CC) -print-file-name=include) |
132 | ||
e2211743 | 133 | CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \ |
c1f5805a | 134 | -D__KERNEL__ |
c8f9c302 DS |
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 | ||
14d0a02a WD |
142 | ifneq ($(CONFIG_SYS_TEXT_BASE),) |
143 | CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) | |
161b2af4 | 144 | endif |
f9328639 | 145 | |
c8f9c302 DS |
146 | ifeq ($(CONFIG_SPL_BUILD),y) |
147 | CPPFLAGS += -DCONFIG_SPL_BUILD | |
3aa29de0 YZ |
148 | ifeq ($(CONFIG_TPL_BUILD),y) |
149 | CPPFLAGS += -DCONFIG_TPL_BUILD | |
150 | endif | |
c8f9c302 DS |
151 | endif |
152 | ||
5c1a7ea6 SG |
153 | # Does this architecture support generic board init? |
154 | ifeq ($(__HAVE_ARCH_GENERIC_BOARD),) | |
155 | ifneq ($(CONFIG_SYS_GENERIC_BOARD),) | |
fada9e20 SG |
156 | CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \ |
157 | Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file) | |
5c1a7ea6 SG |
158 | endif |
159 | endif | |
160 | ||
f9328639 | 161 | ifneq ($(OBJTREE),$(SRCTREE)) |
3d83efbc | 162 | CPPFLAGS += -I$(OBJTREE)/include |
f9328639 MB |
163 | endif |
164 | ||
3d83efbc | 165 | CPPFLAGS += -I$(TOPDIR)/include -I$(SRCTREE)/arch/$(ARCH)/include |
53677ef1 | 166 | CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \ |
f9328639 | 167 | -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS) |
e2211743 | 168 | |
e2211743 | 169 | CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes |
d642c467 MV |
170 | |
171 | ifdef BUILD_TAG | |
172 | CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"' | |
e2211743 WD |
173 | endif |
174 | ||
cca4e4ae WD |
175 | CFLAGS_SSP := $(call cc-option,-fno-stack-protector) |
176 | CFLAGS += $(CFLAGS_SSP) | |
6262e4e7 MF |
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. | |
cca4e4ae WD |
179 | CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \ |
180 | $(call cc-option,-Wno-format-security) | |
181 | CFLAGS += $(CFLAGS_WARN) | |
28eab0d7 | 182 | |
4a30f1e8 TR |
183 | # Report stack usage if supported |
184 | CFLAGS_STACK := $(call cc-option,-fstack-usage) | |
185 | CFLAGS += $(CFLAGS_STACK) | |
186 | ||
5c2aeac5 SG |
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 | ||
e11887a7 HS |
197 | # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format> |
198 | # option to the assembler. | |
199 | AFLAGS_DEBUG := | |
b62fa913 | 200 | |
483a0cf8 MB |
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 | |
483a0cf8 | 206 | endif |
b62fa913 | 207 | |
e2211743 WD |
208 | AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS) |
209 | ||
8aba9dce | 210 | LDFLAGS += $(PLATFORM_LDFLAGS) |
6dc1eceb | 211 | LDFLAGS_FINAL += -Bstatic |
8aba9dce | 212 | |
6dc1eceb | 213 | LDFLAGS_u-boot += -T $(obj)u-boot.lds $(LDFLAGS_FINAL) |
14d0a02a | 214 | ifneq ($(CONFIG_SYS_TEXT_BASE),) |
8aba9dce | 215 | LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE) |
161b2af4 | 216 | endif |
e2211743 | 217 | |
3aa29de0 | 218 | LDFLAGS_$(SPL_BIN) += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL) |
c8f9c302 | 219 | ifneq ($(CONFIG_SPL_TEXT_BASE),) |
3aa29de0 | 220 | LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE) |
c8f9c302 DS |
221 | endif |
222 | ||
e2211743 WD |
223 | ######################################################################### |
224 | ||
14d0a02a | 225 | export CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS |