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