xref: /OK3568_Linux_fs/buildroot/package/gcc/gcc.mk (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1################################################################################
2#
3# Common variables for the gcc-initial and gcc-final packages.
4#
5################################################################################
6
7#
8# Version, site and source
9#
10
11GCC_VERSION = $(call qstrip,$(BR2_GCC_VERSION))
12
13ifeq ($(BR2_GCC_VERSION_ARC),y)
14GCC_SITE = $(call github,foss-for-synopsys-dwc-arc-processors,gcc,$(GCC_VERSION))
15GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz
16else
17GCC_SITE = $(BR2_GNU_MIRROR:/=)/gcc/gcc-$(GCC_VERSION)
18GCC_SOURCE = gcc-$(GCC_VERSION).tar.xz
19endif
20
21#
22# Xtensa special hook
23#
24define HOST_GCC_XTENSA_OVERLAY_EXTRACT
25	$(call arch-xtensa-overlay-extract,$(@D),gcc)
26endef
27
28#
29# Apply patches
30#
31
32# gcc is a special package, not named gcc, but gcc-initial and
33# gcc-final, but patches are nonetheless stored in package/gcc in the
34# tree, and potentially in BR2_GLOBAL_PATCH_DIR directories as well.
35define HOST_GCC_APPLY_PATCHES
36	for patchdir in \
37	    package/gcc/$(GCC_VERSION) \
38	    $(addsuffix /gcc/$(GCC_VERSION),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
39	    $(addsuffix /gcc,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) ; do \
40		if test -d $${patchdir}; then \
41			$(APPLY_PATCHES) $(@D) $${patchdir} \*.patch || exit 1; \
42		fi; \
43	done
44	$(HOST_GCC_APPLY_POWERPC_PATCH)
45endef
46
47HOST_GCC_EXCLUDES = \
48	libjava/* libgo/*
49
50#
51# Create 'build' directory and configure symlink
52#
53
54define HOST_GCC_CONFIGURE_SYMLINK
55	mkdir -p $(@D)/build
56	ln -sf ../configure $(@D)/build/configure
57endef
58
59#
60# Common configuration options
61#
62
63HOST_GCC_COMMON_DEPENDENCIES = \
64	host-binutils \
65	host-gmp \
66	host-mpc \
67	host-mpfr \
68	$(if $(BR2_BINFMT_FLAT),host-elf2flt)
69
70HOST_GCC_COMMON_CONF_OPTS = \
71	--target=$(GNU_TARGET_NAME) \
72	--with-sysroot=$(STAGING_DIR) \
73	--enable-__cxa_atexit \
74	--with-gnu-ld \
75	--disable-libssp \
76	--disable-multilib \
77	--disable-decimal-float \
78	--enable-plugins \
79	--enable-lto \
80	--with-gmp=$(HOST_DIR) \
81	--with-mpc=$(HOST_DIR) \
82	--with-mpfr=$(HOST_DIR) \
83	--with-pkgversion="Buildroot $(BR2_VERSION_FULL)" \
84	--with-bugurl="http://bugs.buildroot.net/" \
85	--without-zstd
86
87ifeq ($(BR2_REPRODUCIBLE),y)
88HOST_GCC_COMMON_CONF_OPTS += --with-debug-prefix-map=$(BASE_DIR)=buildroot
89endif
90
91# Don't build documentation. It takes up extra space / build time,
92# and sometimes needs specific makeinfo versions to work
93HOST_GCC_COMMON_CONF_ENV = \
94	MAKEINFO=missing
95
96GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS)
97GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS)
98
99# used to fix ../../../../libsanitizer/libbacktrace/../../libbacktrace/elf.c:772:21: error: 'st.st_mode' may be used uninitialized in this function [-Werror=maybe-uninitialized]
100ifeq ($(BR2_ENABLE_DEBUG),y)
101GCC_COMMON_TARGET_CFLAGS += -Wno-error
102endif
103
104# Make sure libgcc & libstdc++ always get built with -matomic on ARC700
105ifeq ($(GCC_TARGET_CPU):$(BR2_ARC_ATOMIC_EXT),arc700:y)
106GCC_COMMON_TARGET_CFLAGS += -matomic
107GCC_COMMON_TARGET_CXXFLAGS += -matomic
108endif
109
110# Propagate options used for target software building to GCC target libs
111HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CFLAGS)"
112HOST_GCC_COMMON_CONF_ENV += CXXFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CXXFLAGS)"
113HOST_GCC_COMMON_CONF_ENV += AR_FOR_TARGET=gcc-ar NM_FOR_TARGET=gcc-nm RANLIB_FOR_TARGET=gcc-ranlib
114
115# libitm needs sparc V9+
116ifeq ($(BR2_sparc_v8)$(BR2_sparc_leon3),y)
117HOST_GCC_COMMON_CONF_OPTS += --disable-libitm
118endif
119
120# libmpx uses secure_getenv and struct _libc_fpstate not present in musl
121ifeq ($(BR2_TOOLCHAIN_BUILDROOT_MUSL)$(BR2_TOOLCHAIN_GCC_AT_LEAST_6),yy)
122HOST_GCC_COMMON_CONF_OPTS += --disable-libmpx
123endif
124
125# quadmath support requires wchar
126ifeq ($(BR2_USE_WCHAR)$(BR2_TOOLCHAIN_HAS_LIBQUADMATH),yy)
127HOST_GCC_COMMON_CONF_OPTS += --enable-libquadmath --enable-libquadmath-support
128else
129HOST_GCC_COMMON_CONF_OPTS += --disable-libquadmath --disable-libquadmath-support
130endif
131
132# libsanitizer requires wordexp, not in default uClibc config. Also
133# doesn't build properly with musl.
134ifeq ($(BR2_TOOLCHAIN_BUILDROOT_UCLIBC)$(BR2_TOOLCHAIN_BUILDROOT_MUSL),y)
135HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
136endif
137
138# libsanitizer is broken for SPARC
139# https://bugs.busybox.net/show_bug.cgi?id=7951
140ifeq ($(BR2_sparc)$(BR2_sparc64),y)
141HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
142endif
143
144# libsanitizer is available for mips64{el} since gcc 12 but fail to build
145# with n32 ABI due to struct stat64 definition clash due to mixing
146# kernel and user headers.
147ifeq ($(BR2_mips64)$(BR2_mips64el):$(BR2_MIPS_NABI32),y:y)
148HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
149endif
150
151# libsanitizer bundled in gcc 12 fails to build for mips32 due to
152# mixing kernel and user struct stat.
153ifeq ($(BR2_mips)$(BR2_mipsel):$(BR2_TOOLCHAIN_GCC_AT_LEAST_12),y:y)
154HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
155endif
156
157# The logic in libbacktrace/configure.ac to detect if __sync builtins
158# are available assumes they are as soon as target_subdir is not
159# empty, i.e when cross-compiling. However, some platforms do not have
160# __sync builtins, so help the configure script a bit.
161ifeq ($(BR2_TOOLCHAIN_HAS_SYNC_4),)
162HOST_GCC_COMMON_CONF_ENV += target_configargs="libbacktrace_cv_sys_sync=no"
163endif
164
165# TLS support is not needed on uClibc/no-thread and
166# uClibc/linux-threads, otherwise, for all other situations (glibc,
167# musl and uClibc/NPTL), we need it.
168ifeq ($(BR2_TOOLCHAIN_BUILDROOT_UCLIBC)$(BR2_PTHREADS)$(BR2_PTHREADS_NONE),yy)
169HOST_GCC_COMMON_CONF_OPTS += --disable-tls
170else
171HOST_GCC_COMMON_CONF_OPTS += --enable-tls
172endif
173
174ifeq ($(BR2_PTHREADS_NONE),y)
175HOST_GCC_COMMON_CONF_OPTS += \
176	--disable-threads \
177	--disable-libitm \
178	--disable-libatomic
179else
180HOST_GCC_COMMON_CONF_OPTS += --enable-threads
181endif
182
183# gcc 5 doesn't need cloog any more, see
184# https://gcc.gnu.org/gcc-5/changes.html and we don't support graphite
185# on GCC 4.9.x, so only isl is needed.
186ifeq ($(BR2_GCC_ENABLE_GRAPHITE),y)
187HOST_GCC_COMMON_DEPENDENCIES += host-isl
188HOST_GCC_COMMON_CONF_OPTS += --with-isl=$(HOST_DIR)
189else
190HOST_GCC_COMMON_CONF_OPTS += --without-isl --without-cloog
191endif
192
193ifeq ($(BR2_arc),y)
194HOST_GCC_COMMON_DEPENDENCIES += host-flex host-bison
195endif
196
197ifeq ($(BR2_SOFT_FLOAT),y)
198# only mips*-*-*, arm*-*-* and sparc*-*-* accept --with-float
199# powerpc seems to be needing it as well
200ifeq ($(BR2_arm)$(BR2_armeb)$(BR2_mips)$(BR2_mipsel)$(BR2_mips64)$(BR2_mips64el)$(BR2_powerpc)$(BR2_sparc),y)
201HOST_GCC_COMMON_CONF_OPTS += --with-float=soft
202endif
203endif
204
205# Determine arch/tune/abi/cpu options
206ifneq ($(GCC_TARGET_ARCH),)
207HOST_GCC_COMMON_CONF_OPTS += --with-arch="$(GCC_TARGET_ARCH)"
208endif
209ifneq ($(GCC_TARGET_ABI),)
210HOST_GCC_COMMON_CONF_OPTS += --with-abi="$(GCC_TARGET_ABI)"
211endif
212ifeq ($(BR2_TOOLCHAIN_HAS_MNAN_OPTION),y)
213ifneq ($(GCC_TARGET_NAN),)
214HOST_GCC_COMMON_CONF_OPTS += --with-nan="$(GCC_TARGET_NAN)"
215endif
216endif
217ifneq ($(GCC_TARGET_FP32_MODE),)
218HOST_GCC_COMMON_CONF_OPTS += --with-fp-32="$(GCC_TARGET_FP32_MODE)"
219endif
220ifneq ($(GCC_TARGET_CPU),)
221HOST_GCC_COMMON_CONF_OPTS += --with-cpu=$(GCC_TARGET_CPU)
222endif
223
224ifneq ($(GCC_TARGET_FPU),)
225HOST_GCC_COMMON_CONF_OPTS += --with-fpu=$(GCC_TARGET_FPU)
226endif
227
228ifneq ($(GCC_TARGET_FLOAT_ABI),)
229HOST_GCC_COMMON_CONF_OPTS += --with-float=$(GCC_TARGET_FLOAT_ABI)
230endif
231
232ifneq ($(GCC_TARGET_MODE),)
233HOST_GCC_COMMON_CONF_OPTS += --with-mode=$(GCC_TARGET_MODE)
234endif
235
236# Enable proper double/long double for SPE ABI
237ifeq ($(BR2_powerpc_SPE),y)
238HOST_GCC_COMMON_CONF_OPTS += \
239	--enable-obsolete \
240	--enable-e500_double \
241	--with-long-double-128
242endif
243
244# Set default to Secure-PLT to prevent run-time
245# generation of PLT stubs (supports RELRO and
246# SELinux non-exemem capabilities)
247ifeq ($(BR2_powerpc)$(BR2_powerpc64),y)
248HOST_GCC_COMMON_CONF_OPTS += --enable-secureplt
249endif
250
251# PowerPC64 big endian by default uses the elfv1 ABI, and PowerPC 64
252# little endian by default uses the elfv2 ABI. However, musl has
253# decided to use the elfv2 ABI for both, so we force the elfv2 ABI for
254# Power64 big endian when the selected C library is musl.
255ifeq ($(BR2_TOOLCHAIN_USES_MUSL)$(BR2_powerpc64),yy)
256HOST_GCC_COMMON_CONF_OPTS += \
257	--with-abi=elfv2 \
258	--without-long-double-128
259endif
260
261# Since glibc >= 2.26, poerpc64le requires double/long double which
262# requires at least gcc 6.2.
263# See sysdeps/powerpc/powerpc64le/configure.ac
264ifeq ($(BR2_TOOLCHAIN_USES_GLIBC)$(BR2_TOOLCHAIN_GCC_AT_LEAST_6)$(BR2_powerpc64le),yyy)
265HOST_GCC_COMMON_CONF_OPTS += \
266	--with-long-double-128
267endif
268
269ifeq ($(BR2_s390x),y)
270HOST_GCC_COMMON_CONF_OPTS += \
271	--with-long-double-128
272endif
273
274HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CROSS_PATH_SUFFIX='".br_real"'
275
276# For gcc-initial, we need to tell gcc that the C library will be
277# providing the ssp support, as it can't guess it since the C library
278# hasn't been built yet.
279#
280# For gcc-final, the gcc logic to detect whether SSP support is
281# available or not in the C library is not working properly for
282# uClibc, so let's be explicit as well.
283HOST_GCC_COMMON_MAKE_OPTS = \
284	gcc_cv_libc_provides_ssp=$(if $(BR2_TOOLCHAIN_HAS_SSP),yes,no)
285
286ifeq ($(BR2_CCACHE),y)
287HOST_GCC_COMMON_CCACHE_HASH_FILES += $($(PKG)_DL_DIR)/$(GCC_SOURCE)
288
289# Cfr. PATCH_BASE_DIRS in .stamp_patched, but we catch both versioned
290# and unversioned patches unconditionally. Moreover, to facilitate the
291# addition of gcc patches in BR2_GLOBAL_PATCH_DIR, we allow them to be
292# stored in a sub-directory called 'gcc' even if it's not technically
293# the name of the package.
294HOST_GCC_COMMON_CCACHE_HASH_FILES += \
295	$(sort $(wildcard \
296		package/gcc/$(GCC_VERSION)/*.patch \
297		$(addsuffix /$($(PKG)_RAWNAME)/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
298		$(addsuffix /$($(PKG)_RAWNAME)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
299		$(addsuffix /gcc/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
300		$(addsuffix /gcc/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))))
301ifeq ($(BR2_xtensa),y)
302HOST_GCC_COMMON_CCACHE_HASH_FILES += $(ARCH_XTENSA_OVERLAY_FILE)
303endif
304
305# _CONF_OPTS contains some references to the absolute path of $(HOST_DIR)
306# and a reference to the Buildroot git revision (BR2_VERSION_FULL),
307# so substitute those away.
308HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE_HASH=\"`\
309	printf '%s\n' $(subst $(HOST_DIR),@HOST_DIR@,\
310		$(subst --with-pkgversion="Buildroot $(BR2_VERSION_FULL)",,$($(PKG)_CONF_OPTS))) \
311		| sha256sum - $(HOST_GCC_COMMON_CCACHE_HASH_FILES) \
312		| cut -c -64 | tr -d '\n'`\"
313endif # BR2_CCACHE
314
315# The LTO support in gcc creates wrappers for ar, ranlib and nm which load
316# the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
317# *-gcc-nm and should be used instead of the real programs when -flto is
318# used. However, we should not add the toolchain wrapper for them, and they
319# match the *cc-* pattern. Therefore, an additional case is added for *-ar,
320# *-ranlib and *-nm.
321# According to gfortran manpage, it supports all options supported by gcc, so
322# add gfortran to the list of the program called via the Buildroot wrapper.
323# Avoid that a .br_real is symlinked a second time.
324# Also create <arch>-linux-<tool> symlinks.
325define HOST_GCC_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
326	$(Q)cd $(HOST_DIR)/bin; \
327	for i in $(GNU_TARGET_NAME)-*; do \
328		case "$$i" in \
329		*.br_real) \
330			;; \
331		*-ar|*-ranlib|*-nm) \
332			ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
333			;; \
334		*cc|*cc-*|*++|*++-*|*cpp|*-gfortran|*-gdc) \
335			rm -f $$i.br_real; \
336			mv $$i $$i.br_real; \
337			ln -sf toolchain-wrapper $$i; \
338			ln -sf toolchain-wrapper $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
339			ln -snf $$i.br_real $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}.br_real; \
340			;; \
341		*) \
342			ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
343			;; \
344		esac; \
345	done
346
347endef
348
349include $(sort $(wildcard package/gcc/*/*.mk))
350