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

Contents of /eclass/toolchain.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.584 - (show annotations) (download)
Sat Apr 20 04:12:00 2013 UTC (19 months, 4 weeks ago) by dirtyepic
Branch: MAIN
Changes since 1.583: +3 -2 lines
Extend workaround for bug #411333 to Via C3-2 processors (bug #466454 by Andrew Church).

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

  ViewVC Help
Powered by ViewVC 1.1.20