1 # This file is part of the OpenADK project. OpenADK is copyrighted
2 # material, please see the LICENCE file in the top-level directory.
4 include $(ADK_TOPDIR
)/rules.mk
8 # disable SSP for libstdc++
9 ifeq ($(ADK_TARGET_LIB_MUSL
),y
)
10 TARGET_CFLAGS
:= $(filter-out -fstack-protector-all
,$(TARGET_CFLAGS
))
11 TARGET_CXXFLAGS
:= $(filter-out -fstack-protector-all
,$(TARGET_CXXFLAGS
))
15 TARGET_CFLAGS
:= $(filter-out -flto
,$(TARGET_CFLAGS
))
16 TARGET_CXXFLAGS
:= $(filter-out -flto
,$(TARGET_CXXFLAGS
))
18 # for uClinux, we need to filter out some flags
19 ifeq ($(ADK_TARGET_UCLINUX
),y
)
20 TARGET_CFLAGS
:= $(filter-out -msep-data
,$(TARGET_CFLAGS
))
21 TARGET_CXXFLAGS
:= $(filter-out -msep-data
,$(TARGET_CXXFLAGS
))
24 # for ARM, we need to filter out some flags
25 ifeq ($(ADK_TARGET_ARCH_ARM
),y
)
26 TARGET_CFLAGS
:= $(filter-out -mcpu
=cortex-a9
,$(TARGET_CFLAGS
))
27 TARGET_CXXFLAGS
:= $(filter-out -mcpu
=cortex-a9
,$(TARGET_CXXFLAGS
))
29 ifeq ($(ADK_TARGET_ARCH_ARM
),y
)
30 TARGET_CFLAGS
:= $(filter-out -mcpu
=cortex-a7
,$(TARGET_CFLAGS
))
31 TARGET_CXXFLAGS
:= $(filter-out -mcpu
=cortex-a7
,$(TARGET_CXXFLAGS
))
34 ifeq ($(ADK_TARGET_ARCH_ARM
),y
)
35 TARGET_CFLAGS
:= $(filter-out -mcpu
=xscale
,$(TARGET_CFLAGS
))
36 TARGET_CXXFLAGS
:= $(filter-out -mcpu
=xscale
,$(TARGET_CXXFLAGS
))
39 ifeq ($(ADK_TARGET_USE_STATIC_AND_SHARED_LIBS
),y
)
40 TARGET_CFLAGS
:= $(filter-out -static
,$(TARGET_CFLAGS
))
41 TARGET_CXXFLAGS
:= $(filter-out -static
,$(TARGET_CXXFLAGS
))
44 GCC_CONFOPTS
:= --prefix=$(TOOLCHAIN_DIR
)/usr \
45 --with-bugurl
="$(ADK_VENDOR_URL)" \
46 --build
=$(GNU_HOST_NAME
) \
47 --host
=$(GNU_HOST_NAME
) \
48 --target
=$(GNU_TARGET_NAME
) \
49 --with-gmp
=$(STAGING_HOST_DIR
)/usr \
50 --with-mpfr
=$(STAGING_HOST_DIR
)/usr \
51 --enable-__cxa_atexit \
55 --disable-libsanitizer \
56 --disable-install-libiberty \
58 --disable-libmudflap \
62 --disable-libcilkrts \
63 --disable-libquadmath \
64 --disable-libquadmath-support \
65 --disable-decimal-float \
67 --disable-libstdcxx-pch \
68 --disable-ppl-version-check \
69 --disable-cloog-version-check \
77 ifeq ($(ADK_TARGET_OS_LINUX
),y
)
78 ifeq ($(ADK_TARGET_LIB_UCLIBC_NG
),y
)
79 ifeq ($(ADK_TARGET_WITH_NPTL
),y
)
80 GCC_FINAL_CONFOPTS
:= --enable-tls
--enable-threads
--enable-libatomic
81 GCC_TLS_CONFOPTS
:= --enable-tls
83 ifeq ($(ADK_TARGET_WITH_LT
),y
)
84 GCC_FINAL_CONFOPTS
:= --disable-tls
--enable-threads
--disable-libatomic
85 GCC_TLS_CONFOPTS
:= --disable-tls
87 ifeq ($(ADK_TARGET_LIB_WITHOUT_THREADS
)$(ADK_TARGET_WITHOUT_THREADS
),y
)
88 GCC_FINAL_CONFOPTS
:= --disable-tls
--disable-threads
--disable-libatomic
89 GCC_TLS_CONFOPTS
:= --disable-tls
92 GCC_FINAL_CONFOPTS
:= --enable-tls
--enable-threads
--enable-libatomic
93 GCC_TLS_CONFOPTS
:= --enable-tls
97 ifeq ($(ADK_TARGET_OS_BAREMETAL
),y
)
98 GCC_FINAL_CONFOPTS
:= --disable-libatomic
101 ifeq ($(ADK_TARGET_LIB_NEWLIB
),y
)
102 GCC_FINAL_CONFOPTS
+= --with-newlib
105 ifeq ($(ADK_TARGET_USE_STATIC_LIBS_ONLY
),y
)
106 GCC_FINAL_CONFOPTS
+= --disable-shared
108 GCC_FINAL_CONFOPTS
+= --enable-shared
--enable-cxx-flags
='-fPIC'
111 ifeq ($(ADK_TOOLCHAIN_WITH_SSP
),y
)
112 GCC_FINAL_CONFOPTS
+= --enable-libssp
114 GCC_FINAL_CONFOPTS
+= --disable-libssp
117 ifeq ($(ADK_TOOLCHAIN_WITH_LTO
),y
)
118 GCC_CONFOPTS
+= --enable-lto
120 GCC_CONFOPTS
+= --disable-lto
124 # architecture specific
126 ifneq ($(ADK_TARGET_GCC_CPU
),)
127 GCC_CONFOPTS
+= --with-cpu
=$(ADK_TARGET_GCC_CPU
)
130 ifneq ($(ADK_TARGET_GCC_ARCH
),)
131 GCC_CONFOPTS
+= --with-arch
=$(ADK_TARGET_GCC_ARCH
)
134 ifneq ($(ADK_TARGET_FLOAT
),)
135 GCC_CONFOPTS
+= --with-float
=$(ADK_TARGET_FLOAT
)
138 ifneq ($(ADK_TARGET_FPU
),)
139 GCC_CONFOPTS
+= --with-fpu
=$(ADK_TARGET_FPU
)
142 ifneq ($(ADK_TARGET_INSTRUCTION_SET
),)
143 GCC_CONFOPTS
+= --with-mode
=$(ADK_TARGET_INSTRUCTION_SET
)
146 ifneq ($(ADK_TARGET_NAN_MODE
),)
147 GCC_CONFOPTS
+= --with-nan
=$(ADK_TARGET_NAN_MODE
)
150 # .symver is broken for Blackfin, simple C++ apps fail to link
151 ifeq ($(ADK_TARGET_ARCH_BFIN
),y
)
152 GCC_CONFOPTS
+= --disable-symvers
155 ifeq ($(ADK_TARGET_ARCH_CSKY
),y
)
156 GCC_CONFOPTS
+= --with-cskyabi
=abiv2
--disable-multilib
157 ifeq ($(ADK_TARGET_LITTLE_ENDIAN
),y
)
158 GCC_CONFOPTS
+= --with-endian
=little
160 GCC_CONFOPTS
+= --with-endian
=big
164 ifeq ($(ADK_TARGET_ARCH_METAG
),y
)
165 GCC_CONFOPTS
+= --with-cpu
=2.1 --enable-meta-default
--disable-symvers
168 ifeq ($(ADK_TARGET_ARCH_NDS32
),y
)
169 GCC_CONFOPTS
+= --with-arch
=v3
172 ifeq ($(ADK_TARGET_ARCH_M68K
)$(ADK_TARGET_ARCH_X86_64
)$(ADK_TARGET_ARCH_X86
),)
173 GCC_FINAL_CONFOPTS
+= --disable-biarch
--disable-multilib
176 ifeq ($(ADK_TARGET_CPU_CF
),y
)
177 GCC_CONFOPTS
+= --with-arch
=cf
178 GCC_INITIAL_CONFOPTS
+= --enable-multilib
179 ifeq ($(ADK_TARGET_BINFMT_ELF
)$(ADK_TARGET_WITH_MMU
),y
)
180 GCC_FINAL_CONFOPTS
+= --disable-multilib
--disable-threads
--disable-libatomic
183 GCC_INITIAL_CONFOPTS
+= --disable-multilib
186 ifeq ($(ADK_TARGET_ARCH_SH
),y
)
188 ifeq ($(ADK_TARGET_LITTLE_ENDIAN
),y
)
189 GCC_CONFOPTS
+= --with-endian
=little
191 GCC_CONFOPTS
+= --with-endian
=big
193 ifeq ($(ADK_TARGET_BINFMT_FDPIC
),y
)
194 GCC_CONFOPTS
+= --enable-fdpic
197 ifeq ($(ADK_TARGET_CPU_SH_J2
),y
)
198 GCC_CONFOPTS
+= --with-multilib-list
=mj2
200 ifeq ($(ADK_TARGET_CPU_SH_SH2
),y
)
201 GCC_CONFOPTS
+= --with-multilib-list
=m2
203 ifeq ($(ADK_TARGET_CPU_SH_SH2A
),y
)
204 GCC_CONFOPTS
+= --with-multilib-list
=m2a
,m2a-nofpu
206 ifeq ($(ADK_TARGET_CPU_SH_SH3
),y
)
207 GCC_CONFOPTS
+= --with-multilib-list
=m3
209 ifeq ($(ADK_TARGET_CPU_SH_SH4
),y
)
210 GCC_CONFOPTS
+= --with-multilib-list
=m4
,m4-nofpu
212 ifeq ($(ADK_TARGET_CPU_SH_SH4A
),y
)
213 GCC_CONFOPTS
+= --with-multilib-list
=m4a
,m4a-nofpu
218 ifeq ($(ADK_TARGET_ARCH_X86
),y
)
219 ifeq ($(ADK_TARGET_KERNEL_64
),y
)
220 GCC_FINAL_CONFOPTS
+= --enable-biarch
--enable-targets
=all --disable-multilib
222 GCC_FINAL_CONFOPTS
+= --disable-biarch
--disable-multilib
226 ifeq ($(ADK_TARGET_ARCH_X86_64
),y
)
227 ifneq ($(ADK_TARGET_ABI_X32
),)
228 GCC_CONFOPTS
+= --with-abi
=x32
--enable-multilib
230 GCC_CONFOPTS
+= --disable-biarch
--disable-multilib
234 ifeq ($(ADK_TARGET_ARCH_ALPHA
),y
)
235 GCC_CONFOPTS
+= --without-long-double-128
238 ifeq ($(ADK_TARGET_ARCH_PPC
),y
)
239 GCC_CONFOPTS
+= --with-long-double-64
--enable-secureplt
242 ifeq ($(ADK_TARGET_ARCH_PPC64
),y
)
243 ifeq ($(ADK_TARGET_LIB_GLIBC
),y
)
244 GCC_CONFOPTS
+= --with-long-double-128
--with-abi
=elfv2
246 GCC_CONFOPTS
+= --without-long-double-128
--with-abi
=elfv2
250 ifeq ($(ADK_TARGET_ARCH_S390
),y
)
251 GCC_CONFOPTS
+= --with-long-double-128
254 ifneq ($(ADK_TARGET_ABI_MIPS64
),)
255 GCC_CONFOPTS
+= --with-abi
=${ADK_TARGET_ABI_MIPS64}
258 ifneq ($(ADK_TARGET_ABI_RISCV
),)
259 GCC_CONFOPTS
+= --with-abi
=${ADK_TARGET_ABI_RISCV}
262 ifeq ($(ADK_TOOLCHAIN_GCC_NDS32
),y
)
263 EXTRA_CXXFLAGS
:= --std
=c
++03
266 ifeq (${ADK_MAKE_PARALLEL},y
)
267 GCC_MAKEOPTS
+= -j
${ADK_MAKE_JOBS}
271 ifeq ($(ADK_TOOLCHAIN_WITH_CXX
),y
)
274 ifeq ($(ADK_TOOLCHAIN_WITH_OBJC
),y
)
277 ifeq ($(ADK_TOOLCHAIN_WITH_FORTRAN
),y
)
280 ifeq ($(ADK_TOOLCHAIN_WITH_GO
),y
)
284 LANGUAGES
=$(shell echo
${USE_LANG} |tr
' ' ',')
286 include ${ADK_TOPDIR}/mk
/buildhlp.mk
288 GCC_BUILD_DIR_INITIAL
:= $(WRKBUILD
)-initial
289 GCC_BUILD_DIR_FINAL
:= $(WRKBUILD
)-final
291 $(GCC_BUILD_DIR_INITIAL
)/.configured
:
292 ifeq ($(ADK_TARGET_ARCH_XTENSA
),y
)
293 ifeq ($(ADK_TARGET_ABI
),)
294 tar xf
$(ADK_TOPDIR
)/target
/xtensa
/overlay
/xtensa_
$(ADK_TARGET_CPU_TYPE
).
tar \
295 --strip-components
=1 -C
$(WRKSRC
) gcc
297 tar xf
$(ADK_TOPDIR
)/target
/xtensa
/overlay
/xtensa_
$(ADK_TARGET_CPU_TYPE
)_
$(ADK_TARGET_ABI
).
tar \
298 --strip-components
=1 -C
$(WRKSRC
) gcc
301 mkdir
-p
$(GCC_BUILD_DIR_INITIAL
)
302 # these symlinks are very important, do not remove
303 rm -rf
$(TOOLCHAIN_DIR
)/usr
/$(GNU_TARGET_NAME
)/sys-include
304 mkdir
-p
$(TOOLCHAIN_DIR
)/usr
/$(GNU_TARGET_NAME
)
305 (cd
$(TOOLCHAIN_DIR
)/usr
/$(GNU_TARGET_NAME
); \
306 ln
-s ..
/$(STAGING_HOST2TARGET
)/usr
/include sys-include
)
307 rm -rf
${TOOLCHAIN_DIR}/usr
/$(GNU_TARGET_NAME
)/lib
308 (cd
$(TOOLCHAIN_DIR
)/usr
/$(GNU_TARGET_NAME
); \
309 ln
-s ..
/$(STAGING_HOST2TARGET
)/usr
/lib lib
)
310 ifeq ($(ADK_TARGET_ARCH_SH
),y
)
311 ifeq ($(ADK_TARGET_CPU_SH_SH2
),y
)
312 (cd
${STAGING_TARGET_DIR}/ && ln
-sf . m2
)
314 ifeq ($(ADK_TARGET_CPU_SH_SH2A
),y
)
315 (cd
${STAGING_TARGET_DIR}/ && ln
-sf . m2a
)
317 ifeq ($(ADK_TARGET_CPU_SH_SH3
),y
)
318 (cd
${STAGING_TARGET_DIR}/ && ln
-sf . m3
)
320 ifeq ($(ADK_TARGET_CPU_SH_SH4
),y
)
321 (cd
${STAGING_TARGET_DIR}/ && ln
-sf . m4
)
323 ifeq ($(ADK_TARGET_CPU_SH_SH4A
),y
)
324 (cd
${STAGING_TARGET_DIR}/ && ln
-sf . m4a
)
327 ifeq ($(ADK_TARGET_ARCH_M68K
),y
)
328 # Need to get gcc to generate _all_ the multilib variants
329 # (so both MMU and non-mmu M68k and ColdFire).
330 $(SED
) 's/M68K_MLIB_CPU +=/#M68K_MLIB_CPU +=/' $(WRKBUILD
)/gcc
/config
/m68k
/t-m68k
331 $(SED
) 's/&& (FLAGS ~ "FL_MMU")//' $(WRKBUILD
)/gcc
/config
/m68k
/t-linux
333 $(SED
) '/k prot/agcc_cv_libc_provides_ssp=yes' $(WRKBUILD
)/gcc
/configure
334 cd
$(GCC_BUILD_DIR_INITIAL
); \
335 PATH
='$(TARGET_PATH)' \
338 CFLAGS
="-O0 -g0 -fomit-frame-pointer" \
339 CXXFLAGS
="-O0 -g0 -fomit-frame-pointer $(EXTRA_CXXFLAGS)" \
340 $(WRKBUILD
)/configure \
341 ${GCC_INITIAL_CONFOPTS} \
343 ${GCC_TLS_CONFOPTS} \
344 --enable-languages
=c \
351 $(GCC_BUILD_DIR_INITIAL
)/.compiled
: $(GCC_BUILD_DIR_INITIAL
)/.configured
352 ifeq ($(ADK_TOOLCHAIN_GCC_METAG
),y
)
353 PATH
='$(TARGET_PATH)' \
354 $(MAKE
) ${GCC_MAKEOPTS} -C
$(GCC_BUILD_DIR_INITIAL
) all-gcc
356 PATH
='$(TARGET_PATH)' \
357 $(MAKE
) ${GCC_MAKEOPTS} -C
$(GCC_BUILD_DIR_INITIAL
) all-gcc all-target-libgcc
361 $(WRKBUILD
)/.configured
: $(GCC_BUILD_DIR_INITIAL
)/.compiled
362 ifeq ($(ADK_TOOLCHAIN_GCC_METAG
),y
)
363 PATH
='$(TARGET_PATH)' \
364 $(MAKE
) -C
$(GCC_BUILD_DIR_INITIAL
) install-gcc
366 PATH
='$(TARGET_PATH)' \
367 $(MAKE
) -C
$(GCC_BUILD_DIR_INITIAL
) install-gcc install-target-libgcc
369 # required for newlib
370 (cd
$(TOOLCHAIN_DIR
)/usr
/bin
&& \
371 ln
-sf
$(GNU_TARGET_NAME
)-gcc
$(GNU_TARGET_NAME
)-cc \
375 $(WRKBUILD
)/.compiled
:
376 mkdir
-p
$(GCC_BUILD_DIR_FINAL
)
377 cd
$(GCC_BUILD_DIR_FINAL
); \
378 PATH
='$(TARGET_PATH)' \
380 CXX
='$(HOST_CXX) $(EXTRA_CXXFLAGS)' \
381 CFLAGS_FOR_TARGET
='$(TARGET_CFLAGS)' \
382 CXXFLAGS_FOR_TARGET
='$(TARGET_CXXFLAGS)' \
383 $(WRKBUILD
)/configure \
385 ${GCC_FINAL_CONFOPTS} \
386 --enable-languages
=$(LANGUAGES
) \
387 --with-build-sysroot
='$${prefix}/${STAGING_HOST2TARGET}' \
388 --with-sysroot
='$${prefix}/${STAGING_HOST2TARGET}'
389 PATH
='$(TARGET_PATH)' $(MAKE
) -C
$(GCC_BUILD_DIR_FINAL
) configure-host
390 cd
$(GCC_BUILD_DIR_FINAL
); \
391 PATH
='$(TARGET_PATH)' \
392 $(MAKE
) ${GCC_MAKEOPTS} all
395 $(WRKBUILD
)/.installed
: $(WRKBUILD
)/.compiled
396 cd
$(GCC_BUILD_DIR_FINAL
); \
397 PATH
='$(TARGET_PATH)' \
399 # remove duplicate tools, convert hardlinks to symlinks
401 cd
$(TOOLCHAIN_DIR
)/usr
/$(GNU_TARGET_NAME
)/bin
; \
402 for app in
ar as c
++ g
++ gcc
ld ld.gold
ld.bfd nm objcopy objdump ranlib
strip; do \
403 ln
-sf ..
/..
/bin
/$(GNU_TARGET_NAME
)-$${app} $${app}; \
405 (cd
$(TOOLCHAIN_DIR
)/usr
/bin
&& \
406 ln
-sf
$(GNU_TARGET_NAME
)-gcc
$(GNU_TARGET_NAME
)-gcc-
${PKG_VERSION} && \
407 ln
-sf
$(GNU_TARGET_NAME
)-g
++ $(GNU_TARGET_NAME
)-g
++-${PKG_VERSION} \
412 ifeq ($(ADK_TARGET_CPU_CF
),y
)
413 find
$(STAGING_TARGET_DIR
) -name libgcc.a
-print | while read t
; do
$(GNU_TARGET_NAME
)-ar dv
"$t" _ctors.o
; done
415 # cleanup unneeded docs
416 rm -rf
$(TOOLCHAIN_DIR
)/usr
/share
417 # cleanup unneeded libtool files
418 -find
$(STAGING_TARGET_DIR
) $(STAGING_HOST_DIR
) -name \
*.la
-exec
rm {} \
;
419 # strip target libs and host tools for toolchain builds in non-Debug mode
421 PATH
="$(TARGET_PATH)" debug
='0' prefix='${TARGET_CROSS}' ${BASH} ${SCRIPT_DIR}/rstrip.sh \
422 $(STAGING_TARGET_DIR
) $(TOOLCHAIN_DIR
)/usr
/lib
/gcc
/$(GNU_TARGET_NAME
)
423 debug
='0' prefix=' ' ${BASH} ${SCRIPT_DIR}/rstrip.sh
$(TOOLCHAIN_DIR
)/usr
/bin
427 include ${ADK_TOPDIR}/mk
/toolchain.mk