1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # Maintainer: Toolchain Ninjas <toolchain@gentoo.org>
7 DESCRIPTION="The GNU Compiler Collection"
8 HOMEPAGE="https://gcc.gnu.org/"
9 RESTRICT="strip" # cross-compilers need controlled stripping
11 inherit eutils fixheadtails flag-o-matic gnuconfig libtool multilib pax-utils toolchain-funcs versionator
13 if [[ ${PV} == *_pre9999* ]] ; then
14 EGIT_REPO_URI="git://gcc.gnu.org/git/gcc.git"
16 # gcc-4.7.1_pre9999 -> gcc-4_7-branch
17 # Note that the micro version is required or lots of stuff will break.
18 # To checkout master set gcc_LIVE_BRANCH="master" in the ebuild before
19 # inheriting this eclass.
20 EGIT_BRANCH="${PN}-${PV%.?_pre9999}-branch"
21 EGIT_BRANCH=${EGIT_BRANCH//./_}
25 FEATURES=${FEATURES/multilib-strict/}
27 EXPORTED_FUNCTIONS="pkg_setup src_unpack src_compile src_test src_install pkg_postinst pkg_postrm"
29 0|1) die "Need to upgrade to at least EAPI=2";;
30 2|3) EXPORTED_FUNCTIONS+=" src_prepare src_configure" ;;
31 4*|5*) EXPORTED_FUNCTIONS+=" pkg_pretend src_prepare src_configure" ;;
32 *) die "I don't speak EAPI ${EAPI}."
34 EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
36 #---->> globals <<----
38 export CTARGET=${CTARGET:-${CHOST}}
39 if [[ ${CTARGET} = ${CHOST} ]] ; then
40 if [[ ${CATEGORY} == cross-* ]] ; then
41 export CTARGET=${CATEGORY#cross-}
44 : ${TARGET_ABI:=${ABI}}
45 : ${TARGET_MULTILIB_ABIS:=${MULTILIB_ABIS}}
46 : ${TARGET_DEFAULT_ABI:=${DEFAULT_ABI}}
49 [[ ${CHOST} != ${CTARGET} ]]
52 # General purpose version check. Without a second arg matches up to minor version (x.x.x)
53 tc_version_is_at_least() {
54 version_is_at_least "$1" "${2:-${GCC_RELEASE_VER}}"
57 # General purpose version range check
58 # Note that it matches up to but NOT including the second version
59 tc_version_is_between() {
60 tc_version_is_at_least "${1}" && ! tc_version_is_at_least "${2}"
63 GCC_PV=${TOOLCHAIN_GCC_PV:-${PV}}
65 [[ ${PR} != "r0" ]] && GCC_PVR=${GCC_PVR}-${PR}
66 GCC_RELEASE_VER=$(get_version_component_range 1-3 ${GCC_PV})
67 GCC_BRANCH_VER=$(get_version_component_range 1-2 ${GCC_PV})
68 GCCMAJOR=$(get_version_component_range 1 ${GCC_PV})
69 GCCMINOR=$(get_version_component_range 2 ${GCC_PV})
70 GCCMICRO=$(get_version_component_range 3 ${GCC_PV})
71 [[ ${BRANCH_UPDATE-notset} == "notset" ]] && \
72 BRANCH_UPDATE=$(get_version_component_range 4 ${GCC_PV})
74 # According to gcc/c-cppbuiltin.c, GCC_CONFIG_VER MUST match this regex.
75 # ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)?
76 GCC_CONFIG_VER=${GCC_CONFIG_VER:-$(replace_version_separator 3 '-' ${GCC_PV})}
79 if [[ ${GCC_PV} == *_pre* ]] ; then
80 PRERELEASE=${GCC_PV/_pre/-}
81 elif [[ ${GCC_PV} == *_alpha* ]] ; then
82 SNAPSHOT=${GCC_BRANCH_VER}-${GCC_PV##*_alpha}
83 elif [[ ${GCC_PV} == *_beta* ]] ; then
84 SNAPSHOT=${GCC_BRANCH_VER}-${GCC_PV##*_beta}
85 elif [[ ${GCC_PV} == *_rc* ]] ; then
86 SNAPSHOT=${GCC_PV%_rc*}-RC-${GCC_PV##*_rc}
89 if [[ ${SNAPSHOT} == [56789].0-* ]] ; then
90 # The gcc-5+ releases have dropped the .0 for some reason.
91 SNAPSHOT=${SNAPSHOT/.0}
94 export GCC_FILESDIR=${GCC_FILESDIR:-${FILESDIR}}
96 PREFIX=${TOOLCHAIN_PREFIX:-/usr}
98 if tc_version_is_at_least 3.4.0 ; then
99 LIBPATH=${TOOLCHAIN_LIBPATH:-${PREFIX}/lib/gcc/${CTARGET}/${GCC_CONFIG_VER}}
101 LIBPATH=${TOOLCHAIN_LIBPATH:-${PREFIX}/lib/gcc-lib/${CTARGET}/${GCC_CONFIG_VER}}
103 INCLUDEPATH=${TOOLCHAIN_INCLUDEPATH:-${LIBPATH}/include}
105 if is_crosscompile ; then
106 BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/${CHOST}/${CTARGET}/gcc-bin/${GCC_CONFIG_VER}}
108 BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/${CTARGET}/gcc-bin/${GCC_CONFIG_VER}}
111 DATAPATH=${TOOLCHAIN_DATAPATH:-${PREFIX}/share/gcc-data/${CTARGET}/${GCC_CONFIG_VER}}
113 # Dont install in /usr/include/g++-v3/, but in gcc internal directory.
114 # We will handle /usr/include/g++-v3/ with gcc-config ...
115 STDCXX_INCDIR=${TOOLCHAIN_STDCXX_INCDIR:-${LIBPATH}/include/g++-v${GCC_BRANCH_VER/\.*/}}
117 #---->> LICENSE+SLOT+IUSE logic <<----
119 if tc_version_is_at_least 4.6 ; then
120 LICENSE="GPL-3+ LGPL-3+ || ( GPL-3+ libgcc libstdc++ gcc-runtime-library-exception-3.1 ) FDL-1.3+"
121 elif tc_version_is_at_least 4.4 ; then
122 LICENSE="GPL-3+ LGPL-3+ || ( GPL-3+ libgcc libstdc++ gcc-runtime-library-exception-3.1 ) FDL-1.2+"
123 elif tc_version_is_at_least 4.3 ; then
124 LICENSE="GPL-3+ LGPL-3+ || ( GPL-3+ libgcc libstdc++ ) FDL-1.2+"
125 elif tc_version_is_at_least 4.2 ; then
126 LICENSE="GPL-3+ LGPL-2.1+ || ( GPL-3+ libgcc libstdc++ ) FDL-1.2+"
127 elif tc_version_is_at_least 3.3 ; then
128 LICENSE="GPL-2+ LGPL-2.1+ FDL-1.2+"
130 LICENSE="GPL-2+ LGPL-2.1+ FDL-1.1+"
133 IUSE="multislot regression-test vanilla"
134 IUSE_DEF=( nls nptl )
136 if [[ ${PN} != "kgcc64" && ${PN} != gcc-* ]] ; then
137 IUSE+=" altivec debug"
138 IUSE_DEF+=( cxx fortran )
139 [[ -n ${PIE_VER} ]] && IUSE+=" nopie"
140 [[ -n ${HTB_VER} ]] && IUSE+=" boundschecking"
141 [[ -n ${D_VER} ]] && IUSE+=" d"
142 [[ -n ${SPECS_VER} ]] && IUSE+=" nossp"
143 tc_version_is_at_least 3 && IUSE+=" doc gcj awt hardened multilib objc"
144 tc_version_is_at_least 4.0 && IUSE+=" objc-gc"
145 tc_version_is_between 4.0 4.9 && IUSE+=" mudflap"
146 tc_version_is_at_least 4.1 && IUSE+=" libssp objc++"
147 tc_version_is_at_least 4.2 && IUSE_DEF+=( openmp )
148 tc_version_is_at_least 4.3 && IUSE+=" fixed-point"
149 tc_version_is_at_least 4.7 && IUSE+=" go"
150 # Note: while <=gcc-4.7 also supported graphite, it required forked ppl
151 # versions which we dropped. Since graphite was also experimental in
152 # the older versions, we don't want to bother supporting it. #448024
153 tc_version_is_at_least 4.8 && IUSE+=" graphite" IUSE_DEF+=( sanitize )
154 tc_version_is_at_least 4.9 && IUSE+=" cilk"
155 tc_version_is_at_least 6.0 && IUSE+=" pie +ssp"
158 IUSE+=" ${IUSE_DEF[*]/#/+}"
160 # Support upgrade paths here or people get pissed
161 if ! tc_version_is_at_least 4.7 || is_crosscompile || use multislot || [[ ${GCC_PV} == *_alpha* ]] ; then
162 SLOT="${GCC_CONFIG_VER}"
163 elif ! tc_version_is_at_least 5.0 ; then
164 SLOT="${GCC_BRANCH_VER}"
166 # Upstream changed versioning w/gcc-5+, so SLOT matches major only. #555164
170 #---->> DEPEND <<----
172 RDEPEND="sys-libs/zlib
173 nls? ( virtual/libintl )"
175 tc_version_is_at_least 3 && RDEPEND+=" virtual/libiconv"
177 if tc_version_is_at_least 4 ; then
178 GMP_MPFR_DEPS=">=dev-libs/gmp-4.3.2:0 >=dev-libs/mpfr-2.4.2:0"
179 if tc_version_is_at_least 4.3 ; then
180 RDEPEND+=" ${GMP_MPFR_DEPS}"
181 elif in_iuse fortran ; then
182 RDEPEND+=" fortran? ( ${GMP_MPFR_DEPS} )"
186 tc_version_is_at_least 4.5 && RDEPEND+=" >=dev-libs/mpc-0.8.1:0"
188 if in_iuse graphite ; then
189 if tc_version_is_at_least 5.0 ; then
190 RDEPEND+=" graphite? ( >=dev-libs/isl-0.14 )"
191 elif tc_version_is_at_least 4.8 ; then
194 >=dev-libs/cloog-0.18.0
195 >=dev-libs/isl-0.11.1
201 >=sys-devel/bison-1.875
202 >=sys-devel/flex-2.5.4
203 nls? ( sys-devel/gettext )
205 >=dev-util/dejagnu-1.4.4
206 >=sys-devel/autogen-5.5.4
209 if in_iuse gcj ; then
210 GCJ_DEPS=">=media-libs/libart_lgpl-2.1"
220 tc_version_is_at_least 3.4 && GCJ_GTK_DEPS+=" x11-libs/pango"
221 tc_version_is_at_least 4.2 && GCJ_DEPS+=" app-arch/zip app-arch/unzip"
222 DEPEND+=" gcj? ( awt? ( ${GCJ_GTK_DEPS} ) ${GCJ_DEPS} )"
225 PDEPEND=">=sys-devel/gcc-config-1.7"
227 #---->> S + SRC_URI essentials <<----
229 # Set the source directory depending on whether we're using
230 # a prerelease, snapshot, or release tarball.
232 if [[ -n ${PRERELEASE} ]] ; then
233 echo ${WORKDIR}/gcc-${PRERELEASE}
234 elif [[ -n ${SNAPSHOT} ]] ; then
235 echo ${WORKDIR}/gcc-${SNAPSHOT}
237 echo ${WORKDIR}/gcc-${GCC_RELEASE_VER}
242 local devspace="HTTP~vapier/dist/URI HTTP~rhill/dist/URI
243 HTTP~zorry/patches/gcc/URI HTTP~blueness/dist/URI"
244 devspace=${devspace//HTTP/https:\/\/dev.gentoo.org\/}
245 echo mirror://gentoo/$1 ${devspace//URI/$1}
248 # This function handles the basics of setting the SRC_URI for a gcc ebuild.
249 # To use, set SRC_URI with:
251 # SRC_URI="$(get_gcc_src_uri)"
253 # Other than the variables normally set by portage, this function's behavior
254 # can be altered by setting the following:
257 # If set, this variable signals that we should be using a snapshot of
258 # gcc. It is expected to be in the format "YYYY-MM-DD". Note that if
259 # the ebuild has a _pre suffix, this variable is ignored and the
260 # prerelease tarball is used instead.
263 # If set, this variable signals that we should be using the main
264 # release tarball (determined by ebuild version) and applying a
265 # CVS branch update patch against it. The location of this branch
266 # update patch is assumed to be in ${GENTOO_TOOLCHAIN_BASE_URI}.
267 # Just like with SNAPSHOT, this variable is ignored if the ebuild
272 # This should be set to the version of the gentoo patch tarball.
273 # The resulting filename of this tarball will be:
274 # gcc-${PATCH_GCC_VER:-${GCC_RELEASE_VER}}-patches-${PATCH_VER}.tar.bz2
278 # These variables control patching in various updates for the logic
279 # controlling Position Independant Executables. PIE_VER is expected
280 # to be the version of this patch, and PIE_GCC_VER the gcc version of
284 # PIE_GCC_VER="3.4.0"
285 # The resulting filename of this tarball will be:
286 # gcc-${PIE_GCC_VER:-${GCC_RELEASE_VER}}-piepatches-v${PIE_VER}.tar.bz2
290 # This is for the minispecs files included in the hardened gcc-4.x
291 # The specs files for hardenedno*, vanilla and for building the "specs" file.
292 # SPECS_VER is expected to be the version of this patch, SPECS_GCC_VER
293 # the gcc version of the patch.
295 # SPECS_VER="8.7.6.5"
296 # SPECS_GCC_VER="3.4.0"
297 # The resulting filename of this tarball will be:
298 # gcc-${SPECS_GCC_VER:-${GCC_RELEASE_VER}}-specs-${SPECS_VER}.tar.bz2
302 # These variables control whether or not an ebuild supports Herman
303 # ten Brugge's bounds-checking patches. If you want to use a patch
304 # for an older gcc version with a new gcc, make sure you set
305 # HTB_GCC_VER to that version of gcc.
307 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
308 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
309 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
310 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
311 export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}}
313 # Set where to download gcc itself depending on whether we're using a
314 # prerelease, snapshot, or release tarball.
315 if [[ ${PV} == *9999* ]] ; then
316 # Nothing to do w/git snapshots.
318 elif [[ -n ${PRERELEASE} ]] ; then
319 GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/prerelease-${PRERELEASE}/gcc-${PRERELEASE}.tar.bz2"
320 elif [[ -n ${SNAPSHOT} ]] ; then
321 GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.bz2"
323 GCC_SRC_URI="mirror://gnu/gcc/gcc-${GCC_PV}/gcc-${GCC_RELEASE_VER}.tar.bz2"
324 # we want all branch updates to be against the main release
325 [[ -n ${BRANCH_UPDATE} ]] && \
326 GCC_SRC_URI+=" $(gentoo_urls gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2)"
329 [[ -n ${UCLIBC_VER} ]] && \
330 GCC_SRC_URI+=" $(gentoo_urls gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2)"
331 [[ -n ${PATCH_VER} ]] && \
332 GCC_SRC_URI+=" $(gentoo_urls gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2)"
334 # strawberry pie, Cappuccino and a Gauloises (it's a good thing)
335 [[ -n ${PIE_VER} ]] && \
336 PIE_CORE=${PIE_CORE:-gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2} && \
337 GCC_SRC_URI+=" $(gentoo_urls ${PIE_CORE})"
339 # gcc minispec for the hardened gcc 4 compiler
340 [[ -n ${SPECS_VER} ]] && \
341 GCC_SRC_URI+=" $(gentoo_urls gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2)"
343 # gcc bounds checking patch
344 if [[ -n ${HTB_VER} ]] ; then
345 local HTBFILE="bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
348 mirror://sourceforge/boundschecking/${HTBFILE}
349 $(gentoo_urls ${HTBFILE})
353 [[ -n ${D_VER} ]] && \
354 GCC_SRC_URI+=" d? ( mirror://sourceforge/dgcc/gdc-${D_VER}-src.tar.bz2 )"
356 if in_iuse gcj ; then
357 if tc_version_is_at_least 4.5 ; then
358 GCC_SRC_URI+=" gcj? ( ftp://sourceware.org/pub/java/ecj-4.5.jar )"
359 elif tc_version_is_at_least 4.3 ; then
360 GCC_SRC_URI+=" gcj? ( ftp://sourceware.org/pub/java/ecj-4.3.jar )"
364 echo "${GCC_SRC_URI}"
367 SRC_URI=$(get_gcc_src_uri)
369 #---->> pkg_pretend <<----
371 toolchain_pkg_pretend() {
372 if [[ -n ${PRERELEASE}${SNAPSHOT} || ${PV} == *9999* ]] &&
373 [[ -z ${I_PROMISE_TO_SUPPLY_PATCHES_WITH_BUGS} ]] ; then
374 die "Please \`export I_PROMISE_TO_SUPPLY_PATCHES_WITH_BUGS=1\` or define it" \
375 "in your make.conf if you want to use this version."
378 [[ -z ${UCLIBC_VER} ]] && [[ ${CTARGET} == *-uclibc* ]] && \
379 die "Sorry, this version does not support uClibc"
381 if ! use_if_iuse cxx ; then
382 use_if_iuse go && ewarn 'Go requires a C++ compiler, disabled due to USE="-cxx"'
383 use_if_iuse objc++ && ewarn 'Obj-C++ requires a C++ compiler, disabled due to USE="-cxx"'
384 use_if_iuse gcj && ewarn 'GCJ requires a C++ compiler, disabled due to USE="-cxx"'
390 #---->> pkg_setup <<----
392 toolchain_pkg_setup() {
394 2|3) toolchain_pkg_pretend ;;
397 # we dont want to use the installed compiler's specs to build gcc
399 unset LANGUAGES #265283
402 #---->> src_unpack <<----
404 toolchain_src_unpack() {
405 if [[ ${PV} == *9999* ]]; then
413 pushd "${WORKDIR}" > /dev/null
414 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
415 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
416 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
417 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
418 export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}}
420 if [[ -n ${GCC_A_FAKEIT} ]] ; then
421 unpack ${GCC_A_FAKEIT}
422 elif [[ -n ${PRERELEASE} ]] ; then
423 unpack gcc-${PRERELEASE}.tar.bz2
424 elif [[ -n ${SNAPSHOT} ]] ; then
425 unpack gcc-${SNAPSHOT}.tar.bz2
426 elif [[ ${PV} != *9999* ]] ; then
427 unpack gcc-${GCC_RELEASE_VER}.tar.bz2
428 # We want branch updates to be against a release tarball
429 if [[ -n ${BRANCH_UPDATE} ]] ; then
430 pushd "${S}" > /dev/null
431 epatch "${DISTDIR}"/gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2
436 if [[ -n ${D_VER} ]] && use d ; then
437 pushd "${S}"/gcc > /dev/null
438 unpack gdc-${D_VER}-src.tar.bz2
440 ebegin "Adding support for the D language"
441 ./gcc/d/setup-gcc.sh >& "${T}"/dgcc.log
443 eerror "The D GCC package failed to apply"
444 eerror "Please include this log file when posting a bug report:"
445 eerror " ${T}/dgcc.log"
446 die "failed to include the D language"
451 [[ -n ${PATCH_VER} ]] && \
452 unpack gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2
454 [[ -n ${UCLIBC_VER} ]] && \
455 unpack gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2
458 if [[ -n ${PIE_CORE} ]] ; then
461 unpack gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2
463 [[ -n ${SPECS_VER} ]] && \
464 unpack gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2
467 use_if_iuse boundschecking && unpack "bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
472 #---->> src_prepare <<----
474 toolchain_src_prepare() {
475 export BRANDING_GCC_PKGVERSION="Gentoo ${GCC_PVR}"
478 if ! use vanilla ; then
479 if [[ -n ${PATCH_VER} ]] ; then
480 guess_patch_type_in_dir "${WORKDIR}"/patch
481 EPATCH_MULTI_MSG="Applying Gentoo patches ..." \
482 epatch "${WORKDIR}"/patch
483 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION} p${PATCH_VER}"
485 if [[ -n ${UCLIBC_VER} ]] ; then
486 guess_patch_type_in_dir "${WORKDIR}"/uclibc
487 EPATCH_MULTI_MSG="Applying uClibc patches ..." \
488 epatch "${WORKDIR}"/uclibc
495 if ( tc_version_is_at_least 4.8.2 || use hardened ) && ! use vanilla ; then
499 # install the libstdc++ python into the right location
500 # http://gcc.gnu.org/PR51368
501 if tc_version_is_between 4.5 4.7 ; then
503 '/^pythondir =/s:=.*:= $(datadir)/python:' \
504 "${S}"/libstdc++-v3/python/Makefile.in || die
507 # make sure the pkg config files install into multilib dirs.
508 # since we configure with just one --libdir, we can't use that
509 # (as gcc itself takes care of building multilibs). #435728
510 find "${S}" -name Makefile.in \
511 -exec sed -i '/^pkgconfigdir/s:=.*:=$(toolexeclibdir)/pkgconfig:' {} +
513 # No idea when this first started being fixed, but let's go with 4.3.x for now
514 if ! tc_version_is_at_least 4.3 ; then
516 for x in contrib/test_summary libstdc++-v3/scripts/check_survey.in ; do
517 [[ -e ${x} ]] && fix_files="${fix_files} ${x}"
519 ht_fix_file ${fix_files} */configure *.sh */Makefile.in
522 setup_multilib_osdirnames
525 if tc_version_is_at_least 4.1 ; then
526 if [[ -n ${SNAPSHOT} || -n ${PRERELEASE} ]] ; then
527 # BASE-VER must be a three-digit version number
528 # followed by an optional -pre string
529 # eg. 4.5.1, 4.6.2-pre20120213, 4.7.0-pre9999
530 # If BASE-VER differs from ${PV/_/-} then libraries get installed in
531 # the wrong directory.
532 echo ${PV/_/-} > "${S}"/gcc/BASE-VER
536 # >= gcc-4.3 doesn't bundle ecj.jar, so copy it
537 if tc_version_is_at_least 4.3 && use gcj ; then
538 if tc_version_is_at_least 4.5 ; then
539 einfo "Copying ecj-4.5.jar"
540 cp -pPR "${DISTDIR}/ecj-4.5.jar" "${S}/ecj.jar" || die
542 einfo "Copying ecj-4.3.jar"
543 cp -pPR "${DISTDIR}/ecj-4.3.jar" "${S}/ecj.jar" || die
547 # disable --as-needed from being compiled into gcc specs
548 # natively when using a gcc version < 3.4.4
549 # http://gcc.gnu.org/PR14992
550 if ! tc_version_is_at_least 3.4.4 ; then
551 sed -i -e s/HAVE_LD_AS_NEEDED/USE_LD_AS_NEEDED/g "${S}"/gcc/config.in
554 # In gcc 3.3.x and 3.4.x, rename the java bins to gcc-specific names
555 # in line with gcc-4.
556 if tc_version_is_between 3.3 4.0 ; then
557 do_gcc_rename_java_bins
560 # Prevent libffi from being installed
561 if tc_version_is_between 3.0 4.8 ; then
562 sed -i -e 's/\(install.*:\) install-.*recursive/\1/' "${S}"/libffi/Makefile.in || die
563 sed -i -e 's/\(install-data-am:\).*/\1/' "${S}"/libffi/include/Makefile.in || die
566 # Fixup libtool to correctly generate .la files with portage
567 elibtoolize --portage --shallow --no-uclibc
571 # update configure files
573 einfo "Fixing misc issues in configure files"
574 for f in $(grep -l 'autoconf version 2.13' $(find "${S}" -name configure)) ; do
575 ebegin " Updating ${f/${S}\/} [LANG]"
576 patch "${f}" "${GCC_FILESDIR}"/gcc-configure-LANG.patch >& "${T}"/configure-patch.log \
577 || eerror "Please file a bug about this"
580 sed -i 's|A-Za-z0-9|[:alnum:]|g' "${S}"/gcc/*.awk #215828
582 # Prevent new texinfo from breaking old versions (see #198182, #464008)
583 tc_version_is_at_least 4.1 && epatch "${GCC_FILESDIR}"/gcc-configure-texinfo.patch
585 if [[ -x contrib/gcc_update ]] ; then
586 einfo "Touching generated files"
587 ./contrib/gcc_update --touch | \
594 guess_patch_type_in_dir() {
595 [[ -n $(ls "$1"/*.bz2 2>/dev/null) ]] \
596 && EPATCH_SUFFIX="patch.bz2" \
597 || EPATCH_SUFFIX="patch"
600 do_gcc_HTB_patches() {
601 use_if_iuse boundschecking || return 0
603 # modify the bounds checking patch with a regression patch
604 epatch "${WORKDIR}/bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch"
605 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, HTB-${HTB_GCC_VER}-${HTB_VER}"
608 do_gcc_PIE_patches() {
610 use vanilla && return 0
612 if tc_version_is_at_least 4.3.2 ; then
613 guess_patch_type_in_dir "${WORKDIR}"/piepatch/
614 EPATCH_MULTI_MSG="Applying pie patches ..." \
615 epatch "${WORKDIR}"/piepatch/
617 guess_patch_type_in_dir "${WORKDIR}"/piepatch/upstream
619 # corrects startfile/endfile selection and shared/static/pie flag usage
620 EPATCH_MULTI_MSG="Applying upstream pie patches ..." \
621 epatch "${WORKDIR}"/piepatch/upstream
622 # adds non-default pie support (rs6000)
623 EPATCH_MULTI_MSG="Applying non-default pie patches ..." \
624 epatch "${WORKDIR}"/piepatch/nondef
625 # adds default pie support (rs6000 too) if DEFAULT_PIE[_SSP] is defined
626 EPATCH_MULTI_MSG="Applying default pie patches ..." \
627 epatch "${WORKDIR}"/piepatch/def
630 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, pie-${PIE_VER}"
633 # configure to build with the hardened GCC specs as the default
635 # we want to be able to control the pie patch logic via something other
637 sed -e '/^ALL_CFLAGS/iHARD_CFLAGS = ' \
638 -e 's|^ALL_CFLAGS = |ALL_CFLAGS = $(HARD_CFLAGS) |' \
639 -i "${S}"/gcc/Makefile.in
640 # Need to add HARD_CFLAGS to ALL_CXXFLAGS on >= 4.7
641 if tc_version_is_at_least 4.7 ; then
642 sed -e '/^ALL_CXXFLAGS/iHARD_CFLAGS = ' \
643 -e 's|^ALL_CXXFLAGS = |ALL_CXXFLAGS = $(HARD_CFLAGS) |' \
644 -i "${S}"/gcc/Makefile.in
647 # defaults to enable for all toolchains
648 local gcc_hard_flags=""
649 if use hardened ; then
650 if hardened_gcc_works ; then
651 einfo "Updating gcc to use automatic PIE + SSP building ..."
652 gcc_hard_flags+=" -DEFAULT_PIE_SSP"
653 elif hardened_gcc_works pie ; then
654 einfo "Updating gcc to use automatic PIE building ..."
655 ewarn "SSP has not been enabled by default"
656 gcc_hard_flags+=" -DEFAULT_PIE"
657 elif hardened_gcc_works ssp ; then
658 einfo "Updating gcc to use automatic SSP building ..."
659 ewarn "PIE has not been enabled by default"
660 gcc_hard_flags+=" -DEFAULT_SSP"
662 # do nothing if hardened is't supported, but don't die either
663 ewarn "hardened is not supported for this arch in this gcc version"
666 # rebrand to make bug reports easier
667 BRANDING_GCC_PKGVERSION=${BRANDING_GCC_PKGVERSION/Gentoo/Gentoo Hardened}
669 if hardened_gcc_works ssp ; then
670 einfo "Updating gcc to use automatic SSP building ..."
671 gcc_hard_flags+=" -DEFAULT_SSP"
676 -e "/^HARD_CFLAGS = /s|=|= ${gcc_hard_flags} |" \
677 "${S}"/gcc/Makefile.in || die
681 # This is a historical wart. The original Gentoo/amd64 port used:
682 # lib32 - 32bit binaries (x86)
683 # lib64 - 64bit binaries (x86_64)
684 # lib - "native" binaries (a symlink to lib64)
685 # Most other distros use the logic (including mainline gcc):
686 # lib - 32bit binaries (x86)
687 # lib64 - 64bit binaries (x86_64)
688 # Over time, Gentoo is migrating to the latter form.
690 # Unfortunately, due to distros picking the lib32 behavior, newer gcc
691 # versions will dynamically detect whether to use lib or lib32 for its
692 # 32bit multilib. So, to keep the automagic from getting things wrong
693 # while people are transitioning from the old style to the new style,
694 # we always set the MULTILIB_OSDIRNAMES var for relevant targets.
695 setup_multilib_osdirnames() {
696 is_multilib || return 0
699 local libdirs="../lib64 ../lib32"
701 # this only makes sense for some Linux targets
703 x86_64*-linux*) config="i386" ;;
704 powerpc64*-linux*) config="rs6000" ;;
705 sparc64*-linux*) config="sparc" ;;
706 s390x*-linux*) config="s390" ;;
712 if tc_version_is_at_least 4.6 ; then
713 sed_args+=( -e 's:$[(]call if_multiarch[^)]*[)]::g' )
715 if [[ ${SYMLINK_LIB} == "yes" ]] ; then
716 einfo "updating multilib directories to be: ${libdirs}"
717 if tc_version_is_at_least 4.6.4 || tc_version_is_at_least 4.7 ; then
718 sed_args+=( -e '/^MULTILIB_OSDIRNAMES.*lib32/s:[$][(]if.*):../lib32:' )
720 sed_args+=( -e "/^MULTILIB_OSDIRNAMES/s:=.*:= ${libdirs}:" )
723 einfo "using upstream multilib; disabling lib32 autodetection"
724 sed_args+=( -r -e 's:[$][(]if.*,(.*)[)]:\1:' )
726 sed -i "${sed_args[@]}" "${S}"/gcc/config/${config} || die
729 gcc_version_patch() {
730 # gcc-4.3+ has configure flags (whoo!)
731 tc_version_is_at_least 4.3 && return 0
733 local version_string=${GCC_CONFIG_VER}
734 [[ -n ${BRANCH_UPDATE} ]] && version_string+=" ${BRANCH_UPDATE}"
736 einfo "patching gcc version: ${version_string} (${BRANDING_GCC_PKGVERSION})"
738 local gcc_sed=( -e 's:gcc\.gnu\.org/bugs\.html:bugs\.gentoo\.org/:' )
739 if grep -qs VERSUFFIX "${S}"/gcc/version.c ; then
740 gcc_sed+=( -e "/VERSUFFIX \"\"/s:\"\":\" (${BRANDING_GCC_PKGVERSION})\":" )
742 version_string="${version_string} (${BRANDING_GCC_PKGVERSION})"
743 gcc_sed+=( -e "/const char version_string\[\] = /s:= \".*\":= \"${version_string}\":" )
745 sed -i "${gcc_sed[@]}" "${S}"/gcc/version.c || die
748 do_gcc_rename_java_bins() {
749 # bug #139918 - conflict between gcc and java-config-2 for ownership of
750 # /usr/bin/rmi{c,registry}. Done with mv & sed rather than a patch
751 # because patches would be large (thanks to the rename of man files),
752 # and it's clear from the sed invocations that all that changes is the
753 # rmi{c,registry} names to grmi{c,registry} names.
754 # Kevin F. Quinn 2006-07-12
755 einfo "Renaming jdk executables rmic and rmiregistry to grmic and grmiregistry."
756 # 1) Move the man files if present (missing prior to gcc-3.4)
757 for manfile in rmic rmiregistry ; do
758 [[ -f ${S}/gcc/doc/${manfile}.1 ]] || continue
759 mv "${S}"/gcc/doc/${manfile}.1 "${S}"/gcc/doc/g${manfile}.1
761 # 2) Fixup references in the docs if present (mission prior to gcc-3.4)
762 for jfile in gcc/doc/gcj.info gcc/doc/grmic.1 gcc/doc/grmiregistry.1 gcc/java/gcj.texi ; do
763 [[ -f ${S}/${jfile} ]] || continue
764 sed -i -e 's:rmiregistry:grmiregistry:g' "${S}"/${jfile} ||
765 die "Failed to fixup file ${jfile} for rename to grmiregistry"
766 sed -i -e 's:rmic:grmic:g' "${S}"/${jfile} ||
767 die "Failed to fixup file ${jfile} for rename to grmic"
769 # 3) Fixup Makefiles to build the changed executable names
770 # These are present in all 3.x versions, and are the important bit
771 # to get gcc to build with the new names.
772 for jfile in libjava/Makefile.am libjava/Makefile.in gcc/java/Make-lang.in ; do
773 sed -i -e 's:rmiregistry:grmiregistry:g' "${S}"/${jfile} ||
774 die "Failed to fixup file ${jfile} for rename to grmiregistry"
775 # Careful with rmic on these files; it's also the name of a directory
776 # which should be left unchanged. Replace occurrences of 'rmic$',
777 # 'rmic_' and 'rmic '.
778 sed -i -e 's:rmic\([$_ ]\):grmic\1:g' "${S}"/${jfile} ||
779 die "Failed to fixup file ${jfile} for rename to grmic"
783 #---->> src_configure <<----
785 toolchain_src_configure() {
789 einfo "CFLAGS=\"${CFLAGS}\""
790 einfo "CXXFLAGS=\"${CXXFLAGS}\""
791 einfo "LDFLAGS=\"${LDFLAGS}\""
793 # Force internal zip based jar script to avoid random
794 # issues with 3rd party jar implementations. #384291
797 # For hardened gcc 4.3 piepatchset to build the hardened specs
798 # file (build.specs) to use when building gcc.
799 if ! tc_version_is_at_least 4.4 && want_minispecs ; then
800 setup_minispecs_gcc_build_specs
803 local confgcc=( --host=${CHOST} )
805 if is_crosscompile || tc-is-cross-compiler ; then
806 # Straight from the GCC install doc:
807 # "GCC has code to correctly determine the correct value for target
808 # for nearly all native systems. Therefore, we highly recommend you
809 # not provide a configure target when configuring a native compiler."
810 confgcc+=( --target=${CTARGET} )
812 [[ -n ${CBUILD} ]] && confgcc+=( --build=${CBUILD} )
816 --bindir="${BINPATH}"
817 --includedir="${INCLUDEPATH}"
818 --datadir="${DATAPATH}"
819 --mandir="${DATAPATH}/man"
820 --infodir="${DATAPATH}/info"
821 --with-gxx-include-dir="${STDCXX_INCDIR}"
824 # Stick the python scripts in their own slotted directory (bug #279252)
826 # --with-python-dir=DIR
827 # Specifies where to install the Python modules used for aot-compile. DIR
828 # should not include the prefix used in installation. For example, if the
829 # Python modules are to be installed in /usr/lib/python2.5/site-packages,
830 # then --with-python-dir=/lib/python2.5/site-packages should be passed.
832 # This should translate into "/share/gcc-data/${CTARGET}/${GCC_CONFIG_VER}/python"
833 if tc_version_is_at_least 4.4 ; then
834 confgcc+=( --with-python-dir=${DATAPATH/$PREFIX/}/python )
840 is_cxx && GCC_LANG+=",c++"
841 is_d && GCC_LANG+=",d"
842 is_gcj && GCC_LANG+=",java"
843 is_go && GCC_LANG+=",go"
844 if is_objc || is_objcxx ; then
846 if tc_version_is_at_least 4 ; then
847 use objc-gc && confgcc+=( --enable-objc-gc )
849 is_objcxx && GCC_LANG+=",obj-c++"
852 # fortran support just got sillier! the lang value can be f77 for
853 # fortran77, f95 for fortran95, or just plain old fortran for the
854 # currently supported standard depending on gcc version.
855 is_fortran && GCC_LANG+=",fortran"
856 is_f77 && GCC_LANG+=",f77"
857 is_f95 && GCC_LANG+=",f95"
859 # We do NOT want 'ADA support' in here!
860 # is_ada && GCC_LANG+=",ada"
862 confgcc+=( --enable-languages=${GCC_LANG} )
874 confgcc+=( --enable-nls --without-included-gettext )
876 confgcc+=( --disable-nls )
879 tc_version_is_at_least 3.4 || confgcc+=( --disable-libunwind-exceptions )
881 # Use the default ("release") checking because upstream usually neglects
882 # to test "disabled" so it has a history of breaking. #317217
883 if tc_version_is_at_least 3.4 ; then
884 # The "release" keyword is new to 4.0. #551636
885 local off=$(tc_version_is_at_least 4.0 && echo release || echo no)
886 confgcc+=( --enable-checking="${GCC_CHECKS_LIST:-$(usex debug yes ${off})}" )
890 tc_version_is_at_least 4.3 && confgcc+=(
891 --with-bugurl=https://bugs.gentoo.org/
892 --with-pkgversion="${BRANDING_GCC_PKGVERSION}"
895 # If we want hardened support with the newer piepatchset for >=gcc 4.4
896 if tc_version_is_at_least 4.4 && want_minispecs ; then
897 confgcc+=( $(use_enable hardened esp) )
900 # allow gcc to search for clock funcs in the main C lib.
901 # if it can't find them, then tough cookies -- we aren't
902 # going to link in -lrt to all C++ apps. #411681
903 if tc_version_is_at_least 4.4 && is_cxx ; then
904 confgcc+=( --enable-libstdcxx-time )
907 # # Turn on the -Wl,--build-id flag by default for ELF targets. #525942
908 # # This helps with locating debug files.
910 # *-linux-*|*-elf|*-eabi)
911 # tc_version_is_at_least 4.5 && confgcc+=(
912 # --enable-linker-build-id
917 # newer gcc versions like to bootstrap themselves with C++,
918 # so we need to manually disable it ourselves
919 if tc_version_is_between 4.7 4.8 && ! is_cxx ; then
920 confgcc+=( --disable-build-with-cxx --disable-build-poststage1-with-cxx )
923 ### Cross-compiler options
924 if is_crosscompile ; then
925 # Enable build warnings by default with cross-compilers when system
926 # paths are included (e.g. via -I flags).
927 confgcc+=( --enable-poison-system-directories )
929 # When building a stage1 cross-compiler (just C compiler), we have to
930 # disable a bunch of features or gcc goes boom
933 *-linux) needed_libc=no-fucking-clue;;
934 *-dietlibc) needed_libc=dietlibc;;
935 *-elf|*-eabi) needed_libc=newlib;;
936 *-freebsd*) needed_libc=freebsd-lib;;
937 *-gnu*) needed_libc=glibc;;
938 *-klibc) needed_libc=klibc;;
939 *-musl*) needed_libc=musl;;
941 if ! echo '#include <features.h>' | \
942 $(tc-getCPP ${CTARGET}) -E -dD - 2>/dev/null | \
943 grep -q __HAVE_SHARED__
945 confgcc+=( --disable-shared )
949 *-cygwin) needed_libc=cygwin;;
951 *-w64-mingw*) needed_libc=mingw64-runtime;;
952 mingw*|*-mingw*) needed_libc=mingw-runtime;;
953 avr) confgcc+=( --enable-shared --disable-threads );;
955 if [[ -n ${needed_libc} ]] ; then
956 local confgcc_no_libc=( --disable-shared )
957 tc_version_is_at_least 4.8 && confgcc_no_libc+=( --disable-libatomic )
958 if ! has_version ${CATEGORY}/${needed_libc} ; then
960 "${confgcc_no_libc[@]}"
964 elif built_with_use --hidden --missing false ${CATEGORY}/${needed_libc} crosscompile_opts_headers-only ; then
966 "${confgcc_no_libc[@]}"
967 --with-sysroot=${PREFIX}/${CTARGET}
970 confgcc+=( --with-sysroot=${PREFIX}/${CTARGET} )
974 tc_version_is_at_least 4.2 && confgcc+=( --disable-bootstrap )
976 if tc-is-static-only ; then
977 confgcc+=( --disable-shared )
979 confgcc+=( --enable-shared )
982 mingw*|*-mingw*|*-cygwin)
983 confgcc+=( --enable-threads=win32 ) ;;
985 confgcc+=( --enable-threads=posix ) ;;
989 # __cxa_atexit is "essential for fully standards-compliant handling of
990 # destructors", but apparently requires glibc.
994 --disable-__cxa_atexit
995 $(use_enable nptl tls)
997 tc_version_is_between 3.3 3.4 && confgcc+=( --enable-sjlj-exceptions )
998 if tc_version_is_between 3.4 4.3 ; then
999 confgcc+=( --enable-clocale=uclibc )
1003 confgcc+=( --with-newlib )
1007 --enable-__cxa_atexit
1008 --enable-clocale=gnu
1012 confgcc+=( --enable-__cxa_atexit )
1015 confgcc+=( --enable-__cxa_atexit )
1021 gcc-multilib-configure
1023 # ppc altivec support
1024 confgcc+=( $(use_enable altivec) )
1026 # gcc has fixed-point arithmetic support in 4.3 for mips targets that can
1027 # significantly increase compile time by several hours. This will allow
1028 # users to control this feature in the event they need the support.
1029 tc_version_is_at_least 4.3 && confgcc+=( $(use_enable fixed-point) )
1031 case $(tc-is-softfloat) in
1032 yes) confgcc+=( --with-float=soft ) ;;
1033 softfp) confgcc+=( --with-float=softfp ) ;;
1035 # If they've explicitly opt-ed in, do hardfloat,
1036 # otherwise let the gcc default kick in.
1037 case ${CTARGET//_/-} in
1038 *-hardfloat-*|*eabihf) confgcc+=( --with-float=hard ) ;;
1042 local with_abi_map=()
1044 arm) #264534 #414395
1045 local a arm_arch=${CTARGET%%-*}
1046 # Remove trailing endian variations first: eb el be bl b l
1047 for a in e{b,l} {b,l}e b l ; do
1048 if [[ ${arm_arch} == *${a} ]] ; then
1049 arm_arch=${arm_arch%${a}}
1053 # Convert armv7{a,r,m} to armv7-{a,r,m}
1054 [[ ${arm_arch} == armv7? ]] && arm_arch=${arm_arch/7/7-}
1055 # See if this is a valid --with-arch flag
1056 if (srcdir=${S}/gcc target=${CTARGET} with_arch=${arm_arch};
1057 . "${srcdir}"/config.gcc) &>/dev/null
1059 confgcc+=( --with-arch=${arm_arch} )
1062 # Make default mode thumb for microcontroller classes #418209
1063 [[ ${arm_arch} == *-m ]] && confgcc+=( --with-mode=thumb )
1066 if [[ $(tc-is-softfloat) == "no" ]] && \
1067 [[ ${CTARGET} == armv[67]* ]] && \
1068 tc_version_is_at_least 4.5
1070 # Follow the new arm hardfp distro standard by default
1071 confgcc+=( --with-float=hard )
1073 armv6*) confgcc+=( --with-fpu=vfp ) ;;
1074 armv7*) confgcc+=( --with-fpu=vfpv3-d16 ) ;;
1079 # Add --with-abi flags to set default ABI
1080 confgcc+=( --with-abi=$(gcc-abi-map ${TARGET_DEFAULT_ABI}) )
1083 # drop the older/ABI checks once this get's merged into some
1084 # version of gcc upstream
1085 if tc_version_is_at_least 4.8 && has x32 $(get_all_abis TARGET) ; then
1086 confgcc+=( --with-abi=$(gcc-abi-map ${TARGET_DEFAULT_ABI}) )
1090 # Default arch for x86 is normally i386, lets give it a bump
1091 # since glibc will do so based on CTARGET anyways
1092 confgcc+=( --with-arch=${CTARGET%%-*} )
1095 # Enable sjlj exceptions for backward compatibility on hppa
1096 [[ ${GCCMAJOR} == "3" ]] && confgcc+=( --enable-sjlj-exceptions )
1099 # Set up defaults based on current CFLAGS
1100 is-flagq -mfloat-gprs=double && confgcc+=( --enable-e500-double )
1101 [[ ${CTARGET//_/-} == *-e500v2-* ]] && confgcc+=( --enable-e500-double )
1105 # if the target can do biarch (-m32/-m64), enable it. overhead should
1106 # be small, and should simplify building of 64bit kernels in a 32bit
1107 # userland by not needing sys-devel/kgcc64. #349405
1109 ppc|ppc64) tc_version_is_at_least 3.4 && confgcc+=( --enable-targets=all ) ;;
1110 sparc) tc_version_is_at_least 4.4 && confgcc+=( --enable-targets=all ) ;;
1111 amd64|x86) tc_version_is_at_least 4.3 && confgcc+=( --enable-targets=all ) ;;
1114 # On Darwin we need libdir to be set in order to get correct install names
1115 # for things like libobjc-gnu, libgcj and libfortran. If we enable it on
1116 # non-Darwin we screw up the behaviour this eclass relies on. We in
1117 # particular need this over --libdir for bug #255315.
1118 [[ ${CTARGET} == *-darwin* ]] && \
1119 confgcc+=( --enable-version-specific-runtime-libs )
1124 confgcc+=( --disable-libgcj )
1126 confgcc+=( --enable-java-awt=gtk )
1129 if tc_version_is_at_least 4.2 ; then
1130 if in_iuse openmp ; then
1131 # Make sure target has pthreads support. #326757 #335883
1132 # There shouldn't be a chicken & egg problem here as openmp won't
1133 # build without a C library, and you can't build that w/out
1134 # already having a compiler ...
1135 if ! is_crosscompile || \
1136 $(tc-getCPP ${CTARGET}) -E - <<<"#include <pthread.h>" >& /dev/null
1138 confgcc+=( $(use_enable openmp libgomp) )
1140 # Force disable as the configure script can be dumb #359855
1141 confgcc+=( --disable-libgomp )
1144 # For gcc variants where we don't want openmp (e.g. kgcc)
1145 confgcc+=( --disable-libgomp )
1149 if tc_version_is_at_least 4.0 ; then
1150 if in_iuse mudflap ; then
1151 confgcc+=( $(use_enable mudflap libmudflap) )
1153 confgcc+=( --disable-libmudflap )
1156 if use_if_iuse libssp ; then
1157 confgcc+=( --enable-libssp )
1159 if hardened_gcc_is_stable ssp; then
1160 export gcc_cv_libc_provides_ssp=yes
1162 confgcc+=( --disable-libssp )
1166 if in_iuse cilk ; then
1167 confgcc+=( $(use_enable cilk libcilkrts) )
1170 # newer gcc's come with libquadmath, but only fortran uses
1171 # it, so auto punt it when we don't care
1172 if tc_version_is_at_least 4.6 && ! is_fortran ; then
1173 confgcc+=( --disable-libquadmath )
1176 if tc_version_is_at_least 4.6 ; then
1177 confgcc+=( --enable-lto )
1178 elif tc_version_is_at_least 4.5 ; then
1179 confgcc+=( --disable-lto )
1182 # graphite was added in 4.4 but we only support it in 4.8+ due to external
1183 # library issues. #448024
1184 if tc_version_is_at_least 5.0 ; then
1185 confgcc+=( $(use_with graphite isl) )
1186 use graphite && confgcc+=( --disable-isl-version-check )
1187 elif tc_version_is_at_least 4.8 ; then
1188 confgcc+=( $(use_with graphite cloog) )
1189 use graphite && confgcc+=( --disable-isl-version-check )
1190 elif tc_version_is_at_least 4.4 ; then
1191 confgcc+=( --without-{cloog,ppl} )
1194 if tc_version_is_at_least 4.8 ; then
1195 confgcc+=( $(use_enable sanitize libsanitizer) )
1198 if tc_version_is_at_least 6.0 ; then
1200 $(use_enable pie default-pie)
1201 # This defaults to -fstack-protector-strong.
1202 $(use_enable ssp default-ssp)
1206 # Disable gcc info regeneration -- it ships with generated info pages
1207 # already. Our custom version/urls/etc... trigger it. #464008
1208 export gcc_cv_prog_makeinfo_modern=no
1210 # Do not let the X detection get in our way. We know things can be found
1211 # via system paths, so no need to hardcode things that'll break multilib.
1212 # Older gcc versions will detect ac_x_libraries=/usr/lib64 which ends up
1213 # killing the 32bit builds which want /usr/lib.
1214 export ac_cv_have_x='have_x=yes ac_x_includes= ac_x_libraries='
1216 confgcc+=( "$@" ${EXTRA_ECONF} )
1218 # Nothing wrong with a good dose of verbosity
1220 einfo "PREFIX: ${PREFIX}"
1221 einfo "BINPATH: ${BINPATH}"
1222 einfo "LIBPATH: ${LIBPATH}"
1223 einfo "DATAPATH: ${DATAPATH}"
1224 einfo "STDCXX_INCDIR: ${STDCXX_INCDIR}"
1226 einfo "Languages: ${GCC_LANG}"
1228 einfo "Configuring GCC with: ${confgcc[@]//--/\n\t--}"
1231 # Build in a separate build tree
1232 mkdir -p "${WORKDIR}"/build
1233 pushd "${WORKDIR}"/build > /dev/null
1235 # and now to do the actual configuration
1237 echo "${S}"/configure "${confgcc[@]}"
1238 # Older gcc versions did not detect bash and re-exec itself, so force the
1239 # use of bash. Newer ones will auto-detect, but this is not harmeful.
1240 CONFIG_SHELL="/bin/bash" \
1241 bash "${S}"/configure "${confgcc[@]}" || die "failed to run configure"
1243 # return to whatever directory we were in before
1247 # Replace -m flags unsupported by the version being built with the best
1248 # available equivalent
1249 downgrade_arch_flags() {
1250 local arch bver i isa myarch mytune rep ver
1252 bver=${1:-${GCC_BRANCH_VER}}
1253 [[ $(gcc-version) < ${bver} ]] && return 0
1254 [[ $(tc-arch) != amd64 && $(tc-arch) != x86 ]] && return 0
1256 myarch=$(get-flag march)
1257 mytune=$(get-flag mtune)
1259 # If -march=native isn't supported we have to tease out the actual arch
1260 if [[ ${myarch} == native || ${mytune} == native ]] ; then
1261 if [[ ${bver} < 4.2 ]] ; then
1262 arch=$($(tc-getCC) -march=native -v -E -P - </dev/null 2>&1 \
1263 | sed -rn "/cc1.*-march/s:.*-march=([^ ']*).*:\1:p")
1264 replace-cpu-flags native ${arch}
1268 # Handle special -mtune flags
1269 [[ ${mytune} == intel && ${bver} < 4.9 ]] && replace-cpu-flags intel generic
1270 [[ ${mytune} == generic && ${bver} < 4.2 ]] && filter-flags '-mtune=*'
1271 [[ ${mytune} == x86-64 ]] && filter-flags '-mtune=*'
1272 [[ ${bver} < 3.4 ]] && filter-flags '-mtune=*'
1274 # "added" "arch" "replacement"
1278 4.9 broadwell core-avx2
1279 4.9 haswell core-avx2
1280 4.9 ivybridge core-avx-i
1282 4.9 sandybridge corei7-avx
1283 4.9 silvermont corei7
1288 4.7 core-avx2 core-avx-i
1291 4.6 core-avx-i core2
1293 4.6 corei7-avx core2
1296 4.3 athlon64-sse3 k8
1299 4.3 geode k6-2 # gcc.gnu.org/PR41989#c22
1302 3.4 athlon-fx x86-64
1307 3.4 pentium-m pentium3
1308 3.4 pentium3m pentium3
1309 3.4 pentium4m pentium4
1312 for ((i = 0; i < ${#archlist[@]}; i += 3)) ; do
1313 myarch=$(get-flag march)
1314 mytune=$(get-flag mtune)
1317 arch=${archlist[i + 1]}
1318 rep=${archlist[i + 2]}
1320 [[ ${myarch} != ${arch} && ${mytune} != ${arch} ]] && continue
1322 if [[ ${ver} > ${bver} ]] ; then
1323 einfo "Replacing ${myarch} (added in gcc ${ver}) with ${rep}..."
1324 [[ ${myarch} == ${arch} ]] && replace-cpu-flags ${myarch} ${rep}
1325 [[ ${mytune} == ${arch} ]] && replace-cpu-flags ${mytune} ${rep}
1332 # we only check -mno* here since -m* get removed by strip-flags later on
1368 for ((i = 0; i < ${#isalist[@]}; i += 2)) ; do
1370 isa=${isalist[i + 1]}
1371 [[ ${ver} > ${bver} ]] && filter-flags ${isa} ${isa/-m/-mno-}
1375 gcc_do_filter_flags() {
1377 replace-flags -O? -O2
1379 # dont want to funk ourselves
1380 filter-flags '-mabi*' -m31 -m32 -m64
1382 filter-flags -frecord-gcc-switches # 490738
1383 filter-flags -mno-rtm -mno-htm # 506202
1385 if tc_version_is_between 3.2 3.4 ; then
1386 # XXX: this is so outdated it's barely useful, but it don't hurt...
1387 replace-cpu-flags G3 750
1388 replace-cpu-flags G4 7400
1389 replace-cpu-flags G5 7400
1391 # XXX: should add a sed or something to query all supported flags
1392 # from the gcc source and trim everything else ...
1393 filter-flags -f{no-,}unit-at-a-time -f{no-,}web -mno-tls-direct-seg-refs
1394 filter-flags -f{no-,}stack-protector{,-all}
1395 filter-flags -fvisibility-inlines-hidden -fvisibility=hidden
1398 if tc_version_is_at_least 3.4 ; then
1401 filter-flags '-mcpu=*'
1403 tc_version_is_between 4.4 4.5 && append-flags -mno-avx # 357287
1405 if tc_version_is_between 4.6 4.7 ; then
1406 # https://bugs.gentoo.org/411333
1407 # https://bugs.gentoo.org/466454
1408 replace-cpu-flags c3-2 pentium2 pentium3 pentium3m pentium-m i686
1412 # https://bugs.gentoo.org/454426
1413 append-ldflags -Wl,--no-relax
1416 # temporary workaround for random ICEs reproduced by multiple users
1417 # https://bugs.gentoo.org/457062
1418 tc_version_is_between 4.6 4.8 && MAKEOPTS+=" -j1"
1421 # http://gcc.gnu.org/PR25127
1422 tc_version_is_between 4.0 4.2 && \
1423 filter-flags '-mcpu=*' '-march=*' '-mtune=*'
1428 strip-unsupported-flags
1430 # these are set here so we have something sane at configure time
1431 if is_crosscompile ; then
1432 # Set this to something sane for both native and target
1437 local VAR="CFLAGS_"${CTARGET//-/_}
1441 export GCJFLAGS=${GCJFLAGS:-${CFLAGS}}
1444 setup_minispecs_gcc_build_specs() {
1445 # Setup the "build.specs" file for gcc 4.3 to use when building.
1446 if hardened_gcc_works pie ; then
1447 cat "${WORKDIR}"/specs/pie.specs >> "${WORKDIR}"/build.specs
1449 if hardened_gcc_works ssp ; then
1450 for s in ssp sspall ; do
1451 cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs
1454 for s in nostrict znow ; do
1455 cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs
1457 export GCC_SPECS="${WORKDIR}"/build.specs
1460 gcc-multilib-configure() {
1461 if ! is_multilib ; then
1462 confgcc+=( --disable-multilib )
1463 # Fun times: if we are building for a target that has multiple
1464 # possible ABI formats, and the user has told us to pick one
1465 # that isn't the default, then not specifying it via the list
1466 # below will break that on us.
1468 confgcc+=( --enable-multilib )
1471 # translate our notion of multilibs into gcc's
1473 for abi in $(get_all_abis TARGET) ; do
1474 local l=$(gcc-abi-map ${abi})
1475 [[ -n ${l} ]] && list+=",${l}"
1477 if [[ -n ${list} ]] ; then
1480 tc_version_is_at_least 4.8 && confgcc+=( --with-multilib-list=${list:1} )
1487 # Convert the ABI name we use in Gentoo to what gcc uses
1490 mips*) map=("o32 32" "n32 n32" "n64 64") ;;
1491 x86_64*) map=("amd64 m64" "x86 m32" "x32 mx32") ;;
1495 for m in "${map[@]}" ; do
1497 [[ $1 == ${l[0]} ]] && echo ${l[1]} && break
1501 #----> src_compile <----
1503 toolchain_src_compile() {
1504 touch "${S}"/gcc/c-gperf.h
1506 # Do not make manpages if we do not have perl ...
1507 [[ ! -x /usr/bin/perl ]] \
1508 && find "${WORKDIR}"/build -name '*.[17]' | xargs touch
1510 gcc_do_make ${GCC_MAKE_TARGET}
1514 # This function accepts one optional argument, the make target to be used.
1515 # If omitted, gcc_do_make will try to guess whether it should use all,
1516 # or bootstrap-lean depending on CTARGET and arch.
1517 # An example of how to use this function:
1519 # gcc_do_make all-target-libstdc++-v3
1521 [[ -n ${1} ]] && GCC_MAKE_TARGET=${1}
1524 if is_crosscompile || tc-is-cross-compiler ; then
1525 # 3 stage bootstrapping doesnt quite work when you cant run the
1526 # resulting binaries natively ^^;
1527 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-all}
1529 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-bootstrap-lean}
1532 # Older versions of GCC could not do profiledbootstrap in parallel due to
1533 # collisions with profiling info.
1534 # boundschecking also seems to introduce parallel build issues.
1535 if [[ ${GCC_MAKE_TARGET} == "profiledbootstrap" ]] || use_if_iuse boundschecking ; then
1536 ! tc_version_is_at_least 4.6 && export MAKEOPTS="${MAKEOPTS} -j1"
1539 if [[ ${GCC_MAKE_TARGET} == "all" ]] ; then
1540 STAGE1_CFLAGS=${STAGE1_CFLAGS-"${CFLAGS}"}
1541 elif [[ $(gcc-version) == "3.4" && ${GCC_BRANCH_VER} == "3.4" ]] && gcc-specs-ssp ; then
1543 STAGE1_CFLAGS=${STAGE1_CFLAGS-"-O2"}
1546 if is_crosscompile; then
1547 # In 3.4, BOOT_CFLAGS is never used on a crosscompile...
1548 # but I'll leave this in anyways as someone might have had
1549 # some reason for putting it in here... --eradicator
1550 BOOT_CFLAGS=${BOOT_CFLAGS-"-O2"}
1552 # we only want to use the system's CFLAGS if not building a
1554 BOOT_CFLAGS=${BOOT_CFLAGS-"$(get_abi_CFLAGS ${TARGET_DEFAULT_ABI}) ${CFLAGS}"}
1557 einfo "Compiling ${PN} (${GCC_MAKE_TARGET})..."
1559 pushd "${WORKDIR}"/build >/dev/null
1562 LDFLAGS="${LDFLAGS}" \
1563 STAGE1_CFLAGS="${STAGE1_CFLAGS}" \
1564 LIBPATH="${LIBPATH}" \
1565 BOOT_CFLAGS="${BOOT_CFLAGS}" \
1566 ${GCC_MAKE_TARGET} \
1567 || die "emake failed with ${GCC_MAKE_TARGET}"
1569 if ! is_crosscompile && use cxx && use_if_iuse doc ; then
1570 if type -p doxygen > /dev/null ; then
1571 if tc_version_is_at_least 4.3 ; then
1572 cd "${CTARGET}"/libstdc++-v3/doc
1573 emake doc-man-doxygen || ewarn "failed to make docs"
1574 elif tc_version_is_at_least 3.0 ; then
1575 cd "${CTARGET}"/libstdc++-v3
1576 emake doxygen-man || ewarn "failed to make docs"
1578 # Clean bogus manpages. #113902
1579 find -name '*_build_*' -delete
1580 # Blow away generated directory references. Newer versions of gcc
1581 # have gotten better at this, but not perfect. This is easier than
1582 # backporting all of the various doxygen patches. #486754
1583 find -name '*_.3' -exec grep -l ' Directory Reference ' {} + | \
1586 ewarn "Skipping libstdc++ manpage generation since you don't have doxygen installed"
1593 #---->> src_test <<----
1595 toolchain_src_test() {
1596 if use regression-test ; then
1597 cd "${WORKDIR}"/build
1602 #---->> src_install <<----
1604 toolchain_src_install() {
1605 cd "${WORKDIR}"/build
1607 # Do allow symlinks in private gcc include dir as this can break the build
1608 find gcc/include*/ -type l -delete
1610 # Copy over the info pages. We disabled their generation earlier, but the
1611 # build system only expects to install out of the build dir, not the source. #464008
1614 for x in "${S}"/gcc/doc/*.info* ; do
1615 if [[ -f ${x} ]] ; then
1616 cp "${x}" gcc/doc/ || die
1620 # We remove the generated fixincludes, as they can cause things to break
1621 # (ncurses, openssl, etc). We do not prevent them from being built, as
1622 # in the following commit which we revert:
1623 # https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/eclass/toolchain.eclass?r1=1.647&r2=1.648
1624 # This is because bsd userland needs fixedincludes to build gcc, while
1625 # linux does not. Both can dispose of them afterwards.
1627 grep -q 'It has been auto-edited by fixincludes from' "${x}" \
1629 done < <(find gcc/include*/ -name '*.h')
1631 # Do the 'make install' from the build directory
1632 S="${WORKDIR}"/build emake -j1 DESTDIR="${D}" install || die
1634 # Punt some tools which are really only useful while building gcc
1635 find "${D}" -name install-tools -prune -type d -exec rm -rf "{}" \;
1636 # This one comes with binutils
1637 find "${D}" -name libiberty.a -delete
1639 # Move the libraries to the proper location
1642 # Basic sanity check
1643 if ! is_crosscompile ; then
1645 eval $(grep ^EXEEXT= "${WORKDIR}"/build/gcc/config.log)
1646 [[ -r ${D}${BINPATH}/gcc${EXEEXT} ]] || die "gcc not found in ${D}"
1649 dodir /etc/env.d/gcc
1650 create_gcc_env_entry
1652 # Setup the gcc_env_entry for hardened gcc 4 with minispecs
1653 want_minispecs && copy_minispecs_gcc_specs
1655 # Make sure we dont have stuff lying around that
1656 # can nuke multiple versions of gcc
1661 # Ugh: we really need to auto-detect this list.
1662 # It's constantly out of date.
1663 for x in cpp gcc g++ c++ gcov g77 gcj gcjh gfortran gccgo ; do
1664 # For some reason, g77 gets made instead of ${CTARGET}-g77...
1665 # this should take care of that
1666 [[ -f ${x} ]] && mv ${x} ${CTARGET}-${x}
1668 if [[ -f ${CTARGET}-${x} ]] ; then
1669 if ! is_crosscompile ; then
1670 ln -sf ${CTARGET}-${x} ${x}
1671 dosym ${BINPATH}/${CTARGET}-${x} \
1672 /usr/bin/${x}-${GCC_CONFIG_VER}
1674 # Create versioned symlinks
1675 dosym ${BINPATH}/${CTARGET}-${x} \
1676 /usr/bin/${CTARGET}-${x}-${GCC_CONFIG_VER}
1679 if [[ -f ${CTARGET}-${x}-${GCC_CONFIG_VER} ]] ; then
1680 rm -f ${CTARGET}-${x}-${GCC_CONFIG_VER}
1681 ln -sf ${CTARGET}-${x} ${CTARGET}-${x}-${GCC_CONFIG_VER}
1685 # Now do the fun stripping stuff
1686 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${BINPATH}"
1687 env RESTRICT="" CHOST=${CTARGET} prepstrip "${D}${LIBPATH}"
1688 # gcc used to install helper binaries in lib/ but then moved to libexec/
1689 [[ -d ${D}${PREFIX}/libexec/gcc ]] && \
1690 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}"
1693 if is_crosscompile; then
1694 rm -rf "${D}"/usr/share/{man,info}
1695 rm -rf "${D}"${DATAPATH}/{man,info}
1697 if tc_version_is_at_least 3.0 ; then
1698 local cxx_mandir=$(find "${WORKDIR}/build/${CTARGET}/libstdc++-v3" -name man)
1699 if [[ -d ${cxx_mandir} ]] ; then
1700 cp -r "${cxx_mandir}"/man? "${D}/${DATAPATH}"/man/
1703 has noinfo ${FEATURES} \
1704 && rm -r "${D}/${DATAPATH}"/info \
1705 || prepinfo "${DATAPATH}"
1706 has noman ${FEATURES} \
1707 && rm -r "${D}/${DATAPATH}"/man \
1708 || prepman "${DATAPATH}"
1710 # prune empty dirs left behind
1711 find "${D}" -depth -type d -delete 2>/dev/null
1713 # install testsuite results
1714 if use regression-test; then
1716 find "${WORKDIR}"/build -type f -name "*.sum" -print0 | xargs -0 dodoc
1717 find "${WORKDIR}"/build -type f -path "*/testsuite/*.log" -print0 \
1721 # Rather install the script, else portage with changing $FILESDIR
1722 # between binary and source package borks things ....
1723 if ! is_crosscompile ; then
1724 insinto "${DATAPATH}"
1725 newins "${GCC_FILESDIR}"/awk/fixlafiles.awk-no_gcc_la fixlafiles.awk || die
1726 find "${D}/${LIBPATH}" -name libstdc++.la -type f -delete
1727 find "${D}/${LIBPATH}" -name 'lib*san.la' -type f -delete #487550 #546700
1728 exeinto "${DATAPATH}"
1729 doexe "${GCC_FILESDIR}"/fix_libtool_files.sh || die
1730 doexe "${GCC_FILESDIR}"/c{89,99} || die
1733 # Use gid of 0 because some stupid ports don't have
1734 # the group 'root' set to gid 0. Send to /dev/null
1735 # for people who are testing as non-root.
1736 chown -R root:0 "${D}"${LIBPATH} 2>/dev/null
1738 # Move pretty-printers to gdb datadir to shut ldconfig up
1739 local py gdbdir=/usr/share/gdb/auto-load${LIBPATH/\/lib\//\/$(get_libdir)\/}
1740 pushd "${D}"${LIBPATH} >/dev/null
1741 for py in $(find . -name '*-gdb.py') ; do
1742 local multidir=${py%/*}
1743 insinto "${gdbdir}/${multidir}"
1744 sed -i "/^libdir =/s:=.*:= '${LIBPATH}/${multidir}':" "${py}" || die #348128
1745 doins "${py}" || die
1750 # Don't scan .gox files for executable stacks - false positives
1751 export QA_EXECSTACK="usr/lib*/go/*/*.gox"
1752 export QA_WX_LOAD="usr/lib*/go/*/*.gox"
1754 # Disable RANDMMAP so PCH works. #301299
1755 if tc_version_is_at_least 4.3 ; then
1756 pax-mark -r "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}/cc1"
1757 pax-mark -r "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}/cc1plus"
1761 # Move around the libs to the right location. For some reason,
1762 # when installing gcc, it dumps internal libraries into /usr/lib
1763 # instead of the private gcc lib path
1765 # older versions of gcc did not support --print-multi-os-directory
1766 tc_version_is_at_least 3.2 || return 0
1768 local x multiarg removedirs=""
1769 for multiarg in $($(XGCC) -print-multi-lib) ; do
1770 multiarg=${multiarg#*;}
1771 multiarg=${multiarg//@/ -}
1773 local OS_MULTIDIR=$($(XGCC) ${multiarg} --print-multi-os-directory)
1774 local MULTIDIR=$($(XGCC) ${multiarg} --print-multi-directory)
1775 local TODIR=${D}${LIBPATH}/${MULTIDIR}
1778 [[ -d ${TODIR} ]] || mkdir -p ${TODIR}
1781 ${LIBPATH}/${OS_MULTIDIR} \
1782 ${LIBPATH}/../${MULTIDIR} \
1783 ${PREFIX}/lib/${OS_MULTIDIR} \
1784 ${PREFIX}/${CTARGET}/lib/${OS_MULTIDIR}
1786 removedirs="${removedirs} ${FROMDIR}"
1787 FROMDIR=${D}${FROMDIR}
1788 if [[ ${FROMDIR} != "${TODIR}" && -d ${FROMDIR} ]] ; then
1789 local files=$(find "${FROMDIR}" -maxdepth 1 ! -type d 2>/dev/null)
1790 if [[ -n ${files} ]] ; then
1791 mv ${files} "${TODIR}" || die
1795 fix_libtool_libdir_paths "${LIBPATH}/${MULTIDIR}"
1797 # SLOT up libgcj.pc if it's available (and let gcc-config worry about links)
1798 FROMDIR="${PREFIX}/lib/${OS_MULTIDIR}"
1799 for x in "${D}${FROMDIR}"/pkgconfig/libgcj*.pc ; do
1800 [[ -f ${x} ]] || continue
1801 sed -i "/^libdir=/s:=.*:=${LIBPATH}/${MULTIDIR}:" "${x}" || die
1802 mv "${x}" "${D}${FROMDIR}"/pkgconfig/libgcj-${GCC_PV}.pc || die
1806 # We remove directories separately to avoid this case:
1807 # mv SRC/lib/../lib/*.o DEST
1808 # rmdir SRC/lib/../lib/
1809 # mv SRC/lib/../lib32/*.o DEST # Bork
1810 for FROMDIR in ${removedirs} ; do
1811 rmdir "${D}"${FROMDIR} >& /dev/null
1813 find "${D}" -type d | xargs rmdir >& /dev/null
1816 # make sure the libtool archives have libdir set to where they actually
1817 # -are-, and not where they -used- to be. also, any dependencies we have
1818 # on our own .la files need to be updated.
1819 fix_libtool_libdir_paths() {
1822 pushd "${D}" >/dev/null
1824 pushd "./${libpath}" >/dev/null
1825 local dir="${PWD#${D%/}}"
1826 local allarchives=$(echo *.la)
1827 allarchives="\(${allarchives// /\\|}\)"
1830 # The libdir might not have any .la files. #548782
1831 find "./${dir}" -maxdepth 1 -name '*.la' \
1832 -exec sed -i -e "/^libdir=/s:=.*:='${dir}':" {} + || die
1833 # Would be nice to combine these, but -maxdepth can not be specified
1834 # on sub-expressions.
1835 find "./${PREFIX}"/lib* -maxdepth 3 -name '*.la' \
1836 -exec sed -i -e "/^dependency_libs=/s:/[^ ]*/${allarchives}:${libpath}/\1:g" {} + || die
1837 find "./${dir}/" -maxdepth 1 -name '*.la' \
1838 -exec sed -i -e "/^dependency_libs=/s:/[^ ]*/${allarchives}:${libpath}/\1:g" {} + || die
1843 create_gcc_env_entry() {
1844 dodir /etc/env.d/gcc
1845 local gcc_envd_base="/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}"
1847 local gcc_specs_file
1848 local gcc_envd_file="${D}${gcc_envd_base}"
1849 if [[ -z $1 ]] ; then
1850 # I'm leaving the following commented out to remind me that it
1851 # was an insanely -bad- idea. Stuff broke. GCC_SPECS isnt unset
1852 # on chroot or in non-toolchain.eclass gcc ebuilds!
1853 #gcc_specs_file="${LIBPATH}/specs"
1856 gcc_envd_file+="-$1"
1857 gcc_specs_file="${LIBPATH}/$1.specs"
1860 # We want to list the default ABI's LIBPATH first so libtool
1861 # searches that directory first. This is a temporary
1862 # workaround for libtool being stupid and using .la's from
1863 # conflicting ABIs by using the first one in the search path
1864 local ldpaths mosdirs
1865 if tc_version_is_at_least 3.2 ; then
1866 local mdir mosdir abi ldpath
1867 for abi in $(get_all_abis TARGET) ; do
1868 mdir=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory)
1870 [[ ${mdir} != "." ]] && ldpath+="/${mdir}"
1871 ldpaths="${ldpath}${ldpaths:+:${ldpaths}}"
1873 mosdir=$($(XGCC) $(get_abi_CFLAGS ${abi}) -print-multi-os-directory)
1874 mosdirs="${mosdir}${mosdirs:+:${mosdirs}}"
1877 # Older gcc's didn't do multilib, so logic is simple.
1881 cat <<-EOF > ${gcc_envd_file}
1883 ROOTPATH="${BINPATH}"
1884 GCC_PATH="${BINPATH}"
1886 MANPATH="${DATAPATH}/man"
1887 INFOPATH="${DATAPATH}/info"
1888 STDCXX_INCDIR="${STDCXX_INCDIR##*/}"
1889 CTARGET="${CTARGET}"
1890 GCC_SPECS="${gcc_specs_file}"
1891 MULTIOSDIRS="${mosdirs}"
1895 copy_minispecs_gcc_specs() {
1896 # setup the hardenedno* specs files and the vanilla specs file.
1897 if hardened_gcc_works ; then
1898 create_gcc_env_entry hardenednopiessp
1900 if hardened_gcc_works pie ; then
1901 create_gcc_env_entry hardenednopie
1903 if hardened_gcc_works ssp ; then
1904 create_gcc_env_entry hardenednossp
1906 create_gcc_env_entry vanilla
1908 doins "${WORKDIR}"/specs/*.specs || die "failed to install specs"
1909 # Build system specs file which, if it exists, must be a complete set of
1910 # specs as it completely and unconditionally overrides the builtin specs.
1911 if ! tc_version_is_at_least 4.4 ; then
1912 $(XGCC) -dumpspecs > "${WORKDIR}"/specs/specs
1913 cat "${WORKDIR}"/build.specs >> "${WORKDIR}"/specs/specs
1914 doins "${WORKDIR}"/specs/specs || die "failed to install the specs file"
1921 # Move Java headers to compiler-specific dir
1922 for x in "${D}"${PREFIX}/include/gc*.h "${D}"${PREFIX}/include/j*.h ; do
1923 [[ -f ${x} ]] && mv -f "${x}" "${D}"${LIBPATH}/include/
1925 for x in gcj gnu java javax org ; do
1926 if [[ -d ${D}${PREFIX}/include/${x} ]] ; then
1927 dodir /${LIBPATH}/include/${x}
1928 mv -f "${D}"${PREFIX}/include/${x}/* "${D}"${LIBPATH}/include/${x}/
1929 rm -rf "${D}"${PREFIX}/include/${x}
1933 if [[ -d ${D}${PREFIX}/lib/security ]] || [[ -d ${D}${PREFIX}/$(get_libdir)/security ]] ; then
1934 dodir /${LIBPATH}/security
1935 mv -f "${D}"${PREFIX}/lib*/security/* "${D}"${LIBPATH}/security
1936 rm -rf "${D}"${PREFIX}/lib*/security
1939 # Move random gcj files to compiler-specific directories
1940 for x in libgcj.spec logging.properties ; do
1941 x="${D}${PREFIX}/lib/${x}"
1942 [[ -f ${x} ]] && mv -f "${x}" "${D}"${LIBPATH}/
1945 # Rename jar because it could clash with Kaffe's jar if this gcc is
1946 # primary compiler (aka don't have the -<version> extension)
1948 [[ -f jar ]] && mv -f jar gcj-jar
1951 #---->> pkg_post* <<----
1953 toolchain_pkg_postinst() {
1956 if ! is_crosscompile ; then
1958 ewarn "If you have issues with packages unable to locate libstdc++.la,"
1959 ewarn "then try running 'fix_libtool_files.sh' on the old gcc versions."
1961 ewarn "You might want to review the GCC upgrade guide when moving between"
1962 ewarn "major versions (like 4.2 to 4.3):"
1963 ewarn "https://wiki.gentoo.org/wiki/Upgrading_GCC"
1966 # Clean up old paths
1967 rm -f "${ROOT}"/*/rcscripts/awk/fixlafiles.awk "${ROOT}"/sbin/fix_libtool_files.sh
1968 rmdir "${ROOT}"/*/rcscripts{/awk,} 2>/dev/null
1970 mkdir -p "${ROOT}"/usr/{share/gcc-data,sbin,bin}
1971 cp "${ROOT}/${DATAPATH}"/fixlafiles.awk "${ROOT}"/usr/share/gcc-data/ || die
1972 cp "${ROOT}/${DATAPATH}"/fix_libtool_files.sh "${ROOT}"/usr/sbin/ || die
1974 # Since these aren't critical files and portage sucks with
1975 # handling of binpkgs, don't require these to be found
1976 cp "${ROOT}/${DATAPATH}"/c{89,99} "${ROOT}"/usr/bin/ 2>/dev/null
1979 if use regression-test ; then
1980 elog "Testsuite results have been installed into /usr/share/doc/${PF}/testsuite"
1984 if [[ -n ${PRERELEASE}${SNAPSHOT} ]] ; then
1985 einfo "This GCC ebuild is provided for your convenience, and the use"
1986 einfo "of this compiler is not supported by the Gentoo Developers."
1987 einfo "Please report bugs to upstream at http://gcc.gnu.org/bugzilla/"
1991 toolchain_pkg_postrm() {
1992 # to make our lives easier (and saner), we do the fix_libtool stuff here.
1993 # rather than checking SLOT's and trying in upgrade paths, we just see if
1994 # the common libstdc++.la exists in the ${LIBPATH} of the gcc that we are
1995 # unmerging. if it does, that means this was a simple re-emerge.
1997 # clean up the cruft left behind by cross-compilers
1998 if is_crosscompile ; then
1999 if [[ -z $(ls "${ROOT}"/etc/env.d/gcc/${CTARGET}* 2>/dev/null) ]] ; then
2000 rm -f "${ROOT}"/etc/env.d/gcc/config-${CTARGET}
2001 rm -f "${ROOT}"/etc/env.d/??gcc-${CTARGET}
2002 rm -f "${ROOT}"/usr/bin/${CTARGET}-{gcc,{g,c}++}{,32,64}
2007 # ROOT isnt handled by the script
2008 [[ ${ROOT} != "/" ]] && return 0
2010 if [[ ! -e ${LIBPATH}/libstdc++.so ]] ; then
2011 # make sure the profile is sane during same-slot upgrade #289403
2014 einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}'"
2015 /usr/sbin/fix_libtool_files.sh ${GCC_RELEASE_VER}
2016 if [[ -n ${BRANCH_UPDATE} ]] ; then
2017 einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE}'"
2018 /usr/sbin/fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE}
2026 if ! should_we_gcc_config ; then
2027 env -i ROOT="${ROOT}" gcc-config --use-old --force
2031 local current_gcc_config="" current_specs="" use_specs=""
2033 current_gcc_config=$(env -i ROOT="${ROOT}" gcc-config -c ${CTARGET} 2>/dev/null)
2034 if [[ -n ${current_gcc_config} ]] ; then
2035 # figure out which specs-specific config is active
2036 current_specs=$(gcc-config -S ${current_gcc_config} | awk '{print $3}')
2037 [[ -n ${current_specs} ]] && use_specs=-${current_specs}
2039 if [[ -n ${use_specs} ]] && \
2040 [[ ! -e ${ROOT}/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}${use_specs} ]]
2042 ewarn "The currently selected specs-specific gcc config,"
2043 ewarn "${current_specs}, doesn't exist anymore. This is usually"
2044 ewarn "due to enabling/disabling hardened or switching to a version"
2045 ewarn "of gcc that doesnt create multiple specs files. The default"
2046 ewarn "config will be used, and the previous preference forgotten."
2050 gcc-config ${CTARGET}-${GCC_CONFIG_VER}${use_specs}
2053 should_we_gcc_config() {
2054 # if the current config is invalid, we definitely want a new one
2055 # Note: due to bash quirkiness, the following must not be 1 line
2057 curr_config=$(env -i ROOT="${ROOT}" gcc-config -c ${CTARGET} 2>&1) || return 0
2059 # if the previously selected config has the same major.minor (branch) as
2060 # the version we are installing, then it will probably be uninstalled
2061 # for being in the same SLOT, make sure we run gcc-config.
2062 local curr_config_ver=$(env -i ROOT="${ROOT}" gcc-config -S ${curr_config} | awk '{print $2}')
2064 local curr_branch_ver=$(get_version_component_range 1-2 ${curr_config_ver})
2066 # If we're using multislot, just run gcc-config if we're installing
2067 # to the same profile as the current one.
2068 use multislot && return $([[ ${curr_config_ver} == ${GCC_CONFIG_VER} ]])
2070 if [[ ${curr_branch_ver} == ${GCC_BRANCH_VER} ]] ; then
2073 # if we're installing a genuinely different compiler version,
2074 # we should probably tell the user -how- to switch to the new
2075 # gcc version, since we're not going to do it for him/her.
2076 # We don't want to switch from say gcc-3.3 to gcc-3.4 right in
2077 # the middle of an emerge operation (like an 'emerge -e world'
2078 # which could install multiple gcc versions).
2079 # Only warn if we're installing a pkg as we might be called from
2080 # the pkg_{pre,post}rm steps. #446830
2081 if [[ ${EBUILD_PHASE} == *"inst" ]] ; then
2082 einfo "The current gcc config appears valid, so it will not be"
2083 einfo "automatically switched for you. If you would like to"
2084 einfo "switch to the newly installed gcc version, do the"
2087 einfo "gcc-config ${CTARGET}-${GCC_CONFIG_VER}"
2088 einfo "source /etc/profile"
2095 #---->> support and misc functions <<----
2097 # This is to make sure we don't accidentally try to enable support for a
2098 # language that doesnt exist. GCC 3.4 supports f77, while 4.0 supports f95, etc.
2100 # Also add a hook so special ebuilds (kgcc64) can control which languages
2101 # exactly get enabled
2102 gcc-lang-supported() {
2103 grep ^language=\"${1}\" "${S}"/gcc/*/config-lang.in > /dev/null || return 1
2104 [[ -z ${TOOLCHAIN_ALLOWED_LANGS} ]] && return 0
2105 has $1 ${TOOLCHAIN_ALLOWED_LANGS}
2109 gcc-lang-supported ada || return 1
2114 gcc-lang-supported 'c++' || return 1
2115 ! is_crosscompile && tc_version_is_at_least 4.8 && return 0
2120 gcc-lang-supported d || return 1
2125 gcc-lang-supported f77 || return 1
2130 gcc-lang-supported f95 || return 1
2135 gcc-lang-supported fortran || return 1
2140 gcc-lang-supported java || return 1
2141 use cxx && use_if_iuse gcj
2145 gcc-lang-supported go || return 1
2146 use cxx && use_if_iuse go
2150 tc_version_is_at_least 3 || return 1
2155 gcc-lang-supported objc || return 1
2160 gcc-lang-supported 'obj-c++' || return 1
2161 use cxx && use_if_iuse objc++
2164 # Grab a variable from the build system (taken from linux-info.eclass)
2166 local var=$1 makefile=${2:-${WORKDIR}/build/Makefile}
2167 echo -e "e:\\n\\t@echo \$(${var})\\ninclude ${makefile}" | \
2168 r=${makefile%/*} emake --no-print-directory -s -f - 2>/dev/null
2171 XGCC() { get_make_var GCC_FOR_TARGET ; }
2173 # The gentoo piessp patches allow for 3 configurations:
2174 # 1) PIE+SSP by default
2177 hardened_gcc_works() {
2178 if [[ $1 == "pie" ]] ; then
2179 # $gcc_cv_ld_pie is unreliable as it simply take the output of
2180 # `ld --help | grep -- -pie`, that reports the option in all cases, also if
2181 # the loader doesn't actually load the resulting executables.
2182 # To avoid breakage, blacklist FreeBSD here at least
2183 [[ ${CTARGET} == *-freebsd* ]] && return 1
2185 want_pie || return 1
2186 use_if_iuse nopie && return 1
2187 hardened_gcc_is_stable pie
2189 elif [[ $1 == "ssp" ]] ; then
2190 [[ -n ${SPECS_VER} ]] || return 1
2191 use_if_iuse nossp && return 1
2192 hardened_gcc_is_stable ssp
2196 hardened_gcc_works pie || return 1
2197 hardened_gcc_works ssp || return 1
2202 hardened_gcc_is_stable() {
2204 if [[ $1 == "pie" ]] ; then
2205 if [[ ${CTARGET} == *-uclibc* ]] ; then
2206 tocheck=${PIE_UCLIBC_STABLE}
2208 tocheck=${PIE_GLIBC_STABLE}
2210 elif [[ $1 == "ssp" ]] ; then
2211 if [[ ${CTARGET} == *-uclibc* ]] ; then
2212 tocheck=${SSP_UCLIBC_STABLE}
2213 elif [[ ${CTARGET} == *-gnu* ]] ; then
2214 tocheck=${SSP_STABLE}
2217 die "hardened_gcc_stable needs to be called with pie or ssp"
2220 has $(tc-arch) ${tocheck} && return 0
2225 if tc_version_is_at_least 4.3.2 && use hardened ; then
2226 if ! want_pie ; then
2227 ewarn "PIE_VER or SPECS_VER is not defined in the GCC ebuild."
2228 elif use vanilla ; then
2229 ewarn "You will not get hardened features if you have the vanilla USE-flag."
2230 elif use nopie && use nossp ; then
2231 ewarn "You will not get hardened features if you have the nopie and nossp USE-flag."
2232 elif ! hardened_gcc_works ; then
2233 ewarn "Your $(tc-arch) arch is not supported."
2237 ewarn "Hope you know what you are doing. Hardened will not work."
2244 ! use hardened && [[ -n ${PIE_VER} ]] && use nopie && return 1
2245 [[ -n ${PIE_VER} ]] && [[ -n ${SPECS_VER} ]] && return 0
2246 tc_version_is_at_least 4.3.2 && return 1
2247 [[ -z ${PIE_VER} ]] && return 1
2248 use !nopie && return 0
2252 has toolchain_death_notice ${EBUILD_DEATH_HOOKS} || EBUILD_DEATH_HOOKS+=" toolchain_death_notice"
2253 toolchain_death_notice() {
2254 if [[ -e "${WORKDIR}"/build ]] ; then
2255 pushd "${WORKDIR}"/build >/dev/null
2256 (echo '' | $(tc-getCC ${CTARGET}) ${CFLAGS} -v -E - 2>&1) > gccinfo.log
2257 [[ -e "${T}"/build.log ]] && cp "${T}"/build.log .
2258 tar jcf "${WORKDIR}"/gcc-build-logs.tar.bz2 \
2259 gccinfo.log build.log $(find -name config.log)
2260 rm gccinfo.log build.log
2262 eerror "Please include ${WORKDIR}/gcc-build-logs.tar.bz2 in your bug report."