1 ################################################################################
3 # Common variables for the gcc-initial and gcc-final packages.
5 ################################################################################
8 # Version, site and source
11 GCC_VERSION = $(call qstrip,$(BR2_GCC_VERSION))
13 ifeq ($(BR2_GCC_VERSION_ARC),y)
14 GCC_SITE = $(call github,foss-for-synopsys-dwc-arc-processors,gcc,$(GCC_VERSION))
15 GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz
16 else ifeq ($(BR2_or1k),y)
17 GCC_SITE = $(call github,openrisc,or1k-gcc,$(GCC_VERSION))
18 GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz
20 GCC_SITE = $(BR2_GNU_MIRROR:/=)/gcc/gcc-$(GCC_VERSION)
21 # From version 5.5.0, 6.4.0 and 7.2.0 a bz2 release tarball is not
22 # provided anymore. Use the xz tarball instead.
23 ifeq ($(BR2_GCC_VERSION_5_X)$(BR2_GCC_VERSION_6_X)$(BR2_GCC_VERSION_7_X),y)
24 GCC_SOURCE = gcc-$(GCC_VERSION).tar.xz
26 GCC_SOURCE = gcc-$(GCC_VERSION).tar.bz2
27 endif # BR2_GCC_VERSION_6_X
33 define HOST_GCC_XTENSA_OVERLAY_EXTRACT
34 $(call arch-xtensa-overlay-extract,$(@D),gcc)
41 ifeq ($(ARCH),powerpc)
42 ifneq ($(BR2_SOFT_FLOAT),)
43 define HOST_GCC_APPLY_POWERPC_PATCH
44 $(APPLY_PATCHES) $(@D) package/gcc/$(GCC_VERSION) 1000-powerpc-link-with-math-lib.patch.conditional
49 # gcc is a special package, not named gcc, but gcc-initial and
50 # gcc-final, but patches are nonetheless stored in package/gcc in the
51 # tree, and potentially in BR2_GLOBAL_PATCH_DIR directories as well.
52 define HOST_GCC_APPLY_PATCHES
54 package/gcc/$(GCC_VERSION) \
55 $(addsuffix /gcc/$(GCC_VERSION),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
56 $(addsuffix /gcc,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) ; do \
57 if test -d $${patchdir}; then \
58 $(APPLY_PATCHES) $(@D) $${patchdir} \*.patch || exit 1; \
61 $(HOST_GCC_APPLY_POWERPC_PATCH)
66 gcc/testsuite/* libstdc++-v3/testsuite/*
68 define HOST_GCC_FAKE_TESTSUITE
69 mkdir -p $(@D)/libstdc++-v3/testsuite/
70 echo "all:" > $(@D)/libstdc++-v3/testsuite/Makefile.in
71 echo "install:" >> $(@D)/libstdc++-v3/testsuite/Makefile.in
75 # Create 'build' directory and configure symlink
78 define HOST_GCC_CONFIGURE_SYMLINK
80 ln -sf ../configure $(@D)/build/configure
84 # Common configuration options
87 HOST_GCC_COMMON_DEPENDENCIES = \
92 $(if $(BR2_BINFMT_FLAT),host-elf2flt)
94 HOST_GCC_COMMON_CONF_OPTS = \
95 --target=$(GNU_TARGET_NAME) \
96 --with-sysroot=$(STAGING_DIR) \
97 --disable-__cxa_atexit \
101 --with-gmp=$(HOST_DIR) \
102 --with-mpc=$(HOST_DIR) \
103 --with-mpfr=$(HOST_DIR) \
104 --with-pkgversion="Buildroot $(BR2_VERSION_FULL)" \
105 --with-bugurl="http://bugs.buildroot.net/"
107 # Don't build documentation. It takes up extra space / build time,
108 # and sometimes needs specific makeinfo versions to work
109 HOST_GCC_COMMON_CONF_ENV = \
112 GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS)
113 GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS)
115 # Propagate options used for target software building to GCC target libs
116 HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CFLAGS)"
117 HOST_GCC_COMMON_CONF_ENV += CXXFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CXXFLAGS)"
119 # libitm needs sparc V9+
120 ifeq ($(BR2_sparc_v8)$(BR2_sparc_leon3),y)
121 HOST_GCC_COMMON_CONF_OPTS += --disable-libitm
124 # libmpx uses secure_getenv and struct _libc_fpstate not present in musl
125 ifeq ($(BR2_TOOLCHAIN_BUILDROOT_MUSL)$(BR2_TOOLCHAIN_GCC_AT_LEAST_6),yy)
126 HOST_GCC_COMMON_CONF_OPTS += --disable-libmpx
129 # quadmath support requires wchar
130 ifeq ($(BR2_USE_WCHAR)$(BR2_TOOLCHAIN_HAS_LIBQUADMATH),yy)
131 HOST_GCC_COMMON_CONF_OPTS += --enable-libquadmath
133 HOST_GCC_COMMON_CONF_OPTS += --disable-libquadmath
136 # libsanitizer requires wordexp, not in default uClibc config. Also
137 # doesn't build properly with musl.
138 ifeq ($(BR2_TOOLCHAIN_BUILDROOT_UCLIBC)$(BR2_TOOLCHAIN_BUILDROOT_MUSL),y)
139 HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
142 # libsanitizer is broken for SPARC
143 # https://bugs.busybox.net/show_bug.cgi?id=7951
144 ifeq ($(BR2_sparc)$(BR2_sparc64),y)
145 HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
148 # TLS support is not needed on uClibc/no-thread and
149 # uClibc/linux-threads, otherwise, for all other situations (glibc,
150 # musl and uClibc/NPTL), we need it.
151 ifeq ($(BR2_TOOLCHAIN_BUILDROOT_UCLIBC)$(BR2_PTHREADS)$(BR2_PTHREADS_NONE),yy)
152 HOST_GCC_COMMON_CONF_OPTS += --disable-tls
154 HOST_GCC_COMMON_CONF_OPTS += --enable-tls
157 ifeq ($(BR2_GCC_ENABLE_LTO),y)
158 HOST_GCC_COMMON_CONF_OPTS += --enable-plugins --enable-lto
161 ifeq ($(BR2_GCC_ENABLE_LIBMUDFLAP),y)
162 HOST_GCC_COMMON_CONF_OPTS += --enable-libmudflap
164 HOST_GCC_COMMON_CONF_OPTS += --disable-libmudflap
167 ifeq ($(BR2_PTHREADS_NONE),y)
168 HOST_GCC_COMMON_CONF_OPTS += \
173 HOST_GCC_COMMON_CONF_OPTS += --enable-threads
176 # gcc 5 doesn't need cloog any more, see
177 # https://gcc.gnu.org/gcc-5/changes.html and we don't support graphite
178 # on GCC 4.9.x, so only isl is needed.
179 ifeq ($(BR2_GCC_ENABLE_GRAPHITE),y)
180 HOST_GCC_COMMON_DEPENDENCIES += host-isl
181 HOST_GCC_COMMON_CONF_OPTS += --with-isl=$(HOST_DIR)
183 HOST_GCC_COMMON_CONF_OPTS += --without-isl --without-cloog
186 ifeq ($(BR2_arc)$(BR2_or1k),y)
187 HOST_GCC_COMMON_DEPENDENCIES += host-flex host-bison
190 ifeq ($(BR2_SOFT_FLOAT),y)
191 # only mips*-*-*, arm*-*-* and sparc*-*-* accept --with-float
192 # powerpc seems to be needing it as well
193 ifeq ($(BR2_arm)$(BR2_armeb)$(BR2_mips)$(BR2_mipsel)$(BR2_mips64)$(BR2_mips64el)$(BR2_powerpc)$(BR2_sparc),y)
194 HOST_GCC_COMMON_CONF_OPTS += --with-float=soft
198 ifeq ($(BR2_GCC_SUPPORTS_FINEGRAINEDMTUNE),y)
199 HOST_GCC_COMMON_CONF_OPTS += --disable-decimal-float
202 # Determine arch/tune/abi/cpu options
203 ifeq ($(BR2_GCC_ARCH_HAS_CONFIGURABLE_DEFAULTS),y)
204 ifneq ($(call qstrip,$(BR2_GCC_TARGET_ARCH)),)
205 HOST_GCC_COMMON_CONF_OPTS += --with-arch=$(BR2_GCC_TARGET_ARCH)
207 ifneq ($(call qstrip,$(BR2_GCC_TARGET_ABI)),)
208 HOST_GCC_COMMON_CONF_OPTS += --with-abi=$(BR2_GCC_TARGET_ABI)
210 ifeq ($(BR2_TOOLCHAIN_HAS_MNAN_OPTION),y)
211 ifneq ($(call qstrip,$(BR2_GCC_TARGET_NAN)),)
212 HOST_GCC_COMMON_CONF_OPTS += --with-nan=$(BR2_GCC_TARGET_NAN)
215 ifneq ($(call qstrip,$(BR2_GCC_TARGET_FP32_MODE)),)
216 HOST_GCC_COMMON_CONF_OPTS += --with-fp-32=$(BR2_GCC_TARGET_FP32_MODE)
218 ifneq ($(call qstrip,$(BR2_GCC_TARGET_CPU)),)
219 ifneq ($(call qstrip,$(BR2_GCC_TARGET_CPU_REVISION)),)
220 HOST_GCC_COMMON_CONF_OPTS += --with-cpu=$(call qstrip,$(BR2_GCC_TARGET_CPU)-$(BR2_GCC_TARGET_CPU_REVISION))
222 HOST_GCC_COMMON_CONF_OPTS += --with-cpu=$(call qstrip,$(BR2_GCC_TARGET_CPU))
226 GCC_TARGET_FPU = $(call qstrip,$(BR2_GCC_TARGET_FPU))
227 ifneq ($(GCC_TARGET_FPU),)
228 HOST_GCC_COMMON_CONF_OPTS += --with-fpu=$(GCC_TARGET_FPU)
231 GCC_TARGET_FLOAT_ABI = $(call qstrip,$(BR2_GCC_TARGET_FLOAT_ABI))
232 ifneq ($(GCC_TARGET_FLOAT_ABI),)
233 HOST_GCC_COMMON_CONF_OPTS += --with-float=$(GCC_TARGET_FLOAT_ABI)
236 GCC_TARGET_MODE = $(call qstrip,$(BR2_GCC_TARGET_MODE))
237 ifneq ($(GCC_TARGET_MODE),)
238 HOST_GCC_COMMON_CONF_OPTS += --with-mode=$(GCC_TARGET_MODE)
240 endif # BR2_GCC_ARCH_HAS_CONFIGURABLE_DEFAULTS
242 # Enable proper double/long double for SPE ABI
243 ifeq ($(BR2_powerpc_SPE),y)
244 HOST_GCC_COMMON_CONF_OPTS += \
245 --enable-e500_double \
246 --with-long-double-128
249 # PowerPC64 big endian by default uses the elfv1 ABI, and PowerPC 64
250 # little endian by default uses the elfv2 ABI. However, musl has
251 # decided to use the elfv2 ABI for both, so we force the elfv2 ABI for
252 # Power64 big endian when the selected C library is musl.
253 ifeq ($(BR2_TOOLCHAIN_USES_MUSL)$(BR2_powerpc64),yy)
254 HOST_GCC_COMMON_CONF_OPTS += \
256 --without-long-double-128
259 # Since glibc >= 2.26, poerpc64le requires double/long double which
260 # requires at least gcc 6.2.
261 # See sysdeps/powerpc/powerpc64le/configure.ac
262 ifeq ($(BR2_TOOLCHAIN_USES_GLIBC)$(BR2_TOOLCHAIN_GCC_AT_LEAST_6)$(BR2_powerpc64le),yyy)
263 HOST_GCC_COMMON_CONF_OPTS += \
264 --with-long-double-128
267 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CROSS_PATH_SUFFIX='".br_real"'
268 ifeq ($(BR2_GCC_ARCH_HAS_CONFIGURABLE_DEFAULTS),)
269 ifeq ($(call qstrip,$(BR2_GCC_TARGET_CPU_REVISION)),)
270 HOST_GCC_COMMON_WRAPPER_TARGET_CPU := $(call qstrip,$(BR2_GCC_TARGET_CPU))
272 HOST_GCC_COMMON_WRAPPER_TARGET_CPU := $(call qstrip,$(BR2_GCC_TARGET_CPU)-$(BR2_GCC_TARGET_CPU_REVISION))
274 HOST_GCC_COMMON_WRAPPER_TARGET_ARCH := $(call qstrip,$(BR2_GCC_TARGET_ARCH))
275 HOST_GCC_COMMON_WRAPPER_TARGET_ABI := $(call qstrip,$(BR2_GCC_TARGET_ABI))
276 HOST_GCC_COMMON_WRAPPER_TARGET_NAN := $(call qstrip,$(BR2_GCC_TARGET_NAN))
277 HOST_GCC_COMMON_WRAPPER_TARGET_FP32_MODE := $(call qstrip,$(BR2_GCC_TARGET_FP32_MODE))
278 HOST_GCC_COMMON_WRAPPER_TARGET_FPU := $(call qstrip,$(BR2_GCC_TARGET_FPU))
279 HOST_GCC_COMMON_WRAPPER_TARGET_FLOAT_ABI := $(call qstrip,$(BR2_GCC_TARGET_FLOAT_ABI))
280 HOST_GCC_COMMON_WRAPPER_TARGET_MODE := $(call qstrip,$(BR2_GCC_TARGET_MODE))
282 ifneq ($(HOST_GCC_COMMON_WRAPPER_TARGET_ARCH),)
283 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_ARCH='"$(HOST_GCC_COMMON_WRAPPER_TARGET_ARCH)"'
285 ifneq ($(HOST_GCC_COMMON_WRAPPER_TARGET_CPU),)
286 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CPU='"$(HOST_GCC_COMMON_WRAPPER_TARGET_CPU)"'
288 ifneq ($(HOST_GCC_COMMON_WRAPPER_TARGET_ABI),)
289 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_ABI='"$(HOST_GCC_COMMON_WRAPPER_TARGET_ABI)"'
291 ifneq ($(HOST_GCC_COMMON_WRAPPER_TARGET_NAN),)
292 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_NAN='"$(HOST_GCC_COMMON_WRAPPER_TARGET_NAN)"'
294 ifneq ($(HOST_GCC_COMMON_WRAPPER_TARGET_FP32_MODE),)
295 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_FP32_MODE='"$(HOST_GCC_COMMON_WRAPPER_TARGET_FP32_MODE)"'
297 ifneq ($(HOST_GCC_COMMON_WRAPPER_TARGET_FPU),)
298 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_FPU='"$(HOST_GCC_COMMON_WRAPPER_TARGET_FPU)"'
300 ifneq ($(HOST_GCC_COMMON_WRAPPER_TARGET_FLOAT_ABI),)
301 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_FLOAT_ABI='"$(HOST_GCC_COMMON_WRAPPER_TARGET_FLOAT_ABI)"'
303 ifneq ($(HOST_GCC_COMMON_WRAPPER_TARGET_MODE),)
304 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_MODE='"$(HOST_GCC_COMMON_WRAPPER_TARGET_MODE)"'
306 endif # !BR2_GCC_ARCH_HAS_CONFIGURABLE_DEFAULTS
308 # For gcc-initial, we need to tell gcc that the C library will be
309 # providing the ssp support, as it can't guess it since the C library
310 # hasn't been built yet.
312 # For gcc-final, the gcc logic to detect whether SSP support is
313 # available or not in the C library is not working properly for
314 # uClibc, so let's be explicit as well.
315 HOST_GCC_COMMON_MAKE_OPTS = \
316 gcc_cv_libc_provides_ssp=$(if $(BR2_TOOLCHAIN_HAS_SSP),yes,no)
318 ifeq ($(BR2_CCACHE),y)
319 HOST_GCC_COMMON_CCACHE_HASH_FILES += $(GCC_DL_DIR)/$(GCC_SOURCE)
321 # Cfr. PATCH_BASE_DIRS in .stamp_patched, but we catch both versioned
322 # and unversioned patches unconditionally. Moreover, to facilitate the
323 # addition of gcc patches in BR2_GLOBAL_PATCH_DIR, we allow them to be
324 # stored in a sub-directory called 'gcc' even if it's not technically
325 # the name of the package.
326 HOST_GCC_COMMON_CCACHE_HASH_FILES += \
328 package/gcc/$(GCC_VERSION)/*.patch \
329 $(addsuffix /$($(PKG)_RAWNAME)/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
330 $(addsuffix /$($(PKG)_RAWNAME)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
331 $(addsuffix /gcc/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
332 $(addsuffix /gcc/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))))
333 ifeq ($(BR2_xtensa),y)
334 HOST_GCC_COMMON_CCACHE_HASH_FILES += $(ARCH_XTENSA_OVERLAY_TAR)
336 ifeq ($(ARCH),powerpc)
337 ifneq ($(BR2_SOFT_FLOAT),)
338 HOST_GCC_COMMON_CCACHE_HASH_FILES += package/gcc/$(GCC_VERSION)/1000-powerpc-link-with-math-lib.patch.conditional
342 # _CONF_OPTS contains some references to the absolute path of $(HOST_DIR)
343 # and a reference to the Buildroot git revision (BR2_VERSION_FULL),
344 # so substitute those away.
345 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE_HASH=\"`\
346 printf '%s\n' $(subst $(HOST_DIR),@HOST_DIR@,\
347 $(subst --with-pkgversion="Buildroot $(BR2_VERSION_FULL)",,$($(PKG)_CONF_OPTS))) \
348 | sha256sum - $(HOST_GCC_COMMON_CCACHE_HASH_FILES) \
349 | cut -c -64 | tr -d '\n'`\"
352 # The LTO support in gcc creates wrappers for ar, ranlib and nm which load
353 # the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
354 # *-gcc-nm and should be used instead of the real programs when -flto is
355 # used. However, we should not add the toolchain wrapper for them, and they
356 # match the *cc-* pattern. Therefore, an additional case is added for *-ar,
358 # According to gfortran manpage, it supports all options supported by gcc, so
359 # add gfortran to the list of the program called via the Buildroot wrapper.
360 # Avoid that a .br_real is symlinked a second time.
361 # Also create <arch>-linux-<tool> symlinks.
362 define HOST_GCC_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
363 $(Q)cd $(HOST_DIR)/bin; \
364 for i in $(GNU_TARGET_NAME)-*; do \
368 *-ar|*-ranlib|*-nm) \
369 ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
371 *cc|*cc-*|*++|*++-*|*cpp|*-gfortran) \
373 mv $$i $$i.br_real; \
374 ln -sf toolchain-wrapper $$i; \
375 ln -sf toolchain-wrapper $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
376 ln -snf $$i.br_real $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}.br_real; \
379 ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
386 include $(sort $(wildcard package/gcc/*/*.mk))