kernel/4.4: add missing config options
[openwrt/openwrt.git] / rules.mk
1 #
2 # Copyright (C) 2006-2010 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 ifneq ($(__rules_inc),1)
9 __rules_inc=1
10
11 ifeq ($(DUMP),)
12 -include $(TOPDIR)/.config
13 endif
14 include $(TOPDIR)/include/debug.mk
15 include $(TOPDIR)/include/verbose.mk
16
17 export TMP_DIR:=$(TOPDIR)/tmp
18
19 qstrip=$(strip $(subst ",,$(1)))
20 #"))
21
22 empty:=
23 space:= $(empty) $(empty)
24 comma:=,
25 merge=$(subst $(space),,$(1))
26 confvar=$(call merge,$(foreach v,$(1),$(if $($(v)),y,n)))
27 strip_last=$(patsubst %.$(lastword $(subst .,$(space),$(1))),%,$(1))
28
29 paren_left = (
30 paren_right = )
31 chars_lower = a b c d e f g h i j k l m n o p q r s t u v w x y z
32 chars_upper = A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
33
34 define sep
35
36 endef
37
38 define newline
39
40
41 endef
42
43 __tr_list = $(join $(join $(1),$(foreach char,$(1),$(comma))),$(2))
44 __tr_head_stripped = $(subst $(space),,$(foreach cv,$(call __tr_list,$(1),$(2)),$$$(paren_left)subst$(cv)$(comma)))
45 __tr_head = $(subst $(paren_left)subst,$(paren_left)subst$(space),$(__tr_head_stripped))
46 __tr_tail = $(subst $(space),,$(foreach cv,$(1),$(paren_right)))
47 __tr_template = $(__tr_head)$$(1)$(__tr_tail)
48
49 $(eval toupper = $(call __tr_template,$(chars_lower),$(chars_upper)))
50 $(eval tolower = $(call __tr_template,$(chars_upper),$(chars_lower)))
51
52 _SINGLE=export MAKEFLAGS=$(space);
53 CFLAGS:=
54 ARCH:=$(subst i486,i386,$(subst i586,i386,$(subst i686,i386,$(call qstrip,$(CONFIG_ARCH)))))
55 ARCH_PACKAGES:=$(call qstrip,$(CONFIG_TARGET_ARCH_PACKAGES))
56 BOARD:=$(call qstrip,$(CONFIG_TARGET_BOARD))
57 TARGET_OPTIMIZATION:=$(call qstrip,$(CONFIG_TARGET_OPTIMIZATION))
58 export EXTRA_OPTIMIZATION:=$(call qstrip,$(CONFIG_EXTRA_OPTIMIZATION))
59 TARGET_SUFFIX=$(call qstrip,$(CONFIG_TARGET_SUFFIX))
60 BUILD_SUFFIX:=$(call qstrip,$(CONFIG_BUILD_SUFFIX))
61 SUBDIR:=$(patsubst $(TOPDIR)/%,%,${CURDIR})
62 export SHELL:=/usr/bin/env bash
63
64 OPTIMIZE_FOR_CPU=$(subst i386,i486,$(ARCH))
65
66 ifeq ($(ARCH),powerpc)
67 FPIC:=-fPIC
68 else
69 FPIC:=-fpic
70 endif
71
72 HOST_FPIC:=-fPIC
73
74 ARCH_SUFFIX:=$(call qstrip,$(CONFIG_CPU_TYPE))
75 GCC_ARCH:=
76
77 ifneq ($(ARCH_SUFFIX),)
78 ARCH_SUFFIX:=_$(ARCH_SUFFIX)
79 endif
80 ifneq ($(filter -march=armv%,$(TARGET_OPTIMIZATION)),)
81 GCC_ARCH:=$(patsubst -march=%,%,$(filter -march=armv%,$(TARGET_OPTIMIZATION)))
82 endif
83 ifdef CONFIG_HAS_SPE_FPU
84 TARGET_SUFFIX:=$(TARGET_SUFFIX)spe
85 endif
86 ifdef CONFIG_MIPS64_ABI
87 ifneq ($(CONFIG_MIPS64_ABI_O32),y)
88 ARCH_SUFFIX:=$(ARCH_SUFFIX)_$(call qstrip,$(CONFIG_MIPS64_ABI))
89 endif
90 endif
91
92 DL_DIR:=$(if $(call qstrip,$(CONFIG_DOWNLOAD_FOLDER)),$(call qstrip,$(CONFIG_DOWNLOAD_FOLDER)),$(TOPDIR)/dl)
93 BIN_DIR:=$(if $(call qstrip,$(CONFIG_BINARY_FOLDER)),$(call qstrip,$(CONFIG_BINARY_FOLDER)),$(TOPDIR)/bin/$(BOARD))
94 INCLUDE_DIR:=$(TOPDIR)/include
95 SCRIPT_DIR:=$(TOPDIR)/scripts
96 BUILD_DIR_BASE:=$(TOPDIR)/build_dir
97 BUILD_DIR_HOST:=$(BUILD_DIR_BASE)/host
98 STAGING_DIR_HOST:=$(TOPDIR)/staging_dir/host
99 ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
100 GCCV:=$(call qstrip,$(CONFIG_GCC_VERSION))
101 LIBC:=$(call qstrip,$(CONFIG_LIBC))
102 LIBCV:=$(call qstrip,$(CONFIG_LIBC_VERSION))
103 REAL_GNU_TARGET_NAME=$(OPTIMIZE_FOR_CPU)-openwrt-linux$(if $(TARGET_SUFFIX),-$(TARGET_SUFFIX))
104 GNU_TARGET_NAME=$(OPTIMIZE_FOR_CPU)-openwrt-linux
105 DIR_SUFFIX:=_$(LIBC)-$(LIBCV)$(if $(CONFIG_arm),_eabi)
106 BIN_DIR:=$(BIN_DIR)$(if $(CONFIG_USE_MUSL),,-$(LIBC))
107 TARGET_DIR_NAME = target-$(ARCH)$(ARCH_SUFFIX)$(DIR_SUFFIX)$(if $(BUILD_SUFFIX),_$(BUILD_SUFFIX))
108 TOOLCHAIN_DIR_NAME = toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)$(DIR_SUFFIX)
109 else
110 ifeq ($(CONFIG_NATIVE_TOOLCHAIN),)
111 GNU_TARGET_NAME=$(call qstrip,$(CONFIG_TARGET_NAME))
112 else
113 GNU_TARGET_NAME=$(shell gcc -dumpmachine)
114 endif
115 REAL_GNU_TARGET_NAME=$(GNU_TARGET_NAME)
116 TARGET_DIR_NAME:=target-$(GNU_TARGET_NAME)$(if $(BUILD_SUFFIX),_$(BUILD_SUFFIX))
117 TOOLCHAIN_DIR_NAME:=toolchain-$(GNU_TARGET_NAME)
118 endif
119
120 PACKAGE_DIR:=$(BIN_DIR)/packages
121 BUILD_DIR:=$(BUILD_DIR_BASE)/$(TARGET_DIR_NAME)
122 STAGING_DIR:=$(TOPDIR)/staging_dir/$(TARGET_DIR_NAME)
123 BUILD_DIR_TOOLCHAIN:=$(BUILD_DIR_BASE)/$(TOOLCHAIN_DIR_NAME)
124 TOOLCHAIN_DIR:=$(TOPDIR)/staging_dir/$(TOOLCHAIN_DIR_NAME)
125 STAMP_DIR:=$(BUILD_DIR)/stamp
126 STAMP_DIR_HOST=$(BUILD_DIR_HOST)/stamp
127 TARGET_ROOTFS_DIR?=$(if $(call qstrip,$(CONFIG_TARGET_ROOTFS_DIR)),$(call qstrip,$(CONFIG_TARGET_ROOTFS_DIR)),$(BUILD_DIR))
128 TARGET_DIR:=$(TARGET_ROOTFS_DIR)/root-$(BOARD)
129 STAGING_DIR_ROOT:=$(STAGING_DIR)/root-$(BOARD)
130 BUILD_LOG_DIR:=$(TOPDIR)/logs
131 PKG_INFO_DIR := $(STAGING_DIR)/pkginfo
132
133 TARGET_PATH:=$(subst $(space),:,$(filter-out .,$(filter-out ./,$(subst :,$(space),$(PATH)))))
134 TARGET_CFLAGS:=$(TARGET_OPTIMIZATION)$(if $(CONFIG_DEBUG), -g3) $(EXTRA_OPTIMIZATION)
135 TARGET_CXXFLAGS = $(TARGET_CFLAGS)
136 TARGET_ASFLAGS_DEFAULT = $(TARGET_CFLAGS)
137 TARGET_ASFLAGS = $(TARGET_ASFLAGS_DEFAULT)
138 TARGET_CPPFLAGS:=-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include
139 TARGET_LDFLAGS:=-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib
140 ifneq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
141 LIBGCC_S_PATH=$(realpath $(wildcard $(call qstrip,$(CONFIG_LIBGCC_ROOT_DIR))/$(call qstrip,$(CONFIG_LIBGCC_FILE_SPEC))))
142 LIBGCC_S=$(if $(LIBGCC_S_PATH),-L$(dir $(LIBGCC_S_PATH)) -lgcc_s)
143 LIBGCC_A=$(realpath $(lastword $(wildcard $(dir $(LIBGCC_S_PATH))/gcc/*/*/libgcc.a)))
144 else
145 LIBGCC_A=$(lastword $(wildcard $(TOOLCHAIN_DIR)/lib/gcc/*/*/libgcc.a))
146 LIBGCC_S=$(if $(wildcard $(TOOLCHAIN_DIR)/lib/libgcc_s.so),-L$(TOOLCHAIN_DIR)/lib -lgcc_s,$(LIBGCC_A))
147 endif
148 LIBRPC=-lrpc
149 LIBRPC_DEPENDS=+librpc
150
151 ifeq ($(CONFIG_ARCH_64BIT),y)
152 LIB_SUFFIX:=64
153 endif
154
155 ifndef DUMP
156 ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
157 -include $(TOOLCHAIN_DIR)/info.mk
158 export GCC_HONOUR_COPTS:=0
159 TARGET_CROSS:=$(if $(TARGET_CROSS),$(TARGET_CROSS),$(OPTIMIZE_FOR_CPU)-openwrt-linux$(if $(TARGET_SUFFIX),-$(TARGET_SUFFIX))-)
160 TARGET_CFLAGS+= -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result
161 TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/usr/include
162 ifeq ($(CONFIG_USE_MUSL),y)
163 TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/include/fortify
164 endif
165 TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/include
166 TARGET_LDFLAGS+= -L$(TOOLCHAIN_DIR)/usr/lib -L$(TOOLCHAIN_DIR)/lib
167 TARGET_PATH:=$(TOOLCHAIN_DIR)/bin:$(TARGET_PATH)
168 else
169 ifeq ($(CONFIG_NATIVE_TOOLCHAIN),)
170 TARGET_CROSS:=$(call qstrip,$(CONFIG_TOOLCHAIN_PREFIX))
171 TOOLCHAIN_ROOT_DIR:=$(call qstrip,$(CONFIG_TOOLCHAIN_ROOT))
172 TOOLCHAIN_BIN_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_BIN_PATH)))
173 TOOLCHAIN_INC_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_INC_PATH)))
174 TOOLCHAIN_LIB_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_LIB_PATH)))
175 ifneq ($(TOOLCHAIN_BIN_DIRS),)
176 TARGET_PATH:=$(subst $(space),:,$(TOOLCHAIN_BIN_DIRS)):$(TARGET_PATH)
177 endif
178 ifneq ($(TOOLCHAIN_INC_DIRS),)
179 TARGET_CPPFLAGS+= $(patsubst %,-I%,$(TOOLCHAIN_INC_DIRS))
180 endif
181 ifneq ($(TOOLCHAIN_LIB_DIRS),)
182 TARGET_LDFLAGS+= $(patsubst %,-L%,$(TOOLCHAIN_LIB_DIRS))
183 endif
184 TARGET_PATH:=$(TOOLCHAIN_DIR)/bin:$(TARGET_PATH)
185 endif
186 endif
187 endif
188 TARGET_PATH_PKG:=$(STAGING_DIR)/host/bin:$(TARGET_PATH)
189
190 ifeq ($(CONFIG_SOFT_FLOAT),y)
191 SOFT_FLOAT_CONFIG_OPTION:=--with-float=soft
192 ifeq ($(CONFIG_arm),y)
193 TARGET_CFLAGS+= -mfloat-abi=soft
194 else
195 TARGET_CFLAGS+= -msoft-float
196 endif
197 else
198 SOFT_FLOAT_CONFIG_OPTION:=
199 ifeq ($(CONFIG_arm),y)
200 TARGET_CFLAGS+= -mfloat-abi=hard
201 endif
202 endif
203
204 export PATH:=$(TARGET_PATH)
205 export STAGING_DIR STAGING_DIR_HOST
206 export SH_FUNC:=. $(INCLUDE_DIR)/shell.sh;
207
208 PKG_CONFIG:=$(STAGING_DIR_HOST)/bin/pkg-config
209
210 export PKG_CONFIG
211
212 HOSTCC:=gcc
213 HOSTCXX:=g++
214 HOST_CPPFLAGS:=-I$(STAGING_DIR_HOST)/include -I$(STAGING_DIR_HOST)/usr/include
215 HOST_CFLAGS:=-O2 $(HOST_CPPFLAGS)
216 HOST_LDFLAGS:=-L$(STAGING_DIR_HOST)/lib -L$(STAGING_DIR_HOST)/usr/lib
217
218 ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
219 TARGET_AR:=$(TARGET_CROSS)gcc-ar
220 TARGET_RANLIB:=$(TARGET_CROSS)gcc-ranlib
221 TARGET_NM:=$(TARGET_CROSS)gcc-nm
222 else
223 TARGET_AR:=$(TARGET_CROSS)ar
224 TARGET_RANLIB:=$(TARGET_CROSS)ranlib
225 TARGET_NM:=$(TARGET_CROSS)nm
226 endif
227
228 BUILD_KEY=$(TOPDIR)/key-build
229
230 TARGET_CC:=$(TARGET_CROSS)gcc
231 TARGET_CXX:=$(TARGET_CROSS)g++
232 KPATCH:=$(SCRIPT_DIR)/patch-kernel.sh
233 SED:=$(STAGING_DIR_HOST)/bin/sed -i -e
234 CP:=cp -fpR
235 LN:=ln -sf
236 XARGS:=xargs -r
237
238 BASH:=bash
239 TAR:=tar
240 FIND:=find
241 PATCH:=patch
242 PYTHON:=python
243
244 INSTALL_BIN:=install -m0755
245 INSTALL_DIR:=install -d -m0755
246 INSTALL_DATA:=install -m0644
247 INSTALL_CONF:=install -m0600
248
249 TARGET_CC_NOCACHE:=$(TARGET_CC)
250 TARGET_CXX_NOCACHE:=$(TARGET_CXX)
251 HOSTCC_NOCACHE:=$(HOSTCC)
252 HOSTCXX_NOCACHE:=$(HOSTCXX)
253 export TARGET_CC_NOCACHE
254 export TARGET_CXX_NOCACHE
255 export HOSTCC_NOCACHE
256
257 ifneq ($(CONFIG_CCACHE),)
258 TARGET_CC:= ccache_cc
259 TARGET_CXX:= ccache_cxx
260 HOSTCC:= ccache $(HOSTCC)
261 HOSTCXX:= ccache $(HOSTCXX)
262 endif
263
264 TARGET_CONFIGURE_OPTS = \
265 AR="$(TARGET_AR)" \
266 AS="$(TARGET_CC) -c $(TARGET_ASFLAGS)" \
267 LD=$(TARGET_CROSS)ld \
268 NM="$(TARGET_NM)" \
269 CC="$(TARGET_CC)" \
270 GCC="$(TARGET_CC)" \
271 CXX="$(TARGET_CXX)" \
272 RANLIB="$(TARGET_RANLIB)" \
273 STRIP=$(TARGET_CROSS)strip \
274 OBJCOPY=$(TARGET_CROSS)objcopy \
275 OBJDUMP=$(TARGET_CROSS)objdump \
276 SIZE=$(TARGET_CROSS)size
277
278 # strip an entire directory
279 ifneq ($(CONFIG_NO_STRIP),)
280 RSTRIP:=:
281 STRIP:=:
282 else
283 ifneq ($(CONFIG_USE_STRIP),)
284 STRIP:=$(TARGET_CROSS)strip $(call qstrip,$(CONFIG_STRIP_ARGS))
285 else
286 ifneq ($(CONFIG_USE_SSTRIP),)
287 STRIP:=$(STAGING_DIR_HOST)/bin/sstrip
288 endif
289 endif
290 RSTRIP= \
291 export CROSS="$(TARGET_CROSS)" \
292 $(if $(PKG_BUILD_ID),KEEP_BUILD_ID=1) \
293 $(if $(CONFIG_KERNEL_KALLSYMS),NO_RENAME=1) \
294 $(if $(CONFIG_KERNEL_PROFILING),KEEP_SYMBOLS=1); \
295 NM="$(TARGET_CROSS)nm" \
296 STRIP="$(STRIP)" \
297 STRIP_KMOD="$(SCRIPT_DIR)/strip-kmod.sh" \
298 PATCHELF="$(STAGING_DIR_HOST)/bin/patchelf" \
299 $(SCRIPT_DIR)/rstrip.sh
300 endif
301
302 ifeq ($(CONFIG_IPV6),y)
303 DISABLE_IPV6:=
304 else
305 DISABLE_IPV6:=--disable-ipv6
306 endif
307
308 TAR_OPTIONS:=-xf -
309
310 ifeq ($(CONFIG_BUILD_LOG),y)
311 BUILD_LOG:=1
312 endif
313
314 export BISON_PKGDATADIR:=$(STAGING_DIR_HOST)/share/bison
315 export M4:=$(STAGING_DIR_HOST)/bin/m4
316
317 define shvar
318 V_$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
319 endef
320
321 define shexport
322 export $(call shvar,$(1))=$$(call $(1))
323 endef
324
325 define include_mk
326 $(eval -include $(if $(DUMP),,$(STAGING_DIR)/mk/$(strip $(1))))
327 endef
328
329 # Execute commands under flock
330 # $(1) => The shell expression.
331 # $(2) => The lock name. If not given, the global lock will be used.
332 define locked
333 SHELL= \
334 $(STAGING_DIR_HOST)/bin/flock \
335 $(TMP_DIR)/.$(if $(2),$(strip $(2)),global).flock \
336 -c '$(subst ','\'',$(1))'
337 endef
338
339 # Recursively copy paths into another directory, purge dangling
340 # symlinks before.
341 # $(1) => File glob expression
342 # $(2) => Destination directory
343 define file_copy
344 for src_dir in $(sort $(foreach d,$(wildcard $(1)),$(dir $(d)))); do \
345 ( cd $$src_dir; find -type f -or -type d ) | \
346 ( cd $(2); while :; do \
347 read FILE; \
348 [ -z "$$FILE" ] && break; \
349 [ -L "$$FILE" ] || continue; \
350 echo "Removing symlink $(2)/$$FILE"; \
351 rm -f "$$FILE"; \
352 done; ); \
353 done; \
354 $(CP) $(1) $(2)
355 endef
356
357 # file extension
358 ext=$(word $(words $(subst ., ,$(1))),$(subst ., ,$(1)))
359
360 all:
361 FORCE: ;
362 .PHONY: FORCE
363
364 val.%:
365 @$(if $(filter undefined,$(origin $*)),\
366 echo "$* undefined" >&2, \
367 echo '$(subst ','"'"',$($*))' \
368 )
369
370 var.%:
371 @$(if $(filter undefined,$(origin $*)),\
372 echo "$* undefined" >&2, \
373 echo "$*='"'$(subst ','"'\"'\"'"',$($*))'"'" \
374 )
375
376 endif #__rules_inc