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

Contents of /eclass/toolchain.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.600 - (show annotations) (download)
Thu Aug 15 04:39:24 2013 UTC (16 months ago) by dirtyepic
Branch: MAIN
Changes since 1.599: +5 -5 lines
alpha not only needs -Wl,--norelax for 4.6 to build itself, but also for it
to build other versions. So let's just always enable it.

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

  ViewVC Help
Powered by ViewVC 1.1.20