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