/[gentoo-x86]/eclass/toolchain.eclass
Gentoo

Contents of /eclass/toolchain.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.606 - (show annotations) (download)
Mon Nov 25 03:11:57 2013 UTC (9 months ago) by dirtyepic
Branch: MAIN
Changes since 1.605: +3 -1 lines
Prevent comparison failures due to -frecord-gcc-switches (bug #490738).

1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/toolchain.eclass,v 1.605 2013/11/09 10:05:12 dirtyepic Exp $
4
5 # Maintainer: Toolchain Ninjas <toolchain@gentoo.org>
6
7 #---->> eclass stuff <<----
8 DESCRIPTION="The GNU Compiler Collection"
9 HOMEPAGE="http://gcc.gnu.org/"
10 LICENSE="GPL-2 LGPL-2.1"
11 RESTRICT="strip" # cross-compilers need controlled stripping
12
13 inherit eutils versionator libtool toolchain-funcs flag-o-matic gnuconfig multilib fixheadtails pax-utils
14
15 if [[ ${PV} == *_pre9999* ]] ; then
16 EGIT_REPO_URI="git://gcc.gnu.org/git/gcc.git"
17 # naming style:
18 # gcc-4.7.1_pre9999 -> gcc-4_7-branch
19 # Note that the micro version is required or lots of stuff will break.
20 # To checkout master set gcc_LIVE_BRANCH="master" in the ebuild before
21 # inheriting this eclass.
22 EGIT_BRANCH="${PN}-${PV%.?_pre9999}-branch"
23 EGIT_BRANCH=${EGIT_BRANCH//./_}
24 inherit git-2
25 fi
26
27 FEATURES=${FEATURES/multilib-strict/}
28
29 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_test src_install pkg_postinst pkg_postrm
30 #----<< eclass stuff >>----
31
32 #---->> globals <<----
33 export CTARGET=${CTARGET:-${CHOST}}
34 if [[ ${CTARGET} = ${CHOST} ]] ; then
35 if [[ ${CATEGORY/cross-} != ${CATEGORY} ]] ; then
36 export CTARGET=${CATEGORY/cross-}
37 fi
38 fi
39 : ${TARGET_ABI:=${ABI}}
40 : ${TARGET_MULTILIB_ABIS:=${MULTILIB_ABIS}}
41 : ${TARGET_DEFAULT_ABI:=${DEFAULT_ABI}}
42
43 is_crosscompile() {
44 [[ ${CHOST} != ${CTARGET} ]]
45 }
46
47 # General purpose version check. Without a second arg matches up to minor version (x.x.x)
48 # (ie. 4.6.0_pre9999 matches 4 or 4.6 or 4.6.0 but not 4.6.1)
49 tc_version_is_at_least() {
50 version_is_at_least "$1" "${2:-${GCC_RELEASE_VER}}"
51 }
52
53 GCC_PV=${TOOLCHAIN_GCC_PV:-${PV}}
54 GCC_PVR=${GCC_PV}
55 [[ ${PR} != "r0" ]] && GCC_PVR=${GCC_PVR}-${PR}
56 GCC_RELEASE_VER=$(get_version_component_range 1-3 ${GCC_PV})
57 GCC_BRANCH_VER=$(get_version_component_range 1-2 ${GCC_PV})
58 GCCMAJOR=$(get_version_component_range 1 ${GCC_PV})
59 GCCMINOR=$(get_version_component_range 2 ${GCC_PV})
60 GCCMICRO=$(get_version_component_range 3 ${GCC_PV})
61 [[ ${BRANCH_UPDATE-notset} == "notset" ]] && \
62 BRANCH_UPDATE=$(get_version_component_range 4 ${GCC_PV})
63
64 # According to gcc/c-cppbuiltin.c, GCC_CONFIG_VER MUST match this regex.
65 # ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)?
66 GCC_CONFIG_VER=${GCC_CONFIG_VER:-$(replace_version_separator 3 '-' ${GCC_PV})}
67
68 # Pre-release support
69 if [[ ${GCC_PV} != ${GCC_PV/_pre/-} ]] ; then
70 PRERELEASE=${GCC_PV/_pre/-}
71 fi
72
73 # make _alpha and _beta ebuilds automatically use a snapshot
74 if [[ ${GCC_PV} == *_alpha* ]] ; then
75 SNAPSHOT=${GCC_BRANCH_VER}-${GCC_PV##*_alpha}
76 elif [[ ${GCC_PV} == *_beta* ]] ; then
77 SNAPSHOT=${GCC_BRANCH_VER}-${GCC_PV##*_beta}
78 elif [[ ${GCC_PV} == *_rc* ]] ; then
79 SNAPSHOT=${GCC_PV%_rc*}-RC-${GCC_PV##*_rc}
80 fi
81
82 export GCC_FILESDIR=${GCC_FILESDIR:-${FILESDIR}}
83 PREFIX=${TOOLCHAIN_PREFIX:-/usr}
84
85 if tc_version_is_at_least 3.4.0 ; then
86 LIBPATH=${TOOLCHAIN_LIBPATH:-${PREFIX}/lib/gcc/${CTARGET}/${GCC_CONFIG_VER}}
87 else
88 LIBPATH=${TOOLCHAIN_LIBPATH:-${PREFIX}/lib/gcc-lib/${CTARGET}/${GCC_CONFIG_VER}}
89 fi
90 INCLUDEPATH=${TOOLCHAIN_INCLUDEPATH:-${LIBPATH}/include}
91
92 if is_crosscompile ; then
93 BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/${CHOST}/${CTARGET}/gcc-bin/${GCC_CONFIG_VER}}
94 else
95 BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/${CTARGET}/gcc-bin/${GCC_CONFIG_VER}}
96 fi
97
98 DATAPATH=${TOOLCHAIN_DATAPATH:-${PREFIX}/share/gcc-data/${CTARGET}/${GCC_CONFIG_VER}}
99
100 # Dont install in /usr/include/g++-v3/, but in gcc internal directory.
101 # We will handle /usr/include/g++-v3/ with gcc-config ...
102 STDCXX_INCDIR=${TOOLCHAIN_STDCXX_INCDIR:-${LIBPATH}/include/g++-v${GCC_BRANCH_VER/\.*/}}
103 #----<< globals >>----
104
105 #---->> SLOT+IUSE logic <<----
106 IUSE="multislot nls nptl regression-test vanilla"
107
108 if [[ ${PN} != "kgcc64" && ${PN} != gcc-* ]] ; then
109 IUSE+=" altivec cxx fortran"
110 [[ -n ${PIE_VER} ]] && IUSE+=" nopie"
111 [[ -n ${HTB_VER} ]] && IUSE+=" boundschecking"
112 [[ -n ${D_VER} ]] && IUSE+=" d"
113 [[ -n ${SPECS_VER} ]] && IUSE+=" nossp"
114 tc_version_is_at_least 3 && IUSE+=" doc gcj gtk hardened multilib objc"
115 tc_version_is_at_least 4.0 && IUSE+=" objc-gc"
116 tc_version_is_at_least 4.0 && ! tc_version_is_at_least 4.9 && IUSE+=" mudflap"
117 tc_version_is_at_least 4.1 && IUSE+=" libssp objc++"
118 tc_version_is_at_least 4.2 && IUSE+=" openmp"
119 tc_version_is_at_least 4.3 && IUSE+=" fixed-point"
120 tc_version_is_at_least 4.6 && IUSE+=" graphite"
121 tc_version_is_at_least 4.6 && IUSE+=" lto"
122 tc_version_is_at_least 4.7 && IUSE+=" go"
123 fi
124
125 # Support upgrade paths here or people get pissed
126 if use multislot ; then
127 SLOT="${GCC_CONFIG_VER}"
128 else
129 SLOT="${GCC_BRANCH_VER}"
130 fi
131 #----<< SLOT+IUSE logic >>----
132
133 #---->> DEPEND <<----
134 RDEPEND="sys-libs/zlib
135 nls? ( sys-devel/gettext )"
136
137 tc_version_is_at_least 3 && RDEPEND+=" virtual/libiconv"
138
139 if tc_version_is_at_least 4 ; then
140 GMP_MPFR_DEPS=">=dev-libs/gmp-4.3.2 >=dev-libs/mpfr-2.4.2"
141 if tc_version_is_at_least 4.3 ; then
142 RDEPEND+=" ${GMP_MPFR_DEPS}"
143 elif in_iuse fortran ; then
144 RDEPEND+=" fortran? ( ${GMP_MPFR_DEPS} )"
145 fi
146 fi
147
148 tc_version_is_at_least 4.5 && RDEPEND+=" >=dev-libs/mpc-0.8.1"
149
150 if in_iuse graphite ; then
151 if tc_version_is_at_least 4.8 ; then
152 RDEPEND+="
153 graphite? (
154 >=dev-libs/cloog-0.18.0
155 >=dev-libs/isl-0.11.1
156 )"
157 else
158 RDEPEND+="
159 graphite? (
160 >=dev-libs/cloog-ppl-0.15.10
161 >=dev-libs/ppl-0.11
162 )"
163 fi
164 fi
165
166 DEPEND="${RDEPEND}
167 >=sys-devel/bison-1.875
168 >=sys-devel/flex-2.5.4
169 regression-test? (
170 >=dev-util/dejagnu-1.4.4
171 >=sys-devel/autogen-5.5.4
172 )"
173
174 if in_iuse gcj ; then
175 GCJ_DEPS=">=media-libs/libart_lgpl-2.1"
176 GCJ_GTK_DEPS="
177 x11-libs/libXt
178 x11-libs/libX11
179 x11-libs/libXtst
180 x11-proto/xproto
181 x11-proto/xextproto
182 =x11-libs/gtk+-2*
183 virtual/pkgconfig
184 amd64? ( multilib? (
185 app-emulation/emul-linux-x86-gtklibs
186 app-emulation/emul-linux-x86-xlibs
187 ) )
188 "
189 tc_version_is_at_least 3.4 && GCJ_GTK_DEPS+=" x11-libs/pango"
190 tc_version_is_at_least 4.2 && GCJ_DEPS+=" app-arch/zip app-arch/unzip"
191 DEPEND+=" gcj? ( gtk? ( ${GCJ_GTK_DEPS} ) ${GCJ_DEPS} )"
192 fi
193
194 PDEPEND=">=sys-devel/gcc-config-1.7"
195 #----<< DEPEND >>----
196
197 #---->> S + SRC_URI essentials <<----
198
199 # Set the source directory depending on whether we're using
200 # a prerelease, snapshot, or release tarball.
201 S=$(
202 if [[ -n ${PRERELEASE} ]] ; then
203 echo ${WORKDIR}/gcc-${PRERELEASE}
204 elif [[ -n ${SNAPSHOT} ]] ; then
205 echo ${WORKDIR}/gcc-${SNAPSHOT}
206 else
207 echo ${WORKDIR}/gcc-${GCC_RELEASE_VER}
208 fi
209 )
210
211 # This function handles the basics of setting the SRC_URI for a gcc ebuild.
212 # To use, set SRC_URI with:
213 #
214 # SRC_URI="$(get_gcc_src_uri)"
215 #
216 # Other than the variables normally set by portage, this function's behavior
217 # can be altered by setting the following:
218 #
219 # SNAPSHOT
220 # If set, this variable signals that we should be using a snapshot of
221 # gcc. It is expected to be in the format "YYYY-MM-DD". Note that if
222 # the ebuild has a _pre suffix, this variable is ignored and the
223 # prerelease tarball is used instead.
224 #
225 # BRANCH_UPDATE
226 # If set, this variable signals that we should be using the main
227 # release tarball (determined by ebuild version) and applying a
228 # CVS branch update patch against it. The location of this branch
229 # update patch is assumed to be in ${GENTOO_TOOLCHAIN_BASE_URI}.
230 # Just like with SNAPSHOT, this variable is ignored if the ebuild
231 # has a _pre suffix.
232 #
233 # PATCH_VER
234 # PATCH_GCC_VER
235 # This should be set to the version of the gentoo patch tarball.
236 # The resulting filename of this tarball will be:
237 # gcc-${PATCH_GCC_VER:-${GCC_RELEASE_VER}}-patches-${PATCH_VER}.tar.bz2
238 #
239 # PIE_VER
240 # PIE_GCC_VER
241 # These variables control patching in various updates for the logic
242 # controlling Position Independant Executables. PIE_VER is expected
243 # to be the version of this patch, and PIE_GCC_VER the gcc version of
244 # the patch:
245 # An example:
246 # PIE_VER="8.7.6.5"
247 # PIE_GCC_VER="3.4.0"
248 # The resulting filename of this tarball will be:
249 # gcc-${PIE_GCC_VER:-${GCC_RELEASE_VER}}-piepatches-v${PIE_VER}.tar.bz2
250 #
251 # SPECS_VER
252 # SPECS_GCC_VER
253 # This is for the minispecs files included in the hardened gcc-4.x
254 # The specs files for hardenedno*, vanilla and for building the "specs" file.
255 # SPECS_VER is expected to be the version of this patch, SPECS_GCC_VER
256 # the gcc version of the patch.
257 # An example:
258 # SPECS_VER="8.7.6.5"
259 # SPECS_GCC_VER="3.4.0"
260 # The resulting filename of this tarball will be:
261 # gcc-${SPECS_GCC_VER:-${GCC_RELEASE_VER}}-specs-${SPECS_VER}.tar.bz2
262 #
263 # HTB_VER
264 # HTB_GCC_VER
265 # These variables control whether or not an ebuild supports Herman
266 # ten Brugge's bounds-checking patches. If you want to use a patch
267 # for an older gcc version with a new gcc, make sure you set
268 # HTB_GCC_VER to that version of gcc.
269 #
270 gentoo_urls() {
271 local devspace="HTTP~vapier/dist/URI HTTP~dirtyepic/dist/URI
272 HTTP~halcy0n/patches/URI HTTP~zorry/patches/gcc/URI"
273 devspace=${devspace//HTTP/http:\/\/dev.gentoo.org\/}
274 echo mirror://gentoo/$1 ${devspace//URI/$1}
275 }
276
277 get_gcc_src_uri() {
278 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
279 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
280 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
281 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
282 export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}}
283
284 # Set where to download gcc itself depending on whether we're using a
285 # prerelease, snapshot, or release tarball.
286 if [[ -n ${PRERELEASE} ]] ; then
287 GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/prerelease-${PRERELEASE}/gcc-${PRERELEASE}.tar.bz2"
288 elif [[ -n ${SNAPSHOT} ]] ; then
289 GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.bz2"
290 elif [[ ${PV} != *9999* ]] ; then
291 GCC_SRC_URI="mirror://gnu/gcc/gcc-${GCC_PV}/gcc-${GCC_RELEASE_VER}.tar.bz2"
292 # we want all branch updates to be against the main release
293 [[ -n ${BRANCH_UPDATE} ]] && \
294 GCC_SRC_URI+=" $(gentoo_urls gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2)"
295 fi
296
297 [[ -n ${UCLIBC_VER} ]] && \
298 GCC_SRC_URI+=" $(gentoo_urls gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2)"
299 [[ -n ${PATCH_VER} ]] && \
300 GCC_SRC_URI+=" $(gentoo_urls gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2)"
301
302 # strawberry pie, Cappuccino and a Gauloises (it's a good thing)
303 [[ -n ${PIE_VER} ]] && \
304 PIE_CORE=${PIE_CORE:-gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2} && \
305 GCC_SRC_URI+=" $(gentoo_urls ${PIE_CORE})"
306
307 # gcc minispec for the hardened gcc 4 compiler
308 [[ -n ${SPECS_VER} ]] && \
309 GCC_SRC_URI+=" $(gentoo_urls gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2)"
310
311 # gcc bounds checking patch
312 if [[ -n ${HTB_VER} ]] ; then
313 local HTBFILE="bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
314 GCC_SRC_URI+="
315 boundschecking? (
316 mirror://sourceforge/boundschecking/${HTBFILE}
317 $(gentoo_urls ${HTBFILE})
318 )"
319 fi
320
321 [[ -n ${D_VER} ]] && \
322 GCC_SRC_URI+=" d? ( mirror://sourceforge/dgcc/gdc-${D_VER}-src.tar.bz2 )"
323
324 if in_iuse gcj ; then
325 if tc_version_is_at_least 4.5 ; then
326 GCC_SRC_URI+=" gcj? ( ftp://sourceware.org/pub/java/ecj-4.5.jar )"
327 elif tc_version_is_at_least 4.3 ; then
328 GCC_SRC_URI+=" gcj? ( ftp://sourceware.org/pub/java/ecj-4.3.jar )"
329 fi
330 fi
331
332 echo "${GCC_SRC_URI}"
333 }
334 SRC_URI=$(get_gcc_src_uri)
335 #---->> S + SRC_URI essentials >>----
336
337 #---->> support checks <<----
338
339 # Grab a variable from the build system (taken from linux-info.eclass)
340 get_make_var() {
341 local var=$1 makefile=${2:-${WORKDIR}/build/Makefile}
342 echo -e "e:\\n\\t@echo \$(${var})\\ninclude ${makefile}" | \
343 r=${makefile%/*} emake --no-print-directory -s -f - 2>/dev/null
344 }
345 XGCC() { get_make_var GCC_FOR_TARGET ; }
346
347 # The gentoo piessp patches allow for 3 configurations:
348 # 1) PIE+SSP by default
349 # 2) PIE by default
350 # 3) SSP by default
351 hardened_gcc_works() {
352 if [[ $1 == "pie" ]] ; then
353 # $gcc_cv_ld_pie is unreliable as it simply take the output of
354 # `ld --help | grep -- -pie`, that reports the option in all cases, also if
355 # the loader doesn't actually load the resulting executables.
356 # To avoid breakage, blacklist FreeBSD here at least
357 [[ ${CTARGET} == *-freebsd* ]] && return 1
358
359 want_pie || return 1
360 use_if_iuse nopie && return 1
361 hardened_gcc_is_stable pie
362 return $?
363 elif [[ $1 == "ssp" ]] ; then
364 [[ -n ${SPECS_VER} ]] || return 1
365 use_if_iuse nossp && return 1
366 hardened_gcc_is_stable ssp
367 return $?
368 else
369 # laziness ;)
370 hardened_gcc_works pie || return 1
371 hardened_gcc_works ssp || return 1
372 return 0
373 fi
374 }
375
376 hardened_gcc_is_stable() {
377 local tocheck
378 if [[ $1 == "pie" ]] ; then
379 if [[ ${CTARGET} == *-uclibc* ]] ; then
380 tocheck=${PIE_UCLIBC_STABLE}
381 else
382 tocheck=${PIE_GLIBC_STABLE}
383 fi
384 elif [[ $1 == "ssp" ]] ; then
385 if [[ ${CTARGET} == *-uclibc* ]] ; then
386 tocheck=${SSP_UCLIBC_STABLE}
387 else
388 tocheck=${SSP_STABLE}
389 fi
390 else
391 die "hardened_gcc_stable needs to be called with pie or ssp"
392 fi
393
394 has $(tc-arch) ${tocheck} && return 0
395 return 1
396 }
397
398 want_pie() {
399 ! use hardened && [[ -n ${PIE_VER} ]] && use nopie && return 1
400 [[ -n ${PIE_VER} ]] && [[ -n ${SPECS_VER} ]] && return 0
401 tc_version_is_at_least 4.3.2 && return 1
402 [[ -z ${PIE_VER} ]] && return 1
403 use !nopie && return 0
404 return 1
405 }
406
407 want_minispecs() {
408 if tc_version_is_at_least 4.3.2 && use hardened ; then
409 if ! want_pie ; then
410 ewarn "PIE_VER or SPECS_VER is not defined in the GCC ebuild."
411 elif use vanilla ; then
412 ewarn "You will not get hardened features if you have the vanilla USE-flag."
413 elif use nopie && use nossp ; then
414 ewarn "You will not get hardened features if you have the nopie and nossp USE-flag."
415 elif ! hardened_gcc_works ; then
416 ewarn "Your $(tc-arch) arch is not supported."
417 else
418 return 0
419 fi
420 ewarn "Hope you know what you are doing. Hardened will not work."
421 return 0
422 fi
423 return 1
424 }
425
426 # This is to make sure we don't accidentally try to enable support for a
427 # language that doesnt exist. GCC 3.4 supports f77, while 4.0 supports f95, etc.
428 #
429 # Also add a hook so special ebuilds (kgcc64) can control which languages
430 # exactly get enabled
431 gcc-lang-supported() {
432 grep ^language=\"${1}\" "${S}"/gcc/*/config-lang.in > /dev/null || return 1
433 [[ -z ${TOOLCHAIN_ALLOWED_LANGS} ]] && return 0
434 has $1 ${TOOLCHAIN_ALLOWED_LANGS}
435 }
436 #----<< support checks >>----
437
438 #---->> specs + env.d logic <<----
439
440 # configure to build with the hardened GCC specs as the default
441 make_gcc_hard() {
442 # defaults to enable for all hardened toolchains
443 local gcc_hard_flags="-DEFAULT_RELRO -DEFAULT_BIND_NOW"
444
445 if hardened_gcc_works ; then
446 einfo "Updating gcc to use automatic PIE + SSP building ..."
447 gcc_hard_flags+=" -DEFAULT_PIE_SSP"
448 elif hardened_gcc_works pie ; then
449 einfo "Updating gcc to use automatic PIE building ..."
450 ewarn "SSP has not been enabled by default"
451 gcc_hard_flags+=" -DEFAULT_PIE"
452 elif hardened_gcc_works ssp ; then
453 einfo "Updating gcc to use automatic SSP building ..."
454 ewarn "PIE has not been enabled by default"
455 gcc_hard_flags+=" -DEFAULT_SSP"
456 else
457 # do nothing if hardened isnt supported, but dont die either
458 ewarn "hardened is not supported for this arch in this gcc version"
459 ebeep
460 return 0
461 fi
462
463 sed -i \
464 -e "/^HARD_CFLAGS = /s|=|= ${gcc_hard_flags} |" \
465 "${S}"/gcc/Makefile.in || die
466
467 # rebrand to make bug reports easier
468 BRANDING_GCC_PKGVERSION=${BRANDING_GCC_PKGVERSION/Gentoo/Gentoo Hardened}
469 }
470
471 create_gcc_env_entry() {
472 dodir /etc/env.d/gcc
473 local gcc_envd_base="/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}"
474
475 local gcc_specs_file
476 local gcc_envd_file="${D}${gcc_envd_base}"
477 if [[ -z $1 ]] ; then
478 # I'm leaving the following commented out to remind me that it
479 # was an insanely -bad- idea. Stuff broke. GCC_SPECS isnt unset
480 # on chroot or in non-toolchain.eclass gcc ebuilds!
481 #gcc_specs_file="${LIBPATH}/specs"
482 gcc_specs_file=""
483 else
484 gcc_envd_file+="-$1"
485 gcc_specs_file="${LIBPATH}/$1.specs"
486 fi
487
488 # We want to list the default ABI's LIBPATH first so libtool
489 # searches that directory first. This is a temporary
490 # workaround for libtool being stupid and using .la's from
491 # conflicting ABIs by using the first one in the search path
492 local ldpaths mosdirs
493 if tc_version_is_at_least 3.2 ; then
494 local mdir mosdir abi ldpath
495 for abi in $(get_all_abis TARGET) ; do
496 mdir=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory)
497 ldpath=${LIBPATH}
498 [[ ${mdir} != "." ]] && ldpath+="/${mdir}"
499 ldpaths="${ldpath}${ldpaths:+:${ldpaths}}"
500
501 mosdir=$($(XGCC) $(get_abi_CFLAGS ${abi}) -print-multi-os-directory)
502 mosdirs="${mosdir}${mosdirs:+:${mosdirs}}"
503 done
504 else
505 # Older gcc's didn't do multilib, so logic is simple.
506 ldpaths=${LIBPATH}
507 fi
508
509 cat <<-EOF > ${gcc_envd_file}
510 PATH="${BINPATH}"
511 ROOTPATH="${BINPATH}"
512 GCC_PATH="${BINPATH}"
513 LDPATH="${ldpaths}"
514 MANPATH="${DATAPATH}/man"
515 INFOPATH="${DATAPATH}/info"
516 STDCXX_INCDIR="${STDCXX_INCDIR##*/}"
517 CTARGET="${CTARGET}"
518 GCC_SPECS="${gcc_specs_file}"
519 MULTIOSDIRS="${mosdirs}"
520 EOF
521 }
522
523 setup_minispecs_gcc_build_specs() {
524 # Setup the "build.specs" file for gcc 4.3 to use when building.
525 if hardened_gcc_works pie ; then
526 cat "${WORKDIR}"/specs/pie.specs >> "${WORKDIR}"/build.specs
527 fi
528 if hardened_gcc_works ssp ; then
529 for s in ssp sspall ; do
530 cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs
531 done
532 fi
533 for s in nostrict znow ; do
534 cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs
535 done
536 export GCC_SPECS="${WORKDIR}"/build.specs
537 }
538
539 copy_minispecs_gcc_specs() {
540 # setup the hardenedno* specs files and the vanilla specs file.
541 if hardened_gcc_works ; then
542 create_gcc_env_entry hardenednopiessp
543 fi
544 if hardened_gcc_works pie ; then
545 create_gcc_env_entry hardenednopie
546 fi
547 if hardened_gcc_works ssp ; then
548 create_gcc_env_entry hardenednossp
549 fi
550 create_gcc_env_entry vanilla
551 insinto ${LIBPATH}
552 doins "${WORKDIR}"/specs/*.specs || die "failed to install specs"
553 # Build system specs file which, if it exists, must be a complete set of
554 # specs as it completely and unconditionally overrides the builtin specs.
555 if ! tc_version_is_at_least 4.4 ; then
556 $(XGCC) -dumpspecs > "${WORKDIR}"/specs/specs
557 cat "${WORKDIR}"/build.specs >> "${WORKDIR}"/specs/specs
558 doins "${WORKDIR}"/specs/specs || die "failed to install the specs file"
559 fi
560 }
561
562 #----<< specs + env.d logic >>----
563
564 #---->> pkg_* <<----
565 toolchain_pkg_setup() {
566 if [[ -n ${PRERELEASE}${SNAPSHOT} || ${PV} == *9999* ]] &&
567 [[ -z ${I_PROMISE_TO_SUPPLY_PATCHES_WITH_BUGS} ]] ; then
568 die "Please \`export I_PROMISE_TO_SUPPLY_PATCHES_WITH_BUGS=1\` or define it" \
569 "in your make.conf if you want to use this version."
570 fi
571
572 # we dont want to use the installed compiler's specs to build gcc!
573 unset GCC_SPECS
574
575 if ! use_if_iuse cxx ; then
576 use_if_iuse go && ewarn 'Go requires a C++ compiler, disabled due to USE="-cxx"'
577 use_if_iuse objc++ && ewarn 'Obj-C++ requires a C++ compiler, disabled due to USE="-cxx"'
578 use_if_iuse gcj && ewarn 'GCJ requires a C++ compiler, disabled due to USE="-cxx"'
579 fi
580
581 want_minispecs
582
583 unset LANGUAGES #265283
584 }
585
586 toolchain_pkg_postinst() {
587 do_gcc_config
588
589 if ! is_crosscompile ; then
590 echo
591 ewarn "If you have issues with packages unable to locate libstdc++.la,"
592 ewarn "then try running 'fix_libtool_files.sh' on the old gcc versions."
593 echo
594 ewarn "You might want to review the GCC upgrade guide when moving between"
595 ewarn "major versions (like 4.2 to 4.3):"
596 ewarn "http://www.gentoo.org/doc/en/gcc-upgrading.xml"
597 echo
598
599 # Clean up old paths
600 rm -f "${ROOT}"/*/rcscripts/awk/fixlafiles.awk "${ROOT}"/sbin/fix_libtool_files.sh
601 rmdir "${ROOT}"/*/rcscripts{/awk,} 2>/dev/null
602
603 mkdir -p "${ROOT}"/usr/{share/gcc-data,sbin,bin}
604 cp "${ROOT}/${DATAPATH}"/fixlafiles.awk "${ROOT}"/usr/share/gcc-data/ || die
605 cp "${ROOT}/${DATAPATH}"/fix_libtool_files.sh "${ROOT}"/usr/sbin/ || die
606
607 # Since these aren't critical files and portage sucks with
608 # handling of binpkgs, don't require these to be found
609 cp "${ROOT}/${DATAPATH}"/c{89,99} "${ROOT}"/usr/bin/ 2>/dev/null
610 fi
611
612 if use regression-test ; then
613 elog "Testsuite results have been installed into /usr/share/doc/${PF}/testsuite"
614 echo
615 fi
616 }
617
618 toolchain_pkg_postrm() {
619 # to make our lives easier (and saner), we do the fix_libtool stuff here.
620 # rather than checking SLOT's and trying in upgrade paths, we just see if
621 # the common libstdc++.la exists in the ${LIBPATH} of the gcc that we are
622 # unmerging. if it does, that means this was a simple re-emerge.
623
624 # clean up the cruft left behind by cross-compilers
625 if is_crosscompile ; then
626 if [[ -z $(ls "${ROOT}"/etc/env.d/gcc/${CTARGET}* 2>/dev/null) ]] ; then
627 rm -f "${ROOT}"/etc/env.d/gcc/config-${CTARGET}
628 rm -f "${ROOT}"/etc/env.d/??gcc-${CTARGET}
629 rm -f "${ROOT}"/usr/bin/${CTARGET}-{gcc,{g,c}++}{,32,64}
630 fi
631 return 0
632 fi
633
634 # ROOT isnt handled by the script
635 [[ ${ROOT} != "/" ]] && return 0
636
637 if [[ ! -e ${LIBPATH}/libstdc++.so ]] ; then
638 # make sure the profile is sane during same-slot upgrade #289403
639 do_gcc_config
640
641 einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}'"
642 /usr/sbin/fix_libtool_files.sh ${GCC_RELEASE_VER}
643 if [[ -n ${BRANCH_UPDATE} ]] ; then
644 einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE}'"
645 /usr/sbin/fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE}
646 fi
647 fi
648
649 return 0
650 }
651
652 #---->> pkg_* <<----
653
654 #---->> src_* <<----
655
656 guess_patch_type_in_dir() {
657 [[ -n $(ls "$1"/*.bz2 2>/dev/null) ]] \
658 && EPATCH_SUFFIX="patch.bz2" \
659 || EPATCH_SUFFIX="patch"
660 }
661
662 do_gcc_rename_java_bins() {
663 # bug #139918 - conflict between gcc and java-config-2 for ownership of
664 # /usr/bin/rmi{c,registry}. Done with mv & sed rather than a patch
665 # because patches would be large (thanks to the rename of man files),
666 # and it's clear from the sed invocations that all that changes is the
667 # rmi{c,registry} names to grmi{c,registry} names.
668 # Kevin F. Quinn 2006-07-12
669 einfo "Renaming jdk executables rmic and rmiregistry to grmic and grmiregistry."
670 # 1) Move the man files if present (missing prior to gcc-3.4)
671 for manfile in rmic rmiregistry ; do
672 [[ -f ${S}/gcc/doc/${manfile}.1 ]] || continue
673 mv "${S}"/gcc/doc/${manfile}.1 "${S}"/gcc/doc/g${manfile}.1
674 done
675 # 2) Fixup references in the docs if present (mission prior to gcc-3.4)
676 for jfile in gcc/doc/gcj.info gcc/doc/grmic.1 gcc/doc/grmiregistry.1 gcc/java/gcj.texi ; do
677 [[ -f ${S}/${jfile} ]] || continue
678 sed -i -e 's:rmiregistry:grmiregistry:g' "${S}"/${jfile} ||
679 die "Failed to fixup file ${jfile} for rename to grmiregistry"
680 sed -i -e 's:rmic:grmic:g' "${S}"/${jfile} ||
681 die "Failed to fixup file ${jfile} for rename to grmic"
682 done
683 # 3) Fixup Makefiles to build the changed executable names
684 # These are present in all 3.x versions, and are the important bit
685 # to get gcc to build with the new names.
686 for jfile in libjava/Makefile.am libjava/Makefile.in gcc/java/Make-lang.in ; do
687 sed -i -e 's:rmiregistry:grmiregistry:g' "${S}"/${jfile} ||
688 die "Failed to fixup file ${jfile} for rename to grmiregistry"
689 # Careful with rmic on these files; it's also the name of a directory
690 # which should be left unchanged. Replace occurrences of 'rmic$',
691 # 'rmic_' and 'rmic '.
692 sed -i -e 's:rmic\([$_ ]\):grmic\1:g' "${S}"/${jfile} ||
693 die "Failed to fixup file ${jfile} for rename to grmic"
694 done
695 }
696
697 toolchain_src_unpack() {
698 [[ -z ${UCLIBC_VER} ]] && [[ ${CTARGET} == *-uclibc* ]] && \
699 die "Sorry, this version does not support uClibc"
700
701 if [[ ${PV} == *9999* ]]; then
702 git-2_src_unpack
703 else
704 gcc_quick_unpack
705 fi
706
707 export BRANDING_GCC_PKGVERSION="Gentoo ${GCC_PVR}"
708 cd "${S}"
709
710 if ! use vanilla ; then
711 if [[ -n ${PATCH_VER} ]] ; then
712 guess_patch_type_in_dir "${WORKDIR}"/patch
713 EPATCH_MULTI_MSG="Applying Gentoo patches ..." \
714 epatch "${WORKDIR}"/patch
715 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION} p${PATCH_VER}"
716 fi
717 if [[ -n ${UCLIBC_VER} ]] ; then
718 guess_patch_type_in_dir "${WORKDIR}"/uclibc
719 EPATCH_MULTI_MSG="Applying uClibc patches ..." \
720 epatch "${WORKDIR}"/uclibc
721 fi
722 fi
723 do_gcc_HTB_patches
724 do_gcc_PIE_patches
725 epatch_user
726
727 use hardened && make_gcc_hard
728
729 # install the libstdc++ python into the right location
730 # http://gcc.gnu.org/PR51368
731 if tc_version_is_at_least 4.5 && ! tc_version_is_at_least 4.7 ; then
732 sed -i \
733 '/^pythondir =/s:=.*:= $(datadir)/python:' \
734 "${S}"/libstdc++-v3/python/Makefile.in || die
735 fi
736
737 # make sure the pkg config files install into multilib dirs.
738 # since we configure with just one --libdir, we can't use that
739 # (as gcc itself takes care of building multilibs). #435728
740 find "${S}" -name Makefile.in \
741 -exec sed -i '/^pkgconfigdir/s:=.*:=$(toolexeclibdir)/pkgconfig:' {} +
742
743 # No idea when this first started being fixed, but let's go with 4.3.x for now
744 if ! tc_version_is_at_least 4.3 ; then
745 fix_files=""
746 for x in contrib/test_summary libstdc++-v3/scripts/check_survey.in ; do
747 [[ -e ${x} ]] && fix_files="${fix_files} ${x}"
748 done
749 ht_fix_file ${fix_files} */configure *.sh */Makefile.in
750 fi
751
752 setup_multilib_osdirnames
753 gcc_version_patch
754
755 if tc_version_is_at_least 4.1 ; then
756 if [[ -n ${SNAPSHOT} || -n ${PRERELEASE} ]] ; then
757 # BASE-VER must be a three-digit version number
758 # followed by an optional -pre string
759 # eg. 4.5.1, 4.6.2-pre20120213, 4.7.0-pre9999
760 # If BASE-VER differs from ${PV/_/-} then libraries get installed in
761 # the wrong directory.
762 echo ${PV/_/-} > "${S}"/gcc/BASE-VER
763 fi
764 fi
765
766 # >= gcc-4.3 doesn't bundle ecj.jar, so copy it
767 if tc_version_is_at_least 4.3 && use gcj ; then
768 if tc_version_is_at_least 4.5 ; then
769 einfo "Copying ecj-4.5.jar"
770 cp -pPR "${DISTDIR}/ecj-4.5.jar" "${S}/ecj.jar" || die
771 else
772 einfo "Copying ecj-4.3.jar"
773 cp -pPR "${DISTDIR}/ecj-4.3.jar" "${S}/ecj.jar" || die
774 fi
775 fi
776
777 # disable --as-needed from being compiled into gcc specs
778 # natively when using a gcc version < 3.4.4
779 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14992
780 if ! tc_version_is_at_least 3.4.4 ; then
781 sed -i -e s/HAVE_LD_AS_NEEDED/USE_LD_AS_NEEDED/g "${S}"/gcc/config.in
782 fi
783
784 # In gcc 3.3.x and 3.4.x, rename the java bins to gcc-specific names
785 # in line with gcc-4.
786 if tc_version_is_at_least 3.3 && ! tc_version_is_at_least 4.0 ; then
787 do_gcc_rename_java_bins
788 fi
789
790 # Prevent libffi from being installed
791 if tc_version_is_at_least 3.0 && ! tc_version_is_at_least 4.8 ; then
792 sed -i -e 's/\(install.*:\) install-.*recursive/\1/' "${S}"/libffi/Makefile.in || die
793 sed -i -e 's/\(install-data-am:\).*/\1/' "${S}"/libffi/include/Makefile.in || die
794 fi
795
796 # Fixup libtool to correctly generate .la files with portage
797 elibtoolize --portage --shallow --no-uclibc
798
799 gnuconfig_update
800
801 # update configure files
802 local f
803 einfo "Fixing misc issues in configure files"
804 # TODO - check if we can drop this now that we don't gen info files
805 tc_version_is_at_least 4.1 && epatch "${GCC_FILESDIR}"/gcc-configure-texinfo.patch
806 for f in $(grep -l 'autoconf version 2.13' $(find "${S}" -name configure)) ; do
807 ebegin " Updating ${f/${S}\/} [LANG]"
808 patch "${f}" "${GCC_FILESDIR}"/gcc-configure-LANG.patch >& "${T}"/configure-patch.log \
809 || eerror "Please file a bug about this"
810 eend $?
811 done
812 sed -i 's|A-Za-z0-9|[:alnum:]|g' "${S}"/gcc/*.awk #215828
813
814 if [[ -x contrib/gcc_update ]] ; then
815 einfo "Touching generated files"
816 ./contrib/gcc_update --touch | \
817 while read f ; do
818 einfo " ${f%%...}"
819 done
820 fi
821 }
822
823 gcc-abi-map() {
824 # Convert the ABI name we use in Gentoo to what gcc uses
825 local map=()
826 case ${CTARGET} in
827 mips*) map=("o32 32" "n32 n32" "n64 64") ;;
828 x86_64*) map=("amd64 m64" "x86 m32" "x32 mx32") ;;
829 esac
830
831 local m
832 for m in "${map[@]}" ; do
833 l=( ${m} )
834 [[ $1 == ${l[0]} ]] && echo ${l[1]} && break
835 done
836 }
837
838 gcc-multilib-configure() {
839 if ! is_multilib ; then
840 confgcc+=( --disable-multilib )
841 # Fun times: if we are building for a target that has multiple
842 # possible ABI formats, and the user has told us to pick one
843 # that isn't the default, then not specifying it via the list
844 # below will break that on us.
845 else
846 confgcc+=( --enable-multilib )
847 fi
848
849 # translate our notion of multilibs into gcc's
850 local abi list
851 for abi in $(get_all_abis TARGET) ; do
852 local l=$(gcc-abi-map ${abi})
853 [[ -n ${l} ]] && list+=",${l}"
854 done
855 if [[ -n ${list} ]] ; then
856 case ${CTARGET} in
857 x86_64*)
858 tc_version_is_at_least 4.7 && confgcc+=( --with-multilib-list=${list:1} )
859 ;;
860 esac
861 fi
862 }
863
864 gcc-compiler-configure() {
865 gcc-multilib-configure
866
867 if tc_version_is_at_least 4.0 ; then
868 if in_iuse mudflap ; then
869 confgcc+=( $(use_enable mudflap libmudflap) )
870 else
871 confgcc+=( --disable-libmudflap )
872 fi
873
874 if use_if_iuse libssp ; then
875 confgcc+=( --enable-libssp )
876 else
877 export gcc_cv_libc_provides_ssp=yes
878 confgcc+=( --disable-libssp )
879 fi
880
881 # If we want hardened support with the newer piepatchset for >=gcc 4.4
882 if tc_version_is_at_least 4.4 && want_minispecs ; then
883 confgcc+=( $(use_enable hardened esp) )
884 fi
885
886 if tc_version_is_at_least 4.2 ; then
887 if in_iuse openmp ; then
888 # Make sure target has pthreads support. #326757 #335883
889 # There shouldn't be a chicken&egg problem here as openmp won't
890 # build without a C library, and you can't build that w/out
891 # already having a compiler ...
892 if ! is_crosscompile || \
893 $(tc-getCPP ${CTARGET}) -E - <<<"#include <pthread.h>" >& /dev/null
894 then
895 confgcc+=( $(use_enable openmp libgomp) )
896 else
897 # Force disable as the configure script can be dumb #359855
898 confgcc+=( --disable-libgomp )
899 fi
900 else
901 # For gcc variants where we don't want openmp (e.g. kgcc)
902 confgcc+=( --disable-libgomp )
903 fi
904 fi
905
906 # Stick the python scripts in their own slotted directory
907 # bug #279252
908 #
909 # --with-python-dir=DIR
910 # Specifies where to install the Python modules used for aot-compile. DIR
911 # should not include the prefix used in installation. For example, if the
912 # Python modules are to be installed in /usr/lib/python2.5/site-packages,
913 # then --with-python-dir=/lib/python2.5/site-packages should be passed.
914 #
915 # This should translate into "/share/gcc-data/${CTARGET}/${GCC_CONFIG_VER}/python"
916 if tc_version_is_at_least 4.4 ; then
917 confgcc+=( --with-python-dir=${DATAPATH/$PREFIX/}/python )
918 fi
919 fi
920
921 # Enable build warnings by default with cross-compilers when system
922 # paths are included (e.g. via -I flags).
923 is_crosscompile && confgcc+=( --enable-poison-system-directories )
924
925 # For newer versions of gcc, use the default ("release"), because no
926 # one (even upstream apparently) tests with it disabled. #317217
927 if tc_version_is_at_least 4 || [[ -n ${GCC_CHECKS_LIST} ]] ; then
928 confgcc+=( --enable-checking=${GCC_CHECKS_LIST:-release} )
929 else
930 confgcc+=( --disable-checking )
931 fi
932
933 # GTK+ is preferred over xlib in 3.4.x (xlib is unmaintained
934 # right now). Much thanks to <csm@gnu.org> for the heads up.
935 # Travis Tilley <lv@gentoo.org> (11 Jul 2004)
936 if ! is_gcj ; then
937 confgcc+=( --disable-libgcj )
938 elif use gtk ; then
939 confgcc+=( --enable-java-awt=gtk )
940 fi
941
942 # allow gcc to search for clock funcs in the main C lib.
943 # if it can't find them, then tough cookies -- we aren't
944 # going to link in -lrt to all C++ apps. #411681
945 if tc_version_is_at_least 4.4 && is_cxx ; then
946 confgcc+=( --enable-libstdcxx-time )
947 fi
948
949 # newer gcc versions like to bootstrap themselves with C++,
950 # so we need to manually disable it ourselves
951 if tc_version_is_at_least 4.7 && ! is_cxx ; then
952 confgcc+=( --disable-build-with-cxx --disable-build-poststage1-with-cxx )
953 fi
954
955 # newer gcc's come with libquadmath, but only fortran uses
956 # it, so auto punt it when we don't care
957 if tc_version_is_at_least 4.6 && ! is_fortran ; then
958 confgcc+=( --disable-libquadmath )
959 fi
960
961 local with_abi_map=()
962 case $(tc-arch) in
963 arm) #264534 #414395
964 local a arm_arch=${CTARGET%%-*}
965 # Remove trailing endian variations first: eb el be bl b l
966 for a in e{b,l} {b,l}e b l ; do
967 if [[ ${arm_arch} == *${a} ]] ; then
968 arm_arch=${arm_arch%${a}}
969 break
970 fi
971 done
972 # Convert armv7{a,r,m} to armv7-{a,r,m}
973 [[ ${arm_arch} == armv7? ]] && arm_arch=${arm_arch/7/7-}
974 # See if this is a valid --with-arch flag
975 if (srcdir=${S}/gcc target=${CTARGET} with_arch=${arm_arch};
976 . "${srcdir}"/config.gcc) &>/dev/null
977 then
978 confgcc+=( --with-arch=${arm_arch} )
979 fi
980
981 # Make default mode thumb for microcontroller classes #418209
982 [[ ${arm_arch} == *-m ]] && confgcc+=( --with-mode=thumb )
983
984 # Enable hardvfp
985 if [[ $(tc-is-softfloat) == "no" ]] && \
986 [[ ${CTARGET} == armv[67]* ]] && \
987 tc_version_is_at_least 4.5
988 then
989 # Follow the new arm hardfp distro standard by default
990 confgcc+=( --with-float=hard )
991 case ${CTARGET} in
992 armv6*) confgcc+=( --with-fpu=vfp ) ;;
993 armv7*) confgcc+=( --with-fpu=vfpv3-d16 ) ;;
994 esac
995 fi
996 ;;
997 mips)
998 # Add --with-abi flags to set default ABI
999 confgcc+=( --with-abi=$(gcc-abi-map ${TARGET_DEFAULT_ABI}) )
1000 ;;
1001 amd64)
1002 # drop the older/ABI checks once this get's merged into some
1003 # version of gcc upstream
1004 if tc_version_is_at_least 4.7 && has x32 $(get_all_abis TARGET) ; then
1005 confgcc+=( --with-abi=$(gcc-abi-map ${TARGET_DEFAULT_ABI}) )
1006 fi
1007 ;;
1008 x86)
1009 # Default arch for x86 is normally i386, lets give it a bump
1010 # since glibc will do so based on CTARGET anyways
1011 confgcc+=( --with-arch=${CTARGET%%-*} )
1012 ;;
1013 hppa)
1014 # Enable sjlj exceptions for backward compatibility on hppa
1015 [[ ${GCCMAJOR} == "3" ]] && confgcc+=( --enable-sjlj-exceptions )
1016 ;;
1017 ppc)
1018 # Set up defaults based on current CFLAGS
1019 is-flagq -mfloat-gprs=double && confgcc+=( --enable-e500-double )
1020 [[ ${CTARGET//_/-} == *-e500v2-* ]] && confgcc+=( --enable-e500-double )
1021 ;;
1022 esac
1023
1024 local GCC_LANG="c"
1025 is_cxx && GCC_LANG+=",c++"
1026 is_d && GCC_LANG+=",d"
1027 is_gcj && GCC_LANG+=",java"
1028 is_go && GCC_LANG+=",go"
1029 if is_objc || is_objcxx ; then
1030 GCC_LANG+=",objc"
1031 if tc_version_is_at_least 4 ; then
1032 use objc-gc && confgcc+=( --enable-objc-gc )
1033 fi
1034 is_objcxx && GCC_LANG+=",obj-c++"
1035 fi
1036 is_treelang && GCC_LANG+=",treelang"
1037
1038 # fortran support just got sillier! the lang value can be f77 for
1039 # fortran77, f95 for fortran95, or just plain old fortran for the
1040 # currently supported standard depending on gcc version.
1041 is_fortran && GCC_LANG+=",fortran"
1042 is_f77 && GCC_LANG+=",f77"
1043 is_f95 && GCC_LANG+=",f95"
1044
1045 # We do NOT want 'ADA support' in here!
1046 # is_ada && GCC_LANG+=",ada"
1047
1048 einfo "configuring for GCC_LANG: ${GCC_LANG}"
1049 confgcc+=( --enable-languages=${GCC_LANG} )
1050 }
1051
1052 gcc_do_configure() {
1053 local confgcc=(
1054 # Set configuration based on path variables
1055 --prefix="${PREFIX}"
1056 --bindir="${BINPATH}"
1057 --includedir="${INCLUDEPATH}"
1058 --datadir="${DATAPATH}"
1059 --mandir="${DATAPATH}/man"
1060 --infodir="${DATAPATH}/info"
1061 --with-gxx-include-dir="${STDCXX_INCDIR}"
1062 )
1063 # On Darwin we need libdir to be set in order to get correct install names
1064 # for things like libobjc-gnu, libgcj and libfortran. If we enable it on
1065 # non-Darwin we screw up the behaviour this eclass relies on. We in
1066 # particular need this over --libdir for bug #255315.
1067 [[ ${CTARGET} == *-darwin* ]] && \
1068 confgcc+=( --enable-version-specific-runtime-libs )
1069
1070 # All our cross-compile logic goes here ! woo !
1071 confgcc+=( --host=${CHOST} )
1072 if is_crosscompile || tc-is-cross-compiler ; then
1073 # Straight from the GCC install doc:
1074 # "GCC has code to correctly determine the correct value for target
1075 # for nearly all native systems. Therefore, we highly recommend you
1076 # not provide a configure target when configuring a native compiler."
1077 confgcc+=( --target=${CTARGET} )
1078 fi
1079 [[ -n ${CBUILD} ]] && confgcc+=( --build=${CBUILD} )
1080
1081 # ppc altivec support
1082 confgcc+=( $(use_enable altivec) )
1083
1084 # gcc has fixed-point arithmetic support in 4.3 for mips targets that can
1085 # significantly increase compile time by several hours. This will allow
1086 # users to control this feature in the event they need the support.
1087 tc_version_is_at_least 4.3 && confgcc+=( $(use_enable fixed-point) )
1088
1089 # graphite was added in 4.4 but we only support it in 4.6+ due to external
1090 # library issues. 4.6/4.7 uses cloog-ppl which is a fork of CLooG with a
1091 # PPL backend. 4.8+ uses upstream CLooG with the ISL backend. We install
1092 # cloog-ppl into a non-standard location to prevent collisions.
1093 if tc_version_is_at_least 4.8 ; then
1094 confgcc+=( $(use_with graphite cloog) )
1095 use graphite && confgcc+=( --disable-isl-version-check )
1096 elif tc_version_is_at_least 4.6 ; then
1097 confgcc+=( $(use_with graphite cloog) )
1098 confgcc+=( $(use_with graphite ppl) )
1099 use graphite && confgcc+=( --with-cloog-include=/usr/include/cloog-ppl )
1100 use graphite && confgcc+=( --disable-ppl-version-check )
1101 elif tc_version_is_at_least 4.4 ; then
1102 confgcc+=( --without-cloog )
1103 confgcc+=( --without-ppl )
1104 fi
1105
1106 if tc_version_is_at_least 4.6 ; then
1107 confgcc+=( $(use_enable lto) )
1108 elif tc_version_is_at_least 4.5 ; then
1109 confgcc+=( --disable-lto )
1110 fi
1111
1112 case $(tc-is-softfloat) in
1113 yes) confgcc+=( --with-float=soft ) ;;
1114 softfp) confgcc+=( --with-float=softfp ) ;;
1115 *)
1116 # If they've explicitly opt-ed in, do hardfloat,
1117 # otherwise let the gcc default kick in.
1118 [[ ${CTARGET//_/-} == *-hardfloat-* ]] \
1119 && confgcc+=( --with-float=hard )
1120 ;;
1121 esac
1122
1123 # Native Language Support
1124 if use nls ; then
1125 confgcc+=( --enable-nls --without-included-gettext )
1126 else
1127 confgcc+=( --disable-nls )
1128 fi
1129
1130 # reasonably sane globals (hopefully)
1131 confgcc+=(
1132 --with-system-zlib
1133 --enable-obsolete
1134 --disable-werror
1135 --enable-secureplt
1136 )
1137
1138 gcc-compiler-configure || die
1139
1140 if is_crosscompile ; then
1141 # When building a stage1 cross-compiler (just C compiler), we have to
1142 # disable a bunch of features or gcc goes boom
1143 local needed_libc=""
1144 case ${CTARGET} in
1145 *-linux) needed_libc=no-fucking-clue;;
1146 *-dietlibc) needed_libc=dietlibc;;
1147 *-elf|*-eabi) needed_libc=newlib;;
1148 *-freebsd*) needed_libc=freebsd-lib;;
1149 *-gnu*) needed_libc=glibc;;
1150 *-klibc) needed_libc=klibc;;
1151 *-musl*) needed_libc=musl;;
1152 *-uclibc*)
1153 if ! echo '#include <features.h>' | \
1154 $(tc-getCPP ${CTARGET}) -E -dD - 2>/dev/null | \
1155 grep -q __HAVE_SHARED__
1156 then #291870
1157 confgcc+=( --disable-shared )
1158 fi
1159 needed_libc=uclibc
1160 ;;
1161 *-cygwin) needed_libc=cygwin;;
1162 x86_64-*-mingw*|\
1163 *-w64-mingw*) needed_libc=mingw64-runtime;;
1164 mingw*|*-mingw*) needed_libc=mingw-runtime;;
1165 avr) confgcc+=( --enable-shared --disable-threads );;
1166 esac
1167 if [[ -n ${needed_libc} ]] ; then
1168 local confgcc_no_libc=( --disable-shared )
1169 tc_version_is_at_least 4.8 && confgcc_no_libc+=( --disable-libatomic )
1170 if ! has_version ${CATEGORY}/${needed_libc} ; then
1171 confgcc+=(
1172 "${confgcc_no_libc[@]}"
1173 --disable-threads
1174 --without-headers
1175 )
1176 elif built_with_use --hidden --missing false ${CATEGORY}/${needed_libc} crosscompile_opts_headers-only ; then
1177 confgcc+=(
1178 "${confgcc_no_libc[@]}"
1179 --with-sysroot=${PREFIX}/${CTARGET}
1180 )
1181 else
1182 confgcc+=( --with-sysroot=${PREFIX}/${CTARGET} )
1183 fi
1184 fi
1185
1186 tc_version_is_at_least 4.2 && confgcc+=( --disable-bootstrap )
1187 else
1188 if tc-is-static-only ; then
1189 confgcc+=( --disable-shared )
1190 else
1191 confgcc+=( --enable-shared )
1192 fi
1193 case ${CHOST} in
1194 mingw*|*-mingw*|*-cygwin)
1195 confgcc+=( --enable-threads=win32 ) ;;
1196 *)
1197 confgcc+=( --enable-threads=posix ) ;;
1198 esac
1199 fi
1200 # __cxa_atexit is "essential for fully standards-compliant handling of
1201 # destructors", but apparently requires glibc.
1202 case ${CTARGET} in
1203 *-uclibc*)
1204 confgcc+=(
1205 --disable-__cxa_atexit
1206 $(use_enable nptl tls)
1207 )
1208 [[ ${GCCMAJOR}.${GCCMINOR} == 3.3 ]] && confgcc+=( --enable-sjlj-exceptions )
1209 if tc_version_is_at_least 3.4 && ! tc_version_is_at_least 4.3 ; then
1210 confgcc+=( --enable-clocale=uclibc )
1211 fi
1212 ;;
1213 *-elf|*-eabi)
1214 confgcc+=( --with-newlib )
1215 ;;
1216 *-gnu*)
1217 confgcc+=(
1218 --enable-__cxa_atexit
1219 --enable-clocale=gnu
1220 )
1221 ;;
1222 *-freebsd*)
1223 confgcc+=( --enable-__cxa_atexit )
1224 ;;
1225 *-solaris*)
1226 confgcc+=( --enable-__cxa_atexit )
1227 ;;
1228 esac
1229
1230 tc_version_is_at_least 3.4 || confgcc+=( --disable-libunwind-exceptions )
1231
1232 # if the target can do biarch (-m32/-m64), enable it. overhead should
1233 # be small, and should simplify building of 64bit kernels in a 32bit
1234 # userland by not needing sys-devel/kgcc64. #349405
1235 case $(tc-arch) in
1236 ppc|ppc64) tc_version_is_at_least 3.4 && confgcc+=( --enable-targets=all ) ;;
1237 sparc) tc_version_is_at_least 4.4 && confgcc+=( --enable-targets=all ) ;;
1238 amd64|x86) tc_version_is_at_least 4.3 && confgcc+=( --enable-targets=all ) ;;
1239 esac
1240
1241 tc_version_is_at_least 4.3 && confgcc+=(
1242 --with-bugurl=http://bugs.gentoo.org/
1243 --with-pkgversion="${BRANDING_GCC_PKGVERSION}"
1244 )
1245
1246 confgcc+=(
1247 "$@"
1248 ${EXTRA_ECONF}
1249 )
1250
1251 # Disable gcc info regeneration -- it ships with generated info pages
1252 # already. Our custom version/urls/etc... trigger it. #464008
1253 export gcc_cv_prog_makeinfo_modern=no
1254
1255 # Do not let the X detection get in our way. We know things can be found
1256 # via system paths, so no need to hardcode things that'll break multilib.
1257 # Older gcc versions will detect ac_x_libraries=/usr/lib64 which ends up
1258 # killing the 32bit builds which want /usr/lib.
1259 export ac_cv_have_x='have_x=yes ac_x_includes= ac_x_libraries='
1260
1261 # Nothing wrong with a good dose of verbosity
1262 echo
1263 einfo "PREFIX: ${PREFIX}"
1264 einfo "BINPATH: ${BINPATH}"
1265 einfo "LIBPATH: ${LIBPATH}"
1266 einfo "DATAPATH: ${DATAPATH}"
1267 einfo "STDCXX_INCDIR: ${STDCXX_INCDIR}"
1268 echo
1269 einfo "Configuring GCC with: ${confgcc[@]//--/\n\t--}"
1270 echo
1271
1272 # Build in a separate build tree
1273 mkdir -p "${WORKDIR}"/build
1274 pushd "${WORKDIR}"/build > /dev/null
1275
1276 # and now to do the actual configuration
1277 addwrite /dev/zero
1278 echo "${S}"/configure "${confgcc[@]}"
1279 "${S}"/configure "${confgcc[@]}" || die "failed to run configure"
1280
1281 # return to whatever directory we were in before
1282 popd > /dev/null
1283 }
1284
1285 has toolchain_death_notice ${EBUILD_DEATH_HOOKS} || EBUILD_DEATH_HOOKS+=" toolchain_death_notice"
1286 toolchain_death_notice() {
1287 if [[ -e "${WORKDIR}"/build ]] ; then
1288 pushd "${WORKDIR}"/build >/dev/null
1289 (echo '' | $(tc-getCC ${CTARGET}) ${CFLAGS} -v -E - 2>&1) > gccinfo.log
1290 [[ -e "${T}"/build.log ]] && cp "${T}"/build.log .
1291 tar jcf "${WORKDIR}"/gcc-build-logs.tar.bz2 \
1292 gccinfo.log build.log $(find -name config.log)
1293 rm gccinfo.log build.log
1294 eerror
1295 eerror "Please include ${WORKDIR}/gcc-build-logs.tar.bz2 in your bug report."
1296 eerror
1297 popd >/dev/null
1298 fi
1299 }
1300
1301 # This function accepts one optional argument, the make target to be used.
1302 # If ommitted, gcc_do_make will try to guess whether it should use all,
1303 # profiledbootstrap, or bootstrap-lean depending on CTARGET and arch. An
1304 # example of how to use this function:
1305 #
1306 # gcc_do_make all-target-libstdc++-v3
1307 #
1308 # In addition to the target to be used, the following variables alter the
1309 # behavior of this function:
1310 #
1311 # LDFLAGS
1312 # Flags to pass to ld
1313 #
1314 # STAGE1_CFLAGS
1315 # CFLAGS to use during stage1 of a gcc bootstrap
1316 #
1317 # BOOT_CFLAGS
1318 # CFLAGS to use during stages 2+3 of a gcc bootstrap.
1319 #
1320 # Travis Tilley <lv@gentoo.org> (04 Sep 2004)
1321 #
1322 gcc_do_make() {
1323 # Set make target to $1 if passed
1324 [[ -n $1 ]] && GCC_MAKE_TARGET=$1
1325 # default target
1326 if is_crosscompile || tc-is-cross-compiler ; then
1327 # 3 stage bootstrapping doesnt quite work when you cant run the
1328 # resulting binaries natively ^^;
1329 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-all}
1330 else
1331 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-bootstrap-lean}
1332 fi
1333
1334 # the gcc docs state that parallel make isnt supported for the
1335 # profiledbootstrap target, as collisions in profile collecting may occur.
1336 # boundschecking also seems to introduce parallel build issues.
1337 if [[ ${GCC_MAKE_TARGET} == "profiledbootstrap" ]] ||
1338 use_if_iuse boundschecking
1339 then
1340 export MAKEOPTS="${MAKEOPTS} -j1"
1341 fi
1342
1343 if [[ ${GCC_MAKE_TARGET} == "all" ]] ; then
1344 STAGE1_CFLAGS=${STAGE1_CFLAGS-"${CFLAGS}"}
1345 elif [[ $(gcc-version) == "3.4" && ${GCC_BRANCH_VER} == "3.4" ]] && gcc-specs-ssp ; then
1346 # See bug #79852
1347 STAGE1_CFLAGS=${STAGE1_CFLAGS-"-O2"}
1348 fi
1349
1350 if is_crosscompile; then
1351 # In 3.4, BOOT_CFLAGS is never used on a crosscompile...
1352 # but I'll leave this in anyways as someone might have had
1353 # some reason for putting it in here... --eradicator
1354 BOOT_CFLAGS=${BOOT_CFLAGS-"-O2"}
1355 else
1356 # we only want to use the system's CFLAGS if not building a
1357 # cross-compiler.
1358 BOOT_CFLAGS=${BOOT_CFLAGS-"$(get_abi_CFLAGS ${TARGET_DEFAULT_ABI}) ${CFLAGS}"}
1359 fi
1360
1361 pushd "${WORKDIR}"/build >/dev/null
1362
1363 emake \
1364 LDFLAGS="${LDFLAGS}" \
1365 STAGE1_CFLAGS="${STAGE1_CFLAGS}" \
1366 LIBPATH="${LIBPATH}" \
1367 BOOT_CFLAGS="${BOOT_CFLAGS}" \
1368 ${GCC_MAKE_TARGET} \
1369 || die "emake failed with ${GCC_MAKE_TARGET}"
1370
1371 if ! is_crosscompile && use cxx && use_if_iuse doc ; then
1372 if type -p doxygen > /dev/null ; then
1373 if tc_version_is_at_least 4.3 ; then
1374 cd "${CTARGET}"/libstdc++-v3/doc
1375 emake doc-man-doxygen || ewarn "failed to make docs"
1376 elif tc_version_is_at_least 3.0 ; then
1377 cd "${CTARGET}"/libstdc++-v3
1378 emake doxygen-man || ewarn "failed to make docs"
1379 fi
1380 else
1381 ewarn "Skipping libstdc++ manpage generation since you don't have doxygen installed"
1382 fi
1383 fi
1384
1385 popd >/dev/null
1386 }
1387
1388 gcc_do_filter_flags() {
1389 strip-flags
1390
1391 # In general gcc does not like optimization, and adds -O2 where
1392 # it is safe. This is especially true for gcc 3.3 + 3.4
1393 replace-flags -O? -O2
1394
1395 # dont want to funk ourselves
1396 filter-flags '-mabi*' -m31 -m32 -m64
1397
1398 filter-flags '-frecord-gcc-switches' # 490738
1399
1400 case ${GCC_BRANCH_VER} in
1401 3.2|3.3)
1402 replace-cpu-flags k8 athlon64 opteron x86-64
1403 replace-cpu-flags pentium-m pentium3m pentium3
1404 replace-cpu-flags G3 750
1405 replace-cpu-flags G4 7400
1406 replace-cpu-flags G5 7400
1407
1408 case $(tc-arch) in
1409 amd64)
1410 replace-cpu-flags core2 nocona
1411 filter-flags '-mtune=*'
1412 ;;
1413 x86)
1414 replace-cpu-flags core2 prescott
1415 filter-flags '-mtune=*'
1416 ;;
1417 esac
1418
1419 # XXX: should add a sed or something to query all supported flags
1420 # from the gcc source and trim everything else ...
1421 filter-flags -f{no-,}unit-at-a-time -f{no-,}web -mno-tls-direct-seg-refs
1422 filter-flags -f{no-,}stack-protector{,-all}
1423 filter-flags -fvisibility-inlines-hidden -fvisibility=hidden
1424 ;;
1425 3.4|4.*)
1426 case $(tc-arch) in
1427 amd64|x86)
1428 filter-flags '-mcpu=*'
1429 ;;
1430 alpha)
1431 # https://bugs.gentoo.org/454426
1432 append-ldflags -Wl,--no-relax
1433 ;;
1434 sparc)
1435 # temporary workaround for random ICEs reproduced by multiple users
1436 # https://bugs.gentoo.org/457062
1437 [[ ${GCC_BRANCH_VER} == 4.6 || ${GCC_BRANCH_VER} == 4.7 ]] && \
1438 MAKEOPTS+=" -j1"
1439 ;;
1440 *-macos)
1441 # http://gcc.gnu.org/PR25127
1442 [[ ${GCC_BRANCH_VER} == 4.0 || ${GCC_BRANCH_VER} == 4.1 ]] && \
1443 filter-flags '-mcpu=*' '-march=*' '-mtune=*'
1444 ;;
1445 esac
1446 ;;
1447 esac
1448
1449 case ${GCC_BRANCH_VER} in
1450 4.6)
1451 case $(tc-arch) in
1452 amd64|x86)
1453 # https://bugs.gentoo.org/411333
1454 # https://bugs.gentoo.org/466454
1455 replace-cpu-flags c3-2 pentium2 pentium3 pentium3m pentium-m i686
1456 ;;
1457 esac
1458 ;;
1459 esac
1460
1461 strip-unsupported-flags
1462
1463 # TODO: Move to gcc_do_make()
1464
1465 # CFLAGS logic (verified with 3.4.3):
1466 # CFLAGS:
1467 # This conflicts when creating a crosscompiler, so set to a sane
1468 # default in this case:
1469 # used in ./configure and elsewhere for the native compiler
1470 # used by gcc when creating libiberty.a
1471 # used by xgcc when creating libstdc++ (and probably others)!
1472 # this behavior should be removed...
1473 #
1474 # CXXFLAGS:
1475 # used by xgcc when creating libstdc++
1476 #
1477 # STAGE1_CFLAGS (not used in creating a crosscompile gcc):
1478 # used by ${CHOST}-gcc for building stage1 compiler
1479 #
1480 # BOOT_CFLAGS (not used in creating a crosscompile gcc):
1481 # used by xgcc for building stage2/3 compiler
1482
1483 if is_crosscompile ; then
1484 # Set this to something sane for both native and target
1485 CFLAGS="-O2 -pipe"
1486 FFLAGS=${CFLAGS}
1487 FCFLAGS=${CFLAGS}
1488
1489 local VAR="CFLAGS_"${CTARGET//-/_}
1490 CXXFLAGS=${!VAR}
1491 fi
1492
1493 export GCJFLAGS=${GCJFLAGS:-${CFLAGS}}
1494 }
1495
1496 toolchain_src_compile() {
1497 gcc_do_filter_flags
1498 einfo "CFLAGS=\"${CFLAGS}\""
1499 einfo "CXXFLAGS=\"${CXXFLAGS}\""
1500
1501 # Force internal zip based jar script to avoid random
1502 # issues with 3rd party jar implementations. #384291
1503 export JAR=no
1504
1505 # For hardened gcc 4.3 piepatchset to build the hardened specs
1506 # file (build.specs) to use when building gcc.
1507 if ! tc_version_is_at_least 4.4 && want_minispecs ; then
1508 setup_minispecs_gcc_build_specs
1509 fi
1510 # Build in a separate build tree
1511 mkdir -p "${WORKDIR}"/build
1512 pushd "${WORKDIR}"/build > /dev/null
1513
1514 einfo "Configuring ${PN} ..."
1515 gcc_do_configure
1516
1517 touch "${S}"/gcc/c-gperf.h
1518
1519 # Do not make manpages if we do not have perl ...
1520 [[ ! -x /usr/bin/perl ]] \
1521 && find "${WORKDIR}"/build -name '*.[17]' | xargs touch
1522
1523 einfo "Compiling ${PN} ..."
1524 gcc_do_make ${GCC_MAKE_TARGET}
1525
1526 popd > /dev/null
1527 }
1528
1529 toolchain_src_test() {
1530 if use regression-test ; then
1531 cd "${WORKDIR}"/build
1532 emake -k check
1533 fi
1534 }
1535
1536 toolchain_src_install() {
1537 cd "${WORKDIR}"/build
1538
1539 # Do allow symlinks in private gcc include dir as this can break the build
1540 find gcc/include*/ -type l -delete
1541
1542 # Copy over the info pages. We disabled their generation earlier, but the
1543 # build system only expects to install out of the build dir, not the source. #464008
1544 mkdir -p gcc/doc
1545 local x=
1546 for x in "${S}"/gcc/doc/*.info* ; do
1547 if [[ -f ${x} ]] ; then
1548 cp "${x}" gcc/doc/ || die
1549 fi
1550 done
1551
1552 # Remove generated headers, as they can cause things to break
1553 # (ncurses, openssl, etc).
1554 while read x ; do
1555 grep -q 'It has been auto-edited by fixincludes from' "${x}" \
1556 && rm -f "${x}"
1557 done < <(find gcc/include*/ -name '*.h')
1558
1559 # Do the 'make install' from the build directory
1560 S="${WORKDIR}"/build emake -j1 DESTDIR="${D}" install || die
1561
1562 # Punt some tools which are really only useful while building gcc
1563 find "${D}" -name install-tools -prune -type d -exec rm -rf "{}" \;
1564 # This one comes with binutils
1565 find "${D}" -name libiberty.a -delete
1566
1567 # Move the libraries to the proper location
1568 gcc_movelibs
1569
1570 # Basic sanity check
1571 if ! is_crosscompile ; then
1572 local EXEEXT
1573 eval $(grep ^EXEEXT= "${WORKDIR}"/build/gcc/config.log)
1574 [[ -r ${D}${BINPATH}/gcc${EXEEXT} ]] || die "gcc not found in ${D}"
1575 fi
1576
1577 dodir /etc/env.d/gcc
1578 create_gcc_env_entry
1579
1580 # Setup the gcc_env_entry for hardened gcc 4 with minispecs
1581 want_minispecs && copy_minispecs_gcc_specs
1582
1583 # Make sure we dont have stuff lying around that
1584 # can nuke multiple versions of gcc
1585 gcc_slot_java
1586
1587 dodir /usr/bin
1588 cd "${D}"${BINPATH}
1589 # Ugh: we really need to auto-detect this list.
1590 # It's constantly out of date.
1591 for x in cpp gcc g++ c++ gcov g77 gcj gcjh gfortran gccgo ; do
1592 # For some reason, g77 gets made instead of ${CTARGET}-g77...
1593 # this should take care of that
1594 [[ -f ${x} ]] && mv ${x} ${CTARGET}-${x}
1595
1596 if [[ -f ${CTARGET}-${x} ]] ; then
1597 if ! is_crosscompile ; then
1598 ln -sf ${CTARGET}-${x} ${x}
1599 dosym ${BINPATH}/${CTARGET}-${x} \
1600 /usr/bin/${x}-${GCC_CONFIG_VER}
1601 fi
1602 # Create versioned symlinks
1603 dosym ${BINPATH}/${CTARGET}-${x} \
1604 /usr/bin/${CTARGET}-${x}-${GCC_CONFIG_VER}
1605 fi
1606
1607 if [[ -f ${CTARGET}-${x}-${GCC_CONFIG_VER} ]] ; then
1608 rm -f ${CTARGET}-${x}-${GCC_CONFIG_VER}
1609 ln -sf ${CTARGET}-${x} ${CTARGET}-${x}-${GCC_CONFIG_VER}
1610 fi
1611 done
1612
1613 # Now do the fun stripping stuff
1614 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${BINPATH}"
1615 env RESTRICT="" CHOST=${CTARGET} prepstrip "${D}${LIBPATH}"
1616 # gcc used to install helper binaries in lib/ but then moved to libexec/
1617 [[ -d ${D}${PREFIX}/libexec/gcc ]] && \
1618 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}"
1619
1620 cd "${S}"
1621 if is_crosscompile; then
1622 rm -rf "${D}"/usr/share/{man,info}
1623 rm -rf "${D}"${DATAPATH}/{man,info}
1624 else
1625 if tc_version_is_at_least 3.0 ; then
1626 local cxx_mandir=$(find "${WORKDIR}/build/${CTARGET}/libstdc++-v3" -name man)
1627 if [[ -d ${cxx_mandir} ]] ; then
1628 # clean bogus manpages #113902
1629 find "${cxx_mandir}" -name '*_build_*' -exec rm {} \;
1630 cp -r "${cxx_mandir}"/man? "${D}/${DATAPATH}"/man/
1631 fi
1632 fi
1633 has noinfo ${FEATURES} \
1634 && rm -r "${D}/${DATAPATH}"/info \
1635 || prepinfo "${DATAPATH}"
1636 has noman ${FEATURES} \
1637 && rm -r "${D}/${DATAPATH}"/man \
1638 || prepman "${DATAPATH}"
1639 fi
1640 # prune empty dirs left behind
1641 find "${D}" -depth -type d -delete 2>/dev/null
1642
1643 # install testsuite results
1644 if use regression-test; then
1645 docinto testsuite
1646 find "${WORKDIR}"/build -type f -name "*.sum" -print0 | xargs -0 dodoc
1647 find "${WORKDIR}"/build -type f -path "*/testsuite/*.log" -print0 \
1648 | xargs -0 dodoc
1649 fi
1650
1651 # Rather install the script, else portage with changing $FILESDIR
1652 # between binary and source package borks things ....
1653 if ! is_crosscompile ; then
1654 insinto "${DATAPATH}"
1655 if tc_version_is_at_least 4.0 ; then
1656 newins "${GCC_FILESDIR}"/awk/fixlafiles.awk-no_gcc_la fixlafiles.awk || die
1657 find "${D}/${LIBPATH}" -name libstdc++.la -type f -exec rm "{}" \;
1658 find "${D}/${LIBPATH}" -name "lib?san.la" -type f -exec rm "{}" \; # 487550
1659 else
1660 doins "${GCC_FILESDIR}"/awk/fixlafiles.awk || die
1661 fi
1662 exeinto "${DATAPATH}"
1663 doexe "${GCC_FILESDIR}"/fix_libtool_files.sh || die
1664 doexe "${GCC_FILESDIR}"/c{89,99} || die
1665 fi
1666
1667 # Use gid of 0 because some stupid ports don't have
1668 # the group 'root' set to gid 0. Send to /dev/null
1669 # for people who are testing as non-root.
1670 chown -R root:0 "${D}"${LIBPATH} 2>/dev/null
1671
1672 # Move pretty-printers to gdb datadir to shut ldconfig up
1673 local py gdbdir=/usr/share/gdb/auto-load${LIBPATH/\/lib\//\/$(get_libdir)\/}
1674 pushd "${D}"${LIBPATH} >/dev/null
1675 for py in $(find . -name '*-gdb.py') ; do
1676 local multidir=${py%/*}
1677 insinto "${gdbdir}/${multidir}"
1678 sed -i "/^libdir =/s:=.*:= '${LIBPATH}/${multidir}':" "${py}" || die #348128
1679 doins "${py}" || die
1680 rm "${py}" || die
1681 done
1682 popd >/dev/null
1683
1684 # Don't scan .gox files for executable stacks - false positives
1685 export QA_EXECSTACK="usr/lib*/go/*/*.gox"
1686 export QA_WX_LOAD="usr/lib*/go/*/*.gox"
1687
1688 # Disable RANDMMAP so PCH works. #301299
1689 if tc_version_is_at_least 4.3 ; then
1690 pax-mark -r "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}/cc1"
1691 pax-mark -r "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}/cc1plus"
1692 fi
1693 }
1694
1695 gcc_slot_java() {
1696 local x
1697
1698 # Move Java headers to compiler-specific dir
1699 for x in "${D}"${PREFIX}/include/gc*.h "${D}"${PREFIX}/include/j*.h ; do
1700 [[ -f ${x} ]] && mv -f "${x}" "${D}"${LIBPATH}/include/
1701 done
1702 for x in gcj gnu java javax org ; do
1703 if [[ -d ${D}${PREFIX}/include/${x} ]] ; then
1704 dodir /${LIBPATH}/include/${x}
1705 mv -f "${D}"${PREFIX}/include/${x}/* "${D}"${LIBPATH}/include/${x}/
1706 rm -rf "${D}"${PREFIX}/include/${x}
1707 fi
1708 done
1709
1710 if [[ -d ${D}${PREFIX}/lib/security ]] || [[ -d ${D}${PREFIX}/$(get_libdir)/security ]] ; then
1711 dodir /${LIBPATH}/security
1712 mv -f "${D}"${PREFIX}/lib*/security/* "${D}"${LIBPATH}/security
1713 rm -rf "${D}"${PREFIX}/lib*/security
1714 fi
1715
1716 # Move random gcj files to compiler-specific directories
1717 for x in libgcj.spec logging.properties ; do
1718 x="${D}${PREFIX}/lib/${x}"
1719 [[ -f ${x} ]] && mv -f "${x}" "${D}"${LIBPATH}/
1720 done
1721
1722 # Rename jar because it could clash with Kaffe's jar if this gcc is
1723 # primary compiler (aka don't have the -<version> extension)
1724 cd "${D}"${BINPATH}
1725 [[ -f jar ]] && mv -f jar gcj-jar
1726 }
1727
1728 # Move around the libs to the right location. For some reason,
1729 # when installing gcc, it dumps internal libraries into /usr/lib
1730 # instead of the private gcc lib path
1731 gcc_movelibs() {
1732 # older versions of gcc did not support --print-multi-os-directory
1733 tc_version_is_at_least 3.2 || return 0
1734
1735 local x multiarg removedirs=""
1736 for multiarg in $($(XGCC) -print-multi-lib) ; do
1737 multiarg=${multiarg#*;}
1738 multiarg=${multiarg//@/ -}
1739
1740 local OS_MULTIDIR=$($(XGCC) ${multiarg} --print-multi-os-directory)
1741 local MULTIDIR=$($(XGCC) ${multiarg} --print-multi-directory)
1742 local TODIR=${D}${LIBPATH}/${MULTIDIR}
1743 local FROMDIR=
1744
1745 [[ -d ${TODIR} ]] || mkdir -p ${TODIR}
1746
1747 for FROMDIR in \
1748 ${LIBPATH}/${OS_MULTIDIR} \
1749 ${LIBPATH}/../${MULTIDIR} \
1750 ${PREFIX}/lib/${OS_MULTIDIR} \
1751 ${PREFIX}/${CTARGET}/lib/${OS_MULTIDIR}
1752 do
1753 removedirs="${removedirs} ${FROMDIR}"
1754 FROMDIR=${D}${FROMDIR}
1755 if [[ ${FROMDIR} != "${TODIR}" && -d ${FROMDIR} ]] ; then
1756 local files=$(find "${FROMDIR}" -maxdepth 1 ! -type d 2>/dev/null)
1757 if [[ -n ${files} ]] ; then
1758 mv ${files} "${TODIR}"
1759 fi
1760 fi
1761 done
1762 fix_libtool_libdir_paths "${LIBPATH}/${MULTIDIR}"
1763
1764 # SLOT up libgcj.pc if it's available (and let gcc-config worry about links)
1765 FROMDIR="${PREFIX}/lib/${OS_MULTIDIR}"
1766 for x in "${D}${FROMDIR}"/pkgconfig/libgcj*.pc ; do
1767 [[ -f ${x} ]] || continue
1768 sed -i "/^libdir=/s:=.*:=${LIBPATH}/${MULTIDIR}:" "${x}"
1769 mv "${x}" "${D}${FROMDIR}"/pkgconfig/libgcj-${GCC_PV}.pc || die
1770 done
1771 done
1772
1773 # We remove directories separately to avoid this case:
1774 # mv SRC/lib/../lib/*.o DEST
1775 # rmdir SRC/lib/../lib/
1776 # mv SRC/lib/../lib32/*.o DEST # Bork
1777 for FROMDIR in ${removedirs} ; do
1778 rmdir "${D}"${FROMDIR} >& /dev/null
1779 done
1780 find "${D}" -type d | xargs rmdir >& /dev/null
1781 }
1782 #----<< src_* >>----
1783
1784 #---->> unorganized crap in need of refactoring follows
1785
1786 # gcc_quick_unpack will unpack the gcc tarball and patches in a way that is
1787 # consistant with the behavior of get_gcc_src_uri. The only patch it applies
1788 # itself is the branch update if present.
1789 #
1790 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
1791 #
1792 gcc_quick_unpack() {
1793 pushd "${WORKDIR}" > /dev/null
1794 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
1795 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
1796 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
1797 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
1798 export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}}
1799
1800 if [[ -n ${GCC_A_FAKEIT} ]] ; then
1801 unpack ${GCC_A_FAKEIT}
1802 elif [[ -n ${PRERELEASE} ]] ; then
1803 unpack gcc-${PRERELEASE}.tar.bz2
1804 elif [[ -n ${SNAPSHOT} ]] ; then
1805 unpack gcc-${SNAPSHOT}.tar.bz2
1806 elif [[ ${PV} != *9999* ]] ; then
1807 unpack gcc-${GCC_RELEASE_VER}.tar.bz2
1808 # We want branch updates to be against a release tarball
1809 if [[ -n ${BRANCH_UPDATE} ]] ; then
1810 pushd "${S}" > /dev/null
1811 epatch "${DISTDIR}"/gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2
1812 popd > /dev/null
1813 fi
1814 fi
1815
1816 if [[ -n ${D_VER} ]] && use d ; then
1817 pushd "${S}"/gcc > /dev/null
1818 unpack gdc-${D_VER}-src.tar.bz2
1819 cd ..
1820 ebegin "Adding support for the D language"
1821 ./gcc/d/setup-gcc.sh >& "${T}"/dgcc.log
1822 if ! eend $? ; then
1823 eerror "The D gcc package failed to apply"
1824 eerror "Please include this log file when posting a bug report:"
1825 eerror " ${T}/dgcc.log"
1826 die "failed to include the D language"
1827 fi
1828 popd > /dev/null
1829 fi
1830
1831 [[ -n ${PATCH_VER} ]] && \
1832 unpack gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2
1833
1834 [[ -n ${UCLIBC_VER} ]] && \
1835 unpack gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2
1836
1837 if want_pie ; then
1838 if [[ -n ${PIE_CORE} ]] ; then
1839 unpack ${PIE_CORE}
1840 else
1841 unpack gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2
1842 fi
1843 [[ -n ${SPECS_VER} ]] && \
1844 unpack gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2
1845 fi
1846
1847 use_if_iuse boundschecking && unpack "bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
1848
1849 popd > /dev/null
1850 }
1851
1852 do_gcc_HTB_patches() {
1853 use_if_iuse boundschecking || return 0
1854
1855 # modify the bounds checking patch with a regression patch
1856 epatch "${WORKDIR}/bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch"
1857 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, HTB-${HTB_GCC_VER}-${HTB_VER}"
1858 }
1859
1860 # do various updates to PIE logic
1861 do_gcc_PIE_patches() {
1862 want_pie || return 0
1863
1864 use vanilla && return 0
1865
1866 if tc_version_is_at_least 4.3.2 ; then
1867 guess_patch_type_in_dir "${WORKDIR}"/piepatch/
1868 EPATCH_MULTI_MSG="Applying pie patches ..." \
1869 epatch "${WORKDIR}"/piepatch/
1870 else
1871 guess_patch_type_in_dir "${WORKDIR}"/piepatch/upstream
1872
1873 # corrects startfile/endfile selection and shared/static/pie flag usage
1874 EPATCH_MULTI_MSG="Applying upstream pie patches ..." \
1875 epatch "${WORKDIR}"/piepatch/upstream
1876 # adds non-default pie support (rs6000)
1877 EPATCH_MULTI_MSG="Applying non-default pie patches ..." \
1878 epatch "${WORKDIR}"/piepatch/nondef
1879 # adds default pie support (rs6000 too) if DEFAULT_PIE[_SSP] is defined
1880 EPATCH_MULTI_MSG="Applying default pie patches ..." \
1881 epatch "${WORKDIR}"/piepatch/def
1882 fi
1883
1884 # we want to be able to control the pie patch logic via something other
1885 # than ALL_CFLAGS...
1886 sed -e '/^ALL_CFLAGS/iHARD_CFLAGS = ' \
1887 -e 's|^ALL_CFLAGS = |ALL_CFLAGS = $(HARD_CFLAGS) |' \
1888 -i "${S}"/gcc/Makefile.in
1889 # Need to add HARD_CFLAGS to ALL_CXXFLAGS on >= 4.7
1890 if tc_version_is_at_least 4.7 ; then
1891 sed -e '/^ALL_CXXFLAGS/iHARD_CFLAGS = ' \
1892 -e 's|^ALL_CXXFLAGS = |ALL_CXXFLAGS = $(HARD_CFLAGS) |' \
1893 -i "${S}"/gcc/Makefile.in
1894 fi
1895
1896 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, pie-${PIE_VER}"
1897 }
1898
1899 should_we_gcc_config() {
1900 # if the current config is invalid, we definitely want a new one
1901 # Note: due to bash quirkiness, the following must not be 1 line
1902 local curr_config
1903 curr_config=$(env -i ROOT="${ROOT}" gcc-config -c ${CTARGET} 2>&1) || return 0
1904
1905 # if the previously selected config has the same major.minor (branch) as
1906 # the version we are installing, then it will probably be uninstalled
1907 # for being in the same SLOT, make sure we run gcc-config.
1908 local curr_config_ver=$(env -i ROOT="${ROOT}" gcc-config -S ${curr_config} | awk '{print $2}')
1909
1910 local curr_branch_ver=$(get_version_component_range 1-2 ${curr_config_ver})
1911
1912 # If we're using multislot, just run gcc-config if we're installing
1913 # to the same profile as the current one.
1914 use multislot && return $([[ ${curr_config_ver} == ${GCC_CONFIG_VER} ]])
1915
1916 if [[ ${curr_branch_ver} == ${GCC_BRANCH_VER} ]] ; then
1917 return 0
1918 else
1919 # if we're installing a genuinely different compiler version,
1920 # we should probably tell the user -how- to switch to the new
1921 # gcc version, since we're not going to do it for him/her.
1922 # We don't want to switch from say gcc-3.3 to gcc-3.4 right in
1923 # the middle of an emerge operation (like an 'emerge -e world'
1924 # which could install multiple gcc versions).
1925 # Only warn if we're installing a pkg as we might be called from
1926 # the pkg_{pre,post}rm steps. #446830
1927 if [[ ${EBUILD_PHASE} == *"inst" ]] ; then
1928 einfo "The current gcc config appears valid, so it will not be"
1929 einfo "automatically switched for you. If you would like to"
1930 einfo "switch to the newly installed gcc version, do the"
1931 einfo "following:"
1932 echo
1933 einfo "gcc-config ${CTARGET}-${GCC_CONFIG_VER}"
1934 einfo "source /etc/profile"
1935 echo
1936 fi
1937 return 1
1938 fi
1939 }
1940
1941 do_gcc_config() {
1942 if ! should_we_gcc_config ; then
1943 env -i ROOT="${ROOT}" gcc-config --use-old --force
1944 return 0
1945 fi
1946
1947 local current_gcc_config="" current_specs="" use_specs=""
1948
1949 current_gcc_config=$(env -i ROOT="${ROOT}" gcc-config -c ${CTARGET} 2>/dev/null)
1950 if [[ -n ${current_gcc_config} ]] ; then
1951 # figure out which specs-specific config is active
1952 current_specs=$(gcc-config -S ${current_gcc_config} | awk '{print $3}')
1953 [[ -n ${current_specs} ]] && use_specs=-${current_specs}
1954 fi
1955 if [[ -n ${use_specs} ]] && \
1956 [[ ! -e ${ROOT}/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}${use_specs} ]]
1957 then
1958 ewarn "The currently selected specs-specific gcc config,"
1959 ewarn "${current_specs}, doesn't exist anymore. This is usually"
1960 ewarn "due to enabling/disabling hardened or switching to a version"
1961 ewarn "of gcc that doesnt create multiple specs files. The default"
1962 ewarn "config will be used, and the previous preference forgotten."
1963 use_specs=""
1964 fi
1965
1966 gcc-config ${CTARGET}-${GCC_CONFIG_VER}${use_specs}
1967 }
1968
1969 # This function allows us to gentoo-ize GCCs version number and bugzilla
1970 # URL without needing to use patches.
1971 gcc_version_patch() {
1972 # gcc-4.3+ has configure flags (whoo!)
1973 tc_version_is_at_least 4.3 && return 0
1974
1975 local version_string=${GCC_CONFIG_VER}
1976 [[ -n ${BRANCH_UPDATE} ]] && version_string+=" ${BRANCH_UPDATE}"
1977
1978 einfo "patching gcc version: ${version_string} (${BRANDING_GCC_PKGVERSION})"
1979
1980 local gcc_sed=( -e 's:gcc\.gnu\.org/bugs\.html:bugs\.gentoo\.org/:' )
1981 if grep -qs VERSUFFIX "${S}"/gcc/version.c ; then
1982 gcc_sed+=( -e "/VERSUFFIX \"\"/s:\"\":\" (${BRANDING_GCC_PKGVERSION})\":" )
1983 else
1984 version_string="${version_string} (${BRANDING_GCC_PKGVERSION})"
1985 gcc_sed+=( -e "/const char version_string\[\] = /s:= \".*\":= \"${version_string}\":" )
1986 fi
1987 sed -i "${gcc_sed[@]}" "${S}"/gcc/version.c || die
1988 }
1989
1990 # This is a historical wart. The original Gentoo/amd64 port used:
1991 # lib32 - 32bit binaries (x86)
1992 # lib64 - 64bit binaries (x86_64)
1993 # lib - "native" binaries (a symlink to lib64)
1994 # Most other distros use the logic (including mainline gcc):
1995 # lib - 32bit binaries (x86)
1996 # lib64 - 64bit binaries (x86_64)
1997 # Over time, Gentoo is migrating to the latter form.
1998 #
1999 # Unfortunately, due to distros picking the lib32 behavior, newer gcc
2000 # versions will dynamically detect whether to use lib or lib32 for its
2001 # 32bit multilib. So, to keep the automagic from getting things wrong
2002 # while people are transitioning from the old style to the new style,
2003 # we always set the MULTILIB_OSDIRNAMES var for relevant targets.
2004 setup_multilib_osdirnames() {
2005 is_multilib || return 0
2006
2007 local config
2008 local libdirs="../lib64 ../lib32"
2009
2010 # this only makes sense for some Linux targets
2011 case ${CTARGET} in
2012 x86_64*-linux*) config="i386" ;;
2013 powerpc64*-linux*) config="rs6000" ;;
2014 sparc64*-linux*) config="sparc" ;;
2015 s390x*-linux*) config="s390" ;;
2016 *) return 0 ;;
2017 esac
2018 config+="/t-linux64"
2019
2020 local sed_args=()
2021 if tc_version_is_at_least 4.6 ; then
2022 sed_args+=( -e 's:$[(]call if_multiarch[^)]*[)]::g' )
2023 fi
2024 if [[ ${SYMLINK_LIB} == "yes" ]] ; then
2025 einfo "updating multilib directories to be: ${libdirs}"
2026 if tc_version_is_at_least 4.6.4 || tc_version_is_at_least 4.7 ; then
2027 sed_args+=( -e '/^MULTILIB_OSDIRNAMES.*lib32/s:[$][(]if.*):../lib32:' )
2028 else
2029 sed_args+=( -e "/^MULTILIB_OSDIRNAMES/s:=.*:= ${libdirs}:" )
2030 fi
2031 else
2032 einfo "using upstream multilib; disabling lib32 autodetection"
2033 sed_args+=( -r -e 's:[$][(]if.*,(.*)[)]:\1:' )
2034 fi
2035 sed -i "${sed_args[@]}" "${S}"/gcc/config/${config} || die
2036 }
2037
2038 # make sure the libtool archives have libdir set to where they actually
2039 # -are-, and not where they -used- to be. also, any dependencies we have
2040 # on our own .la files need to be updated.
2041 fix_libtool_libdir_paths() {
2042 pushd "${D}" >/dev/null
2043
2044 pushd "./${1}" >/dev/null
2045 local dir="${PWD#${D%/}}"
2046 local allarchives=$(echo *.la)
2047 allarchives="\(${allarchives// /\\|}\)"
2048 popd >/dev/null
2049
2050 sed -i \
2051 -e "/^libdir=/s:=.*:='${dir}':" \
2052 ./${dir}/*.la
2053 sed -i \
2054 -e "/^dependency_libs=/s:/[^ ]*/${allarchives}:${LIBPATH}/\1:g" \
2055 $(find ./${PREFIX}/lib* -maxdepth 3 -name '*.la') \
2056 ./${dir}/*.la
2057
2058 popd >/dev/null
2059 }
2060
2061 is_multilib() {
2062 tc_version_is_at_least 3 || return 1
2063 use multilib
2064 }
2065
2066 is_cxx() {
2067 gcc-lang-supported 'c++' || return 1
2068 use cxx
2069 }
2070
2071 is_d() {
2072 gcc-lang-supported d || return 1
2073 use_if_iuse d
2074 }
2075
2076 is_f77() {
2077 gcc-lang-supported f77 || return 1
2078 use fortran
2079 }
2080
2081 is_f95() {
2082 gcc-lang-supported f95 || return 1
2083 use fortran
2084 }
2085
2086 is_fortran() {
2087 gcc-lang-supported fortran || return 1
2088 use fortran
2089 }
2090
2091 is_gcj() {
2092 gcc-lang-supported java || return 1
2093 use cxx && use_if_iuse gcj
2094 }
2095
2096 is_go() {
2097 gcc-lang-supported go || return 1
2098 use cxx && use_if_iuse go
2099 }
2100
2101 is_objc() {
2102 gcc-lang-supported objc || return 1
2103 use_if_iuse objc
2104 }
2105
2106 is_objcxx() {
2107 gcc-lang-supported 'obj-c++' || return 1
2108 use cxx && use_if_iuse objc++
2109 }
2110
2111 is_ada() {
2112 gcc-lang-supported ada || return 1
2113 use ada
2114 }
2115
2116 is_treelang() {
2117 use_if_iuse boundschecking && return 1 #260532
2118 is_crosscompile && return 1 #199924
2119 gcc-lang-supported treelang || return 1
2120 #use treelang
2121 return 0
2122 }

  ViewVC Help
Powered by ViewVC 1.1.20