gcc: apply patches stored in global patches directories
[buildroot-gz.git] / package / gcc / gcc.mk
blobb6a3ac9ad1cf409b6400edb425056b492a5d933f
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_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
17 GCC_SITE = $(BR2_GNU_MIRROR:/=)/gcc/gcc-$(GCC_VERSION)
18 endif
20 GCC_SOURCE ?= gcc-$(GCC_VERSION).tar.bz2
23 # Xtensa special hook
26 HOST_GCC_XTENSA_OVERLAY_TAR = $(BR2_XTENSA_OVERLAY_DIR)/xtensa_$(call qstrip,$(BR2_XTENSA_CORE_NAME)).tar
28 define HOST_GCC_XTENSA_OVERLAY_EXTRACT
29 tar xf $(HOST_GCC_XTENSA_OVERLAY_TAR) -C $(@D) --strip-components=1 gcc
30 endef
33 # Apply patches
36 ifeq ($(ARCH),powerpc)
37 ifneq ($(BR2_SOFT_FLOAT),)
38 define HOST_GCC_APPLY_POWERPC_PATCH
39 $(APPLY_PATCHES) $(@D) package/gcc/$(GCC_VERSION) 1000-powerpc-link-with-math-lib.patch.conditional
40 endef
41 endif
42 endif
44 # gcc is a special package, not named gcc, but gcc-initial and
45 # gcc-final, but patches are nonetheless stored in package/gcc in the
46 # tree, and potentially in BR2_GLOBAL_PATCH_DIR directories as well.
47 define HOST_GCC_APPLY_PATCHES
48 for patchdir in \
49 package/gcc/$(GCC_VERSION) \
50 $(addsuffix /gcc/$(GCC_VERSION),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
51 $(addsuffix /gcc,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) ; do \
52 if test -d $${patchdir}; then \
53 $(APPLY_PATCHES) $(@D) $${patchdir} \*.patch || exit 1; \
54 fi; \
55 done
56 $(HOST_GCC_APPLY_POWERPC_PATCH)
57 endef
59 HOST_GCC_EXCLUDES = \
60 libjava/* libgo/* \
61 gcc/testsuite/* libstdc++-v3/testsuite/*
63 define HOST_GCC_FAKE_TESTSUITE
64 mkdir -p $(@D)/libstdc++-v3/testsuite/
65 echo "all:" > $(@D)/libstdc++-v3/testsuite/Makefile.in
66 echo "install:" >> $(@D)/libstdc++-v3/testsuite/Makefile.in
67 endef
70 # Create 'build' directory and configure symlink
73 define HOST_GCC_CONFIGURE_SYMLINK
74 mkdir -p $(@D)/build
75 ln -sf ../configure $(@D)/build/configure
76 endef
79 # Common configuration options
82 HOST_GCC_COMMON_DEPENDENCIES = \
83 host-binutils \
84 host-gmp \
85 host-mpfr \
86 $(if $(BR2_BINFMT_FLAT),host-elf2flt)
88 HOST_GCC_COMMON_CONF_OPTS = \
89 --target=$(GNU_TARGET_NAME) \
90 --with-sysroot=$(STAGING_DIR) \
91 --disable-__cxa_atexit \
92 --with-gnu-ld \
93 --disable-libssp \
94 --disable-multilib \
95 --with-gmp=$(HOST_DIR)/usr \
96 --with-mpfr=$(HOST_DIR)/usr \
97 --with-pkgversion="Buildroot $(BR2_VERSION_FULL)" \
98 --with-bugurl="http://bugs.buildroot.net/"
100 # Don't build documentation. It takes up extra space / build time,
101 # and sometimes needs specific makeinfo versions to work
102 HOST_GCC_COMMON_CONF_ENV = \
103 MAKEINFO=missing
105 GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS)
106 GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS)
108 # Propagate options used for target software building to GCC target libs
109 HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CFLAGS)"
110 HOST_GCC_COMMON_CONF_ENV += CXXFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CXXFLAGS)"
112 # libitm needs sparc V9+
113 ifeq ($(BR2_sparc_v8)$(BR2_sparc_leon3),y)
114 HOST_GCC_COMMON_CONF_OPTS += --disable-libitm
115 endif
117 # quadmath support requires wchar
118 ifeq ($(BR2_USE_WCHAR),)
119 HOST_GCC_COMMON_CONF_OPTS += --disable-libquadmath
120 endif
122 # libsanitizer requires wordexp, not in default uClibc config. Also
123 # doesn't build properly with musl.
124 ifeq ($(BR2_TOOLCHAIN_BUILDROOT_UCLIBC)$(BR2_TOOLCHAIN_BUILDROOT_MUSL),y)
125 HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
126 endif
128 # libsanitizer is broken for SPARC
129 # https://bugs.busybox.net/show_bug.cgi?id=7951
130 ifeq ($(BR2_sparc)$(BR2_sparc64),y)
131 HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
132 endif
134 ifeq ($(BR2_GCC_ENABLE_TLS),y)
135 HOST_GCC_COMMON_CONF_OPTS += --enable-tls
136 else
137 HOST_GCC_COMMON_CONF_OPTS += --disable-tls
138 endif
140 ifeq ($(BR2_GCC_ENABLE_LTO),y)
141 HOST_GCC_COMMON_CONF_OPTS += --enable-plugins --enable-lto
142 endif
144 ifeq ($(BR2_GCC_ENABLE_LIBMUDFLAP),y)
145 HOST_GCC_COMMON_CONF_OPTS += --enable-libmudflap
146 else
147 HOST_GCC_COMMON_CONF_OPTS += --disable-libmudflap
148 endif
150 ifeq ($(BR2_PTHREADS_NONE),y)
151 HOST_GCC_COMMON_CONF_OPTS += \
152 --disable-threads \
153 --disable-libitm \
154 --disable-libatomic
155 else
156 HOST_GCC_COMMON_CONF_OPTS += --enable-threads
157 endif
159 ifeq ($(BR2_GCC_NEEDS_MPC),y)
160 HOST_GCC_COMMON_DEPENDENCIES += host-mpc
161 HOST_GCC_COMMON_CONF_OPTS += --with-mpc=$(HOST_DIR)/usr
162 endif
164 ifeq ($(BR2_GCC_ENABLE_GRAPHITE),y)
165 HOST_GCC_COMMON_DEPENDENCIES += host-isl
166 HOST_GCC_COMMON_CONF_OPTS += --with-isl=$(HOST_DIR)/usr
167 # gcc 5 doesn't need cloog any more, see
168 # https://gcc.gnu.org/gcc-5/changes.html
169 ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_5),)
170 HOST_GCC_COMMON_DEPENDENCIES += host-cloog
171 HOST_GCC_COMMON_CONF_OPTS += --with-cloog=$(HOST_DIR)/usr
172 endif
173 else
174 HOST_GCC_COMMON_CONF_OPTS += --without-isl --without-cloog
175 endif
177 ifeq ($(BR2_arc),y)
178 HOST_GCC_COMMON_DEPENDENCIES += host-flex host-bison
179 endif
181 ifeq ($(BR2_SOFT_FLOAT),y)
182 # only mips*-*-*, arm*-*-* and sparc*-*-* accept --with-float
183 # powerpc seems to be needing it as well
184 ifeq ($(BR2_arm)$(BR2_armeb)$(BR2_mips)$(BR2_mipsel)$(BR2_mips64)$(BR2_mips64el)$(BR2_powerpc)$(BR2_sparc),y)
185 HOST_GCC_COMMON_CONF_OPTS += --with-float=soft
186 endif
187 endif
189 ifeq ($(BR2_GCC_SUPPORTS_FINEGRAINEDMTUNE),y)
190 HOST_GCC_COMMON_CONF_OPTS += --disable-decimal-float
191 endif
193 # Determine arch/tune/abi/cpu options
194 ifneq ($(call qstrip,$(BR2_GCC_TARGET_ARCH)),)
195 HOST_GCC_COMMON_CONF_OPTS += --with-arch=$(BR2_GCC_TARGET_ARCH)
196 endif
197 ifneq ($(call qstrip,$(BR2_GCC_TARGET_ABI)),)
198 HOST_GCC_COMMON_CONF_OPTS += --with-abi=$(BR2_GCC_TARGET_ABI)
199 endif
200 ifneq ($(call qstrip,$(BR2_GCC_TARGET_CPU)),)
201 ifneq ($(call qstrip,$(BR2_GCC_TARGET_CPU_REVISION)),)
202 HOST_GCC_COMMON_CONF_OPTS += --with-cpu=$(call qstrip,$(BR2_GCC_TARGET_CPU)-$(BR2_GCC_TARGET_CPU_REVISION))
203 else
204 HOST_GCC_COMMON_CONF_OPTS += --with-cpu=$(call qstrip,$(BR2_GCC_TARGET_CPU))
205 endif
206 endif
208 GCC_TARGET_FPU = $(call qstrip,$(BR2_GCC_TARGET_FPU))
209 ifneq ($(GCC_TARGET_FPU),)
210 HOST_GCC_COMMON_CONF_OPTS += --with-fpu=$(GCC_TARGET_FPU)
211 endif
213 GCC_TARGET_FLOAT_ABI = $(call qstrip,$(BR2_GCC_TARGET_FLOAT_ABI))
214 ifneq ($(GCC_TARGET_FLOAT_ABI),)
215 HOST_GCC_COMMON_CONF_OPTS += --with-float=$(GCC_TARGET_FLOAT_ABI)
216 endif
218 GCC_TARGET_MODE = $(call qstrip,$(BR2_GCC_TARGET_MODE))
219 ifneq ($(GCC_TARGET_MODE),)
220 HOST_GCC_COMMON_CONF_OPTS += --with-mode=$(GCC_TARGET_MODE)
221 endif
223 # Enable proper double/long double for SPE ABI
224 ifeq ($(BR2_powerpc_SPE),y)
225 HOST_GCC_COMMON_CONF_OPTS += \
226 --enable-e500_double \
227 --with-long-double-128
228 endif
230 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CROSS_PATH_SUFFIX='".br_real"'
232 # For gcc-initial, we need to tell gcc that the C library will be
233 # providing the ssp support, as it can't guess it since the C library
234 # hasn't been built yet.
236 # For gcc-final, the gcc logic to detect whether SSP support is
237 # available or not in the C library is not working properly for
238 # uClibc, so let's be explicit as well.
239 HOST_GCC_COMMON_MAKE_OPTS = \
240 gcc_cv_libc_provides_ssp=$(if $(BR2_TOOLCHAIN_HAS_SSP),yes,no)
242 ifeq ($(BR2_CCACHE),y)
243 HOST_GCC_COMMON_CCACHE_HASH_FILES += $(DL_DIR)/$(GCC_SOURCE)
245 # Cfr. PATCH_BASE_DIRS in .stamp_patched, but we catch both versioned
246 # and unversioned patches unconditionally. Moreover, to facilitate the
247 # addition of gcc patches in BR2_GLOBAL_PATCH_DIR, we allow them to be
248 # stored in a sub-directory called 'gcc' even if it's not technically
249 # the name of the package.
250 HOST_GCC_COMMON_CCACHE_HASH_FILES += \
251 $(sort $(wildcard \
252 package/gcc/$(GCC_VERSION)/*.patch \
253 $(addsuffix /$((PKG)_RAWNAME)/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
254 $(addsuffix /$((PKG)_RAWNAME)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
255 $(addsuffix /gcc/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
256 $(addsuffix /gcc/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))))
257 ifeq ($(BR2_xtensa),y)
258 HOST_GCC_COMMON_CCACHE_HASH_FILES += $(HOST_GCC_XTENSA_OVERLAY_TAR)
259 endif
260 ifeq ($(ARCH),powerpc)
261 ifneq ($(BR2_SOFT_FLOAT),)
262 HOST_GCC_COMMON_CCACHE_HASH_FILES += package/gcc/$(GCC_VERSION)/1000-powerpc-link-with-math-lib.patch.conditional
263 endif
264 endif
266 # _CONF_OPTS contains some references to the absolute path of $(HOST_DIR)
267 # and a reference to the Buildroot git revision (BR2_VERSION_FULL),
268 # so substitute those away.
269 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE_HASH=\"`\
270 printf '%s\n' $(subst $(HOST_DIR),@HOST_DIR@,\
271 $(subst --with-pkgversion="Buildroot $(BR2_VERSION_FULL)",,$($(PKG)_CONF_OPTS))) \
272 | sha256sum - $(HOST_GCC_COMMON_CCACHE_HASH_FILES) \
273 | cut -c -64 | tr -d '\n'`\"
274 endif # BR2_CCACHE
276 # The LTO support in gcc creates wrappers for ar, ranlib and nm which load
277 # the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
278 # *-gcc-nm and should be used instead of the real programs when -flto is
279 # used. However, we should not add the toolchain wrapper for them, and they
280 # match the *cc-* pattern. Therefore, an additional case is added for *-ar,
281 # *-ranlib and *-nm.
282 # According to gfortran manpage, it supports all options supported by gcc, so
283 # add gfortran to the list of the program called via the Buildroot wrapper.
284 # Avoid that a .br_real is symlinked a second time.
285 # Also create <arch>-linux-<tool> symlinks.
286 define HOST_GCC_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
287 $(Q)cd $(HOST_DIR)/usr/bin; \
288 for i in $(GNU_TARGET_NAME)-*; do \
289 case "$$i" in \
290 *.br_real) \
291 ;; \
292 *-ar|*-ranlib|*-nm) \
293 ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
294 ;; \
295 *cc|*cc-*|*++|*++-*|*cpp|*-gfortran) \
296 rm -f $$i.br_real; \
297 mv $$i $$i.br_real; \
298 ln -sf toolchain-wrapper $$i; \
299 ln -sf toolchain-wrapper $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
300 ln -snf $$i.br_real $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}.br_real; \
301 ;; \
302 *) \
303 ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
304 ;; \
305 esac; \
306 done
308 endef
310 include $(sort $(wildcard package/gcc/*/*.mk))