2 # Copyright (C) 2006-2010 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 ifneq ($(__rules_inc
),1)
12 -include $(TOPDIR
)/.config
14 include $(TOPDIR
)/include/debug.mk
15 include $(TOPDIR
)/include/verbose.mk
17 export TMP_DIR
:=$(TOPDIR
)/tmp
19 qstrip
=$(strip $(subst ",,$(1)))
23 space
:= $(empty
) $(empty
)
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))
38 _SINGLE
=export MAKEFLAGS
=$(space
);
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
50 OPTIMIZE_FOR_CPU
=$(subst i386
,i486
,$(ARCH
))
52 ifeq ($(ARCH
),powerpc
)
60 ARCH_SUFFIX
:=$(call qstrip
,$(CONFIG_CPU_TYPE
))
63 ifneq ($(ARCH_SUFFIX
),)
64 ARCH_SUFFIX
:=_
$(ARCH_SUFFIX
)
66 ifneq ($(filter -march
=armv
%,$(TARGET_OPTIMIZATION
)),)
67 GCC_ARCH
:=$(patsubst -march
=%,%,$(filter -march
=armv
%,$(TARGET_OPTIMIZATION
)))
69 ifdef CONFIG_HAS_SPE_FPU
70 TARGET_SUFFIX
:=$(TARGET_SUFFIX
)spe
72 ifdef CONFIG_MIPS64_ABI
73 ifneq ($(CONFIG_MIPS64_ABI_O32
),y
)
74 ARCH_SUFFIX
:=$(ARCH_SUFFIX
)_
$(call qstrip
,$(CONFIG_MIPS64_ABI
))
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_UCLIBC
),,-$(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
)
96 ifeq ($(CONFIG_NATIVE_TOOLCHAIN
),)
97 GNU_TARGET_NAME
=$(call qstrip
,$(CONFIG_TARGET_NAME
))
99 GNU_TARGET_NAME
=$(shell gcc
-dumpmachine
)
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
)
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
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
)))
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
))
135 LIBRPC_DEPENDS
=+librpc
137 ifeq ($(CONFIG_ARCH_64BIT
),y
)
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
$(if
$(CONFIG_GCC_VERSION_4_4
)$(CONFIG_GCC_VERSION_4_5
),,-Wno-error
=unused-but-set-variable
)
147 TARGET_CPPFLAGS
+= -I
$(TOOLCHAIN_DIR
)/usr
/include -I
$(TOOLCHAIN_DIR
)/include
148 TARGET_LDFLAGS
+= -L
$(TOOLCHAIN_DIR
)/usr
/lib
-L
$(TOOLCHAIN_DIR
)/lib
149 TARGET_PATH
:=$(TOOLCHAIN_DIR
)/bin
:$(TARGET_PATH
)
151 ifeq ($(CONFIG_NATIVE_TOOLCHAIN
),)
152 TARGET_CROSS
:=$(call qstrip
,$(CONFIG_TOOLCHAIN_PREFIX
))
153 TOOLCHAIN_ROOT_DIR
:=$(call qstrip
,$(CONFIG_TOOLCHAIN_ROOT
))
154 TOOLCHAIN_BIN_DIRS
:=$(patsubst .
/%,$(TOOLCHAIN_ROOT_DIR
)/%,$(call qstrip
,$(CONFIG_TOOLCHAIN_BIN_PATH
)))
155 TOOLCHAIN_INC_DIRS
:=$(patsubst .
/%,$(TOOLCHAIN_ROOT_DIR
)/%,$(call qstrip
,$(CONFIG_TOOLCHAIN_INC_PATH
)))
156 TOOLCHAIN_LIB_DIRS
:=$(patsubst .
/%,$(TOOLCHAIN_ROOT_DIR
)/%,$(call qstrip
,$(CONFIG_TOOLCHAIN_LIB_PATH
)))
157 ifneq ($(TOOLCHAIN_BIN_DIRS
),)
158 TARGET_PATH
:=$(subst $(space
),:,$(TOOLCHAIN_BIN_DIRS
)):$(TARGET_PATH
)
160 ifneq ($(TOOLCHAIN_INC_DIRS
),)
161 TARGET_CPPFLAGS
+= $(patsubst %,-I
%,$(TOOLCHAIN_INC_DIRS
))
163 ifneq ($(TOOLCHAIN_LIB_DIRS
),)
164 TARGET_LDFLAGS
+= $(patsubst %,-L
%,$(TOOLCHAIN_LIB_DIRS
))
166 TARGET_PATH
:=$(TOOLCHAIN_DIR
)/bin
:$(TARGET_PATH
)
170 TARGET_PATH_PKG
:=$(STAGING_DIR
)/host
/bin
:$(TARGET_PATH
)
172 ifeq ($(CONFIG_SOFT_FLOAT
),y
)
173 SOFT_FLOAT_CONFIG_OPTION
:=--with-float
=soft
174 ifeq ($(CONFIG_arm
),y
)
175 TARGET_CFLAGS
+= -mfloat-abi
=soft
177 TARGET_CFLAGS
+= -msoft-float
180 SOFT_FLOAT_CONFIG_OPTION
:=
181 ifeq ($(CONFIG_arm
),y
)
182 TARGET_CFLAGS
+= -mfloat-abi
=hard
186 export PATH
:=$(TARGET_PATH
)
188 export SH_FUNC
:=.
$(INCLUDE_DIR
)/shell.sh
;
190 PKG_CONFIG
:=$(STAGING_DIR_HOST
)/bin
/pkg-config
196 HOST_CPPFLAGS
:=-I
$(STAGING_DIR_HOST
)/include -I
$(STAGING_DIR_HOST
)/usr
/include
197 HOST_CFLAGS
:=-O2
$(HOST_CPPFLAGS
)
198 HOST_LDFLAGS
:=-L
$(STAGING_DIR_HOST
)/lib
-L
$(STAGING_DIR_HOST
)/usr
/lib
200 ifeq ($(CONFIG_GCC_VERSION_4_4
)$(CONFIG_GCC_VERSION_4_6
)$(CONFIG_EXTERNAL_TOOLCHAIN
),)
201 TARGET_AR
:=$(TARGET_CROSS
)gcc-ar
202 TARGET_RANLIB
:=$(TARGET_CROSS
)gcc-ranlib
203 TARGET_NM
:=$(TARGET_CROSS
)gcc-nm
205 TARGET_AR
:=$(TARGET_CROSS
)ar
206 TARGET_RANLIB
:=$(TARGET_CROSS
)ranlib
207 TARGET_NM
:=$(TARGET_CROSS
)nm
210 BUILD_KEY
=$(TOPDIR
)/key-build
212 TARGET_CC
:=$(TARGET_CROSS
)gcc
213 TARGET_CXX
:=$(TARGET_CROSS
)g
++
214 KPATCH
:=$(SCRIPT_DIR
)/patch-kernel.sh
215 SED
:=$(STAGING_DIR_HOST
)/bin
/sed
-i
-e
226 INSTALL_BIN
:=install -m0755
227 INSTALL_DIR
:=install -d
-m0755
228 INSTALL_DATA
:=install -m0644
229 INSTALL_CONF
:=install -m0600
231 TARGET_CC_NOCACHE
:=$(TARGET_CC
)
232 TARGET_CXX_NOCACHE
:=$(TARGET_CXX
)
233 HOSTCC_NOCACHE
:=$(HOSTCC
)
234 HOSTCXX_NOCACHE
:=$(HOSTCXX
)
235 export TARGET_CC_NOCACHE
236 export TARGET_CXX_NOCACHE
237 export HOSTCC_NOCACHE
239 ifneq ($(CONFIG_CCACHE
),)
240 TARGET_CC
:= ccache_cc
241 TARGET_CXX
:= ccache_cxx
242 HOSTCC
:= ccache
$(HOSTCC
)
243 HOSTCXX
:= ccache
$(HOSTCXX
)
246 TARGET_CONFIGURE_OPTS
= \
248 AS
="$(TARGET_CC) -c $(TARGET_ASFLAGS)" \
249 LD
=$(TARGET_CROSS
)ld \
253 CXX
="$(TARGET_CXX)" \
254 RANLIB
="$(TARGET_RANLIB)" \
255 STRIP
=$(TARGET_CROSS
)strip \
256 OBJCOPY
=$(TARGET_CROSS
)objcopy \
257 OBJDUMP
=$(TARGET_CROSS
)objdump \
258 SIZE
=$(TARGET_CROSS
)size
260 # strip an entire directory
261 ifneq ($(CONFIG_NO_STRIP
),)
265 ifneq ($(CONFIG_USE_STRIP
),)
266 STRIP
:=$(TARGET_CROSS
)strip $(call qstrip
,$(CONFIG_STRIP_ARGS
))
268 ifneq ($(CONFIG_USE_SSTRIP
),)
269 STRIP
:=$(STAGING_DIR_HOST
)/bin
/sstrip
273 export CROSS
="$(TARGET_CROSS)" \
274 $(if
$(CONFIG_KERNEL_KALLSYMS
),NO_RENAME
=1) \
275 $(if
$(CONFIG_KERNEL_PROFILING
),KEEP_SYMBOLS
=1); \
276 NM
="$(TARGET_CROSS)nm" \
278 STRIP_KMOD
="$(SCRIPT_DIR)/strip-kmod.sh" \
279 PATCHELF
="$(STAGING_DIR_HOST)/bin/patchelf" \
280 $(SCRIPT_DIR
)/rstrip.sh
283 ifeq ($(CONFIG_IPV6
),y
)
286 DISABLE_IPV6
:=--disable-ipv6
291 ifeq ($(CONFIG_BUILD_LOG
),y
)
295 export BISON_PKGDATADIR
:=$(STAGING_DIR_HOST
)/share
/bison
296 export M4
:=$(STAGING_DIR_HOST
)/bin
/m4
299 V_
$(subst .
,_
,$(subst -,_
,$(subst /,_
,$(1))))
303 export $(call shvar
,$(1))=$$(call
$(1))
307 $(eval
-include $(if
$(DUMP
),,$(STAGING_DIR
)/mk
/$(strip $(1))))
310 # Execute commands under flock
311 # $(1) => The shell expression.
312 # $(2) => The lock name. If not given, the global lock will be used.
315 $(STAGING_DIR_HOST
)/bin
/flock \
316 $(TMP_DIR
)/.
$(if
$(2),$(strip $(2)),global
).flock \
317 -c
'$(subst ','\'',$(1))'
320 # Recursively copy paths into another directory, purge dangling
322 # $(1) => File glob expression
323 # $(2) => Destination directory
325 for src_dir in $(sort $(foreach d,$(wildcard $(1)),$(dir $(d)))); do \
326 ( cd $$src_dir; find -type f -or -type d ) | \
327 ( cd $(2); while :; do \
329 [ -z "$$FILE" ] && break; \
330 [ -L "$$FILE" ] || continue; \
331 echo "Removing symlink $(2)/$$FILE"; \
339 ext=$(word $(words $(subst ., ,$(1))),$(subst ., ,$(1)))
346 @$(if $(filter undefined,$(origin $*)),\
347 echo "$* undefined" >&2, \
348 echo '$(subst ','"'"',$($*))' \
352 @
$(if
$(filter undefined
,$(origin $*)),\
353 echo
"$* undefined" >&2, \
354 echo
"$*='"'$(subst ','"'\"'\"'"',$($*))'"'" \