ath9k: add stability fixes for long standing hang issues (FS#13, #34, #373, #383)
[openwrt/staging/yousong.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 DEFAULT_SUBDIR_TARGETS:=clean download prepare compile install update refresh prereq dist distcheck configure check check-depends
105
106 define DefaultTargets
107 $(foreach t,$(DEFAULT_SUBDIR_TARGETS) $(1),
108 .$(t):
109 $(t): .$(t)
110 .PHONY: $(t) .$(t)
111 )
112 endef
113
114 DL_DIR:=$(if $(call qstrip,$(CONFIG_DOWNLOAD_FOLDER)),$(call qstrip,$(CONFIG_DOWNLOAD_FOLDER)),$(TOPDIR)/dl)
115 OUTPUT_DIR:=$(if $(call qstrip,$(CONFIG_BINARY_FOLDER)),$(call qstrip,$(CONFIG_BINARY_FOLDER)),$(TOPDIR)/bin)
116 BIN_DIR:=$(OUTPUT_DIR)/targets/$(BOARD)/$(SUBTARGET)
117 INCLUDE_DIR:=$(TOPDIR)/include
118 SCRIPT_DIR:=$(TOPDIR)/scripts
119 BUILD_DIR_BASE:=$(TOPDIR)/build_dir
120 ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
121 GCCV:=$(call qstrip,$(CONFIG_GCC_VERSION))
122 LIBC:=$(call qstrip,$(CONFIG_LIBC))
123 LIBCV:=$(call qstrip,$(CONFIG_LIBC_VERSION))
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)-$(LIBCV)$(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 TARGET_DIR_NAME:=target-$(GNU_TARGET_NAME)$(if $(BUILD_SUFFIX),_$(BUILD_SUFFIX))
138 TOOLCHAIN_DIR_NAME:=toolchain-$(GNU_TARGET_NAME)
139 endif
140
141 ifeq ($(or $(CONFIG_EXTERNAL_TOOLCHAIN),$(CONFIG_GCC_VERSION_4_8),$(CONFIG_TARGET_uml)),)
142 iremap = -iremap $(1):$(2)
143 endif
144
145 PACKAGE_DIR:=$(BIN_DIR)/packages
146 BUILD_DIR:=$(BUILD_DIR_BASE)/$(TARGET_DIR_NAME)
147 STAGING_DIR:=$(TOPDIR)/staging_dir/$(TARGET_DIR_NAME)
148 BUILD_DIR_TOOLCHAIN:=$(BUILD_DIR_BASE)/$(TOOLCHAIN_DIR_NAME)
149 TOOLCHAIN_DIR:=$(TOPDIR)/staging_dir/$(TOOLCHAIN_DIR_NAME)
150 STAMP_DIR:=$(BUILD_DIR)/stamp
151 STAMP_DIR_HOST=$(BUILD_DIR_HOST)/stamp
152 TARGET_ROOTFS_DIR?=$(if $(call qstrip,$(CONFIG_TARGET_ROOTFS_DIR)),$(call qstrip,$(CONFIG_TARGET_ROOTFS_DIR)),$(BUILD_DIR))
153 TARGET_DIR:=$(TARGET_ROOTFS_DIR)/root-$(BOARD)
154 STAGING_DIR_ROOT:=$(STAGING_DIR)/root-$(BOARD)
155 BUILD_LOG_DIR:=$(TOPDIR)/logs
156 PKG_INFO_DIR := $(STAGING_DIR)/pkginfo
157
158 BUILD_DIR_HOST:=$(if $(IS_PACKAGE_BUILD),$(BUILD_DIR_BASE)/hostpkg,$(BUILD_DIR_BASE)/host)
159 STAGING_DIR_HOST:=$(TOPDIR)/staging_dir/host
160 STAGING_DIR_HOSTPKG:=$(TOPDIR)/staging_dir/hostpkg
161
162 TARGET_PATH:=$(subst $(space),:,$(filter-out .,$(filter-out ./,$(subst :,$(space),$(PATH)))))
163 TARGET_INIT_PATH:=$(call qstrip,$(CONFIG_TARGET_INIT_PATH))
164 TARGET_INIT_PATH:=$(if $(TARGET_INIT_PATH),$(TARGET_INIT_PATH),/usr/sbin:/sbin:/usr/bin:/bin)
165 TARGET_CFLAGS:=$(TARGET_OPTIMIZATION)$(if $(CONFIG_DEBUG), -g3) $(call qstrip,$(CONFIG_EXTRA_OPTIMIZATION))
166 TARGET_CXXFLAGS = $(TARGET_CFLAGS)
167 TARGET_ASFLAGS_DEFAULT = $(TARGET_CFLAGS)
168 TARGET_ASFLAGS = $(TARGET_ASFLAGS_DEFAULT)
169 TARGET_CPPFLAGS:=-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include
170 TARGET_LDFLAGS:=-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib
171 ifneq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
172 LIBGCC_S_PATH=$(realpath $(wildcard $(call qstrip,$(CONFIG_LIBGCC_ROOT_DIR))/$(call qstrip,$(CONFIG_LIBGCC_FILE_SPEC))))
173 LIBGCC_S=$(if $(LIBGCC_S_PATH),-L$(dir $(LIBGCC_S_PATH)) -lgcc_s)
174 LIBGCC_A=$(realpath $(lastword $(wildcard $(dir $(LIBGCC_S_PATH))/gcc/*/*/libgcc.a)))
175 else
176 LIBGCC_A=$(lastword $(wildcard $(TOOLCHAIN_DIR)/lib/gcc/*/*/libgcc.a))
177 LIBGCC_S=$(if $(wildcard $(TOOLCHAIN_DIR)/lib/libgcc_s.so),-L$(TOOLCHAIN_DIR)/lib -lgcc_s,$(LIBGCC_A))
178 endif
179 LIBRPC=-lrpc
180 LIBRPC_DEPENDS=+librpc
181
182 ifeq ($(CONFIG_ARCH_64BIT),y)
183 LIB_SUFFIX:=64
184 endif
185
186 ifndef DUMP
187 ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
188 -include $(TOOLCHAIN_DIR)/info.mk
189 export GCC_HONOUR_COPTS:=0
190 TARGET_CROSS:=$(if $(TARGET_CROSS),$(TARGET_CROSS),$(OPTIMIZE_FOR_CPU)-openwrt-linux$(if $(TARGET_SUFFIX),-$(TARGET_SUFFIX))-)
191 TARGET_CFLAGS+= -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result
192 TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/usr/include
193 ifeq ($(CONFIG_USE_MUSL),y)
194 TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/include/fortify
195 endif
196 TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/include
197 TARGET_LDFLAGS+= -L$(TOOLCHAIN_DIR)/usr/lib -L$(TOOLCHAIN_DIR)/lib
198 TARGET_PATH:=$(TOOLCHAIN_DIR)/bin:$(TARGET_PATH)
199 else
200 ifeq ($(CONFIG_NATIVE_TOOLCHAIN),)
201 TARGET_CROSS:=$(call qstrip,$(CONFIG_TOOLCHAIN_PREFIX))
202 TOOLCHAIN_ROOT_DIR:=$(call qstrip,$(CONFIG_TOOLCHAIN_ROOT))
203 TOOLCHAIN_BIN_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_BIN_PATH)))
204 TOOLCHAIN_INC_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_INC_PATH)))
205 TOOLCHAIN_LIB_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_LIB_PATH)))
206 ifneq ($(TOOLCHAIN_BIN_DIRS),)
207 TARGET_PATH:=$(subst $(space),:,$(TOOLCHAIN_BIN_DIRS)):$(TARGET_PATH)
208 endif
209 ifneq ($(TOOLCHAIN_INC_DIRS),)
210 TARGET_CPPFLAGS+= $(patsubst %,-I%,$(TOOLCHAIN_INC_DIRS))
211 endif
212 ifneq ($(TOOLCHAIN_LIB_DIRS),)
213 TARGET_LDFLAGS+= $(patsubst %,-L%,$(TOOLCHAIN_LIB_DIRS))
214 endif
215 TARGET_PATH:=$(TOOLCHAIN_DIR)/bin:$(TARGET_PATH)
216 endif
217 endif
218 endif
219 TARGET_PATH_PKG:=$(STAGING_DIR)/host/bin:$(STAGING_DIR_HOSTPKG)/bin:$(TARGET_PATH)
220
221 ifeq ($(CONFIG_SOFT_FLOAT),y)
222 SOFT_FLOAT_CONFIG_OPTION:=--with-float=soft
223 ifeq ($(CONFIG_arm),y)
224 TARGET_CFLAGS+= -mfloat-abi=soft
225 else
226 TARGET_CFLAGS+= -msoft-float
227 endif
228 else
229 SOFT_FLOAT_CONFIG_OPTION:=
230 ifeq ($(CONFIG_arm),y)
231 TARGET_CFLAGS+= -mfloat-abi=hard
232 endif
233 endif
234
235 export PATH:=$(TARGET_PATH)
236 export STAGING_DIR STAGING_DIR_HOST STAGING_DIR_HOSTPKG
237 export SH_FUNC:=. $(INCLUDE_DIR)/shell.sh;
238
239 PKG_CONFIG:=$(STAGING_DIR_HOST)/bin/pkg-config
240
241 export PKG_CONFIG
242
243 HOSTCC:=gcc
244 HOSTCXX:=g++
245 HOST_CPPFLAGS:=-I$(STAGING_DIR_HOST)/include -I$(STAGING_DIR_HOST)/usr/include $(if $(IS_PACKAGE_BUILD),-I$(STAGING_DIR_HOSTPKG)/include -I$(STAGING_DIR)/host/include)
246 HOST_CFLAGS:=-O2 $(HOST_CPPFLAGS)
247 HOST_LDFLAGS:=-L$(STAGING_DIR_HOST)/lib -L$(STAGING_DIR_HOST)/usr/lib $(if $(IS_PACKAGE_BUILD),-L$(STAGING_DIR_HOSTPKG)/lib -L$(STAGING_DIR)/host/lib)
248
249 ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
250 TARGET_AR:=$(TARGET_CROSS)gcc-ar
251 TARGET_RANLIB:=$(TARGET_CROSS)gcc-ranlib
252 TARGET_NM:=$(TARGET_CROSS)gcc-nm
253 else
254 TARGET_AR:=$(TARGET_CROSS)ar
255 TARGET_RANLIB:=$(TARGET_CROSS)ranlib
256 TARGET_NM:=$(TARGET_CROSS)nm
257 endif
258
259 BUILD_KEY=$(TOPDIR)/key-build
260
261 TARGET_CC:=$(TARGET_CROSS)gcc
262 TARGET_CXX:=$(TARGET_CROSS)g++
263 KPATCH:=$(SCRIPT_DIR)/patch-kernel.sh
264 SED:=$(STAGING_DIR_HOST)/bin/sed -i -e
265 CP:=cp -fpR
266 LN:=ln -sf
267 XARGS:=xargs -r
268
269 BASH:=bash
270 TAR:=tar
271 FIND:=find
272 PATCH:=patch
273 PYTHON:=python
274
275 INSTALL_BIN:=install -m0755
276 INSTALL_DIR:=install -d -m0755
277 INSTALL_DATA:=install -m0644
278 INSTALL_CONF:=install -m0600
279
280 TARGET_CC_NOCACHE:=$(TARGET_CC)
281 TARGET_CXX_NOCACHE:=$(TARGET_CXX)
282 HOSTCC_NOCACHE:=$(HOSTCC)
283 HOSTCXX_NOCACHE:=$(HOSTCXX)
284 export TARGET_CC_NOCACHE
285 export TARGET_CXX_NOCACHE
286 export HOSTCC_NOCACHE
287
288 ifneq ($(CONFIG_CCACHE),)
289 TARGET_CC:= ccache_cc
290 TARGET_CXX:= ccache_cxx
291 HOSTCC:= ccache $(HOSTCC)
292 HOSTCXX:= ccache $(HOSTCXX)
293 endif
294
295 TARGET_CONFIGURE_OPTS = \
296 AR="$(TARGET_AR)" \
297 AS="$(TARGET_CC) -c $(TARGET_ASFLAGS)" \
298 LD=$(TARGET_CROSS)ld \
299 NM="$(TARGET_NM)" \
300 CC="$(TARGET_CC)" \
301 GCC="$(TARGET_CC)" \
302 CXX="$(TARGET_CXX)" \
303 RANLIB="$(TARGET_RANLIB)" \
304 STRIP=$(TARGET_CROSS)strip \
305 OBJCOPY=$(TARGET_CROSS)objcopy \
306 OBJDUMP=$(TARGET_CROSS)objdump \
307 SIZE=$(TARGET_CROSS)size
308
309 # strip an entire directory
310 ifneq ($(CONFIG_NO_STRIP),)
311 RSTRIP:=:
312 STRIP:=:
313 else
314 ifneq ($(CONFIG_USE_STRIP),)
315 STRIP:=$(TARGET_CROSS)strip $(call qstrip,$(CONFIG_STRIP_ARGS))
316 else
317 ifneq ($(CONFIG_USE_SSTRIP),)
318 STRIP:=$(STAGING_DIR_HOST)/bin/sstrip
319 endif
320 endif
321 RSTRIP= \
322 export CROSS="$(TARGET_CROSS)" \
323 $(if $(PKG_BUILD_ID),KEEP_BUILD_ID=1) \
324 $(if $(CONFIG_KERNEL_KALLSYMS),NO_RENAME=1) \
325 $(if $(CONFIG_KERNEL_PROFILING),KEEP_SYMBOLS=1); \
326 NM="$(TARGET_CROSS)nm" \
327 STRIP="$(STRIP)" \
328 STRIP_KMOD="$(SCRIPT_DIR)/strip-kmod.sh" \
329 PATCHELF="$(STAGING_DIR_HOST)/bin/patchelf" \
330 $(SCRIPT_DIR)/rstrip.sh
331 endif
332
333 ifeq ($(CONFIG_IPV6),y)
334 DISABLE_IPV6:=
335 else
336 DISABLE_IPV6:=--disable-ipv6
337 endif
338
339 TAR_OPTIONS:=-xf -
340
341 ifeq ($(CONFIG_BUILD_LOG),y)
342 BUILD_LOG:=1
343 endif
344
345 export BISON_PKGDATADIR:=$(STAGING_DIR_HOST)/share/bison
346 export M4:=$(STAGING_DIR_HOST)/bin/m4
347
348 define shvar
349 V_$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
350 endef
351
352 define shexport
353 export $(call shvar,$(1))=$$(call $(1))
354 endef
355
356 define include_mk
357 $(eval -include $(if $(DUMP),,$(STAGING_DIR)/mk/$(strip $(1))))
358 endef
359
360 # Execute commands under flock
361 # $(1) => The shell expression.
362 # $(2) => The lock name. If not given, the global lock will be used.
363 ifneq ($(wildcard $(STAGING_DIR_HOST)/bin/flock),)
364 define locked
365 SHELL= \
366 flock \
367 $(TMP_DIR)/.$(if $(2),$(strip $(2)),global).flock \
368 -c '$(subst ','\'',$(1))'
369 endef
370 else
371 locked=$(1)
372 endif
373
374 # Recursively copy paths into another directory, purge dangling
375 # symlinks before.
376 # $(1) => File glob expression
377 # $(2) => Destination directory
378 define file_copy
379 for src_dir in $(sort $(foreach d,$(wildcard $(1)),$(dir $(d)))); do \
380 ( cd $$src_dir; find -type f -or -type d ) | \
381 ( cd $(2); while :; do \
382 read FILE; \
383 [ -z "$$FILE" ] && break; \
384 [ -L "$$FILE" ] || continue; \
385 echo "Removing symlink $(2)/$$FILE"; \
386 rm -f "$$FILE"; \
387 done; ); \
388 done; \
389 $(CP) $(1) $(2)
390 endef
391
392 # Calculate sha256sum of any plain file within a given directory
393 # $(1) => Input directory
394 define sha256sums
395 (cd $(1); find . -maxdepth 1 -type f -not -name 'sha256sums' -printf "%P\n" | sort | \
396 xargs -r $(STAGING_DIR_HOST)/bin/mkhash -n sha256 | sed -ne 's!^\(.*\) \(.*\)$$!\1 *\2!p' > sha256sums)
397 endef
398
399 # file extension
400 ext=$(word $(words $(subst ., ,$(1))),$(subst ., ,$(1)))
401
402 all:
403 FORCE: ;
404 .PHONY: FORCE
405
406 check: FORCE
407 @true
408
409 val.%:
410 @$(if $(filter undefined,$(origin $*)),\
411 echo "$* undefined" >&2, \
412 echo '$(subst ','"'"',$($*))' \
413 )
414
415 var.%:
416 @$(if $(filter undefined,$(origin $*)),\
417 echo "$* undefined" >&2, \
418 echo "$*='"'$(subst ','"'\"'\"'"',$($*))'"'" \
419 )
420
421 endif #__rules_inc