1 # This file is part of the OpenADK project. OpenADK is copyrighted
2 # material, please see the LICENCE file in the top-level directory.
5 INSTALL_DIR
= install -d
-m0755
6 INSTALL_DATA
= install -m0644
7 INSTALL_BIN
= install -m0755
8 INSTALL_SCRIPT
= install -m0755
9 MAKEFLAGS
= $(EXTRA_MAKEFLAGS
)
10 BUILD_USER
= $(shell id
-un
)
11 BUILD_GROUP
= $(shell id
-gn
)
12 ADK_SUFFIX
:= ${ADK_TARGET_SYSTEM}_
${ADK_TARGET_LIBC}_
${ADK_TARGET_CPU_ARCH}
13 ifneq ($(ADK_TARGET_FLOAT
),)
14 ADK_SUFFIX
:= $(ADK_SUFFIX
)_
$(ADK_TARGET_FLOAT
)
16 ifneq ($(ADK_TARGET_ABI
),)
17 ADK_SUFFIX
:= $(ADK_SUFFIX
)_
$(ADK_TARGET_ABI
)
19 ifneq ($(ADK_TARGET_CPU_TYPE
),)
20 ADK_SUFFIX
:= $(ADK_SUFFIX
)_
$(ADK_TARGET_CPU_TYPE
)
22 ifeq ($(ADK_TARGET_WITH_MMU
),)
23 ADK_SUFFIX
:= $(ADK_SUFFIX
)_nommu
27 BASE_DIR
:= $(ADK_TOPDIR
)
29 DL_DIR?
= $(BASE_DIR
)/dl
31 DL_DIR?
= $(ADK_DL_DIR
)
33 SCRIPT_DIR
:= $(BASE_DIR
)/scripts
34 STAGING_HOST_DIR
:= ${BASE_DIR}/host_
${GNU_HOST_NAME}
35 HOST_BUILD_DIR
:= ${BASE_DIR}/host_build_
${GNU_HOST_NAME}
36 TOOLCHAIN_DIR
:= ${BASE_DIR}/toolchain_
${ADK_SUFFIX}
39 FW_DIR_PFX
:= $(BASE_DIR
)/firmware
40 BUILD_DIR_PFX
:= $(BASE_DIR
)/build_
*
41 STAGING_PKG_DIR_PFX
:= ${BASE_DIR}/pkg_
*
42 STAGING_TARGET_DIR_PFX
:=${BASE_DIR}/target_
*
43 TOOLCHAIN_DIR_PFX
= $(BASE_DIR
)/toolchain_
*
44 STAGING_HOST_DIR_PFX
:= ${BASE_DIR}/host_
*
45 TARGET_DIR_PFX
:= $(BASE_DIR
)/root_
*
47 TARGET_DIR
:= $(BASE_DIR
)/root_
${ADK_SUFFIX}
48 FW_DIR
:= $(BASE_DIR
)/firmware
/${ADK_SUFFIX}
49 BUILD_DIR
:= ${BASE_DIR}/build_
${ADK_SUFFIX}
50 STAGING_TARGET_DIR
:= ${BASE_DIR}/target_
${ADK_SUFFIX}
51 STAGING_PKG_DIR
:= ${BASE_DIR}/pkg_
${ADK_SUFFIX}
52 STAGING_HOST2TARGET
:= ..
/..
/target_
${ADK_SUFFIX}
53 TOOLCHAIN_BUILD_DIR
= $(BASE_DIR
)/toolchain_build_
${ADK_SUFFIX}
54 PACKAGE_DIR
:= $(FW_DIR
)/packages
55 SCRIPT_TARGET_DIR
:= ${STAGING_TARGET_DIR}/scripts
58 TARGET_PATH
= ${SCRIPT_DIR}:${STAGING_TARGET_DIR}/scripts
:${TOOLCHAIN_DIR}/usr
/bin
:${STAGING_HOST_DIR}/usr
/bin
:${_PATH}
59 HOST_PATH
= ${SCRIPT_DIR}:${TOOLCHAIN_DIR}/usr
/bin
:${STAGING_HOST_DIR}/usr
/bin
:${_PATH}
60 AUTOTOOL_PATH
= ${TOOLCHAIN_DIR}/usr
/bin
:${STAGING_HOST_DIR}/usr
/bin
:${STAGING_TARGET_DIR}/scripts
:${_PATH}
62 ifeq ($(ADK_DISABLE_HONOUR_CFLAGS
),)
63 GCC_CHECK
:= GCC_HONOUR_COPTS
=2
68 ifeq ($(ADK_TARGET_UCLINUX
),y
)
69 ADK_TARGET_LINUXTYPE
:= uclinux
71 ADK_TARGET_LINUXTYPE
:= linux
74 GNU_TARGET_NAME
:= $(ADK_TARGET_CPU_ARCH
)-$(ADK_VENDOR
)-$(ADK_TARGET_LINUXTYPE
)-$(ADK_TARGET_SUFFIX
)
75 ifeq ($(ADK_TARGET_ARCH_C6X
),y
)
76 GNU_TARGET_NAME
:= $(ADK_TARGET_CPU_ARCH
)-$(ADK_TARGET_LINUXTYPE
)
78 TARGET_CROSS
:= $(TOOLCHAIN_DIR
)/usr
/bin
/$(GNU_TARGET_NAME
)-
79 TARGET_COMPILER_PREFIX?
=${TARGET_CROSS}
80 CONFIGURE_TRIPLE
:= --build
=${GNU_HOST_NAME} \
81 --host
=${GNU_TARGET_NAME} \
82 --target
=${GNU_TARGET_NAME}
84 ifneq ($(strip ${ADK_USE_CCACHE}),)
85 TARGET_COMPILER_PREFIX
=$(STAGING_HOST_DIR
)/usr
/bin
/ccache
${TARGET_CROSS}
89 TARGET_CC
:= ${TARGET_COMPILER_PREFIX}gcc
91 # use a gcc wrapper for coldfire/arm uclinux support
92 ifeq ($(ADK_TARGET_UCLINUX
),y
)
93 ifeq ($(ADK_TARGET_ARCH_M68K
),y
)
94 TARGET_CC
:= adk-uclinux-gcc
96 ifeq ($(ADK_TARGET_ARCH_ARM
),y
)
97 TARGET_CC
:= adk-uclinux-gcc
101 TARGET_CXX
:= ${TARGET_COMPILER_PREFIX}g
++
102 TARGET_LD
:= ${TARGET_COMPILER_PREFIX}ld
103 ifneq ($(ADK_TARGET_USE_LTO
),)
104 TARGET_AR
:= ${TARGET_COMPILER_PREFIX}gcc-ar
105 TARGET_RANLIB
:= ${TARGET_COMPILER_PREFIX}gcc-ranlib
107 TARGET_AR
:= ${TARGET_COMPILER_PREFIX}ar
108 TARGET_RANLIB
:= ${TARGET_COMPILER_PREFIX}ranlib
111 ifneq ($(ADK_TARGET_ABI_CFLAGS
),)
112 TARGET_CC
+= $(ADK_TARGET_ABI_CFLAGS
)
113 TARGET_CXX
+= $(ADK_TARGET_ABI_CFLAGS
)
117 TARGET_CFLAGS
:= -fwrapv
-fno-ident
118 TARGET_CXXFLAGS
:= -fwrapv
-fno-ident
119 TARGET_LDFLAGS
:= -L
$(STAGING_TARGET_DIR
)/lib
-L
$(STAGING_TARGET_DIR
)/usr
/lib \
120 -Wl
,-O1
-Wl
,-rpath
-Wl
,/usr
/lib \
121 -Wl
,-rpath-link
-Wl
,${STAGING_TARGET_DIR}/usr
/lib
123 ifeq ($(ADK_DISABLE_HONOUR_CFLAGS
),)
124 TARGET_CFLAGS
+= -fhonour-copts
125 TARGET_CXXFLAGS
+= -fhonour-copts
128 # for architectures where gcc --with-cpu matches -mcpu=
129 ifneq ($(ADK_TARGET_GCC_CPU
),)
130 ifeq ($(ADK_CPU_ARC700
),y
)
131 TARGET_CFLAGS
+= -mcpu
=ARC700
132 TARGET_CXXFLAGS
+= -mcpu
=ARC700
134 TARGET_CFLAGS
+= -mcpu
=$(ADK_TARGET_GCC_CPU
)
135 TARGET_CXXFLAGS
+= -mcpu
=$(ADK_TARGET_GCC_CPU
)
139 # for archiectures where gcc --with-arch matches -march=
140 ifneq ($(ADK_TARGET_GCC_ARCH
),)
141 TARGET_CFLAGS
+= -march
=$(ADK_TARGET_GCC_ARCH
)
142 TARGET_CXXFLAGS
+= -march
=$(ADK_TARGET_GCC_ARCH
)
145 ifneq ($(ADK_TARGET_CPU_FLAGS
),)
146 TARGET_CFLAGS
+= $(ADK_TARGET_CPU_FLAGS
)
147 TARGET_CXXFLAGS
+= $(ADK_TARGET_CPU_FLAGS
)
150 ifneq ($(ADK_TARGET_FPU
),)
151 TARGET_CFLAGS
+= -mfpu
=$(ADK_TARGET_FPU
)
152 TARGET_CXXFLAGS
+= -mfpu
=$(ADK_TARGET_FPU
)
155 ifneq ($(ADK_TARGET_FLOAT
),)
156 ifeq ($(ADK_TARGET_ARCH_ARM
),y
)
157 TARGET_CFLAGS
+= -mfloat-abi
=$(ADK_TARGET_FLOAT
)
158 TARGET_CXXFLAGS
+= -mfloat-abi
=$(ADK_TARGET_FLOAT
)
160 ifeq ($(ADK_TARGET_ARCH_MIPS
),y
)
161 TARGET_CFLAGS
+= -m
$(ADK_TARGET_FLOAT
)-float
162 TARGET_CXXFLAGS
+= -m
$(ADK_TARGET_FLOAT
)-float
166 ifeq ($(ADK_TARGET_ARCH_ARM
),y
)
167 ifeq ($(ADK_TARGET_BINFMT_FLAT
),y
)
168 TARGET_CFLAGS
+= -Wl
,-elf2flt
169 TARGET_CXXFLAGS
+= -Wl
,-elf2flt
173 ifeq ($(ADK_TARGET_ARCH_BFIN
),y
)
174 ifeq ($(ADK_TARGET_BINFMT_FLAT
),y
)
175 TARGET_LDFLAGS
+= -elf2flt
177 ifeq ($(ADK_TARGET_BINFMT_FLAT_SEP_DATA
),y
)
178 TARGET_CFLAGS
+= -msep-data
179 TARGET_CXXFLAGS
+= -msep-data
183 ifeq ($(ADK_TARGET_ARCH_H8300
),y
)
186 ifeq ($(ADK_TARGET_BINFMT_FLAT
),y
)
187 TARGET_CFLAGS
+= -Wl
,-elf2flt
188 TARGET_CXXFLAGS
+= -Wl
,-elf2flt
190 ifeq ($(ADK_TARGET_BINFMT_FLAT_SEP_DATA
),y
)
191 TARGET_CFLAGS
+= -msep-data
192 TARGET_CXXFLAGS
+= -msep-data
196 ifeq ($(ADK_TARGET_ARCH_M68K
),y
)
197 ifeq ($(ADK_TARGET_BINFMT_FLAT
),y
)
198 TARGET_LDFLAGS
+= -elf2flt
200 ifeq ($(ADK_TARGET_BINFMT_FLAT_SEP_DATA
),y
)
201 TARGET_CFLAGS
+= -msep-data
202 TARGET_CXXFLAGS
+= -msep-data
206 ifeq ($(ADK_TARGET_LIB_MUSL
),y
)
207 # use -static-libgcc by default only for musl
208 TARGET_CFLAGS
+= -static-libgcc
209 TARGET_CXXFLAGS
+= -static-libgcc
210 TARGET_LDFLAGS
+= -static-libgcc
213 # security optimization, see http://www.akkadia.org/drepper/dsohowto.pdf
214 ifneq ($(ADK_TARGET_USE_LD_RELRO
),)
215 TARGET_LDFLAGS
+= -Wl
,-z
,relro
217 ifneq ($(ADK_TARGET_USE_LD_BIND_NOW
),)
218 TARGET_LDFLAGS
+= -Wl
,-z
,now
221 # needed for musl ppc
222 ifeq ($(ADK_TARGET_ARCH_PPC
),y
)
223 ifeq ($(ADK_TARGET_LIB_MUSL
),y
)
224 TARGET_LDFLAGS
+= -Wl
,--secure-plt
228 ifeq ($(ADK_TARGET_USE_STATIC_LIBS
),y
)
229 TARGET_CFLAGS
+= -static
230 TARGET_CXXFLAGS
+= -static
231 TARGET_LDFLAGS
+= -static
234 ifneq ($(ADK_TARGET_USE_SSP
),)
235 TARGET_CFLAGS
+= -fstack-protector-all
--param
=ssp-buffer-size
=4
236 TARGET_CXXFLAGS
+= -fstack-protector-all
--param
=ssp-buffer-size
=4
237 TARGET_LDFLAGS
+= -fstack-protector-all
240 ifneq ($(ADK_TARGET_USE_LD_GC
),)
241 TARGET_CFLAGS
+= -fdata-sections
-ffunction-sections
242 TARGET_CXXFLAGS
+= -fdata-sections
-ffunction-sections
243 TARGET_LDFLAGS
+= -Wl
,--gc-sections
246 ifneq ($(ADK_TARGET_USE_LTO
),)
247 TARGET_CFLAGS
+= -flto
248 TARGET_CXXFLAGS
+= -flto
249 TARGET_LDFLAGS
+= -flto
252 # performance optimization, see http://www.akkadia.org/drepper/dsohowto.pdf
253 ifneq ($(ADK_TARGET_USE_GNU_HASHSTYLE
),)
254 TARGET_LDFLAGS
+= -Wl
,--hash-style
=gnu
257 ifeq ($(ADK_TARGET_ARCH_MICROBLAZE
),y
)
258 TARGET_CFLAGS
+= -mxl-barrel-shift
259 TARGET_CXXFLAGS
+= -mxl-barrel-shift
261 ifeq ($(ADK_TARGET_ARCH_XTENSA
),y
)
262 TARGET_CFLAGS
+= -mlongcalls
-mtext-section-literals
263 TARGET_CXXFLAGS
+= -mlongcalls
-mtext-section-literals
266 # add configured compiler flags for optimization
267 TARGET_CFLAGS
+= $(ADK_TARGET_CFLAGS_OPT
)
268 TARGET_CXXFLAGS
+= $(ADK_TARGET_CFLAGS_OPT
)
270 # add compiler flags for debug information
271 ifneq ($(ADK_DEBUG
),)
273 TARGET_CXXFLAGS
+= -g3
276 ifneq ($(ADK_DEBUG
),)
277 TARGET_CFLAGS
+= -fno-omit-frame-pointer
278 TARGET_CXXFLAGS
+= -fno-omit-frame-pointer
279 TARGET_CFLAGS
+= -funwind-tables
-fasynchronous-unwind-tables
280 TARGET_CXXFLAGS
+= -funwind-tables
-fasynchronous-unwind-tables
282 TARGET_CPPFLAGS
+= -DNDEBUG
283 TARGET_CFLAGS
+= -fomit-frame-pointer
284 TARGET_CXXFLAGS
+= -fomit-frame-pointer
285 # stop generating eh_frame stuff
286 TARGET_CFLAGS
+= -fno-unwind-tables
-fno-asynchronous-unwind-tables
287 TARGET_CXXFLAGS
+= -fno-unwind-tables
-fno-asynchronous-unwind-tables
290 ifeq ($(ADK_TARGET_ARCH_ARM
),y
)
291 ifeq ($(ADK_TARGET_ARCH_ARM_WITH_NEON
),y
)
292 TARGET_CFLAGS
+= -funsafe-math-optimizations
293 TARGET_CXXFLAGS
+= -funsafe-math-optimizations
295 ifeq ($(ADK_TARGET_ARCH_ARM_WITH_THUMB
),y
)
296 TARGET_CFLAGS
+= -mthumb
-Wa
,-mimplicit-it
=thumb
297 TARGET_CXXFLAGS
+= -mthumb
-Wa
,-mimplicit-it
=thumb
299 TARGET_CFLAGS
+= -marm
300 TARGET_CXXFLAGS
+= -marm
304 # host compiler and linker flags
305 HOST_CPPFLAGS
:= -I
$(STAGING_HOST_DIR
)/usr
/include
306 HOST_LDFLAGS
:= -L
$(STAGING_HOST_DIR
)/usr
/lib
-Wl
,-rpath
-Wl
,${STAGING_HOST_DIR}/usr
/lib
308 PATCH
= PATH
='${HOST_PATH}' ${BASH} $(SCRIPT_DIR
)/patch.sh
309 PATCHP0
= PATH
='${HOST_PATH}' patch
-p0
311 ifeq ($(ADK_STATIC_TOOLCHAIN
),y
)
312 HOST_STATIC_CFLAGS
:= -static
-Wl
,-static
313 HOST_STATIC_CXXFLAGS
:= -static
-Wl
,-static
314 HOST_STATIC_LDFLAGS
:= -Wl
,-static
315 HOST_STATIC_LLDFLAGS
:= -all-static
318 SED
:= PATH
='${HOST_PATH}' sed
-i
-e
319 XZ
:= PATH
='${HOST_PATH}' xz
320 LINUX_DIR
:= $(BUILD_DIR
)/linux
321 KERNEL_MODULE_FLAGS
:= ARCH
=${ADK_TARGET_ARCH} \
323 KERNEL_PATH
=${LINUX_DIR} \
324 KERNELDIR
=${LINUX_DIR} \
325 KERNEL_DIR
=${LINUX_DIR} \
326 CROSS_COMPILE
="${TARGET_CROSS}" \
327 CFLAGS_MODULE
="-fhonour-copts" \
330 COMMON_ENV
= CONFIG_SHELL
='$(strip ${SHELL})' \
331 AUTOM4TE
='${STAGING_HOST_DIR}/usr/bin/autom4te' \
332 M4
='${STAGING_HOST_DIR}/usr/bin/m4' \
333 LIBTOOLIZE
='${STAGING_HOST_DIR}/usr/bin/libtoolize -q' \
336 ifneq ($(ADK_TARGET_USE_LTO
),)
337 TOOLS_ENV
= AR
='$(TARGET_CROSS)gcc-ar' \
338 RANLIB
='$(TARGET_CROSS)gcc-ranlib' \
339 NM
='$(TARGET_CROSS)gcc-nm'
341 TOOLS_ENV
= AR
='$(TARGET_CROSS)ar' \
342 RANLIB
='$(TARGET_CROSS)ranlib' \
343 NM
='$(TARGET_CROSS)nm'
346 TARGET_ENV
= $(TOOLS_ENV
) \
347 AS
='$(TARGET_CROSS)as' \
348 LD
='$(TARGET_CROSS)ld' \
349 STRIP
='$(TARGET_CROSS)strip' \
350 OBJCOPY
='$(TARGET_CROSS)objcopy' \
353 CXX
='$(TARGET_CXX)' \
354 CROSS
='$(TARGET_CROSS)' \
355 CROSS_COMPILE
='$(TARGET_CROSS)' \
356 CFLAGS
='$(TARGET_CFLAGS)' \
357 CXXFLAGS
='$(TARGET_CXXFLAGS)' \
358 CPPFLAGS
='$(TARGET_CPPFLAGS)' \
359 LDFLAGS
='$(TARGET_LDFLAGS)' \
360 CC_FOR_BUILD
='$(HOST_CC)' \
361 CXX_FOR_BUILD
='$(HOST_CXX)' \
362 CPPFLAGS_FOR_BUILD
='$(HOST_CPPFLAGS)' \
363 CFLAGS_FOR_BUILD
='$(HOST_CFLAGS)' \
364 CXXFLAGS_FOR_BUILD
='$(HOST_CXXFLAGS)' \
365 LDFLAGS_FOR_BUILD
='$(HOST_LDFLAGS)' \
366 LIBS_FOR_BUILD
='$(HOST_LIBS)'
368 HOST_ENV
= CC
='$(HOST_CC)' \
370 CPPFLAGS
='$(HOST_CPPFLAGS)' \
371 CFLAGS
='$(HOST_CFLAGS)' \
372 CXXFLAGS
='$(HOST_CXXFLAGS)' \
373 LDFLAGS
='$(HOST_LDFLAGS)'
375 PKG_SUFFIX
:= $(strip $(subst ",, $(ADK_PACKAGE_SUFFIX)))
377 ifeq ($(ADK_TARGET_PACKAGE_IPKG),y)
378 PKG_BUILD:= PATH='${HOST_PATH}' \
379 ${BASH} ${SCRIPT_DIR}/ipkg-build
380 PKG_INSTALL:= PATH='${HOST_PATH}' \
381 IPKG_TMP=$(BUILD_DIR)/tmp \
382 IPKG_INSTROOT=$(TARGET_DIR) \
383 IPKG_CONF_DIR=$(STAGING_TARGET_DIR)/etc \
384 IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
385 BIN_DIR=$(STAGING_HOST_DIR)/usr/bin \
386 ${BASH} ${SCRIPT_DIR}/ipkg \
387 -force-defaults -force-depends install
388 PKG_STATE_DIR:= $(TARGET_DIR)/usr/lib/ipkg
391 ifeq ($(ADK_TARGET_PACKAGE_OPKG),y)
392 PKG_BUILD:= PATH='${HOST_PATH}' \
393 ${BASH} ${SCRIPT_DIR}/ipkg-build
394 PKG_INSTALL:= PATH='${HOST_PATH}' \
395 IPKG_TMP=$(BUILD_DIR)/tmp \
396 IPKG_INSTROOT=$(TARGET_DIR) \
397 IPKG_CONF_DIR=$(STAGING_TARGET_DIR)/etc \
398 IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
399 BIN_DIR=$(STAGING_HOST_DIR)/usr/bin \
400 ${BASH} ${SCRIPT_DIR}/ipkg \
401 -force-defaults -force-depends install
402 PKG_STATE_DIR:= $(TARGET_DIR)/usr/lib/opkg
405 ifeq ($(ADK_TARGET_PACKAGE_TXZ),y)
406 PKG_BUILD:= PATH='${HOST_PATH}' ${BASH} ${SCRIPT_DIR}/tarpkg build
407 PKG_INSTALL:= PKG_INSTROOT='$(TARGET_DIR)' \
408 PATH='${HOST_PATH}' ${BASH} ${SCRIPT_DIR}/tarpkg install
409 PKG_STATE_DIR:= $(TARGET_DIR)/usr/lib/pkg
412 RSTRIP:= PATH="$(TARGET_PATH
)" prefix='${TARGET_CROSS}' ${BASH} ${SCRIPT_DIR}/rstrip.sh
414 STATCMD:=$(shell if stat -qs .>/dev/null 2>&1; then echo 'stat -f %z';else echo 'stat -c %s';fi)
416 EXTRACT_CMD= PATH='${HOST_PATH}'; mkdir -p ${WRKDIR}; \
418 for file in ${FULLDISTFILES}; do case $$file in \
420 cat $$file | cpio -i -d ;; \
423 *.cpio.Z | *.cpio.gz | *.cgz | *.mcz) \
424 gzip -dc $$file | cpio -i -d ;; \
426 xz -dc $$file | tar -xf - ;; \
427 *.tar.Z | *.tar.gz | *.taz | *.tgz) \
428 gzip -dc $$file | tar -xf - ;; \
429 *.cpio.bz2 | *.cbz) \
430 bzip2 -dc $$file | cpio -i -d ;; \
431 *.tar.bz2 | *.tbz | *.tbz2) \
432 bzip2 -dc $$file | tar -xf - ;; \
434 cat $$file | cpio -id -H zip ;; \
435 *.arm|*.jar|*.ids.gz) \
436 mkdir ${WRKBUILD}; cp $$file ${WRKBUILD} ;; \
438 sh $$file --force --auto-accept ;; \
440 echo "Cannot extract
'$$file'" >&2; \
444 ifeq ($(ADK_VERBOSE),1)
449 FETCH_CMD?= PATH='${HOST_PATH}' wget --timeout=$(ADK_WGET_TIMEOUT) -t 3 --no-check-certificate $(QUIET)
451 ifneq (,$(filter CYGWIN%,${OStype}))
455 include $(ADK_TOPDIR)/mk/mirrors.mk