]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - package/gcc/gcc.mk
ccache: support changing the output directory
[coffee/buildroot.git] / package / gcc / gcc.mk
1 ################################################################################
2 #
3 # Common variables for the gcc-initial and gcc-final packages.
4 #
5 ################################################################################
6
7 #
8 # Version, site and source
9 #
10
11 GCC_VERSION = $(call qstrip,$(BR2_GCC_VERSION))
12
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
19
20 GCC_SOURCE ?= gcc-$(GCC_VERSION).tar.bz2
21
22 #
23 # Xtensa special hook
24 #
25
26 HOST_GCC_XTENSA_OVERLAY_TAR = $(BR2_XTENSA_OVERLAY_DIR)/xtensa_$(call qstrip,$(BR2_XTENSA_CORE_NAME)).tar
27
28 define HOST_GCC_XTENSA_OVERLAY_EXTRACT
29         tar xf $(HOST_GCC_XTENSA_OVERLAY_TAR) -C $(@D) --strip-components=1 gcc
30 endef
31
32 #
33 # Apply patches
34 #
35
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
43
44 define HOST_GCC_APPLY_PATCHES
45         if test -d package/gcc/$(GCC_VERSION); then \
46           $(APPLY_PATCHES) $(@D) package/gcc/$(GCC_VERSION) \*.patch ; \
47         fi;
48         $(HOST_GCC_APPLY_POWERPC_PATCH)
49 endef
50
51 #
52 # Custom extract command to save disk space
53 #
54
55 define HOST_GCC_EXTRACT_CMDS
56         $(call suitable-extractor,$(GCC_SOURCE)) $(DL_DIR)/$(GCC_SOURCE) | \
57                 $(TAR) --strip-components=1 -C $(@D) \
58                 --exclude='libjava/*' \
59                 --exclude='libgo/*' \
60                 --exclude='gcc/testsuite/*' \
61                 --exclude='libstdc++-v3/testsuite/*' \
62                 $(TAR_OPTIONS) -
63         mkdir -p $(@D)/libstdc++-v3/testsuite/
64         echo "all:" > $(@D)/libstdc++-v3/testsuite/Makefile.in
65         echo "install:" >> $(@D)/libstdc++-v3/testsuite/Makefile.in
66 endef
67
68 #
69 # Create 'build' directory and configure symlink
70 #
71
72 define HOST_GCC_CONFIGURE_SYMLINK
73         mkdir -p $(@D)/build
74         ln -sf ../configure $(@D)/build/configure
75 endef
76
77 #
78 # Common configuration options
79 #
80
81 HOST_GCC_COMMON_DEPENDENCIES = \
82         host-binutils \
83         host-gmp \
84         host-mpfr \
85         $(if $(BR2_BINFMT_FLAT),host-elf2flt)
86
87 HOST_GCC_COMMON_CONF_OPTS = \
88         --target=$(GNU_TARGET_NAME) \
89         --with-sysroot=$(STAGING_DIR) \
90         --disable-__cxa_atexit \
91         --with-gnu-ld \
92         --disable-libssp \
93         --disable-multilib \
94         --with-gmp=$(HOST_DIR)/usr \
95         --with-mpfr=$(HOST_DIR)/usr \
96         --with-pkgversion="Buildroot $(BR2_VERSION_FULL)" \
97         --with-bugurl="http://bugs.buildroot.net/"
98
99 # Don't build documentation. It takes up extra space / build time,
100 # and sometimes needs specific makeinfo versions to work
101 HOST_GCC_COMMON_CONF_ENV = \
102         MAKEINFO=missing
103
104 GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS)
105 GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS)
106
107 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43810
108 # Workaround until it's fixed in 4.5.4 or later
109 ifeq ($(ARCH),powerpc)
110 ifeq ($(findstring x4.5.,x$(GCC_VERSION)),x4.5.)
111 GCC_COMMON_TARGET_CFLAGS = $(filter-out -Os,$(GCC_COMMON_TARGET_CFLAGS))
112 GCC_COMMON_TARGET_CXXFLAGS = $(filter-out -Os,$(GCC_COMMON_TARGET_CXXFLAGS))
113 endif
114 endif
115
116 # Xtensa libgcc can't be built with -mtext-section-literals
117 # because of the trick used to generate .init/.fini sections.
118 ifeq ($(BR2_xtensa),y)
119 GCC_COMMON_TARGET_CFLAGS = $(filter-out -mtext-section-literals,$(TARGET_CFLAGS))
120 GCC_COMMON_TARGET_CXXFLAGS = $(filter-out -mtext-section-literals,$(TARGET_CXXFLAGS))
121 endif
122
123 # Propagate options used for target software building to GCC target libs
124 HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CFLAGS)"
125 HOST_GCC_COMMON_CONF_ENV += CXXFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CXXFLAGS)"
126
127 # libitm needs sparc V9+
128 ifeq ($(BR2_sparc_v8)$(BR2_sparc_leon3),y)
129 HOST_GCC_COMMON_CONF_OPTS += --disable-libitm
130 endif
131
132 # gcc 4.6.x quadmath requires wchar
133 ifneq ($(BR2_TOOLCHAIN_BUILDROOT_WCHAR),y)
134 HOST_GCC_COMMON_CONF_OPTS += --disable-libquadmath
135 endif
136
137 # libsanitizer requires wordexp, not in default uClibc config. Also
138 # doesn't build properly with musl.
139 ifeq ($(BR2_TOOLCHAIN_BUILDROOT_UCLIBC)$(BR2_TOOLCHAIN_BUILDROOT_MUSL),y)
140 HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
141 endif
142
143 # libsanitizer is broken for SPARC
144 # https://bugs.busybox.net/show_bug.cgi?id=7951
145 ifeq ($(BR2_sparc),y)
146 HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
147 endif
148
149 ifeq ($(BR2_GCC_ENABLE_TLS),y)
150 HOST_GCC_COMMON_CONF_OPTS += --enable-tls
151 else
152 HOST_GCC_COMMON_CONF_OPTS += --disable-tls
153 endif
154
155 ifeq ($(BR2_GCC_ENABLE_LTO),y)
156 HOST_GCC_COMMON_CONF_OPTS += --enable-plugins --enable-lto
157 endif
158
159 ifeq ($(BR2_GCC_ENABLE_LIBMUDFLAP),y)
160 HOST_GCC_COMMON_CONF_OPTS += --enable-libmudflap
161 else
162 HOST_GCC_COMMON_CONF_OPTS += --disable-libmudflap
163 endif
164
165 ifeq ($(BR2_PTHREADS_NONE),y)
166 HOST_GCC_COMMON_CONF_OPTS += \
167         --disable-threads \
168         --disable-libitm \
169         --disable-libatomic
170 else
171 HOST_GCC_COMMON_CONF_OPTS += --enable-threads
172 endif
173
174 ifeq ($(BR2_GCC_NEEDS_MPC),y)
175 HOST_GCC_COMMON_DEPENDENCIES += host-mpc
176 HOST_GCC_COMMON_CONF_OPTS += --with-mpc=$(HOST_DIR)/usr
177 endif
178
179 ifeq ($(BR2_GCC_ENABLE_GRAPHITE),y)
180 HOST_GCC_COMMON_DEPENDENCIES += host-isl host-cloog
181 HOST_GCC_COMMON_CONF_OPTS += --with-isl=$(HOST_DIR)/usr --with-cloog=$(HOST_DIR)/usr
182 else
183 HOST_GCC_COMMON_CONF_OPTS += --without-isl --without-cloog
184 endif
185
186 ifeq ($(BR2_arc),y)
187 HOST_GCC_COMMON_DEPENDENCIES += host-flex host-bison
188 endif
189
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
195 endif
196 endif
197
198 ifeq ($(BR2_GCC_SUPPORTS_FINEGRAINEDMTUNE),y)
199 HOST_GCC_COMMON_CONF_OPTS += --disable-decimal-float
200 endif
201
202 # Determine arch/tune/abi/cpu options
203 ifneq ($(call qstrip,$(BR2_GCC_TARGET_ARCH)),)
204 HOST_GCC_COMMON_CONF_OPTS += --with-arch=$(BR2_GCC_TARGET_ARCH)
205 endif
206 ifneq ($(call qstrip,$(BR2_GCC_TARGET_ABI)),)
207 HOST_GCC_COMMON_CONF_OPTS += --with-abi=$(BR2_GCC_TARGET_ABI)
208 endif
209 ifneq ($(call qstrip,$(BR2_GCC_TARGET_CPU)),)
210 ifneq ($(call qstrip,$(BR2_GCC_TARGET_CPU_REVISION)),)
211 HOST_GCC_COMMON_CONF_OPTS += --with-cpu=$(call qstrip,$(BR2_GCC_TARGET_CPU)-$(BR2_GCC_TARGET_CPU_REVISION))
212 else
213 HOST_GCC_COMMON_CONF_OPTS += --with-cpu=$(call qstrip,$(BR2_GCC_TARGET_CPU))
214 endif
215 endif
216
217 GCC_TARGET_FPU = $(call qstrip,$(BR2_GCC_TARGET_FPU))
218 ifneq ($(GCC_TARGET_FPU),)
219 HOST_GCC_COMMON_CONF_OPTS += --with-fpu=$(GCC_TARGET_FPU)
220 endif
221
222 GCC_TARGET_FLOAT_ABI = $(call qstrip,$(BR2_GCC_TARGET_FLOAT_ABI))
223 ifneq ($(GCC_TARGET_FLOAT_ABI),)
224 HOST_GCC_COMMON_CONF_OPTS += --with-float=$(GCC_TARGET_FLOAT_ABI)
225 endif
226
227 GCC_TARGET_MODE = $(call qstrip,$(BR2_GCC_TARGET_MODE))
228 ifneq ($(GCC_TARGET_MODE),)
229 HOST_GCC_COMMON_CONF_OPTS += --with-mode=$(GCC_TARGET_MODE)
230 endif
231
232 # Enable proper double/long double for SPE ABI
233 ifeq ($(BR2_powerpc_SPE),y)
234 HOST_GCC_COMMON_CONF_OPTS += \
235         --enable-e500_double \
236         --with-long-double-128
237 endif
238
239 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CROSS_PATH_SUFFIX='".real"'
240
241 ifeq ($(BR2_CCACHE),y)
242 HOST_GCC_COMMON_CCACHE_HASH_FILES += $(DL_DIR)/$(GCC_SOURCE)
243 # Cfr. PATCH_BASE_DIRS in .stamp_patched, but we catch both versioned and
244 # unversioned patches unconditionally
245 HOST_GCC_COMMON_CCACHE_HASH_FILES += \
246         $(wildcard \
247                 package/gcc/$(GCC_VERSION)/*.patch \
248                 $(addsuffix $((PKG)_RAWNAME)/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
249                 $(addsuffix $((PKG)_RAWNAME)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))))
250 ifeq ($(BR2_xtensa),y)
251 HOST_GCC_COMMON_CCACHE_HASH_FILES += $(HOST_GCC_XTENSA_OVERLAY_TAR)
252 endif
253 ifeq ($(ARCH),powerpc)
254 ifneq ($(BR2_SOFT_FLOAT),)
255 HOST_GCC_COMMON_CCACHE_HASH_FILES += package/gcc/$(GCC_VERSION)/1000-powerpc-link-with-math-lib.patch.conditional
256 endif
257 endif
258
259 # _CONF_OPTS contains some references to the absolute path of $(HOST_DIR),
260 # so substitute those away.
261 HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE_HASH=\"`\
262         printf '%s' $(subst $(HOST_DIR),@HOST_DIR@,$($(PKG)_CONF_OPTS)) \
263                 | sha256sum - $(HOST_GCC_COMMON_CCACHE_HASH_FILES) \
264                 | cut -c -64 | tr -d '\n'`\"
265 endif # BR2_CCACHE
266
267 # The LTO support in gcc creates wrappers for ar, ranlib and nm which load
268 # the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
269 # *-gcc-nm and should be used instead of the real programs when -flto is
270 # used. However, we should not add the toolchain wrapper for them, and they
271 # match the *cc-* pattern. Therefore, an additional case is added for *-ar,
272 # *-ranlib and *-nm.
273 # Avoid that a .real is symlinked a second time.
274 # Also create <arch>-linux-<tool> symlinks.
275 define HOST_GCC_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
276         $(Q)cd $(HOST_DIR)/usr/bin; \
277         for i in $(GNU_TARGET_NAME)-*; do \
278                 case "$$i" in \
279                 *.real) \
280                         ;; \
281                 *-ar|*-ranlib|*-nm) \
282                         ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
283                         ;; \
284                 *cc|*cc-*|*++|*++-*|*cpp) \
285                         rm -f $$i.real; \
286                         mv $$i $$i.real; \
287                         ln -sf toolchain-wrapper $$i; \
288                         ln -sf toolchain-wrapper $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
289                         ln -snf $$i.real $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}.real; \
290                         ;; \
291                 *) \
292                         ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
293                         ;; \
294                 esac; \
295         done
296
297 endef
298
299 include $(sort $(wildcard package/gcc/*/*.mk))