blob: e46d7b0f7c15c3a5346d9ffc479c8754f7e3f2f9 [file] [log] [blame]
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07001# Copyright 1999-2008 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07003# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain.eclass,v 1.434 2010/07/05 22:25:09 vapier Exp $
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07004#
5# Maintainer: Toolchain Ninjas <toolchain@gentoo.org>
6
7HOMEPAGE="http://gcc.gnu.org/"
8LICENSE="GPL-2 LGPL-2.1"
Ahmad Sharifabd0bcb2010-10-21 16:18:38 -07009RESTRICT="mirror strip" # cross-compilers need controlled stripping
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -070010
11#---->> eclass stuff <<----
12inherit eutils versionator libtool toolchain-funcs flag-o-matic gnuconfig multilib fixheadtails
13
14EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_test pkg_preinst src_install pkg_postinst pkg_prerm pkg_postrm
15DESCRIPTION="Based on the ${ECLASS} eclass"
16
17FEATURES=${FEATURES/multilib-strict/}
18
Ahmad Sharifef1e44e2010-08-26 10:27:38 -070019toolchain_crosstool_pkg_setup() {
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -070020 gcc_pkg_setup
21}
Ahmad Sharifef1e44e2010-08-26 10:27:38 -070022toolchain_crosstool_src_unpack() {
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -070023 gcc_src_unpack
24}
Ahmad Sharifef1e44e2010-08-26 10:27:38 -070025toolchain_crosstool_src_compile() {
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -070026 gcc_src_compile
27}
Ahmad Sharifef1e44e2010-08-26 10:27:38 -070028toolchain_crosstool_src_test() {
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -070029 gcc_src_test
30}
Ahmad Sharifef1e44e2010-08-26 10:27:38 -070031toolchain_crosstool_pkg_preinst() {
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -070032 ${ETYPE}_pkg_preinst
33}
Ahmad Sharifef1e44e2010-08-26 10:27:38 -070034toolchain_crosstool_src_install() {
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -070035 ${ETYPE}_src_install
36}
Ahmad Sharifef1e44e2010-08-26 10:27:38 -070037toolchain_crosstool_pkg_postinst() {
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -070038 ${ETYPE}_pkg_postinst
39}
Ahmad Sharifef1e44e2010-08-26 10:27:38 -070040toolchain_crosstool_pkg_prerm() {
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -070041 ${ETYPE}_pkg_prerm
42}
Ahmad Sharifef1e44e2010-08-26 10:27:38 -070043toolchain_crosstool_pkg_postrm() {
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -070044 ${ETYPE}_pkg_postrm
45}
46#----<< eclass stuff >>----
47
48
49#---->> globals <<----
50export CTARGET=${CTARGET:-${CHOST}}
51if [[ ${CTARGET} = ${CHOST} ]] ; then
52 if [[ ${CATEGORY/cross-} != ${CATEGORY} ]] ; then
53 export CTARGET=${CATEGORY/cross-}
54 fi
55fi
56is_crosscompile() {
57 [[ ${CHOST} != ${CTARGET} ]]
58}
59
60tc_version_is_at_least() { version_is_at_least "$1" "${2:-${GCC_PV}}" ; }
61
62
63GCC_PV=${TOOLCHAIN_GCC_PV:-${PV}}
64GCC_PVR=${GCC_PV}
65[[ ${PR} != "r0" ]] && GCC_PVR=${GCC_PVR}-${PR}
66GCC_RELEASE_VER=$(get_version_component_range 1-3 ${GCC_PV})
67GCC_BRANCH_VER=$(get_version_component_range 1-2 ${GCC_PV})
68GCCMAJOR=$(get_version_component_range 1 ${GCC_PV})
69GCCMINOR=$(get_version_component_range 2 ${GCC_PV})
70GCCMICRO=$(get_version_component_range 3 ${GCC_PV})
71[[ ${BRANCH_UPDATE-notset} == "notset" ]] && BRANCH_UPDATE=$(get_version_component_range 4 ${GCC_PV})
72
73# According to gcc/c-cppbuiltin.c, GCC_CONFIG_VER MUST match this regex.
74# ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)?
75GCC_CONFIG_VER=${GCC_CONFIG_VER:-$(replace_version_separator 3 '-' ${GCC_PV})}
76
77# Pre-release support
78if [[ ${GCC_PV} != ${GCC_PV/_pre/-} ]] ; then
79 PRERELEASE=${GCC_PV/_pre/-}
80fi
81# make _alpha and _beta ebuilds automatically use a snapshot
82if [[ ${GCC_PV} == *_alpha* ]] ; then
83 SNAPSHOT=${GCC_BRANCH_VER}-${GCC_PV##*_alpha}
84elif [[ ${GCC_PV} == *_beta* ]] ; then
85 SNAPSHOT=${GCC_BRANCH_VER}-${GCC_PV##*_beta}
86elif [[ ${GCC_PV} == *_rc* ]] ; then
87 SNAPSHOT=${GCC_PV%_rc*}-RC-${GCC_PV##*_rc}
88fi
89export GCC_FILESDIR=${GCC_FILESDIR:-${FILESDIR}}
90
91if [[ ${ETYPE} == "gcc-library" ]] ; then
92 GCC_VAR_TYPE=${GCC_VAR_TYPE:-non-versioned}
93 GCC_LIB_COMPAT_ONLY=${GCC_LIB_COMPAT_ONLY:-true}
94 GCC_TARGET_NO_MULTILIB=${GCC_TARGET_NO_MULTILIB:-true}
95else
96 GCC_VAR_TYPE=${GCC_VAR_TYPE:-versioned}
97 GCC_LIB_COMPAT_ONLY="false"
98 GCC_TARGET_NO_MULTILIB=${GCC_TARGET_NO_MULTILIB:-false}
99fi
100
101PREFIX=${TOOLCHAIN_PREFIX:-/usr}
102
103if [[ ${GCC_VAR_TYPE} == "versioned" ]] ; then
104 if tc_version_is_at_least 3.4.0 ; then
105 LIBPATH=${TOOLCHAIN_LIBPATH:-${PREFIX}/lib/gcc/${CTARGET}/${GCC_CONFIG_VER}}
106 else
107 LIBPATH=${TOOLCHAIN_LIBPATH:-${PREFIX}/lib/gcc-lib/${CTARGET}/${GCC_CONFIG_VER}}
108 fi
109 INCLUDEPATH=${TOOLCHAIN_INCLUDEPATH:-${LIBPATH}/include}
110 if is_crosscompile ; then
111 BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/${CHOST}/${CTARGET}/gcc-bin/${GCC_CONFIG_VER}}
112 else
113 BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/${CTARGET}/gcc-bin/${GCC_CONFIG_VER}}
114 fi
115 DATAPATH=${TOOLCHAIN_DATAPATH:-${PREFIX}/share/gcc-data/${CTARGET}/${GCC_CONFIG_VER}}
116 # Dont install in /usr/include/g++-v3/, but in gcc internal directory.
117 # We will handle /usr/include/g++-v3/ with gcc-config ...
118 STDCXX_INCDIR=${TOOLCHAIN_STDCXX_INCDIR:-${LIBPATH}/include/g++-v${GCC_BRANCH_VER/\.*/}}
119elif [[ ${GCC_VAR_TYPE} == "non-versioned" ]] ; then
120 # using non-versioned directories to install gcc, like what is currently
121 # done for ppc64 and 3.3.3_pre, is a BAD IDEA. DO NOT do it!! However...
122 # setting up variables for non-versioned directories might be useful for
123 # specific gcc targets, like libffi. Note that we dont override the value
124 # returned by get_libdir here.
125 LIBPATH=${TOOLCHAIN_LIBPATH:-${PREFIX}/$(get_libdir)}
126 INCLUDEPATH=${TOOLCHAIN_INCLUDEPATH:-${PREFIX}/include}
127 BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/bin}
128 DATAPATH=${TOOLCHAIN_DATAPATH:-${PREFIX}/share}
129 STDCXX_INCDIR=${TOOLCHAIN_STDCXX_INCDIR:-${PREFIX}/include/g++-v3}
130fi
131
132#----<< globals >>----
133
134
135#---->> SLOT+IUSE logic <<----
136if [[ ${ETYPE} == "gcc-library" ]] ; then
137 IUSE="nls build test"
138 SLOT="${CTARGET}-${SO_VERSION_SLOT:-5}"
139else
140 IUSE="multislot nptl test"
141
142 if [[ ${PN} != "kgcc64" && ${PN} != gcc-* ]] ; then
143 IUSE="${IUSE} altivec build fortran nls nocxx"
144 [[ -n ${PIE_VER} ]] && IUSE="${IUSE} nopie"
145 [[ -n ${PP_VER} ]] && IUSE="${IUSE} nossp"
146 [[ -n ${SPECS_VER} ]] && IUSE="${IUSE} nossp"
147 [[ -n ${HTB_VER} ]] && IUSE="${IUSE} boundschecking"
148 [[ -n ${D_VER} ]] && IUSE="${IUSE} d"
149
150 if tc_version_is_at_least 3 ; then
151 IUSE="${IUSE} bootstrap doc gcj gtk hardened libffi multilib objc vanilla"
152
153 # gcc-{nios2,bfin} don't accept these
154 if [[ ${PN} == "gcc" ]] ; then
155 IUSE="${IUSE} n32 n64"
156 fi
157
158 tc_version_is_at_least "4.0" && IUSE="${IUSE} objc-gc mudflap"
159 tc_version_is_at_least "4.1" && IUSE="${IUSE} objc++"
160 tc_version_is_at_least "4.2" && IUSE="${IUSE} openmp"
161 tc_version_is_at_least "4.3" && IUSE="${IUSE} fixed-point"
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700162 if tc_version_is_at_least "4.4" ; then
163 IUSE="${IUSE} graphite"
164 [[ -n ${SPECS_VER} ]] && IUSE="${IUSE} nossp"
165 fi
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700166 tc_version_is_at_least "4.5" && IUSE="${IUSE} lto"
167 fi
168 fi
169
170 # Support upgrade paths here or people get pissed
171 if use multislot ; then
172 SLOT="${CTARGET}-${GCC_CONFIG_VER}"
173 elif is_crosscompile; then
174 SLOT="${CTARGET}-${GCC_BRANCH_VER}"
175 else
176 SLOT="${GCC_BRANCH_VER}"
177 fi
178fi
179#----<< SLOT+IUSE logic >>----
180
181
182#---->> S + SRC_URI essentials <<----
183
184# This function sets the source directory depending on whether we're using
185# a prerelease, snapshot, or release tarball. To use it, just set S with:
186#
187# S="$(gcc_get_s_dir)"
188#
189# Travis Tilley <lv@gentoo.org> (03 Sep 2004)
190#
191gcc_get_s_dir() {
192 local GCC_S
193 if [[ -n ${PRERELEASE} ]] ; then
194 GCC_S=${WORKDIR}/gcc-${PRERELEASE}
195 elif [[ -n ${SNAPSHOT} ]] ; then
196 GCC_S=${WORKDIR}/gcc-${SNAPSHOT}
197 else
198 GCC_S=${WORKDIR}/gcc-${GCC_RELEASE_VER}
199 fi
200 echo "${GCC_S}"
201}
202
203# This function handles the basics of setting the SRC_URI for a gcc ebuild.
204# To use, set SRC_URI with:
205#
206# SRC_URI="$(get_gcc_src_uri)"
207#
208# Other than the variables normally set by portage, this function's behavior
209# can be altered by setting the following:
210#
211# SNAPSHOT
212# If set, this variable signals that we should be using a snapshot
213# of gcc from ftp://sources.redhat.com/pub/gcc/snapshots/. It is
214# expected to be in the format "YYYY-MM-DD". Note that if the ebuild
215# has a _pre suffix, this variable is ignored and the prerelease
216# tarball is used instead.
217#
218# BRANCH_UPDATE
219# If set, this variable signals that we should be using the main
220# release tarball (determined by ebuild version) and applying a
221# CVS branch update patch against it. The location of this branch
222# update patch is assumed to be in ${GENTOO_TOOLCHAIN_BASE_URI}.
223# Just like with SNAPSHOT, this variable is ignored if the ebuild
224# has a _pre suffix.
225#
226# PATCH_VER
227# PATCH_GCC_VER
228# This should be set to the version of the gentoo patch tarball.
229# The resulting filename of this tarball will be:
230# gcc-${PATCH_GCC_VER:-${GCC_RELEASE_VER}}-patches-${PATCH_VER}.tar.bz2
231#
232# PIE_VER
233# PIE_GCC_VER
234# obsoleted: PIE_CORE
235# These variables control patching in various updates for the logic
236# controlling Position Independant Executables. PIE_VER is expected
237# to be the version of this patch, PIE_GCC_VER the gcc version of
238# the patch, and PIE_CORE (obsoleted) the actual filename of the patch.
239# An example:
240# PIE_VER="8.7.6.5"
241# PIE_GCC_VER="3.4.0"
242# The resulting filename of this tarball will be:
243# gcc-${PIE_GCC_VER:-${GCC_RELEASE_VER}}-piepatches-v${PIE_VER}.tar.bz2
244# old syntax (do not define PIE_CORE anymore):
245# PIE_CORE="gcc-3.4.0-piepatches-v${PIE_VER}.tar.bz2"
246#
247# SPECS_VER
248# SPECS_GCC_VER
249# This is for the minispecs files included in the hardened gcc-4.x
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700250# The specs files for hardenedno*, vanilla and for building the "specs" file.
251# SPECS_VER is expected to be the version of this patch, SPECS_GCC_VER
252# the gcc version of the patch.
253# An example:
254# SPECS_VER="8.7.6.5"
255# SPECS_GCC_VER="3.4.0"
256# The resulting filename of this tarball will be:
257# gcc-${SPECS_GCC_VER:-${GCC_RELEASE_VER}}-specs-${SPECS_VER}.tar.bz2
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700258#
259# PP_VER
260# PP_GCC_VER
261# obsoleted: PP_FVER
262# These variables control patching in stack smashing protection
263# support. They both control the version of ProPolice to download.
264#
265# PP_VER / PP_GCC_VER
266# Used to roll our own custom tarballs of ssp.
267# PP_FVER / PP_VER
268# Used for mirroring ssp straight from IBM.
269# PP_VER sets the version of the directory in which to find the
270# patch, and PP_FVER sets the version of the patch itself. For
271# example:
272# PP_VER="3_4"
273# PP_FVER="${PP_VER//_/.}-2"
274# would download gcc3_4/protector-3.4-2.tar.gz
275#
276# HTB_VER
277# HTB_GCC_VER
278# These variables control whether or not an ebuild supports Herman
279# ten Brugge's bounds-checking patches. If you want to use a patch
280# for an older gcc version with a new gcc, make sure you set
281# HTB_GCC_VER to that version of gcc.
282#
283# MAN_VER
284# The version of gcc for which we will download manpages. This will
285# default to ${GCC_RELEASE_VER}, but we may not want to pre-generate man pages
286# for prerelease test ebuilds for example. This allows you to
287# continue using pre-generated manpages from the last stable release.
288# If set to "none", this will prevent the downloading of manpages,
289# which is useful for individual library targets.
290#
291gentoo_urls() {
Ahmad Sharifabd0bcb2010-10-21 16:18:38 -0700292 echo http://commondatastorage.googleapis.com/chromeos-localmirror/distfiles/$1
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700293}
Ahmad Sharifabd0bcb2010-10-21 16:18:38 -0700294
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700295get_gcc_src_uri() {
296 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
297 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
298 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
299 export PP_GCC_VER=${PP_GCC_VER:-${GCC_RELEASE_VER}}
300 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
301 export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}}
302
303 # Set where to download gcc itself depending on whether we're using a
304 # prerelease, snapshot, or release tarball.
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700305 # TODO: Add this back in the future to select between snapshot and
306 # pre-release.
307### if [[ -n ${PRERELEASE} ]] ; then
308### GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/prerelease-${PRERELEASE}/gcc-${PRERELEASE}.tar.bz2"
309### elif [[ -n ${SNAPSHOT} ]] ; then
310### GCC_SRC_URI="ftp://sources.redhat.com/pub/gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.bz2"
311### else
312### GCC_SRC_URI="mirror://gnu/gcc/gcc-${GCC_PV}/gcc-${GCC_RELEASE_VER}.tar.bz2"
313### # we want all branch updates to be against the main release
314### [[ -n ${BRANCH_UPDATE} ]] && \
315### GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2)"
316### fi
317 GCC_SRC_URI="$(gentoo_urls ${COST_PKG_VERSION}.tar.bz2)"
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700318
319 # propolice aka stack smashing protection
320 if [[ -n ${PP_VER} ]] ; then
321 if [[ -n ${PP_FVER} ]] ; then
322 GCC_SRC_URI="${GCC_SRC_URI}
323 !nossp? (
324 http://www.research.ibm.com/trl/projects/security/ssp/gcc${PP_VER}/protector-${PP_FVER}.tar.gz
325 $(gentoo_urls protector-${PP_FVER}.tar.gz)
326 )"
327 else
328 GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${PP_GCC_VER}-ssp-${PP_VER}.tar.bz2)"
329 fi
330 fi
331
332 # uclibc lovin
333 [[ -n ${UCLIBC_VER} ]] && \
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700334 GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}_${COST_SUFFIX}.tar.bz2)"
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700335
336 # PERL cannot be present at bootstrap, and is used to build the man pages.
337 # So... lets include some pre-generated ones, shall we?
338 [[ -n ${MAN_VER} ]] && \
339 GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${MAN_VER}-manpages.tar.bz2)"
340
341 # various gentoo patches
342 [[ -n ${PATCH_VER} ]] && \
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700343 GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}_${COST_SUFFIX}.tar.bz2)"
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700344
345 # strawberry pie, Cappuccino and a Gauloises (it's a good thing)
346 [[ -n ${PIE_VER} ]] && \
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700347 PIE_CORE=${PIE_CORE:-gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}_${COST_SUFFIX}.tar.bz2} && \
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700348 GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls ${PIE_CORE})"
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700349
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700350 # gcc minispec for the hardened gcc 4 compiler
351 [[ -n ${SPECS_VER} ]] && \
352 GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2)"
353
354 # gcc bounds checking patch
355 if [[ -n ${HTB_VER} ]] ; then
356 local HTBFILE="bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
357 GCC_SRC_URI="${GCC_SRC_URI}
358 boundschecking? (
359 mirror://sourceforge/boundschecking/${HTBFILE}
360 $(gentoo_urls ${HTBFILE})
361 )"
362 fi
363
364 # support for the D language
365 [[ -n ${D_VER} ]] && \
366 GCC_SRC_URI="${GCC_SRC_URI} d? ( mirror://sourceforge/dgcc/gdc-${D_VER}-src.tar.bz2 )"
367
368 # >= gcc-4.3 uses ecj.jar and we only add gcj as a use flag under certain
369 # conditions
370 if [[ ${PN} != "kgcc64" && ${PN} != gcc-* ]] ; then
371 tc_version_is_at_least "4.3" && \
372 GCC_SRC_URI="${GCC_SRC_URI}
373 gcj? ( ftp://sourceware.org/pub/java/ecj-4.3.jar )"
374 fi
375
376 echo "${GCC_SRC_URI}"
377}
378S=$(gcc_get_s_dir)
379SRC_URI=$(get_gcc_src_uri)
380#---->> S + SRC_URI essentials >>----
381
382
383#---->> support checks <<----
384
385# Grab a variable from the build system (taken from linux-info.eclass)
386get_make_var() {
387 local var=$1 makefile=${2:-${WORKDIR}/build/Makefile}
388 echo -e "e:\\n\\t@echo \$(${var})\\ninclude ${makefile}" | \
389 r=${makefile%/*} emake --no-print-directory -s -f - 2>/dev/null
390}
391XGCC() { get_make_var GCC_FOR_TARGET ; }
392
393# The gentoo piessp patches allow for 3 configurations:
394# 1) PIE+SSP by default
395# 2) PIE by default
396# 3) SSP by default
397hardened_gcc_works() {
398 if [[ $1 == "pie" ]] ; then
399 # $gcc_cv_ld_pie is unreliable as it simply take the output of
400 # `ld --help | grep -- -pie`, that reports the option in all cases, also if
401 # the loader doesn't actually load the resulting executables.
402 # To avoid breakage, blacklist FreeBSD here at least
403 [[ ${CTARGET} == *-freebsd* ]] && return 1
404
405 want_pie || return 1
406 tc_version_is_at_least 4.3.2 && use nopie && return 1
407 hardened_gcc_is_stable pie && return 0
408 if has "~$(tc-arch)" ${ACCEPT_KEYWORDS} ; then
409 hardened_gcc_check_unsupported pie && return 1
410 ewarn "Allowing pie-by-default for an unstable arch ($(tc-arch))"
411 return 0
412 fi
413 return 1
414 elif [[ $1 == "ssp" ]] ; then
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700415 [[ -n ${PP_VER} ]] || [[ -n ${SPECS_VER} ]] || return 1
416 tc_version_is_at_least 4.3.2 && use nossp && return 1
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700417 hardened_gcc_is_stable ssp && return 0
418 if has "~$(tc-arch)" ${ACCEPT_KEYWORDS} ; then
419 hardened_gcc_check_unsupported ssp && return 1
420 ewarn "Allowing ssp-by-default for an unstable arch ($(tc-arch))"
421 return 0
422 fi
423 return 1
424 else
425 # laziness ;)
426 hardened_gcc_works pie || return 1
427 hardened_gcc_works ssp || return 1
428 return 0
429 fi
430}
431
432hardened_gcc_is_stable() {
433 if [[ $1 == "pie" ]] ; then
434 # HARDENED_* variables are deprecated and here for compatibility
435 local tocheck="${HARDENED_PIE_WORKS} ${HARDENED_GCC_WORKS}"
436 if [[ ${CTARGET} == *-uclibc* ]] ; then
437 tocheck="${tocheck} ${PIE_UCLIBC_STABLE}"
438 else
439 tocheck="${tocheck} ${PIE_GLIBC_STABLE}"
440 fi
441 elif [[ $1 == "ssp" ]] ; then
442 # ditto
443 local tocheck="${HARDENED_SSP_WORKS} ${HARDENED_GCC_WORKS}"
444 if [[ ${CTARGET} == *-uclibc* ]] ; then
445 tocheck="${tocheck} ${SSP_UCLIBC_STABLE}"
446 else
447 tocheck="${tocheck} ${SSP_STABLE}"
448 fi
449 else
450 die "hardened_gcc_stable needs to be called with pie or ssp"
451 fi
452
453 hasq $(tc-arch) ${tocheck} && return 0
454 return 1
455}
456
457hardened_gcc_check_unsupported() {
458 local tocheck=""
459 # if a variable is unset, we assume that all archs are unsupported. since
460 # this function is never called if hardened_gcc_is_stable returns true,
461 # this shouldn't cause problems... however, allowing this logic to work
462 # even with the variables unset will break older ebuilds that dont use them.
463 if [[ $1 == "pie" ]] ; then
464 if [[ ${CTARGET} == *-uclibc* ]] ; then
465 [[ -z ${PIE_UCLIBC_UNSUPPORTED} ]] && return 0
466 tocheck="${tocheck} ${PIE_UCLIBC_UNSUPPORTED}"
467 else
468 [[ -z ${PIE_GLIBC_UNSUPPORTED} ]] && return 0
469 tocheck="${tocheck} ${PIE_GLIBC_UNSUPPORTED}"
470 fi
471 elif [[ $1 == "ssp" ]] ; then
472 if [[ ${CTARGET} == *-uclibc* ]] ; then
473 [[ -z ${SSP_UCLIBC_UNSUPPORTED} ]] && return 0
474 tocheck="${tocheck} ${SSP_UCLIBC_UNSUPPORTED}"
475 else
476 [[ -z ${SSP_UNSUPPORTED} ]] && return 0
477 tocheck="${tocheck} ${SSP_UNSUPPORTED}"
478 fi
479 else
480 die "hardened_gcc_check_unsupported needs to be called with pie or ssp"
481 fi
482
483 hasq $(tc-arch) ${tocheck} && return 0
484 return 1
485}
486
487has_libssp() {
488 [[ -e /$(get_libdir)/libssp.so ]] && return 0
489 return 1
490}
491
492want_libssp() {
493 [[ ${GCC_LIBSSP_SUPPORT} == "true" ]] || return 1
494 has_libssp || return 1
495 [[ -n ${PP_VER} ]] || return 1
496 return 0
497}
498
499_want_stuff() {
500 local var=$1 flag=$2
501 [[ -z ${!var} ]] && return 1
502 use ${flag} && return 0
503 return 1
504}
505want_boundschecking() { _want_stuff HTB_VER boundschecking ; }
506want_pie() {
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700507 ! use hardened && [[ -n ${PIE_VER} ]] && use nopie && return 1
508 [[ -n ${PIE_VER} ]] && [[ -n ${SPECS_VER} ]] && return 0
509 tc_version_is_at_least 4.3.2 && return 1
510 _want_stuff PIE_VER !nopie
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700511}
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700512want_ssp() { _want_stuff PP_VER !nossp ; }
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700513
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700514# SPLIT_SPECS are deprecated for >=GCC 4.4
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700515want_split_specs() {
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700516 tc_version_is_at_least 4.4 && return 1
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700517 [[ ${SPLIT_SPECS} == "true" ]] && want_pie
518}
519want_minispecs() {
520 if tc_version_is_at_least 4.3.2 && use hardened ; then
521 if ! want_pie ; then
522 ewarn "PIE_VER or SPECS_VER is not defiend in the GCC ebuild."
523 elif use vanilla ; then
524 ewarn "You will not get hardened features if you have the vanilla USE-flag."
525 elif use nopie && use nossp ; then
526 ewarn "You will not get hardened features if you have the nopie and nossp USE-flag."
527 elif ! hardened_gcc_works pie && ! hardened_gcc_works ssp && ! use nopie ; then
528 ewarn "Your $(tc-arch) arch is not supported."
529 else
530 return 0
531 fi
532 ewarn "Hope you know what you are doing. Hardened will not work."
533 return 0
534 fi
535 return 1
536}
537# This function checks whether or not glibc has the support required to build
538# Position Independant Executables with gcc.
539glibc_have_pie() {
540 if [[ ! -f ${ROOT}/usr/$(get_libdir)/Scrt1.o ]] ; then
541 echo
542 ewarn "Your glibc does not have support for pie, the file Scrt1.o is missing"
543 ewarn "Please update your glibc to a proper version or disable hardened"
544 echo
545 return 1
546 fi
547}
548
549# This function determines whether or not libc has been patched with stack
550# smashing protection support.
551libc_has_ssp() {
552 [[ ${ROOT} != "/" ]] && return 0
553
554 # lib hacks taken from sandbox configure
555 echo 'int main(){}' > "${T}"/libctest.c
556 LC_ALL=C gcc "${T}"/libctest.c -lc -o libctest -Wl,-verbose &> "${T}"/libctest.log || return 1
557 local libc_file=$(awk '/attempt to open/ { if (($4 ~ /\/libc\.so/) && ($5 == "succeeded")) LIBC = $4; }; END {print LIBC}' "${T}"/libctest.log)
558
559 [[ -z ${libc_file} ]] && die "Unable to find a libc !?"
560
561 # Check for gcc-4.x style ssp support
562 if [[ -n $(readelf -s "${libc_file}" 2>/dev/null | \
563 grep 'FUNC.*GLOBAL.*__stack_chk_fail') ]]
564 then
565 return 0
566 else
567 # Check for gcc-3.x style ssp support
568 if [[ -n $(readelf -s "${libc_file}" 2>/dev/null | \
569 grep 'OBJECT.*GLOBAL.*__guard') ]] && \
570 [[ -n $(readelf -s "${libc_file}" 2>/dev/null | \
571 grep 'FUNC.*GLOBAL.*__stack_smash_handler') ]]
572 then
573 return 0
574 elif is_crosscompile ; then
575 die "'${libc_file}' was detected w/out ssp, that sucks (a lot)"
576 else
577 return 1
578 fi
579 fi
580}
581
582# This is to make sure we don't accidentally try to enable support for a
583# language that doesnt exist. GCC 3.4 supports f77, while 4.0 supports f95, etc.
584#
585# Also add a hook so special ebuilds (kgcc64) can control which languages
586# exactly get enabled
587gcc-lang-supported() {
588 grep ^language=\"${1}\" "${S}"/gcc/*/config-lang.in > /dev/null || return 1
589 [[ -z ${TOOLCHAIN_ALLOWED_LANGS} ]] && return 0
590 has $1 ${TOOLCHAIN_ALLOWED_LANGS}
591}
592
593#----<< support checks >>----
594
595#---->> specs + env.d logic <<----
596
597# defaults to enable for all hardened toolchains
598gcc_common_hard="-DEFAULT_RELRO -DEFAULT_BIND_NOW"
599
600# configure to build with the hardened GCC specs as the default
601make_gcc_hard() {
602 if hardened_gcc_works ; then
603 einfo "Updating gcc to use automatic PIE + SSP building ..."
604 sed -e "s|^HARD_CFLAGS = |HARD_CFLAGS = -DEFAULT_PIE_SSP ${gcc_common_hard} |" \
605 -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!"
606 elif hardened_gcc_works pie ; then
607 einfo "Updating gcc to use automatic PIE building ..."
608 ewarn "SSP has not been enabled by default"
609 sed -e "s|^HARD_CFLAGS = |HARD_CFLAGS = -DEFAULT_PIE ${gcc_common_hard} |" \
610 -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!"
611 elif hardened_gcc_works ssp ; then
612 einfo "Updating gcc to use automatic SSP building ..."
613 ewarn "PIE has not been enabled by default"
614 sed -e "s|^HARD_CFLAGS = |HARD_CFLAGS = -DEFAULT_SSP ${gcc_common_hard} |" \
615 -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!"
616 else
617 # do nothing if hardened isnt supported, but dont die either
618 ewarn "hardened is not supported for this arch in this gcc version"
619 ebeep
620 return 0
621 fi
622
623 # rebrand to make bug reports easier
624 BRANDING_GCC_PKGVERSION=${BRANDING_GCC_PKGVERSION/Gentoo/Gentoo Hardened}
625}
626
627# now we generate different spec files so that the user can select a compiler
628# that enforces certain features in gcc itself and so we don't have to worry
629# about a certain package ignoring CFLAGS/LDFLAGS
630_create_specs_file() {
631 # Usage: _create_specs_file <USE flag> <specs name> <CFLAGS>
632 local uflag=$1 name=$2 flags=${*:3}
633 ebegin "Creating a ${name} gcc specs file"
634 pushd "${WORKDIR}"/build/gcc > /dev/null
635 if [[ -z ${uflag} ]] || use ${uflag} ; then
636 # backup the compiler first
637 cp Makefile Makefile.orig
638 sed -i -e '/^HARD_CFLAGS/s:=.*:='"${flags}"':' Makefile
639 mv xgcc xgcc.foo
640 mv gcc.o gcc.o.foo
641 emake -s xgcc
642 $(XGCC) -dumpspecs > "${WORKDIR}"/build/${name}.specs
643 # restore everything to normal
644 mv gcc.o.foo gcc.o
645 mv xgcc.foo xgcc
646 mv Makefile.orig Makefile
647 else
648 $(XGCC) -dumpspecs > "${WORKDIR}"/build/${name}.specs
649 fi
650 popd > /dev/null
651 eend $([[ -s ${WORKDIR}/build/${name}.specs ]] ; echo $?)
652}
653create_vanilla_specs_file() { _create_specs_file hardened vanilla ; }
654create_hardened_specs_file() { _create_specs_file !hardened hardened ${gcc_common_hard} -DEFAULT_PIE_SSP ; }
655create_hardenednossp_specs_file() { _create_specs_file "" hardenednossp ${gcc_common_hard} -DEFAULT_PIE ; }
656create_hardenednopie_specs_file() { _create_specs_file "" hardenednopie ${gcc_common_hard} -DEFAULT_SSP ; }
657create_hardenednopiessp_specs_file() { _create_specs_file "" hardenednopiessp ${gcc_common_hard} ; }
658
659split_out_specs_files() {
660 local s spec_list="hardenednopiessp vanilla"
661 if hardened_gcc_works ; then
662 spec_list="${spec_list} hardened hardenednossp hardenednopie"
663 elif hardened_gcc_works pie ; then
664 spec_list="${spec_list} hardenednossp"
665 elif hardened_gcc_works ssp ; then
666 spec_list="${spec_list} hardenednopie"
667 fi
668 for s in ${spec_list} ; do
669 create_${s}_specs_file || return 1
670 done
671}
672
673create_gcc_env_entry() {
674 dodir /etc/env.d/gcc
675 local gcc_envd_base="/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}"
676
677 if [[ -z $1 ]] ; then
678 gcc_envd_file="${D}${gcc_envd_base}"
679 # I'm leaving the following commented out to remind me that it
680 # was an insanely -bad- idea. Stuff broke. GCC_SPECS isnt unset
681 # on chroot or in non-toolchain.eclass gcc ebuilds!
682 #gcc_specs_file="${LIBPATH}/specs"
683 gcc_specs_file=""
684 else
685 gcc_envd_file="${D}${gcc_envd_base}-$1"
686 gcc_specs_file="${LIBPATH}/$1.specs"
687 fi
688
689 # phase PATH/ROOTPATH out ...
690 echo "PATH=\"${BINPATH}\"" > ${gcc_envd_file}
691 echo "ROOTPATH=\"${BINPATH}\"" >> ${gcc_envd_file}
692 echo "GCC_PATH=\"${BINPATH}\"" >> ${gcc_envd_file}
693
694 if use multilib && ! has_multilib_profile; then
695 LDPATH="${LIBPATH}"
696 for path in 32 64 ; do
697 [[ -d ${LIBPATH}/${path} ]] && LDPATH="${LDPATH}:${LIBPATH}/${path}"
698 done
699 else
700 local MULTIDIR
701 LDPATH="${LIBPATH}"
702
703 # We want to list the default ABI's LIBPATH first so libtool
704 # searches that directory first. This is a temporary
705 # workaround for libtool being stupid and using .la's from
706 # conflicting ABIs by using the first one in the search path
707
708 local abi=${DEFAULT_ABI}
709 local MULTIDIR=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory)
710 if [[ ${MULTIDIR} == "." ]] ; then
711 LDPATH=${LIBPATH}
712 else
713 LDPATH=${LIBPATH}/${MULTIDIR}
714 fi
715
716 for abi in $(get_all_abis) ; do
717 [[ ${abi} == ${DEFAULT_ABI} ]] && continue
718
719 MULTIDIR=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory)
720 if [[ ${MULTIDIR} == "." ]] ; then
721 LDPATH=${LDPATH}:${LIBPATH}
722 else
723 LDPATH=${LDPATH}:${LIBPATH}/${MULTIDIR}
724 fi
725 done
726 fi
727
728 echo "LDPATH=\"${LDPATH}\"" >> ${gcc_envd_file}
729 echo "MANPATH=\"${DATAPATH}/man\"" >> ${gcc_envd_file}
730 echo "INFOPATH=\"${DATAPATH}/info\"" >> ${gcc_envd_file}
731 echo "STDCXX_INCDIR=\"${STDCXX_INCDIR##*/}\"" >> ${gcc_envd_file}
732
733 is_crosscompile && echo "CTARGET=${CTARGET}" >> ${gcc_envd_file}
734
735 # Set which specs file to use
736 [[ -n ${gcc_specs_file} ]] && echo "GCC_SPECS=\"${gcc_specs_file}\"" >> ${gcc_envd_file}
737}
738setup_minispecs_gcc_build_specs() {
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700739 # Setup the "build.specs" file for gcc 4.3 to use when building.
740 if hardened_gcc_works pie ; then
741 cat "${WORKDIR}"/specs/pie.specs >> "${WORKDIR}"/build.specs
742 fi
743 if hardened_gcc_works ssp ; then
744 for s in ssp sspall ; do
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700745 cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs
746 done
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700747 fi
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700748 for s in nostrict znow ; do
749 cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs
750 done
751 export GCC_SPECS="${WORKDIR}"/build.specs
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700752}
753copy_minispecs_gcc_specs() {
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700754 # setup the hardenedno* specs files and the vanilla specs file.
755 if hardened_gcc_works ; then
756 create_gcc_env_entry hardenednopiessp
757 fi
758 if hardened_gcc_works pie ; then
759 create_gcc_env_entry hardenednopie
760 fi
761 if hardened_gcc_works ssp ; then
762 create_gcc_env_entry hardenednossp
763 fi
764 create_gcc_env_entry vanilla
765 insinto ${LIBPATH}
766 doins "${WORKDIR}"/specs/*.specs || die "failed to install specs"
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700767 # Build system specs file which, if it exists, must be a complete set of
768 # specs as it completely and unconditionally overrides the builtin specs.
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700769 # For gcc 4.3
770 if ! tc_version_is_at_least 4.4 ; then
771 $(XGCC) -dumpspecs > "${WORKDIR}"/specs/specs
772 cat "${WORKDIR}"/build.specs >> "${WORKDIR}"/specs/specs
773 doins "${WORKDIR}"/specs/specs || die "failed to install the specs file"
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700774 fi
775}
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700776
777#----<< specs + env.d logic >>----
778
779#---->> pkg_* <<----
780gcc_pkg_setup() {
781 [[ -z ${ETYPE} ]] && die "Your ebuild needs to set the ETYPE variable"
782
783 if [[ ( $(tc-arch) == "amd64" || $(tc-arch) == "ppc64" ) && ( ${LD_PRELOAD} == "/lib/libsandbox.so" || ${LD_PRELOAD} == "/usr/lib/libsandbox.so" ) ]] && is_multilib ; then
784 eerror "Sandbox in your installed portage does not support compilation."
785 eerror "of a multilib gcc. Please set FEATURES=-sandbox and try again."
786 eerror "After you have a multilib gcc, re-emerge portage to have a working sandbox."
787 die "No 32bit sandbox. Retry with FEATURES=-sandbox."
788 fi
789
790 if [[ ${ETYPE} == "gcc-compiler" ]] ; then
791 case $(tc-arch) in
792 mips)
793 # Must compile for mips64-linux target if we want n32/n64 support
794 case "${CTARGET}" in
795 mips64*) ;;
796 *)
797 if use n32 || use n64; then
798 eerror "n32/n64 can only be used when target host is mips64*-*-linux-*";
799 die "Invalid USE flags for CTARGET ($CTARGET)";
800 fi
801 ;;
802 esac
803
804 #cannot have both n32 & n64 without multilib
805 if use n32 && use n64 && ! is_multilib; then
806 eerror "Please enable multilib if you want to use both n32 & n64";
807 die "Invalid USE flag combination";
808 fi
809 ;;
810 esac
811
812 # Setup variables which would normally be in the profile
813 if is_crosscompile ; then
814 multilib_env ${CTARGET}
815 if ! use multilib ; then
816 MULTILIB_ABIS=${DEFAULT_ABI}
817 fi
818 fi
819
820 # we dont want to use the installed compiler's specs to build gcc!
821 unset GCC_SPECS
822 fi
823
824 want_libssp && libc_has_ssp && \
825 die "libssp cannot be used with a glibc that has been patched to provide ssp symbols"
826 want_minispecs
827
828 unset LANGUAGES #265283
829}
830
831gcc-compiler_pkg_preinst() {
832 :
833}
834
835gcc-compiler_pkg_postinst() {
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700836 do_gcc_config
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700837
838 if ! is_crosscompile ; then
839 echo
840 ewarn "If you have issues with packages unable to locate libstdc++.la,"
841 ewarn "then try running 'fix_libtool_files.sh' on the old gcc versions."
842 echo
843 fi
844
845 # If our gcc-config version doesn't like '-' in it's version string,
846 # tell our users that gcc-config will yell at them, but it's all good.
847 if ! has_version '>=sys-devel/gcc-config-1.3.10-r1' && [[ ${GCC_CONFIG_VER/-/} != ${GCC_CONFIG_VER} ]] ; then
848 ewarn "Your version of gcc-config will issue about having an invalid profile"
849 ewarn "when switching to this profile. It is safe to ignore this warning,"
850 ewarn "and this problem has been corrected in >=sys-devel/gcc-config-1.3.10-r1."
851 fi
852
853 if ! is_crosscompile && ! use multislot && [[ ${GCCMAJOR}.${GCCMINOR} == 3.4 ]] ; then
854 echo
855 ewarn "You should make sure to rebuild all your C++ packages when"
856 ewarn "upgrading between different versions of gcc. For example,"
857 ewarn "when moving to gcc-3.4 from gcc-3.3, emerge gentoolkit and run:"
858 ewarn " # revdep-rebuild --library libstdc++.so.5"
859 echo
860 ewarn "For more information on the steps to take when upgrading "
861 ewarn "from gcc-3.3 please refer to: "
862 ewarn "http://www.gentoo.org/doc/en/gcc-upgrading.xml"
863 echo
864 fi
865
866 if ! is_crosscompile ; then
867 # hack to prevent collisions between SLOT
868 [[ ! -d ${ROOT}/lib/rcscripts/awk ]] \
869 && mkdir -p "${ROOT}"/lib/rcscripts/awk
870 [[ ! -d ${ROOT}/sbin ]] \
871 && mkdir -p "${ROOT}"/sbin
872 cp "${ROOT}/${DATAPATH}"/fixlafiles.awk "${ROOT}"/lib/rcscripts/awk/ || die "installing fixlafiles.awk"
873 cp "${ROOT}/${DATAPATH}"/fix_libtool_files.sh "${ROOT}"/sbin/ || die "installing fix_libtool_files.sh"
874
875 [[ ! -d ${ROOT}/usr/bin ]] \
876 && mkdir -p "${ROOT}"/usr/bin
877 # Since these aren't critical files and portage sucks with
878 # handling of binpkgs, don't require these to be found
879 for x in "${ROOT}/${DATAPATH}"/c{89,99} ; do
880 if [[ -e ${x} ]]; then
881 cp ${x} "${ROOT}"/usr/bin/ || die "installing c89/c99"
882 fi
883 done
884 fi
885}
886
887gcc-compiler_pkg_prerm() {
888 # Don't let these files be uninstalled #87647
889 touch -c "${ROOT}"/sbin/fix_libtool_files.sh \
890 "${ROOT}"/lib/rcscripts/awk/fixlafiles.awk
891}
892
893gcc-compiler_pkg_postrm() {
894 # to make our lives easier (and saner), we do the fix_libtool stuff here.
895 # rather than checking SLOT's and trying in upgrade paths, we just see if
896 # the common libstdc++.la exists in the ${LIBPATH} of the gcc that we are
897 # unmerging. if it does, that means this was a simple re-emerge.
898
899 # clean up the cruft left behind by cross-compilers
900 if is_crosscompile ; then
901 if [[ -z $(ls "${ROOT}"/etc/env.d/gcc/${CTARGET}* 2>/dev/null) ]] ; then
902 rm -f "${ROOT}"/etc/env.d/gcc/config-${CTARGET}
903 rm -f "${ROOT}"/etc/env.d/??gcc-${CTARGET}
904 rm -f "${ROOT}"/usr/bin/${CTARGET}-{gcc,{g,c}++}{,32,64}
905 fi
906 return 0
907 fi
908
909 # ROOT isnt handled by the script
910 [[ ${ROOT} != "/" ]] && return 0
911
912 if [[ ! -e ${LIBPATH}/libstdc++.so ]] ; then
913 # make sure the profile is sane during same-slot upgrade #289403
914 do_gcc_config
915
916 einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}'"
917 /sbin/fix_libtool_files.sh ${GCC_RELEASE_VER}
918 if [[ -n ${BRANCH_UPDATE} ]] ; then
919 einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE}'"
920 /sbin/fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE}
921 fi
922 fi
923
924 return 0
925}
926
927#---->> pkg_* <<----
928
929#---->> src_* <<----
930
931# generic GCC src_unpack, to be called from the ebuild's src_unpack.
932# BIG NOTE regarding hardened support: ebuilds with support for hardened are
933# expected to export the following variable:
934#
935# HARDENED_GCC_WORKS
936# This variable should be set to the archs on which hardened should
937# be allowed. For example: HARDENED_GCC_WORKS="x86 sparc amd64"
938# This allows for additional archs to be supported by hardened when
939# ready.
940#
941# Travis Tilley <lv@gentoo.org> (03 Sep 2004)
942#
943gcc-compiler_src_unpack() {
944 # fail if using pie patches, building hardened, and glibc doesnt have
945 # the necessary support
946 want_pie && use hardened && glibc_have_pie
947
Ahmad Sharifef1e44e2010-08-26 10:27:38 -0700948 if use hardened ; then
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700949 einfo "updating configuration to build hardened GCC"
950 make_gcc_hard || die "failed to make gcc hard"
951 fi
952
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -0700953 if is_libffi ; then
954 # move the libffi target out of gcj and into all
955 sed -i \
956 -e '/^libgcj=/s:target-libffi::' \
957 -e '/^target_lib/s:=":="target-libffi :' \
958 "${S}"/configure || die
959 fi
960}
961gcc-library_src_unpack() {
962 :
963}
964guess_patch_type_in_dir() {
965 [[ -n $(ls "$1"/*.bz2 2>/dev/null) ]] \
966 && EPATCH_SUFFIX="patch.bz2" \
967 || EPATCH_SUFFIX="patch"
968}
969do_gcc_rename_java_bins() {
970 # bug #139918 - conflict between gcc and java-config-2 for ownership of
971 # /usr/bin/rmi{c,registry}. Done with mv & sed rather than a patch
972 # because patches would be large (thanks to the rename of man files),
973 # and it's clear from the sed invocations that all that changes is the
974 # rmi{c,registry} names to grmi{c,registry} names.
975 # Kevin F. Quinn 2006-07-12
976 einfo "Renaming jdk executables rmic and rmiregistry to grmic and grmiregistry."
977 # 1) Move the man files if present (missing prior to gcc-3.4)
978 for manfile in rmic rmiregistry; do
979 [[ -f ${S}/gcc/doc/${manfile}.1 ]] || continue
980 mv "${S}"/gcc/doc/${manfile}.1 "${S}"/gcc/doc/g${manfile}.1
981 done
982 # 2) Fixup references in the docs if present (mission prior to gcc-3.4)
983 for jfile in gcc/doc/gcj.info gcc/doc/grmic.1 gcc/doc/grmiregistry.1 gcc/java/gcj.texi; do
984 [[ -f ${S}/${jfile} ]] || continue
985 sed -i -e 's:rmiregistry:grmiregistry:g' "${S}"/${jfile} ||
986 die "Failed to fixup file ${jfile} for rename to grmiregistry"
987 sed -i -e 's:rmic:grmic:g' "${S}"/${jfile} ||
988 die "Failed to fixup file ${jfile} for rename to grmic"
989 done
990 # 3) Fixup Makefiles to build the changed executable names
991 # These are present in all 3.x versions, and are the important bit
992 # to get gcc to build with the new names.
993 for jfile in libjava/Makefile.am libjava/Makefile.in gcc/java/Make-lang.in; do
994 sed -i -e 's:rmiregistry:grmiregistry:g' "${S}"/${jfile} ||
995 die "Failed to fixup file ${jfile} for rename to grmiregistry"
996 # Careful with rmic on these files; it's also the name of a directory
997 # which should be left unchanged. Replace occurrences of 'rmic$',
998 # 'rmic_' and 'rmic '.
999 sed -i -e 's:rmic\([$_ ]\):grmic\1:g' "${S}"/${jfile} ||
1000 die "Failed to fixup file ${jfile} for rename to grmic"
1001 done
1002}
1003gcc_src_unpack() {
1004 export BRANDING_GCC_PKGVERSION="Gentoo ${GCC_PVR}"
1005
1006 [[ -z ${UCLIBC_VER} ]] && [[ ${CTARGET} == *-uclibc* ]] && die "Sorry, this version does not support uClibc"
1007
1008 gcc_quick_unpack
1009 exclude_gcc_patches
1010
1011 cd "${S}"
1012
1013 if ! use vanilla ; then
1014 if [[ -n ${PATCH_VER} ]] ; then
1015 guess_patch_type_in_dir "${WORKDIR}"/patch
1016 EPATCH_MULTI_MSG="Applying Gentoo patches ..." \
1017 epatch "${WORKDIR}"/patch
1018 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION} p${PATCH_VER}"
1019 fi
1020 if [[ -n ${UCLIBC_VER} ]] ; then
1021 guess_patch_type_in_dir "${WORKDIR}"/uclibc
1022 EPATCH_MULTI_MSG="Applying uClibc patches ..." \
1023 epatch "${WORKDIR}"/uclibc
1024 fi
1025 fi
1026 do_gcc_HTB_patches
1027 do_gcc_SSP_patches
1028 do_gcc_PIE_patches
1029 epatch_user
1030
1031 ${ETYPE}_src_unpack || die "failed to ${ETYPE}_src_unpack"
1032
1033 # protoize don't build on FreeBSD, skip it
1034 ## removed in 4.5, bug #270558 --de.
1035 if [[ ${GCCMAJOR}.${GCCMINOR} < 4.5 ]]; then
1036 if ! is_crosscompile && ! use elibc_FreeBSD ; then
1037 # enable protoize / unprotoize
1038 sed -i -e '/^LANGUAGES =/s:$: proto:' "${S}"/gcc/Makefile.in
1039 fi
1040 fi
1041
1042 fix_files=""
1043 for x in contrib/test_summary libstdc++-v3/scripts/check_survey.in ; do
1044 [[ -e ${x} ]] && fix_files="${fix_files} ${x}"
1045 done
1046 ht_fix_file ${fix_files} */configure *.sh */Makefile.in
1047
1048 if ! is_crosscompile && is_multilib && \
1049 [[ ( $(tc-arch) == "amd64" || $(tc-arch) == "ppc64" ) && -z ${SKIP_MULTILIB_HACK} ]] ; then
1050 disgusting_gcc_multilib_HACK || die "multilib hack failed"
1051 fi
1052
1053 gcc_version_patch
1054 if [[ ${GCCMAJOR}.${GCCMINOR} > 4.0 ]] ; then
1055 if [[ -n ${SNAPSHOT} || -n ${PRERELEASE} ]] ; then
1056 echo ${PV/_/-} > "${S}"/gcc/BASE-VER
1057 fi
1058 fi
1059
1060 # >= gcc-4.3 doesn't bundle ecj.jar, so copy it
1061 if [[ ${GCCMAJOR}.${GCCMINOR} > 4.2 ]] &&
1062 use gcj ; then
1063 cp -pPR "${DISTDIR}/ecj-4.3.jar" "${S}/ecj.jar" || die
1064 fi
1065
1066 # disable --as-needed from being compiled into gcc specs
1067 # natively when using a gcc version < 3.4.4
1068 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14992
1069 if ! tc_version_is_at_least 3.4.4 ; then
1070 sed -i -e s/HAVE_LD_AS_NEEDED/USE_LD_AS_NEEDED/g "${S}"/gcc/config.in
1071 fi
1072
1073 # In gcc 3.3.x and 3.4.x, rename the java bins to gcc-specific names
1074 # in line with gcc-4.
1075 if [[ ${GCCMAJOR} == 3 ]] &&
1076 [[ ${GCCMINOR} -ge 3 ]]
1077 then
1078 do_gcc_rename_java_bins
1079 fi
1080
1081 # Fixup libtool to correctly generate .la files with portage
1082 cd "${S}"
1083 elibtoolize --portage --shallow --no-uclibc
1084
1085 gnuconfig_update
1086
1087 # update configure files
1088 local f
1089 einfo "Fixing misc issues in configure files"
1090 tc_version_is_at_least 4.1 && epatch "${GCC_FILESDIR}"/gcc-configure-texinfo.patch
1091 for f in $(grep -l 'autoconf version 2.13' $(find "${S}" -name configure)) ; do
1092 ebegin " Updating ${f/${S}\/} [LANG]"
1093 patch "${f}" "${GCC_FILESDIR}"/gcc-configure-LANG.patch >& "${T}"/configure-patch.log \
1094 || eerror "Please file a bug about this"
1095 eend $?
1096 done
1097 sed -i 's|A-Za-z0-9|[:alnum:]|g' "${S}"/gcc/*.awk #215828
1098
1099 if [[ -x contrib/gcc_update ]] ; then
1100 einfo "Touching generated files"
1101 ./contrib/gcc_update --touch | \
1102 while read f ; do
1103 einfo " ${f%%...}"
1104 done
1105 fi
1106
1107 disable_multilib_libjava || die "failed to disable multilib java"
1108}
1109
1110gcc-library-configure() {
1111 # multilib support
1112 [[ ${GCC_TARGET_NO_MULTILIB} == "true" ]] \
1113 && confgcc="${confgcc} --disable-multilib" \
1114 || confgcc="${confgcc} --enable-multilib"
1115}
1116
1117gcc-compiler-configure() {
1118 # multilib support
1119 if is_multilib ; then
1120 confgcc="${confgcc} --enable-multilib"
1121 elif [[ ${CTARGET} == *-linux* ]] ; then
1122 confgcc="${confgcc} --disable-multilib"
1123 fi
1124
1125 if tc_version_is_at_least "4.0" ; then
1126 if has mudflap ${IUSE} ; then
1127 confgcc="${confgcc} $(use_enable mudflap libmudflap)"
1128 else
1129 confgcc="${confgcc} --disable-libmudflap"
1130 fi
1131
1132 if want_libssp ; then
1133 confgcc="${confgcc} --enable-libssp"
1134 else
1135 export gcc_cv_libc_provides_ssp=yes
1136 confgcc="${confgcc} --disable-libssp"
1137 fi
1138
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07001139 # If we want hardened support with the newer piepatchset for >=gcc 4.4
1140 if tc_version_is_at_least 4.4 && want_minispecs ; then
1141 confgcc="${confgcc} $(use_enable hardened esp)"
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07001142 fi
1143
1144 if tc_version_is_at_least "4.2" ; then
1145 confgcc="${confgcc} $(use_enable openmp libgomp)"
1146 fi
1147
1148 # enable the cld workaround until we move things to stable.
1149 # by that point, the rest of the software out there should
1150 # have caught up.
1151 if tc_version_is_at_least "4.3" ; then
1152 if ! has ${ARCH} ${KEYWORDS} ; then
1153 confgcc="${confgcc} --enable-cld"
1154 fi
1155 fi
1156
1157 # Stick the python scripts in their own slotted directory
1158 # bug #279252
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07001159 #
1160 # --with-python-dir=DIR
1161 # Specifies where to install the Python modules used for aot-compile. DIR
1162 # should not include the prefix used in installation. For example, if the
1163 # Python modules are to be installed in /usr/lib/python2.5/site-packages,
Raymes Khoury9b521872011-02-03 17:52:58 -08001164 # then –with-python-dir=/lib/python2.5/site-packages should be passed.
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07001165 #
1166 # This should translate into "/share/gcc-data/${CTARGET}/${GCC_CONFIG_VER}/python"
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07001167 if tc_version_is_at_least "4.4" ; then
1168 confgcc="${confgcc} --with-python-dir=${DATAPATH/$PREFIX/}/python"
1169 fi
1170 fi
1171
1172 # GTK+ is preferred over xlib in 3.4.x (xlib is unmaintained
1173 # right now). Much thanks to <csm@gnu.org> for the heads up.
1174 # Travis Tilley <lv@gentoo.org> (11 Jul 2004)
1175 if ! is_gcj ; then
1176 confgcc="${confgcc} --disable-libgcj"
1177 elif use gtk ; then
1178 confgcc="${confgcc} --enable-java-awt=gtk"
1179 fi
1180
1181 case $(tc-arch) in
1182 arm) #264534
1183 local arm_arch="${CTARGET%%-*}"
1184 # Only do this if arm_arch is armv*
1185 if [[ ${arm_arch} == armv* ]] ; then
1186 # Convert armv7{a,r,m} to armv7-{a,r,m}
1187 [[ ${arm_arch} == armv7? ]] && arm_arch=${arm_arch/7/7-}
1188 # Remove endian ('l' / 'eb')
1189 [[ ${arm_arch} == *l ]] && arm_arch=${arm_arch%l}
1190 [[ ${arm_arch} == *eb ]] && arm_arch=${arm_arch%eb}
1191 confgcc="${confgcc} --with-arch=${arm_arch}"
1192 fi
1193
1194 # Enable hardvfp
1195 if [[ ${CTARGET##*-} == *eabi ]] && [[ $(tc-is-hardfloat) == yes ]] && \
1196 tc_version_is_at_least "4.5" ; then
1197 confgcc="${confgcc} --with-float=hard"
1198 fi
1199 ;;
1200 # Add --with-abi flags to set default MIPS ABI
1201 mips)
1202 local mips_abi=""
1203 use n64 && mips_abi="--with-abi=64"
1204 use n32 && mips_abi="--with-abi=n32"
1205 [[ -n ${mips_abi} ]] && confgcc="${confgcc} ${mips_abi}"
1206 ;;
1207 # Default arch for x86 is normally i386, lets give it a bump
1208 # since glibc will do so based on CTARGET anyways
1209 x86)
1210 confgcc="${confgcc} --with-arch=${CTARGET%%-*}"
1211 ;;
1212 # Enable sjlj exceptions for backward compatibility on hppa
1213 hppa)
1214 [[ ${GCCMAJOR} == "3" ]] && confgcc="${confgcc} --enable-sjlj-exceptions"
1215 ;;
1216 esac
1217
1218 GCC_LANG="c"
1219 is_cxx && GCC_LANG="${GCC_LANG},c++"
1220 is_d && GCC_LANG="${GCC_LANG},d"
1221 is_gcj && GCC_LANG="${GCC_LANG},java"
1222 if is_objc || is_objcxx ; then
1223 GCC_LANG="${GCC_LANG},objc"
1224 if tc_version_is_at_least "4.0" ; then
1225 use objc-gc && confgcc="${confgcc} --enable-objc-gc"
1226 fi
1227 is_objcxx && GCC_LANG="${GCC_LANG},obj-c++"
1228 fi
1229 is_treelang && GCC_LANG="${GCC_LANG},treelang"
1230
1231 # fortran support just got sillier! the lang value can be f77 for
1232 # fortran77, f95 for fortran95, or just plain old fortran for the
1233 # currently supported standard depending on gcc version.
1234 is_fortran && GCC_LANG="${GCC_LANG},fortran"
1235 is_f77 && GCC_LANG="${GCC_LANG},f77"
1236 is_f95 && GCC_LANG="${GCC_LANG},f95"
1237
1238 # We do NOT want 'ADA support' in here!
1239 # is_ada && GCC_LANG="${GCC_LANG},ada"
1240
1241 einfo "configuring for GCC_LANG: ${GCC_LANG}"
1242}
1243
1244# Other than the variables described for gcc_setup_variables, the following
1245# will alter tha behavior of gcc_do_configure:
1246#
1247# CTARGET
1248# CBUILD
1249# Enable building for a target that differs from CHOST
1250#
1251# GCC_TARGET_NO_MULTILIB
1252# Disable multilib. Useful when building single library targets.
1253#
1254# GCC_LANG
1255# Enable support for ${GCC_LANG} languages. defaults to just "c"
1256#
1257# Travis Tilley <lv@gentoo.org> (04 Sep 2004)
1258#
1259gcc_do_configure() {
1260 local confgcc
1261
1262 # Set configuration based on path variables
1263 confgcc="${confgcc} \
1264 --prefix=${PREFIX} \
1265 --bindir=${BINPATH} \
1266 --includedir=${INCLUDEPATH} \
1267 --datadir=${DATAPATH} \
1268 --mandir=${DATAPATH}/man \
1269 --infodir=${DATAPATH}/info \
1270 --with-gxx-include-dir=${STDCXX_INCDIR}"
1271 # On Darwin we need libdir to be set in order to get correct install names
1272 # for things like libobjc-gnu, libgcj and libfortran. If we enable it on
1273 # non-Darwin we screw up the behaviour this eclass relies on. We in
1274 # particular need this over --libdir for bug #255315.
1275 [[ ${CHOST} == *-darwin* ]] && \
1276 confgcc="${confgcc} --enable-version-specific-runtime-libs"
1277
1278 # All our cross-compile logic goes here ! woo !
1279 confgcc="${confgcc} --host=${CHOST}"
1280 if is_crosscompile || tc-is-cross-compiler ; then
1281 # Straight from the GCC install doc:
1282 # "GCC has code to correctly determine the correct value for target
1283 # for nearly all native systems. Therefore, we highly recommend you
1284 # not provide a configure target when configuring a native compiler."
1285 confgcc="${confgcc} --target=${CTARGET}"
1286 fi
1287 [[ -n ${CBUILD} ]] && confgcc="${confgcc} --build=${CBUILD}"
1288
1289 # ppc altivec support
1290 confgcc="${confgcc} $(use_enable altivec)"
1291
1292 # gcc has fixed-point arithmetic support in 4.3 for mips targets that can
1293 # significantly increase compile time by several hours. This will allow
1294 # users to control this feature in the event they need the support.
1295 tc_version_is_at_least "4.3" && confgcc="${confgcc} $(use_enable fixed-point)"
1296
1297 # graphite support was added in 4.4, which depends upon external libraries
1298 # for optimizations. This option allows users to determine if they want
1299 # these optimizations and libraries pulled in
1300 tc_version_is_at_least "4.4" && \
1301 confgcc="${confgcc} $(use_with graphite ppl) $(use_with graphite cloog)"
1302
1303 # lto support was added in 4.5, which depends upon elfutils. This allows
1304 # users to enable that option, and pull in the additional library
1305 tc_version_is_at_least "4.5" && \
1306 confgcc="${confgcc} $(use_enable lto)"
1307
1308
1309 [[ $(tc-is-softfloat) == "yes" ]] && confgcc="${confgcc} --with-float=soft"
1310 [[ $(tc-is-hardfloat) == "yes" ]] && confgcc="${confgcc} --with-float=hard"
1311
1312 # Native Language Support
1313 if use nls ; then
1314 confgcc="${confgcc} --enable-nls --without-included-gettext"
1315 else
1316 confgcc="${confgcc} --disable-nls"
1317 fi
1318
1319 # reasonably sane globals (hopefully)
1320 confgcc="${confgcc} \
1321 --with-system-zlib \
1322 --disable-checking \
1323 --disable-werror \
1324 --enable-secureplt"
1325
1326 # etype specific configuration
1327 einfo "running ${ETYPE}-configure"
1328 ${ETYPE}-configure || die
1329
1330 # if not specified, assume we are building for a target that only
1331 # requires C support
1332 GCC_LANG=${GCC_LANG:-c}
1333 confgcc="${confgcc} --enable-languages=${GCC_LANG}"
1334
1335 if is_crosscompile ; then
1336 # When building a stage1 cross-compiler (just C compiler), we have to
1337 # disable a bunch of features or gcc goes boom
1338 local needed_libc=""
1339 case ${CTARGET} in
1340 *-linux) needed_libc=no-fucking-clue;;
1341 *-dietlibc) needed_libc=dietlibc;;
1342 *-elf) needed_libc=newlib;;
1343 *-freebsd*) needed_libc=freebsd-lib;;
1344 *-gnu*) needed_libc=glibc;;
1345 *-klibc) needed_libc=klibc;;
1346 *-uclibc*) needed_libc=uclibc;;
1347 *-cygwin) needed_libc=cygwin;;
1348 mingw*|*-mingw*) needed_libc=mingw-runtime;;
1349 avr) confgcc="${confgcc} --enable-shared --disable-threads";;
1350 esac
1351 if [[ -n ${needed_libc} ]] ; then
1352 if ! has_version ${CATEGORY}/${needed_libc} ; then
1353 confgcc="${confgcc} --disable-shared --disable-threads --without-headers"
1354 elif built_with_use --hidden --missing false ${CATEGORY}/${needed_libc} crosscompile_opts_headers-only ; then
1355 confgcc="${confgcc} --disable-shared --with-sysroot=${PREFIX}/${CTARGET}"
1356 else
1357 confgcc="${confgcc} --with-sysroot=${PREFIX}/${CTARGET}"
1358 fi
1359 fi
1360
1361 if [[ ${GCCMAJOR}.${GCCMINOR} > 4.1 ]] ; then
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07001362 confgcc="${confgcc} --disable-bootstrap"
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07001363 fi
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07001364 else
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07001365 if tc-is-static-only ; then
1366 confgcc="${confgcc} --disable-shared"
1367 else
1368 confgcc="${confgcc} --enable-shared"
1369 fi
1370 case ${CHOST} in
1371 mingw*|*-mingw*|*-cygwin)
1372 confgcc="${confgcc} --enable-threads=win32" ;;
1373 *-mint*)
1374 confgcc="${confgcc} --disable-threads" ;;
1375 *)
1376 confgcc="${confgcc} --enable-threads=posix" ;;
1377 esac
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07001378 fi
1379 [[ ${CTARGET} == *-elf ]] && confgcc="${confgcc} --with-newlib"
1380 # __cxa_atexit is "essential for fully standards-compliant handling of
1381 # destructors", but apparently requires glibc.
1382 if [[ ${CTARGET} == *-uclibc* ]] ; then
1383 confgcc="${confgcc} --disable-__cxa_atexit --enable-target-optspace $(use_enable nptl tls)"
1384 [[ ${GCCMAJOR}.${GCCMINOR} == 3.3 ]] && confgcc="${confgcc} --enable-sjlj-exceptions"
1385 if tc_version_is_at_least 3.4 && [[ ${GCCMAJOR}.${GCCMINOR} < 4.3 ]] ; then
1386 confgcc="${confgcc} --enable-clocale=uclibc"
1387 fi
1388 elif [[ ${CTARGET} == *-gnu* ]] ; then
1389 confgcc="${confgcc} --enable-__cxa_atexit"
1390 confgcc="${confgcc} --enable-clocale=gnu"
1391 elif [[ ${CTARGET} == *-freebsd* ]]; then
1392 confgcc="${confgcc} --enable-__cxa_atexit"
1393 elif [[ ${CTARGET} == *-solaris* ]]; then
1394 confgcc="${confgcc} --enable-__cxa_atexit"
1395 fi
1396 [[ ${GCCMAJOR}.${GCCMINOR} < 3.4 ]] && confgcc="${confgcc} --disable-libunwind-exceptions"
1397
1398 # create a sparc*linux*-{gcc,g++} that can handle -m32 and -m64 (biarch)
1399 if [[ ${CTARGET} == sparc*linux* ]] \
1400 && is_multilib \
1401 && ! is_crosscompile \
1402 && [[ ${GCCMAJOR}.${GCCMINOR} > 4.2 ]]
1403 then
1404 confgcc="${confgcc} --enable-targets=all"
1405 fi
1406
1407 tc_version_is_at_least 4.3 && set -- "$@" \
1408 --with-bugurl=http://bugs.gentoo.org/ \
1409 --with-pkgversion="${BRANDING_GCC_PKGVERSION}"
1410 set -- ${confgcc} "$@" ${EXTRA_ECONF}
1411
1412 # Nothing wrong with a good dose of verbosity
1413 echo
1414 einfo "PREFIX: ${PREFIX}"
1415 einfo "BINPATH: ${BINPATH}"
1416 einfo "LIBPATH: ${LIBPATH}"
1417 einfo "DATAPATH: ${DATAPATH}"
1418 einfo "STDCXX_INCDIR: ${STDCXX_INCDIR}"
1419 echo
1420 einfo "Configuring GCC with: ${@//--/\n\t--}"
1421 echo
1422
1423 # Build in a separate build tree
1424 mkdir -p "${WORKDIR}"/build
1425 pushd "${WORKDIR}"/build > /dev/null
1426
1427 # and now to do the actual configuration
1428 addwrite /dev/zero
1429 echo "${S}"/configure "$@"
1430 "${S}"/configure "$@" || die "failed to run configure"
1431
1432 # return to whatever directory we were in before
1433 popd > /dev/null
1434}
1435
1436# This function accepts one optional argument, the make target to be used.
1437# If ommitted, gcc_do_make will try to guess whether it should use all,
1438# profiledbootstrap, or bootstrap-lean depending on CTARGET and arch. An
1439# example of how to use this function:
1440#
1441# gcc_do_make all-target-libstdc++-v3
1442#
1443# In addition to the target to be used, the following variables alter the
1444# behavior of this function:
1445#
1446# LDFLAGS
1447# Flags to pass to ld
1448#
1449# STAGE1_CFLAGS
1450# CFLAGS to use during stage1 of a gcc bootstrap
1451#
1452# BOOT_CFLAGS
1453# CFLAGS to use during stages 2+3 of a gcc bootstrap.
1454#
1455# Travis Tilley <lv@gentoo.org> (04 Sep 2004)
1456#
1457gcc_do_make() {
1458 # Fix for libtool-portage.patch
1459 local OLDS=${S}
1460 S=${WORKDIR}/build
1461
1462 # Set make target to $1 if passed
1463 [[ -n $1 ]] && GCC_MAKE_TARGET=$1
1464 # default target
1465 if is_crosscompile || tc-is-cross-compiler ; then
1466 # 3 stage bootstrapping doesnt quite work when you cant run the
1467 # resulting binaries natively ^^;
1468 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-all}
1469 else
1470 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-bootstrap-lean}
1471 fi
1472
1473 # the gcc docs state that parallel make isnt supported for the
1474 # profiledbootstrap target, as collisions in profile collecting may occur.
1475 [[ ${GCC_MAKE_TARGET} == "profiledbootstrap" ]] && export MAKEOPTS="${MAKEOPTS} -j1"
1476
1477 # boundschecking seems to introduce parallel build issues
1478 want_boundschecking && export MAKEOPTS="${MAKEOPTS} -j1"
1479
1480 if [[ ${GCC_MAKE_TARGET} == "all" ]] ; then
1481 STAGE1_CFLAGS=${STAGE1_CFLAGS-"${CFLAGS}"}
1482 elif [[ $(gcc-version) == "3.4" && ${GCC_BRANCH_VER} == "3.4" ]] && gcc-specs-ssp ; then
1483 # See bug #79852
1484 STAGE1_CFLAGS=${STAGE1_CFLAGS-"-O2"}
1485 else
1486 STAGE1_CFLAGS=${STAGE1_CFLAGS-"-O"}
1487 fi
1488
1489 if is_crosscompile; then
1490 # In 3.4, BOOT_CFLAGS is never used on a crosscompile...
1491 # but I'll leave this in anyways as someone might have had
1492 # some reason for putting it in here... --eradicator
1493 BOOT_CFLAGS=${BOOT_CFLAGS-"-O2"}
1494 else
1495 # we only want to use the system's CFLAGS if not building a
1496 # cross-compiler.
1497 BOOT_CFLAGS=${BOOT_CFLAGS-"$(get_abi_CFLAGS) ${CFLAGS}"}
1498 fi
1499
1500 pushd "${WORKDIR}"/build
1501
1502 emake \
1503 LDFLAGS="${LDFLAGS}" \
1504 STAGE1_CFLAGS="${STAGE1_CFLAGS}" \
1505 LIBPATH="${LIBPATH}" \
1506 BOOT_CFLAGS="${BOOT_CFLAGS}" \
1507 ${GCC_MAKE_TARGET} \
1508 || die "emake failed with ${GCC_MAKE_TARGET}"
1509
1510 if ! is_crosscompile && ! use nocxx && use doc ; then
1511 if type -p doxygen > /dev/null ; then
1512 if tc_version_is_at_least 4.3 ; then
1513 cd "${CTARGET}"/libstdc++-v3/doc
1514 emake doc-man-doxygen || ewarn "failed to make docs"
1515 elif tc_version_is_at_least 3.0 ; then
1516 cd "${CTARGET}"/libstdc++-v3
1517 emake doxygen-man || ewarn "failed to make docs"
1518 fi
1519 else
1520 ewarn "Skipping libstdc++ manpage generation since you don't have doxygen installed"
1521 fi
1522 fi
1523
1524 popd
1525}
1526
1527# This function will add ${GCC_CONFIG_VER} to the names of all shared libraries in the
1528# directory specified to avoid filename collisions between multiple slotted
1529# non-versioned gcc targets. If no directory is specified, it is assumed that
1530# you want -all- shared objects to have ${GCC_CONFIG_VER} added. Example
1531#
1532# add_version_to_shared ${D}/usr/$(get_libdir)
1533#
1534# Travis Tilley <lv@gentoo.org> (05 Sep 2004)
1535#
1536add_version_to_shared() {
1537 local sharedlib sharedlibdir
1538 [[ -z $1 ]] \
1539 && sharedlibdir=${D} \
1540 || sharedlibdir=$1
1541
1542 for sharedlib in $(find ${sharedlibdir} -name *.so.*) ; do
1543 if [[ ! -L ${sharedlib} ]] ; then
1544 einfo "Renaming `basename "${sharedlib}"` to `basename "${sharedlib/.so*/}-${GCC_CONFIG_VER}.so.${sharedlib/*.so./}"`"
1545 mv "${sharedlib}" "${sharedlib/.so*/}-${GCC_CONFIG_VER}.so.${sharedlib/*.so./}" \
1546 || die
1547 pushd `dirname "${sharedlib}"` > /dev/null || die
1548 ln -sf "`basename "${sharedlib/.so*/}-${GCC_CONFIG_VER}.so.${sharedlib/*.so./}"`" \
1549 "`basename "${sharedlib}"`" || die
1550 popd > /dev/null || die
1551 fi
1552 done
1553}
1554
1555# This is mostly a stub function to be overwritten in an ebuild
1556gcc_do_filter_flags() {
1557 strip-flags
1558
1559 # In general gcc does not like optimization, and add -O2 where
1560 # it is safe. This is especially true for gcc 3.3 + 3.4
1561 replace-flags -O? -O2
1562
1563 # ... sure, why not?
1564 strip-unsupported-flags
1565
1566 # dont want to funk ourselves
1567 filter-flags '-mabi*' -m31 -m32 -m64
1568
1569 case ${GCC_BRANCH_VER} in
1570 3.2|3.3)
1571 replace-cpu-flags k8 athlon64 opteron i686 x86-64
1572 replace-cpu-flags pentium-m pentium3m pentium3
1573 case $(tc-arch) in
1574 amd64|x86) filter-flags '-mtune=*' ;;
1575 # in gcc 3.3 there is a bug on ppc64 where if -mcpu is used,
1576 # the compiler wrongly assumes a 32bit target
1577 ppc64) filter-flags "-mcpu=*";;
1578 esac
1579 case $(tc-arch) in
1580 amd64) replace-cpu-flags core2 nocona;;
1581 x86) replace-cpu-flags core2 prescott;;
1582 esac
1583
1584 replace-cpu-flags G3 750
1585 replace-cpu-flags G4 7400
1586 replace-cpu-flags G5 7400
1587
1588 # XXX: should add a sed or something to query all supported flags
1589 # from the gcc source and trim everything else ...
1590 filter-flags -f{no-,}unit-at-a-time -f{no-,}web -mno-tls-direct-seg-refs
1591 filter-flags -f{no-,}stack-protector{,-all}
1592 filter-flags -fvisibility-inlines-hidden -fvisibility=hidden
1593 ;;
1594 3.4|4.*)
1595 case $(tc-arch) in
1596 x86|amd64) filter-flags '-mcpu=*';;
1597 *-macos)
1598 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25127
1599 [[ ${GCC_BRANCH_VER} == 4.0 || ${GCC_BRANCH_VER} == 4.1 ]] && \
1600 filter-flags '-mcpu=*' '-march=*' '-mtune=*'
1601 ;;
1602 esac
1603 ;;
1604 esac
1605
1606 # Compile problems with these (bug #6641 among others)...
1607 #filter-flags "-fno-exceptions -fomit-frame-pointer -fforce-addr"
1608
1609 # CFLAGS logic (verified with 3.4.3):
1610 # CFLAGS:
1611 # This conflicts when creating a crosscompiler, so set to a sane
1612 # default in this case:
1613 # used in ./configure and elsewhere for the native compiler
1614 # used by gcc when creating libiberty.a
1615 # used by xgcc when creating libstdc++ (and probably others)!
1616 # this behavior should be removed...
1617 #
1618 # CXXFLAGS:
1619 # used by xgcc when creating libstdc++
1620 #
1621 # STAGE1_CFLAGS (not used in creating a crosscompile gcc):
1622 # used by ${CHOST}-gcc for building stage1 compiler
1623 #
1624 # BOOT_CFLAGS (not used in creating a crosscompile gcc):
1625 # used by xgcc for building stage2/3 compiler
1626
1627 if is_crosscompile ; then
1628 # Set this to something sane for both native and target
1629 CFLAGS="-O2 -pipe"
1630
1631 local VAR="CFLAGS_"${CTARGET//-/_}
1632 CXXFLAGS=${!VAR}
1633 fi
1634
1635 export GCJFLAGS=${GCJFLAGS:-${CFLAGS}}
1636}
1637
1638gcc_src_compile() {
1639 gcc_do_filter_flags
1640 einfo "CFLAGS=\"${CFLAGS}\""
1641 einfo "CXXFLAGS=\"${CXXFLAGS}\""
1642
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07001643 # For hardened gcc 4.3 piepatchset to build the hardened specs
1644 # file (build.specs) to use when building gcc.
1645 if ! tc_version_is_at_least 4.4 && want_minispecs ; then
1646 setup_minispecs_gcc_build_specs
1647 fi
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07001648 # Build in a separate build tree
1649 mkdir -p "${WORKDIR}"/build
1650 pushd "${WORKDIR}"/build > /dev/null
1651
1652 # Install our pre generated manpages if we do not have perl ...
1653 [[ ! -x /usr/bin/perl ]] && [[ -n ${MAN_VER} ]] && \
1654 unpack gcc-${MAN_VER}-manpages.tar.bz2
1655
1656 einfo "Configuring ${PN} ..."
1657 gcc_do_configure
1658
1659 touch "${S}"/gcc/c-gperf.h
1660
1661 # Do not make manpages if we do not have perl ...
1662 [[ ! -x /usr/bin/perl ]] \
1663 && find "${WORKDIR}"/build -name '*.[17]' | xargs touch
1664
1665 einfo "Compiling ${PN} ..."
1666 gcc_do_make ${GCC_MAKE_TARGET}
1667
1668 # Do not create multiple specs files for PIE+SSP if boundschecking is in
1669 # USE, as we disable PIE+SSP when it is.
1670 if [[ ${ETYPE} == "gcc-compiler" ]] && want_split_specs && ! want_minispecs; then
1671 split_out_specs_files || die "failed to split out specs"
1672 fi
1673
1674 popd > /dev/null
1675}
1676
1677gcc_src_test() {
1678 cd "${WORKDIR}"/build
1679 emake -j1 -k check || ewarn "check failed and that sucks :("
1680}
1681
1682gcc-library_src_install() {
1683 # Do the 'make install' from the build directory
1684 cd "${WORKDIR}"/build
1685 S=${WORKDIR}/build \
1686 emake -j1 \
1687 DESTDIR="${D}" \
1688 prefix=${PREFIX} \
1689 bindir=${BINPATH} \
1690 includedir=${LIBPATH}/include \
1691 datadir=${DATAPATH} \
1692 mandir=${DATAPATH}/man \
1693 infodir=${DATAPATH}/info \
1694 LIBPATH="${LIBPATH}" \
1695 ${GCC_INSTALL_TARGET} || die
1696
1697 if [[ ${GCC_LIB_COMPAT_ONLY} == "true" ]] ; then
1698 rm -rf "${D}"${INCLUDEPATH}
1699 rm -rf "${D}"${DATAPATH}
1700 pushd "${D}"${LIBPATH}/
1701 rm *.a *.la *.so
1702 popd
1703 fi
1704
1705 if [[ -n ${GCC_LIB_USE_SUBDIR} ]] ; then
1706 mkdir -p "${WORKDIR}"/${GCC_LIB_USE_SUBDIR}/
1707 mv "${D}"${LIBPATH}/* "${WORKDIR}"/${GCC_LIB_USE_SUBDIR}/
1708 mv "${WORKDIR}"/${GCC_LIB_USE_SUBDIR}/ "${D}"${LIBPATH}
1709
1710 dodir /etc/env.d
1711 echo "LDPATH=\"${LIBPATH}/${GCC_LIB_USE_SUBDIR}/\"" >> "${D}"/etc/env.d/99${PN}
1712 fi
1713
1714 if [[ ${GCC_VAR_TYPE} == "non-versioned" ]] ; then
1715 # if we're not using versioned directories, we need to use versioned
1716 # filenames.
1717 add_version_to_shared
1718 fi
1719}
1720
1721gcc-compiler_src_install() {
1722 local x=
1723
1724 cd "${WORKDIR}"/build
1725 # Do allow symlinks in private gcc include dir as this can break the build
1726 find gcc/include*/ -type l -print0 | xargs -0 rm -f
1727 # Remove generated headers, as they can cause things to break
1728 # (ncurses, openssl, etc).
1729 for x in $(find gcc/include*/ -name '*.h') ; do
1730 grep -q 'It has been auto-edited by fixincludes from' "${x}" \
1731 && rm -f "${x}"
1732 done
1733 # Do the 'make install' from the build directory
1734 S=${WORKDIR}/build \
1735 emake -j1 DESTDIR="${D}" install || die
1736 # Punt some tools which are really only useful while building gcc
1737 find "${D}" -name install-tools -prune -type d -exec rm -rf "{}" \;
1738 # This one comes with binutils
1739 find "${D}" -name libiberty.a -exec rm -f "{}" \;
1740
1741 # Move the libraries to the proper location
1742 gcc_movelibs
1743
1744 # Basic sanity check
1745 if ! is_crosscompile ; then
1746 local EXEEXT
1747 eval $(grep ^EXEEXT= "${WORKDIR}"/build/gcc/config.log)
1748 [[ -r ${D}${BINPATH}/gcc${EXEEXT} ]] || die "gcc not found in ${D}"
1749 fi
1750
1751 dodir /etc/env.d/gcc
1752 create_gcc_env_entry
1753
1754 if want_split_specs ; then
1755 if use hardened ; then
1756 create_gcc_env_entry vanilla
1757 fi
1758 ! use hardened && hardened_gcc_works && create_gcc_env_entry hardened
1759 if hardened_gcc_works || hardened_gcc_works pie ; then
1760 create_gcc_env_entry hardenednossp
1761 fi
1762 if hardened_gcc_works || hardened_gcc_works ssp ; then
1763 create_gcc_env_entry hardenednopie
1764 fi
1765 create_gcc_env_entry hardenednopiessp
1766
1767 insinto ${LIBPATH}
1768 doins "${WORKDIR}"/build/*.specs || die "failed to install specs"
1769 fi
1770 # Setup the gcc_env_entry for hardened gcc 4 with minispecs
1771 if want_minispecs ; then
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07001772 copy_minispecs_gcc_specs
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07001773 fi
1774 # Make sure we dont have stuff lying around that
1775 # can nuke multiple versions of gcc
1776
1777 gcc_slot_java
1778
1779 # Move <cxxabi.h> to compiler-specific directories
1780 [[ -f ${D}${STDCXX_INCDIR}/cxxabi.h ]] && \
1781 mv -f "${D}"${STDCXX_INCDIR}/cxxabi.h "${D}"${LIBPATH}/include/
1782
1783 # These should be symlinks
1784 dodir /usr/bin
1785 cd "${D}"${BINPATH}
1786 for x in cpp gcc g++ c++ g77 gcj gcjh gfortran ; do
1787 # For some reason, g77 gets made instead of ${CTARGET}-g77...
1788 # this should take care of that
1789 [[ -f ${x} ]] && mv ${x} ${CTARGET}-${x}
1790
1791 if [[ -f ${CTARGET}-${x} ]] && ! is_crosscompile ; then
1792 ln -sf ${CTARGET}-${x} ${x}
1793
1794 # Create version-ed symlinks
1795 dosym ${BINPATH}/${CTARGET}-${x} \
1796 /usr/bin/${CTARGET}-${x}-${GCC_CONFIG_VER}
1797 dosym ${BINPATH}/${CTARGET}-${x} \
1798 /usr/bin/${x}-${GCC_CONFIG_VER}
1799 fi
1800
1801 if [[ -f ${CTARGET}-${x}-${GCC_CONFIG_VER} ]] ; then
1802 rm -f ${CTARGET}-${x}-${GCC_CONFIG_VER}
1803 ln -sf ${CTARGET}-${x} ${CTARGET}-${x}-${GCC_CONFIG_VER}
1804 fi
1805 done
1806
1807 # I do not know if this will break gcj stuff, so I'll only do it for
1808 # objc for now; basically "ffi.h" is the correct file to include,
1809 # but it gets installed in .../GCCVER/include and yet it does
1810 # "#include <ffitarget.h>" which (correctly, as it's an "extra" file)
1811 # is installed in .../GCCVER/include/libffi; the following fixes
1812 # ffi.'s include of ffitarget.h - Armando Di Cianno <fafhrd@gentoo.org>
1813 if [[ -d ${D}${LIBPATH}/include/libffi ]] ; then
1814 mv -i "${D}"${LIBPATH}/include/libffi/* "${D}"${LIBPATH}/include || die
1815 rm -r "${D}"${LIBPATH}/include/libffi || die
1816 fi
1817
1818 # Now do the fun stripping stuff
1819 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${BINPATH}"
1820 env RESTRICT="" CHOST=${CTARGET} prepstrip "${D}${LIBPATH}"
1821 # gcc used to install helper binaries in lib/ but then moved to libexec/
1822 [[ -d ${D}${PREFIX}/libexec/gcc ]] && \
1823 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}"
1824
1825 cd "${S}"
1826 if is_crosscompile; then
1827 rm -rf "${D}"/usr/share/{man,info}
1828 rm -rf "${D}"${DATAPATH}/{man,info}
1829 else
1830 local cxx_mandir=${WORKDIR}/build/${CTARGET}/libstdc++-v3/docs/doxygen/man
1831 if [[ -d ${cxx_mandir} ]] ; then
1832 # clean bogus manpages #113902
1833 find "${cxx_mandir}" -name '*_build_*' -exec rm {} \;
1834 cp -r "${cxx_mandir}"/man? "${D}/${DATAPATH}"/man/
1835 fi
1836 has noinfo ${FEATURES} \
1837 && rm -r "${D}/${DATAPATH}"/info \
1838 || prepinfo "${DATAPATH}"
1839 has noman ${FEATURES} \
1840 && rm -r "${D}/${DATAPATH}"/man \
1841 || prepman "${DATAPATH}"
1842 fi
1843 # prune empty dirs left behind
1844 for x in 1 2 3 4 ; do
1845 find "${D}" -type d -exec rmdir "{}" \; >& /dev/null
1846 done
1847
1848 # install testsuite results
1849 if use test; then
1850 docinto testsuite
1851 find "${WORKDIR}"/build -type f -name "*.sum" -print0 | xargs -0 dodoc
1852 find "${WORKDIR}"/build -type f -path "*/testsuite/*.log" -print0 \
1853 | xargs -0 dodoc
1854 fi
1855
1856 # Rather install the script, else portage with changing $FILESDIR
1857 # between binary and source package borks things ....
1858 if ! is_crosscompile ; then
1859 insinto "${DATAPATH}"
1860 if tc_version_is_at_least 4.0 ; then
1861 newins "${GCC_FILESDIR}"/awk/fixlafiles.awk-no_gcc_la fixlafiles.awk || die
1862 find "${D}/${LIBPATH}" -name libstdc++.la -type f -exec rm "{}" \;
1863 else
1864 doins "${GCC_FILESDIR}"/awk/fixlafiles.awk || die
1865 fi
1866 exeinto "${DATAPATH}"
1867 doexe "${GCC_FILESDIR}"/fix_libtool_files.sh || die
1868 doexe "${GCC_FILESDIR}"/c{89,99} || die
1869 fi
1870
1871 # use gid of 0 because some stupid ports don't have
1872 # the group 'root' set to gid 0
1873 chown -R root:0 "${D}"${LIBPATH}
1874
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07001875 # Move pretty-printers to gdb datadir to shut ldconfig up
1876 gdbdir=/usr/share/gdb/auto-load
1877 for module in $(find "${D}" -iname "*-gdb.py" -print); do
1878 insinto ${gdbdir}/$(dirname "${module/${D}/}" | \
1879 sed -e "s:/lib/:/$(get_libdir)/:g")
1880 doins "${module}"
1881 rm "${module}"
1882 done
1883}
1884
1885gcc_slot_java() {
1886 local x
1887
1888 # Move Java headers to compiler-specific dir
1889 for x in "${D}"${PREFIX}/include/gc*.h "${D}"${PREFIX}/include/j*.h ; do
1890 [[ -f ${x} ]] && mv -f "${x}" "${D}"${LIBPATH}/include/
1891 done
1892 for x in gcj gnu java javax org ; do
1893 if [[ -d ${D}${PREFIX}/include/${x} ]] ; then
1894 dodir /${LIBPATH}/include/${x}
1895 mv -f "${D}"${PREFIX}/include/${x}/* "${D}"${LIBPATH}/include/${x}/
1896 rm -rf "${D}"${PREFIX}/include/${x}
1897 fi
1898 done
1899
1900 if [[ -d ${D}${PREFIX}/lib/security ]] || [[ -d ${D}${PREFIX}/$(get_libdir)/security ]] ; then
1901 dodir /${LIBPATH}/security
1902 mv -f "${D}"${PREFIX}/lib*/security/* "${D}"${LIBPATH}/security
1903 rm -rf "${D}"${PREFIX}/lib*/security
1904 fi
1905
1906 # Move libgcj.spec to compiler-specific directories
1907 [[ -f ${D}${PREFIX}/lib/libgcj.spec ]] && \
1908 mv -f "${D}"${PREFIX}/lib/libgcj.spec "${D}"${LIBPATH}/libgcj.spec
1909
1910 # SLOT up libgcj.pc (and let gcc-config worry about links)
1911 local libgcj=$(find "${D}"${PREFIX}/lib/pkgconfig/ -name 'libgcj*.pc')
1912 if [[ -n ${libgcj} ]] ; then
1913 sed -i "/^libdir=/s:=.*:=${LIBPATH}:" "${libgcj}"
1914 mv "${libgcj}" "${D}"/usr/lib/pkgconfig/libgcj-${GCC_PV}.pc || die
1915 fi
1916
1917 # Rename jar because it could clash with Kaffe's jar if this gcc is
1918 # primary compiler (aka don't have the -<version> extension)
1919 cd "${D}"${BINPATH}
1920 [[ -f jar ]] && mv -f jar gcj-jar
1921}
1922
1923# Move around the libs to the right location. For some reason,
1924# when installing gcc, it dumps internal libraries into /usr/lib
1925# instead of the private gcc lib path
1926gcc_movelibs() {
1927 # older versions of gcc did not support --print-multi-os-directory
1928 tc_version_is_at_least 3.0 || return 0
1929
1930 local multiarg removedirs=""
1931 for multiarg in $($(XGCC) -print-multi-lib) ; do
1932 multiarg=${multiarg#*;}
1933 multiarg=${multiarg//@/ -}
1934
1935 local OS_MULTIDIR=$($(XGCC) ${multiarg} --print-multi-os-directory)
1936 local MULTIDIR=$($(XGCC) ${multiarg} --print-multi-directory)
1937 local TODIR=${D}${LIBPATH}/${MULTIDIR}
1938 local FROMDIR=
1939
1940 [[ -d ${TODIR} ]] || mkdir -p ${TODIR}
1941
1942 for FROMDIR in \
1943 ${LIBPATH}/${OS_MULTIDIR} \
1944 ${LIBPATH}/../${MULTIDIR} \
1945 ${PREFIX}/lib/${OS_MULTIDIR} \
1946 ${PREFIX}/${CTARGET}/lib/${OS_MULTIDIR} \
1947 ${PREFIX}/lib/${MULTIDIR}
1948 do
1949 removedirs="${removedirs} ${FROMDIR}"
1950 FROMDIR=${D}${FROMDIR}
1951 if [[ ${FROMDIR} != "${TODIR}" && -d ${FROMDIR} ]] ; then
1952 local files=$(find "${FROMDIR}" -maxdepth 1 ! -type d 2>/dev/null)
1953 if [[ -n ${files} ]] ; then
1954 mv ${files} "${TODIR}"
1955 fi
1956 fi
1957 done
1958 fix_libtool_libdir_paths "${LIBPATH}/${MULTIDIR}"
1959 done
1960
1961 # We remove directories separately to avoid this case:
1962 # mv SRC/lib/../lib/*.o DEST
1963 # rmdir SRC/lib/../lib/
1964 # mv SRC/lib/../lib32/*.o DEST # Bork
1965 for FROMDIR in ${removedirs} ; do
1966 rmdir "${D}"${FROMDIR} >& /dev/null
1967 done
1968 find "${D}" -type d | xargs rmdir >& /dev/null
1969}
1970
1971#----<< src_* >>----
1972
1973#---->> unorganized crap in need of refactoring follows
1974
1975# gcc_quick_unpack will unpack the gcc tarball and patches in a way that is
1976# consistant with the behavior of get_gcc_src_uri. The only patch it applies
1977# itself is the branch update if present.
1978#
1979# Travis Tilley <lv@gentoo.org> (03 Sep 2004)
1980#
1981gcc_quick_unpack() {
1982 pushd "${WORKDIR}" > /dev/null
1983 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
1984 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
1985 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
1986 export PP_GCC_VER=${PP_GCC_VER:-${GCC_RELEASE_VER}}
1987 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
1988 export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}}
1989
1990 if [[ -n ${GCC_A_FAKEIT} ]] ; then
1991 unpack ${GCC_A_FAKEIT}
1992 elif [[ -n ${PRERELEASE} ]] ; then
1993 unpack gcc-${PRERELEASE}.tar.bz2
1994 elif [[ -n ${SNAPSHOT} ]] ; then
1995 unpack gcc-${SNAPSHOT}.tar.bz2
1996 else
1997 unpack gcc-${GCC_RELEASE_VER}.tar.bz2
1998 # We want branch updates to be against a release tarball
1999 if [[ -n ${BRANCH_UPDATE} ]] ; then
2000 pushd "${S}" > /dev/null
2001 epatch "${DISTDIR}"/gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2
2002 popd > /dev/null
2003 fi
2004 fi
2005
2006 if [[ -n ${D_VER} ]] && use d ; then
2007 pushd "${S}"/gcc > /dev/null
2008 unpack gdc-${D_VER}-src.tar.bz2
2009 cd ..
2010 ebegin "Adding support for the D language"
2011 ./gcc/d/setup-gcc.sh >& "${T}"/dgcc.log
2012 if ! eend $? ; then
2013 eerror "The D gcc package failed to apply"
2014 eerror "Please include this log file when posting a bug report:"
2015 eerror " ${T}/dgcc.log"
2016 die "failed to include the D language"
2017 fi
2018 popd > /dev/null
2019 fi
2020
2021 [[ -n ${PATCH_VER} ]] && \
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07002022 unpack gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}_${COST_SUFFIX}.tar.bz2
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07002023
2024 [[ -n ${UCLIBC_VER} ]] && \
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07002025 unpack gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}_${COST_SUFFIX}.tar.bz2
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07002026
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07002027 if want_ssp ; then
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07002028 if [[ -n ${PP_FVER} ]] ; then
2029 # The gcc 3.4 propolice versions are meant to be unpacked to ${S}
2030 pushd "${S}" > /dev/null
2031 unpack protector-${PP_FVER}.tar.gz
2032 popd > /dev/null
2033 else
2034 unpack gcc-${PP_GCC_VER}-ssp-${PP_VER}.tar.bz2
2035 fi
2036 fi
2037
2038 if want_pie ; then
2039 if [[ -n ${PIE_CORE} ]] ; then
2040 unpack ${PIE_CORE}
2041 else
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07002042 unpack gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}_${COST_SUFFIX}.tar.bz2
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07002043 fi
2044 [[ -n ${SPECS_VER} ]] && \
2045 unpack gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2
2046 fi
2047
2048 want_boundschecking && \
2049 unpack "bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
2050
2051 popd > /dev/null
2052}
2053
2054# Exclude any unwanted patches, as specified by the following variables:
2055#
2056# GENTOO_PATCH_EXCLUDE
2057# List of filenames, relative to ${WORKDIR}/patch/
2058#
2059# PIEPATCH_EXCLUDE
2060# List of filenames, relative to ${WORKDIR}/piepatch/
2061#
2062# Travis Tilley <lv@gentoo.org> (03 Sep 2004)
2063#
2064exclude_gcc_patches() {
2065 local i
2066 for i in ${GENTOO_PATCH_EXCLUDE} ; do
2067 if [[ -f ${WORKDIR}/patch/${i} ]] ; then
2068 einfo "Excluding patch ${i}"
2069 rm -f "${WORKDIR}"/patch/${i} || die "failed to delete ${i}"
2070 fi
2071 done
2072 for i in ${PIEPATCH_EXCLUDE} ; do
2073 if [[ -f ${WORKDIR}/piepatch/${i} ]] ; then
2074 einfo "Excluding piepatch ${i}"
2075 rm -f "${WORKDIR}"/piepatch/${i} || die "failed to delete ${i}"
2076 fi
2077 done
2078}
2079
2080# Try to apply some stub patches so that gcc won't error out when
2081# passed parameters like -fstack-protector but no ssp is found
2082do_gcc_stub() {
2083 local v stub_patch=""
2084 for v in ${GCC_RELEASE_VER} ${GCC_BRANCH_VER} ; do
2085 stub_patch=${GCC_FILESDIR}/stubs/gcc-${v}-$1-stub.patch
2086 if [[ -e ${stub_patch} ]] && ! use vanilla ; then
2087 EPATCH_SINGLE_MSG="Applying stub patch for $1 ..." \
2088 epatch "${stub_patch}"
2089 return 0
2090 fi
2091 done
2092}
2093
2094do_gcc_HTB_patches() {
2095 if ! want_boundschecking || \
2096 (want_ssp && [[ ${HTB_EXCLUSIVE} == "true" ]])
2097 then
2098 do_gcc_stub htb
2099 return 0
2100 fi
2101
2102 # modify the bounds checking patch with a regression patch
2103 epatch "${WORKDIR}/bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch"
2104 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, HTB-${HTB_GCC_VER}-${HTB_VER}"
2105}
2106
2107# patch in ProPolice Stack Smashing protection
2108do_gcc_SSP_patches() {
2109 # PARISC has no love ... it's our stack :(
2110 if [[ $(tc-arch) == "hppa" ]] || \
2111 ! want_ssp || \
2112 (want_boundschecking && [[ ${HTB_EXCLUSIVE} == "true" ]])
2113 then
2114 do_gcc_stub ssp
2115 return 0
2116 fi
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07002117
2118 local ssppatch
2119 local sspdocs
2120
2121 if [[ -n ${PP_FVER} ]] ; then
2122 # Etoh keeps changing where files are and what the patch is named
2123 if tc_version_is_at_least 3.4.1 ; then
2124 # >3.4.1 uses version in patch name, and also includes docs
2125 ssppatch="${S}/gcc_${PP_VER}.dif"
2126 sspdocs="yes"
2127 elif tc_version_is_at_least 3.4.0 ; then
2128 # >3.4 put files where they belong and 3_4 uses old patch name
2129 ssppatch="${S}/protector.dif"
2130 sspdocs="no"
2131 elif tc_version_is_at_least 3.2.3 ; then
2132 # earlier versions have no directory structure or docs
2133 mv "${S}"/protector.{c,h} "${S}"/gcc
2134 ssppatch="${S}/protector.dif"
2135 sspdocs="no"
2136 fi
2137 else
2138 # Just start packaging the damn thing ourselves
2139 mv "${WORKDIR}"/ssp/protector.{c,h} "${S}"/gcc/
2140 ssppatch=${WORKDIR}/ssp/gcc-${PP_GCC_VER}-ssp.patch
2141 # allow boundschecking and ssp to get along
2142 (want_boundschecking && [[ -e ${WORKDIR}/ssp/htb-ssp.patch ]]) \
2143 && patch -s "${ssppatch}" "${WORKDIR}"/ssp/htb-ssp.patch
2144 fi
2145
2146 [[ -z ${ssppatch} ]] && die "Sorry, SSP is not supported in this version"
2147 epatch ${ssppatch}
2148
2149 if [[ ${PN} == "gcc" && ${sspdocs} == "no" ]] ; then
2150 epatch "${GCC_FILESDIR}"/pro-police-docs.patch
2151 fi
2152
2153 # Don't build crtbegin/end with ssp
2154 sed -e 's|^CRTSTUFF_CFLAGS = |CRTSTUFF_CFLAGS = -fno-stack-protector |'\
2155 -i gcc/Makefile.in || die "Failed to update crtstuff!"
2156
2157 # if gcc in a stage3 defaults to ssp, is version 3.4.0 and a stage1 is built
2158 # the build fails building timevar.o w/:
2159 # cc1: stack smashing attack in function ix86_split_to_parts()
2160 if use build && tc_version_is_at_least 3.4.0 ; then
2161 if gcc -dumpspecs | grep -q "fno-stack-protector:" ; then
2162 epatch "${GCC_FILESDIR}"/3.4.0/gcc-3.4.0-cc1-no-stack-protector.patch
2163 fi
2164 fi
2165
2166 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, ssp-${PP_FVER:-${PP_GCC_VER}-${PP_VER}}"
2167 if want_libssp ; then
2168 update_gcc_for_libssp
2169 else
2170 update_gcc_for_libc_ssp
2171 fi
2172
2173 # Don't build libgcc with ssp
2174 sed -e 's|^\(LIBGCC2_CFLAGS.*\)$|\1 -fno-stack-protector|' \
2175 -i gcc/Makefile.in || die "Failed to update gcc!"
2176}
2177
2178# If glibc or uclibc has been patched to provide the necessary symbols itself,
2179# then lets use those for SSP instead of libgcc.
2180update_gcc_for_libc_ssp() {
2181 if libc_has_ssp ; then
2182 einfo "Updating gcc to use SSP from libc ..."
2183 sed -e 's|^\(LIBGCC2_CFLAGS.*\)$|\1 -D_LIBC_PROVIDES_SSP_|' \
2184 -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!"
2185 fi
2186}
2187
2188# a split out non-libc non-libgcc ssp requires additional spec logic changes
2189update_gcc_for_libssp() {
2190 einfo "Updating gcc to use SSP from libssp..."
2191 sed -e 's|^\(INTERNAL_CFLAGS.*\)$|\1 -D_LIBSSP_PROVIDES_SSP_|' \
2192 -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!"
2193}
2194
2195# do various updates to PIE logic
2196do_gcc_PIE_patches() {
2197 if ! want_pie || \
2198 (want_boundschecking && [[ ${HTB_EXCLUSIVE} == "true" ]])
2199 then
2200 return 0
2201 fi
2202
2203 want_boundschecking \
2204 && rm -f "${WORKDIR}"/piepatch/*/*-boundschecking-no.patch* \
2205 || rm -f "${WORKDIR}"/piepatch/*/*-boundschecking-yes.patch*
2206
2207 use vanilla && return 0
2208
2209 if tc_version_is_at_least 4.3.2; then
2210 guess_patch_type_in_dir "${WORKDIR}"/piepatch/
2211 EPATCH_MULTI_MSG="Applying pie patches ..." \
2212 epatch "${WORKDIR}"/piepatch/
2213 else
2214 guess_patch_type_in_dir "${WORKDIR}"/piepatch/upstream
2215
2216 # corrects startfile/endfile selection and shared/static/pie flag usage
2217 EPATCH_MULTI_MSG="Applying upstream pie patches ..." \
2218 epatch "${WORKDIR}"/piepatch/upstream
2219 # adds non-default pie support (rs6000)
2220 EPATCH_MULTI_MSG="Applying non-default pie patches ..." \
2221 epatch "${WORKDIR}"/piepatch/nondef
2222 # adds default pie support (rs6000 too) if DEFAULT_PIE[_SSP] is defined
2223 EPATCH_MULTI_MSG="Applying default pie patches ..." \
2224 epatch "${WORKDIR}"/piepatch/def
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07002225 fi
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07002226 # we want to be able to control the pie patch logic via something other
2227 # than ALL_CFLAGS...
2228 sed -e '/^ALL_CFLAGS/iHARD_CFLAGS = ' \
2229 -e 's|^ALL_CFLAGS = |ALL_CFLAGS = $(HARD_CFLAGS) |' \
2230 -i "${S}"/gcc/Makefile.in
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07002231
2232 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, pie-${PIE_VER}"
2233}
2234
2235should_we_gcc_config() {
2236 # we always want to run gcc-config if we're bootstrapping, otherwise
2237 # we might get stuck with the c-only stage1 compiler
2238 use bootstrap && return 0
2239 use build && return 0
2240
2241 # if the current config is invalid, we definitely want a new one
2242 # Note: due to bash quirkiness, the following must not be 1 line
2243 local curr_config
2244 curr_config=$(env -i ROOT="${ROOT}" gcc-config -c ${CTARGET} 2>&1) || return 0
2245
2246 # if the previously selected config has the same major.minor (branch) as
2247 # the version we are installing, then it will probably be uninstalled
2248 # for being in the same SLOT, make sure we run gcc-config.
2249 local curr_config_ver=$(env -i ROOT="${ROOT}" gcc-config -S ${curr_config} | awk '{print $2}')
2250
2251 local curr_branch_ver=$(get_version_component_range 1-2 ${curr_config_ver})
2252
2253 # If we're using multislot, just run gcc-config if we're installing
2254 # to the same profile as the current one.
2255 use multislot && return $([[ ${curr_config_ver} == ${GCC_CONFIG_VER} ]])
2256
2257 if [[ ${curr_branch_ver} == ${GCC_BRANCH_VER} ]] ; then
2258 return 0
2259 else
2260 # if we're installing a genuinely different compiler version,
2261 # we should probably tell the user -how- to switch to the new
2262 # gcc version, since we're not going to do it for him/her.
2263 # We don't want to switch from say gcc-3.3 to gcc-3.4 right in
2264 # the middle of an emerge operation (like an 'emerge -e world'
2265 # which could install multiple gcc versions).
2266 einfo "The current gcc config appears valid, so it will not be"
2267 einfo "automatically switched for you. If you would like to"
2268 einfo "switch to the newly installed gcc version, do the"
2269 einfo "following:"
2270 echo
2271 einfo "gcc-config ${CTARGET}-${GCC_CONFIG_VER}"
2272 einfo "source /etc/profile"
2273 echo
2274 ebeep
2275 return 1
2276 fi
2277}
2278
2279do_gcc_config() {
2280 if ! should_we_gcc_config ; then
2281 env -i ROOT="${ROOT}" gcc-config --use-old --force
2282 return 0
2283 fi
2284
2285 local current_gcc_config="" current_specs="" use_specs=""
2286
2287 current_gcc_config=$(env -i ROOT="${ROOT}" gcc-config -c ${CTARGET} 2>/dev/null)
2288 if [[ -n ${current_gcc_config} ]] ; then
2289 # figure out which specs-specific config is active
2290 current_specs=$(gcc-config -S ${current_gcc_config} | awk '{print $3}')
2291 [[ -n ${current_specs} ]] && use_specs=-${current_specs}
2292 fi
2293 if [[ -n ${use_specs} ]] && \
2294 [[ ! -e ${ROOT}/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}${use_specs} ]]
2295 then
2296 ewarn "The currently selected specs-specific gcc config,"
2297 ewarn "${current_specs}, doesn't exist anymore. This is usually"
2298 ewarn "due to enabling/disabling hardened or switching to a version"
2299 ewarn "of gcc that doesnt create multiple specs files. The default"
2300 ewarn "config will be used, and the previous preference forgotten."
2301 ebeep
2302 epause
2303 use_specs=""
2304 fi
2305
2306 gcc-config ${CTARGET}-${GCC_CONFIG_VER}${use_specs}
2307}
2308
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07002309# This function allows us to gentoo-ize gcc's version number and bugzilla
2310# URL without needing to use patches.
2311gcc_version_patch() {
2312 # gcc-4.3+ has configure flags (whoo!)
2313 tc_version_is_at_least 4.3 && return 0
2314
2315 local version_string=${GCC_CONFIG_VER}
2316 [[ -n ${BRANCH_UPDATE} ]] && version_string="${version_string} ${BRANCH_UPDATE}"
2317
2318 einfo "patching gcc version: ${version_string} (${BRANDING_GCC_PKGVERSION})"
2319
2320 if grep -qs VERSUFFIX "${S}"/gcc/version.c ; then
2321 sed -i -e "s~VERSUFFIX \"\"~VERSUFFIX \" (${BRANDING_GCC_PKGVERSION})\"~" \
2322 "${S}"/gcc/version.c || die "failed to update VERSUFFIX with Gentoo branding"
2323 else
2324 version_string="${version_string} (${BRANDING_GCC_PKGVERSION})"
2325 sed -i -e "s~\(const char version_string\[\] = \"\).*\(\".*\)~\1$version_string\2~" \
2326 "${S}"/gcc/version.c || die "failed to update version.c with Gentoo branding."
2327 fi
2328 sed -i -e 's~gcc\.gnu\.org\/bugs\.html~bugs\.gentoo\.org\/~' \
2329 "${S}"/gcc/version.c || die "Failed to change the bug URL"
2330}
2331
2332# The purpose of this DISGUSTING gcc multilib hack is to allow 64bit libs
2333# to live in lib instead of lib64 where they belong, with 32bit libraries
2334# in lib32. This hack has been around since the beginning of the amd64 port,
2335# and we're only now starting to fix everything that's broken. Eventually
2336# this should go away.
2337#
2338# Travis Tilley <lv@gentoo.org> (03 Sep 2004)
2339#
2340disgusting_gcc_multilib_HACK() {
2341 local config
2342 local libdirs
2343 if has_multilib_profile ; then
2344 case $(tc-arch) in
2345 amd64)
2346 config="i386/t-linux64"
2347 libdirs="../$(get_abi_LIBDIR amd64) ../$(get_abi_LIBDIR x86)" \
2348 ;;
2349 ppc64)
2350 config="rs6000/t-linux64"
2351 libdirs="../$(get_abi_LIBDIR ppc64) ../$(get_abi_LIBDIR ppc)" \
2352 ;;
2353 esac
2354 else
2355 die "Your profile is no longer supported by portage."
2356 fi
2357
2358 einfo "updating multilib directories to be: ${libdirs}"
2359 sed -i -e "s:^MULTILIB_OSDIRNAMES.*:MULTILIB_OSDIRNAMES = ${libdirs}:" "${S}"/gcc/config/${config}
2360}
2361
2362disable_multilib_libjava() {
2363 if is_gcj ; then
2364 # We dont want a multilib libjava, so lets use this hack taken from fedora
2365 pushd "${S}" > /dev/null
2366 sed -i -e 's/^all: all-redirect/ifeq (\$(MULTISUBDIR),)\nall: all-redirect\nelse\nall:\n\techo Multilib libjava build disabled\nendif/' libjava/Makefile.in
2367 sed -i -e 's/^install: install-redirect/ifeq (\$(MULTISUBDIR),)\ninstall: install-redirect\nelse\ninstall:\n\techo Multilib libjava install disabled\nendif/' libjava/Makefile.in
2368 sed -i -e 's/^check: check-redirect/ifeq (\$(MULTISUBDIR),)\ncheck: check-redirect\nelse\ncheck:\n\techo Multilib libjava check disabled\nendif/' libjava/Makefile.in
2369 sed -i -e 's/^all: all-recursive/ifeq (\$(MULTISUBDIR),)\nall: all-recursive\nelse\nall:\n\techo Multilib libjava build disabled\nendif/' libjava/Makefile.in
2370 sed -i -e 's/^install: install-recursive/ifeq (\$(MULTISUBDIR),)\ninstall: install-recursive\nelse\ninstall:\n\techo Multilib libjava install disabled\nendif/' libjava/Makefile.in
2371 sed -i -e 's/^check: check-recursive/ifeq (\$(MULTISUBDIR),)\ncheck: check-recursive\nelse\ncheck:\n\techo Multilib libjava check disabled\nendif/' libjava/Makefile.in
2372 popd > /dev/null
2373 fi
2374}
2375
2376# make sure the libtool archives have libdir set to where they actually
2377# -are-, and not where they -used- to be. also, any dependencies we have
2378# on our own .la files need to be updated.
2379fix_libtool_libdir_paths() {
2380 pushd "${D}" >/dev/null
2381
2382 pushd "./${1}" >/dev/null
2383 local dir="${PWD#${D%/}}"
2384 local allarchives=$(echo *.la)
2385 allarchives="\(${allarchives// /\\|}\)"
2386 popd >/dev/null
2387
2388 sed -i \
2389 -e "/^libdir=/s:=.*:='${dir}':" \
2390 ./${dir}/*.la
2391 sed -i \
2392 -e "/^dependency_libs=/s:/[^ ]*/${allarchives}:${LIBPATH}/\1:g" \
2393 $(find ./${PREFIX}/lib* -maxdepth 3 -name '*.la') \
2394 ./${dir}/*.la
2395
2396 popd >/dev/null
2397}
2398
2399is_multilib() {
2400 [[ ${GCCMAJOR} < 3 ]] && return 1
2401 case ${CTARGET} in
2402 mips64*|powerpc64*|s390x*|sparc*|x86_64*)
2403 has_multilib_profile || use multilib ;;
Ahmad Sharifef1e44e2010-08-26 10:27:38 -07002404 *-*-solaris*|*-apple-darwin*|*-mint*)
2405 use multilib ;;
Ahmad Sharifbca7f1a2010-08-18 16:36:56 -07002406 *) false ;;
2407 esac
2408}
2409
2410is_cxx() {
2411 gcc-lang-supported 'c++' || return 1
2412 ! use nocxx
2413}
2414
2415is_d() {
2416 gcc-lang-supported d || return 1
2417 use d
2418}
2419
2420is_f77() {
2421 gcc-lang-supported f77 || return 1
2422 use fortran
2423}
2424
2425is_f95() {
2426 gcc-lang-supported f95 || return 1
2427 use fortran
2428}
2429
2430is_fortran() {
2431 gcc-lang-supported fortran || return 1
2432 use fortran
2433}
2434
2435is_gcj() {
2436 gcc-lang-supported java || return 1
2437 use gcj
2438}
2439
2440is_libffi() {
2441 has libffi ${IUSE} || return 1
2442 use libffi
2443}
2444
2445is_objc() {
2446 gcc-lang-supported objc || return 1
2447 use objc
2448}
2449
2450is_objcxx() {
2451 gcc-lang-supported 'obj-c++' || return 1
2452 use objc++
2453}
2454
2455is_ada() {
2456 gcc-lang-supported ada || return 1
2457 use ada
2458}
2459
2460is_treelang() {
2461 has boundschecking ${IUSE} && use boundschecking && return 1 #260532
2462 is_crosscompile && return 1 #199924
2463 gcc-lang-supported treelang || return 1
2464 #use treelang
2465 return 0
2466}