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