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

Contents of /eclass/toolchain.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.597 - (show annotations) (download)
Wed Jul 24 01:34:38 2013 UTC (23 months, 1 week ago) by dirtyepic
Branch: MAIN
Changes since 1.596: +2 -1 lines
Add back LICENSE (bug #477836).

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.596 2013/07/18 23:45:54 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
1383 strip-flags
1384
1385 # In general gcc does not like optimization, and add -O2 where
1386 # it is safe. This is especially true for gcc 3.3 + 3.4
1387 replace-flags -O? -O2
1388
1389 # ... sure, why not?
1390 strip-unsupported-flags
1391
1392 # dont want to funk ourselves
1393 filter-flags '-mabi*' -m31 -m32 -m64
1394
1395 case ${GCC_BRANCH_VER} in
1396 3.2|3.3)
1397 replace-cpu-flags k8 athlon64 opteron i686 x86-64
1398 replace-cpu-flags pentium-m pentium3m pentium3
1399 case $(tc-arch) in
1400 amd64|x86) filter-flags '-mtune=*' ;;
1401 # in gcc 3.3 there is a bug on ppc64 where if -mcpu is used,
1402 # the compiler wrongly assumes a 32bit target
1403 ppc64) filter-flags "-mcpu=*";;
1404 esac
1405 case $(tc-arch) in
1406 amd64) replace-cpu-flags core2 nocona;;
1407 x86) replace-cpu-flags core2 prescott;;
1408 esac
1409
1410 replace-cpu-flags G3 750
1411 replace-cpu-flags G4 7400
1412 replace-cpu-flags G5 7400
1413
1414 # XXX: should add a sed or something to query all supported flags
1415 # from the gcc source and trim everything else ...
1416 filter-flags -f{no-,}unit-at-a-time -f{no-,}web -mno-tls-direct-seg-refs
1417 filter-flags -f{no-,}stack-protector{,-all}
1418 filter-flags -fvisibility-inlines-hidden -fvisibility=hidden
1419 ;;
1420 3.4|4.*)
1421 case $(tc-arch) in
1422 x86|amd64) filter-flags '-mcpu=*';;
1423 *-macos)
1424 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25127
1425 [[ ${GCC_BRANCH_VER} == 4.0 || ${GCC_BRANCH_VER} == 4.1 ]] && \
1426 filter-flags '-mcpu=*' '-march=*' '-mtune=*'
1427 ;;
1428 esac
1429 ;;
1430 esac
1431
1432 case ${GCC_BRANCH_VER} in
1433 4.6)
1434 # https://bugs.gentoo.org/411333
1435 # https://bugs.gentoo.org/466454
1436 replace-cpu-flags c3-2 pentium2 pentium3 pentium3m pentium-m i686
1437 ;;
1438 esac
1439
1440 # TODO: Move to gcc_do_make()
1441
1442 # CFLAGS logic (verified with 3.4.3):
1443 # CFLAGS:
1444 # This conflicts when creating a crosscompiler, so set to a sane
1445 # default in this case:
1446 # used in ./configure and elsewhere for the native compiler
1447 # used by gcc when creating libiberty.a
1448 # used by xgcc when creating libstdc++ (and probably others)!
1449 # this behavior should be removed...
1450 #
1451 # CXXFLAGS:
1452 # used by xgcc when creating libstdc++
1453 #
1454 # STAGE1_CFLAGS (not used in creating a crosscompile gcc):
1455 # used by ${CHOST}-gcc for building stage1 compiler
1456 #
1457 # BOOT_CFLAGS (not used in creating a crosscompile gcc):
1458 # used by xgcc for building stage2/3 compiler
1459
1460 if is_crosscompile ; then
1461 # Set this to something sane for both native and target
1462 CFLAGS="-O2 -pipe"
1463 FFLAGS=${CFLAGS}
1464 FCFLAGS=${CFLAGS}
1465
1466 local VAR="CFLAGS_"${CTARGET//-/_}
1467 CXXFLAGS=${!VAR}
1468 fi
1469
1470 export GCJFLAGS=${GCJFLAGS:-${CFLAGS}}
1471 }
1472
1473 toolchain_src_compile() {
1474 gcc_do_filter_flags
1475 einfo "CFLAGS=\"${CFLAGS}\""
1476 einfo "CXXFLAGS=\"${CXXFLAGS}\""
1477
1478 # Force internal zip based jar script to avoid random
1479 # issues with 3rd party jar implementations. #384291
1480 export JAR=no
1481
1482 # For hardened gcc 4.3 piepatchset to build the hardened specs
1483 # file (build.specs) to use when building gcc.
1484 if ! tc_version_is_at_least 4.4 && want_minispecs ; then
1485 setup_minispecs_gcc_build_specs
1486 fi
1487 # Build in a separate build tree
1488 mkdir -p "${WORKDIR}"/build
1489 pushd "${WORKDIR}"/build > /dev/null
1490
1491 einfo "Configuring ${PN} ..."
1492 gcc_do_configure
1493
1494 touch "${S}"/gcc/c-gperf.h
1495
1496 # Do not make manpages if we do not have perl ...
1497 [[ ! -x /usr/bin/perl ]] \
1498 && find "${WORKDIR}"/build -name '*.[17]' | xargs touch
1499
1500 einfo "Compiling ${PN} ..."
1501 gcc_do_make ${GCC_MAKE_TARGET}
1502
1503 popd > /dev/null
1504 }
1505
1506 toolchain_src_test() {
1507 if use regression-test ; then
1508 cd "${WORKDIR}"/build
1509 emake -k check
1510 fi
1511 }
1512
1513 toolchain_src_install() {
1514 cd "${WORKDIR}"/build
1515
1516 # Do allow symlinks in private gcc include dir as this can break the build
1517 find gcc/include*/ -type l -delete
1518
1519 # Copy over the info pages. We disabled their generation earlier, but the
1520 # build system only expects to install out of the build dir, not the source. #464008
1521 mkdir -p gcc/doc
1522 local x=
1523 for x in "${S}"/gcc/doc/*.info* ; do
1524 if [[ -f ${x} ]] ; then
1525 cp "${x}" gcc/doc/ || die
1526 fi
1527 done
1528
1529 # Remove generated headers, as they can cause things to break
1530 # (ncurses, openssl, etc).
1531 while read x ; do
1532 grep -q 'It has been auto-edited by fixincludes from' "${x}" \
1533 && rm -f "${x}"
1534 done < <(find gcc/include*/ -name '*.h')
1535
1536 # Do the 'make install' from the build directory
1537 S="${WORKDIR}"/build emake -j1 DESTDIR="${D}" install || die
1538
1539 # Punt some tools which are really only useful while building gcc
1540 find "${D}" -name install-tools -prune -type d -exec rm -rf "{}" \;
1541 # This one comes with binutils
1542 find "${D}" -name libiberty.a -delete
1543
1544 # Move the libraries to the proper location
1545 gcc_movelibs
1546
1547 # Basic sanity check
1548 if ! is_crosscompile ; then
1549 local EXEEXT
1550 eval $(grep ^EXEEXT= "${WORKDIR}"/build/gcc/config.log)
1551 [[ -r ${D}${BINPATH}/gcc${EXEEXT} ]] || die "gcc not found in ${D}"
1552 fi
1553
1554 dodir /etc/env.d/gcc
1555 create_gcc_env_entry
1556
1557 # Setup the gcc_env_entry for hardened gcc 4 with minispecs
1558 want_minispecs && copy_minispecs_gcc_specs
1559
1560 # Make sure we dont have stuff lying around that
1561 # can nuke multiple versions of gcc
1562 gcc_slot_java
1563
1564 dodir /usr/bin
1565 cd "${D}"${BINPATH}
1566 # Ugh: we really need to auto-detect this list.
1567 # It's constantly out of date.
1568 for x in cpp gcc g++ c++ gcov g77 gcj gcjh gfortran gccgo ; do
1569 # For some reason, g77 gets made instead of ${CTARGET}-g77...
1570 # this should take care of that
1571 [[ -f ${x} ]] && mv ${x} ${CTARGET}-${x}
1572
1573 if [[ -f ${CTARGET}-${x} ]] ; then
1574 if ! is_crosscompile ; then
1575 ln -sf ${CTARGET}-${x} ${x}
1576 dosym ${BINPATH}/${CTARGET}-${x} \
1577 /usr/bin/${x}-${GCC_CONFIG_VER}
1578 fi
1579 # Create versioned symlinks
1580 dosym ${BINPATH}/${CTARGET}-${x} \
1581 /usr/bin/${CTARGET}-${x}-${GCC_CONFIG_VER}
1582 fi
1583
1584 if [[ -f ${CTARGET}-${x}-${GCC_CONFIG_VER} ]] ; then
1585 rm -f ${CTARGET}-${x}-${GCC_CONFIG_VER}
1586 ln -sf ${CTARGET}-${x} ${CTARGET}-${x}-${GCC_CONFIG_VER}
1587 fi
1588 done
1589
1590 # Now do the fun stripping stuff
1591 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${BINPATH}"
1592 env RESTRICT="" CHOST=${CTARGET} prepstrip "${D}${LIBPATH}"
1593 # gcc used to install helper binaries in lib/ but then moved to libexec/
1594 [[ -d ${D}${PREFIX}/libexec/gcc ]] && \
1595 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}"
1596
1597 cd "${S}"
1598 if is_crosscompile; then
1599 rm -rf "${D}"/usr/share/{man,info}
1600 rm -rf "${D}"${DATAPATH}/{man,info}
1601 else
1602 if tc_version_is_at_least 3.0 ; then
1603 local cxx_mandir=$(find "${WORKDIR}/build/${CTARGET}/libstdc++-v3" -name man)
1604 if [[ -d ${cxx_mandir} ]] ; then
1605 # clean bogus manpages #113902
1606 find "${cxx_mandir}" -name '*_build_*' -exec rm {} \;
1607 cp -r "${cxx_mandir}"/man? "${D}/${DATAPATH}"/man/
1608 fi
1609 fi
1610 has noinfo ${FEATURES} \
1611 && rm -r "${D}/${DATAPATH}"/info \
1612 || prepinfo "${DATAPATH}"
1613 has noman ${FEATURES} \
1614 && rm -r "${D}/${DATAPATH}"/man \
1615 || prepman "${DATAPATH}"
1616 fi
1617 # prune empty dirs left behind
1618 find "${D}" -depth -type d -delete 2>/dev/null
1619
1620 # install testsuite results
1621 if use regression-test; then
1622 docinto testsuite
1623 find "${WORKDIR}"/build -type f -name "*.sum" -print0 | xargs -0 dodoc
1624 find "${WORKDIR}"/build -type f -path "*/testsuite/*.log" -print0 \
1625 | xargs -0 dodoc
1626 fi
1627
1628 # Rather install the script, else portage with changing $FILESDIR
1629 # between binary and source package borks things ....
1630 if ! is_crosscompile ; then
1631 insinto "${DATAPATH}"
1632 if tc_version_is_at_least 4.0 ; then
1633 newins "${GCC_FILESDIR}"/awk/fixlafiles.awk-no_gcc_la fixlafiles.awk || die
1634 find "${D}/${LIBPATH}" -name libstdc++.la -type f -exec rm "{}" \;
1635 else
1636 doins "${GCC_FILESDIR}"/awk/fixlafiles.awk || die
1637 fi
1638 exeinto "${DATAPATH}"
1639 doexe "${GCC_FILESDIR}"/fix_libtool_files.sh || die
1640 doexe "${GCC_FILESDIR}"/c{89,99} || die
1641 fi
1642
1643 # Use gid of 0 because some stupid ports don't have
1644 # the group 'root' set to gid 0. Send to /dev/null
1645 # for people who are testing as non-root.
1646 chown -R root:0 "${D}"${LIBPATH} 2>/dev/null
1647
1648 # Move pretty-printers to gdb datadir to shut ldconfig up
1649 local py gdbdir=/usr/share/gdb/auto-load${LIBPATH/\/lib\//\/$(get_libdir)\/}
1650 pushd "${D}"${LIBPATH} >/dev/null
1651 for py in $(find . -name '*-gdb.py') ; do
1652 local multidir=${py%/*}
1653 insinto "${gdbdir}/${multidir}"
1654 sed -i "/^libdir =/s:=.*:= '${LIBPATH}/${multidir}':" "${py}" || die #348128
1655 doins "${py}" || die
1656 rm "${py}" || die
1657 done
1658 popd >/dev/null
1659
1660 # Don't scan .gox files for executable stacks - false positives
1661 export QA_EXECSTACK="usr/lib*/go/*/*.gox"
1662 export QA_WX_LOAD="usr/lib*/go/*/*.gox"
1663
1664 # Disable RANDMMAP so PCH works. #301299
1665 if tc_version_is_at_least 4.3 ; then
1666 pax-mark -r "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}/cc1"
1667 pax-mark -r "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}/cc1plus"
1668 fi
1669 }
1670
1671 gcc_slot_java() {
1672 local x
1673
1674 # Move Java headers to compiler-specific dir
1675 for x in "${D}"${PREFIX}/include/gc*.h "${D}"${PREFIX}/include/j*.h ; do
1676 [[ -f ${x} ]] && mv -f "${x}" "${D}"${LIBPATH}/include/
1677 done
1678 for x in gcj gnu java javax org ; do
1679 if [[ -d ${D}${PREFIX}/include/${x} ]] ; then
1680 dodir /${LIBPATH}/include/${x}
1681 mv -f "${D}"${PREFIX}/include/${x}/* "${D}"${LIBPATH}/include/${x}/
1682 rm -rf "${D}"${PREFIX}/include/${x}
1683 fi
1684 done
1685
1686 if [[ -d ${D}${PREFIX}/lib/security ]] || [[ -d ${D}${PREFIX}/$(get_libdir)/security ]] ; then
1687 dodir /${LIBPATH}/security
1688 mv -f "${D}"${PREFIX}/lib*/security/* "${D}"${LIBPATH}/security
1689 rm -rf "${D}"${PREFIX}/lib*/security
1690 fi
1691
1692 # Move random gcj files to compiler-specific directories
1693 for x in libgcj.spec logging.properties ; do
1694 x="${D}${PREFIX}/lib/${x}"
1695 [[ -f ${x} ]] && mv -f "${x}" "${D}"${LIBPATH}/
1696 done
1697
1698 # Rename jar because it could clash with Kaffe's jar if this gcc is
1699 # primary compiler (aka don't have the -<version> extension)
1700 cd "${D}"${BINPATH}
1701 [[ -f jar ]] && mv -f jar gcj-jar
1702 }
1703
1704 # Move around the libs to the right location. For some reason,
1705 # when installing gcc, it dumps internal libraries into /usr/lib
1706 # instead of the private gcc lib path
1707 gcc_movelibs() {
1708 # older versions of gcc did not support --print-multi-os-directory
1709 tc_version_is_at_least 3.2 || return 0
1710
1711 local x multiarg removedirs=""
1712 for multiarg in $($(XGCC) -print-multi-lib) ; do
1713 multiarg=${multiarg#*;}
1714 multiarg=${multiarg//@/ -}
1715
1716 local OS_MULTIDIR=$($(XGCC) ${multiarg} --print-multi-os-directory)
1717 local MULTIDIR=$($(XGCC) ${multiarg} --print-multi-directory)
1718 local TODIR=${D}${LIBPATH}/${MULTIDIR}
1719 local FROMDIR=
1720
1721 [[ -d ${TODIR} ]] || mkdir -p ${TODIR}
1722
1723 for FROMDIR in \
1724 ${LIBPATH}/${OS_MULTIDIR} \
1725 ${LIBPATH}/../${MULTIDIR} \
1726 ${PREFIX}/lib/${OS_MULTIDIR} \
1727 ${PREFIX}/${CTARGET}/lib/${OS_MULTIDIR}
1728 do
1729 removedirs="${removedirs} ${FROMDIR}"
1730 FROMDIR=${D}${FROMDIR}
1731 if [[ ${FROMDIR} != "${TODIR}" && -d ${FROMDIR} ]] ; then
1732 local files=$(find "${FROMDIR}" -maxdepth 1 ! -type d 2>/dev/null)
1733 if [[ -n ${files} ]] ; then
1734 mv ${files} "${TODIR}"
1735 fi
1736 fi
1737 done
1738 fix_libtool_libdir_paths "${LIBPATH}/${MULTIDIR}"
1739
1740 # SLOT up libgcj.pc if it's available (and let gcc-config worry about links)
1741 FROMDIR="${PREFIX}/lib/${OS_MULTIDIR}"
1742 for x in "${D}${FROMDIR}"/pkgconfig/libgcj*.pc ; do
1743 [[ -f ${x} ]] || continue
1744 sed -i "/^libdir=/s:=.*:=${LIBPATH}/${MULTIDIR}:" "${x}"
1745 mv "${x}" "${D}${FROMDIR}"/pkgconfig/libgcj-${GCC_PV}.pc || die
1746 done
1747 done
1748
1749 # We remove directories separately to avoid this case:
1750 # mv SRC/lib/../lib/*.o DEST
1751 # rmdir SRC/lib/../lib/
1752 # mv SRC/lib/../lib32/*.o DEST # Bork
1753 for FROMDIR in ${removedirs} ; do
1754 rmdir "${D}"${FROMDIR} >& /dev/null
1755 done
1756 find "${D}" -type d | xargs rmdir >& /dev/null
1757 }
1758 #----<< src_* >>----
1759
1760 #---->> unorganized crap in need of refactoring follows
1761
1762 # gcc_quick_unpack will unpack the gcc tarball and patches in a way that is
1763 # consistant with the behavior of get_gcc_src_uri. The only patch it applies
1764 # itself is the branch update if present.
1765 #
1766 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
1767 #
1768 gcc_quick_unpack() {
1769 pushd "${WORKDIR}" > /dev/null
1770 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
1771 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
1772 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
1773 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
1774 export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}}
1775
1776 if [[ -n ${GCC_A_FAKEIT} ]] ; then
1777 unpack ${GCC_A_FAKEIT}
1778 elif [[ -n ${PRERELEASE} ]] ; then
1779 unpack gcc-${PRERELEASE}.tar.bz2
1780 elif [[ -n ${SNAPSHOT} ]] ; then
1781 unpack gcc-${SNAPSHOT}.tar.bz2
1782 elif [[ ${PV} != *9999* ]] ; then
1783 unpack gcc-${GCC_RELEASE_VER}.tar.bz2
1784 # We want branch updates to be against a release tarball
1785 if [[ -n ${BRANCH_UPDATE} ]] ; then
1786 pushd "${S}" > /dev/null
1787 epatch "${DISTDIR}"/gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2
1788 popd > /dev/null
1789 fi
1790 fi
1791
1792 if [[ -n ${D_VER} ]] && use d ; then
1793 pushd "${S}"/gcc > /dev/null
1794 unpack gdc-${D_VER}-src.tar.bz2
1795 cd ..
1796 ebegin "Adding support for the D language"
1797 ./gcc/d/setup-gcc.sh >& "${T}"/dgcc.log
1798 if ! eend $? ; then
1799 eerror "The D gcc package failed to apply"
1800 eerror "Please include this log file when posting a bug report:"
1801 eerror " ${T}/dgcc.log"
1802 die "failed to include the D language"
1803 fi
1804 popd > /dev/null
1805 fi
1806
1807 [[ -n ${PATCH_VER} ]] && \
1808 unpack gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2
1809
1810 [[ -n ${UCLIBC_VER} ]] && \
1811 unpack gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2
1812
1813 if want_pie ; then
1814 if [[ -n ${PIE_CORE} ]] ; then
1815 unpack ${PIE_CORE}
1816 else
1817 unpack gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2
1818 fi
1819 [[ -n ${SPECS_VER} ]] && \
1820 unpack gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2
1821 fi
1822
1823 use_if_iuse boundschecking && unpack "bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
1824
1825 popd > /dev/null
1826 }
1827
1828 do_gcc_HTB_patches() {
1829 use_if_iuse boundschecking || return 0
1830
1831 # modify the bounds checking patch with a regression patch
1832 epatch "${WORKDIR}/bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch"
1833 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, HTB-${HTB_GCC_VER}-${HTB_VER}"
1834 }
1835
1836 # do various updates to PIE logic
1837 do_gcc_PIE_patches() {
1838 want_pie || return 0
1839
1840 use vanilla && return 0
1841
1842 if tc_version_is_at_least 4.3.2 ; then
1843 guess_patch_type_in_dir "${WORKDIR}"/piepatch/
1844 EPATCH_MULTI_MSG="Applying pie patches ..." \
1845 epatch "${WORKDIR}"/piepatch/
1846 else
1847 guess_patch_type_in_dir "${WORKDIR}"/piepatch/upstream
1848
1849 # corrects startfile/endfile selection and shared/static/pie flag usage
1850 EPATCH_MULTI_MSG="Applying upstream pie patches ..." \
1851 epatch "${WORKDIR}"/piepatch/upstream
1852 # adds non-default pie support (rs6000)
1853 EPATCH_MULTI_MSG="Applying non-default pie patches ..." \
1854 epatch "${WORKDIR}"/piepatch/nondef
1855 # adds default pie support (rs6000 too) if DEFAULT_PIE[_SSP] is defined
1856 EPATCH_MULTI_MSG="Applying default pie patches ..." \
1857 epatch "${WORKDIR}"/piepatch/def
1858 fi
1859
1860 # we want to be able to control the pie patch logic via something other
1861 # than ALL_CFLAGS...
1862 sed -e '/^ALL_CFLAGS/iHARD_CFLAGS = ' \
1863 -e 's|^ALL_CFLAGS = |ALL_CFLAGS = $(HARD_CFLAGS) |' \
1864 -i "${S}"/gcc/Makefile.in
1865 # Need to add HARD_CFLAGS to ALL_CXXFLAGS on >= 4.7
1866 if tc_version_is_at_least 4.7 ; then
1867 sed -e '/^ALL_CXXFLAGS/iHARD_CFLAGS = ' \
1868 -e 's|^ALL_CXXFLAGS = |ALL_CXXFLAGS = $(HARD_CFLAGS) |' \
1869 -i "${S}"/gcc/Makefile.in
1870 fi
1871
1872 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, pie-${PIE_VER}"
1873 }
1874
1875 should_we_gcc_config() {
1876 # if the current config is invalid, we definitely want a new one
1877 # Note: due to bash quirkiness, the following must not be 1 line
1878 local curr_config
1879 curr_config=$(env -i ROOT="${ROOT}" gcc-config -c ${CTARGET} 2>&1) || return 0
1880
1881 # if the previously selected config has the same major.minor (branch) as
1882 # the version we are installing, then it will probably be uninstalled
1883 # for being in the same SLOT, make sure we run gcc-config.
1884 local curr_config_ver=$(env -i ROOT="${ROOT}" gcc-config -S ${curr_config} | awk '{print $2}')
1885
1886 local curr_branch_ver=$(get_version_component_range 1-2 ${curr_config_ver})
1887
1888 # If we're using multislot, just run gcc-config if we're installing
1889 # to the same profile as the current one.
1890 use multislot && return $([[ ${curr_config_ver} == ${GCC_CONFIG_VER} ]])
1891
1892 if [[ ${curr_branch_ver} == ${GCC_BRANCH_VER} ]] ; then
1893 return 0
1894 else
1895 # if we're installing a genuinely different compiler version,
1896 # we should probably tell the user -how- to switch to the new
1897 # gcc version, since we're not going to do it for him/her.
1898 # We don't want to switch from say gcc-3.3 to gcc-3.4 right in
1899 # the middle of an emerge operation (like an 'emerge -e world'
1900 # which could install multiple gcc versions).
1901 # Only warn if we're installing a pkg as we might be called from
1902 # the pkg_{pre,post}rm steps. #446830
1903 if [[ ${EBUILD_PHASE} == *"inst" ]] ; then
1904 einfo "The current gcc config appears valid, so it will not be"
1905 einfo "automatically switched for you. If you would like to"
1906 einfo "switch to the newly installed gcc version, do the"
1907 einfo "following:"
1908 echo
1909 einfo "gcc-config ${CTARGET}-${GCC_CONFIG_VER}"
1910 einfo "source /etc/profile"
1911 echo
1912 fi
1913 return 1
1914 fi
1915 }
1916
1917 do_gcc_config() {
1918 if ! should_we_gcc_config ; then
1919 env -i ROOT="${ROOT}" gcc-config --use-old --force
1920 return 0
1921 fi
1922
1923 local current_gcc_config="" current_specs="" use_specs=""
1924
1925 current_gcc_config=$(env -i ROOT="${ROOT}" gcc-config -c ${CTARGET} 2>/dev/null)
1926 if [[ -n ${current_gcc_config} ]] ; then
1927 # figure out which specs-specific config is active
1928 current_specs=$(gcc-config -S ${current_gcc_config} | awk '{print $3}')
1929 [[ -n ${current_specs} ]] && use_specs=-${current_specs}
1930 fi
1931 if [[ -n ${use_specs} ]] && \
1932 [[ ! -e ${ROOT}/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}${use_specs} ]]
1933 then
1934 ewarn "The currently selected specs-specific gcc config,"
1935 ewarn "${current_specs}, doesn't exist anymore. This is usually"
1936 ewarn "due to enabling/disabling hardened or switching to a version"
1937 ewarn "of gcc that doesnt create multiple specs files. The default"
1938 ewarn "config will be used, and the previous preference forgotten."
1939 use_specs=""
1940 fi
1941
1942 gcc-config ${CTARGET}-${GCC_CONFIG_VER}${use_specs}
1943 }
1944
1945 # This function allows us to gentoo-ize GCCs version number and bugzilla
1946 # URL without needing to use patches.
1947 gcc_version_patch() {
1948 # gcc-4.3+ has configure flags (whoo!)
1949 tc_version_is_at_least 4.3 && return 0
1950
1951 local version_string=${GCC_CONFIG_VER}
1952 [[ -n ${BRANCH_UPDATE} ]] && version_string+=" ${BRANCH_UPDATE}"
1953
1954 einfo "patching gcc version: ${version_string} (${BRANDING_GCC_PKGVERSION})"
1955
1956 local gcc_sed=( -e 's:gcc\.gnu\.org/bugs\.html:bugs\.gentoo\.org/:' )
1957 if grep -qs VERSUFFIX "${S}"/gcc/version.c ; then
1958 gcc_sed+=( -e "/VERSUFFIX \"\"/s:\"\":\" (${BRANDING_GCC_PKGVERSION})\":" )
1959 else
1960 version_string="${version_string} (${BRANDING_GCC_PKGVERSION})"
1961 gcc_sed+=( -e "/const char version_string\[\] = /s:= \".*\":= \"${version_string}\":" )
1962 fi
1963 sed -i "${gcc_sed[@]}" "${S}"/gcc/version.c || die
1964 }
1965
1966 # This is a historical wart. The original Gentoo/amd64 port used:
1967 # lib32 - 32bit binaries (x86)
1968 # lib64 - 64bit binaries (x86_64)
1969 # lib - "native" binaries (a symlink to lib64)
1970 # Most other distros use the logic (including mainline gcc):
1971 # lib - 32bit binaries (x86)
1972 # lib64 - 64bit binaries (x86_64)
1973 # Over time, Gentoo is migrating to the latter form.
1974 #
1975 # Unfortunately, due to distros picking the lib32 behavior, newer gcc
1976 # versions will dynamically detect whether to use lib or lib32 for its
1977 # 32bit multilib. So, to keep the automagic from getting things wrong
1978 # while people are transitioning from the old style to the new style,
1979 # we always set the MULTILIB_OSDIRNAMES var for relevant targets.
1980 setup_multilib_osdirnames() {
1981 is_multilib || return 0
1982
1983 local config
1984 local libdirs="../lib64 ../lib32"
1985
1986 # this only makes sense for some Linux targets
1987 case ${CTARGET} in
1988 x86_64*-linux*) config="i386" ;;
1989 powerpc64*-linux*) config="rs6000" ;;
1990 sparc64*-linux*) config="sparc" ;;
1991 s390x*-linux*) config="s390" ;;
1992 *) return 0 ;;
1993 esac
1994 config+="/t-linux64"
1995
1996 local sed_args=()
1997 if tc_version_is_at_least 4.6 ; then
1998 sed_args+=( -e 's:$[(]call if_multiarch[^)]*[)]::g' )
1999 fi
2000 if [[ ${SYMLINK_LIB} == "yes" ]] ; then
2001 einfo "updating multilib directories to be: ${libdirs}"
2002 if tc_version_is_at_least 4.6.4 || tc_version_is_at_least 4.7 ; then
2003 sed_args+=( -e '/^MULTILIB_OSDIRNAMES.*lib32/s:[$][(]if.*):../lib32:' )
2004 else
2005 sed_args+=( -e "/^MULTILIB_OSDIRNAMES/s:=.*:= ${libdirs}:" )
2006 fi
2007 else
2008 einfo "using upstream multilib; disabling lib32 autodetection"
2009 sed_args+=( -r -e 's:[$][(]if.*,(.*)[)]:\1:' )
2010 fi
2011 sed -i "${sed_args[@]}" "${S}"/gcc/config/${config} || die
2012 }
2013
2014 # make sure the libtool archives have libdir set to where they actually
2015 # -are-, and not where they -used- to be. also, any dependencies we have
2016 # on our own .la files need to be updated.
2017 fix_libtool_libdir_paths() {
2018 pushd "${D}" >/dev/null
2019
2020 pushd "./${1}" >/dev/null
2021 local dir="${PWD#${D%/}}"
2022 local allarchives=$(echo *.la)
2023 allarchives="\(${allarchives// /\\|}\)"
2024 popd >/dev/null
2025
2026 sed -i \
2027 -e "/^libdir=/s:=.*:='${dir}':" \
2028 ./${dir}/*.la
2029 sed -i \
2030 -e "/^dependency_libs=/s:/[^ ]*/${allarchives}:${LIBPATH}/\1:g" \
2031 $(find ./${PREFIX}/lib* -maxdepth 3 -name '*.la') \
2032 ./${dir}/*.la
2033
2034 popd >/dev/null
2035 }
2036
2037 is_multilib() {
2038 tc_version_is_at_least 3 || return 1
2039 use multilib
2040 }
2041
2042 is_cxx() {
2043 gcc-lang-supported 'c++' || return 1
2044 use cxx
2045 }
2046
2047 is_d() {
2048 gcc-lang-supported d || return 1
2049 use_if_iuse d
2050 }
2051
2052 is_f77() {
2053 gcc-lang-supported f77 || return 1
2054 use fortran
2055 }
2056
2057 is_f95() {
2058 gcc-lang-supported f95 || return 1
2059 use fortran
2060 }
2061
2062 is_fortran() {
2063 gcc-lang-supported fortran || return 1
2064 use fortran
2065 }
2066
2067 is_gcj() {
2068 gcc-lang-supported java || return 1
2069 use cxx && use_if_iuse gcj
2070 }
2071
2072 is_go() {
2073 gcc-lang-supported go || return 1
2074 use cxx && use_if_iuse go
2075 }
2076
2077 is_objc() {
2078 gcc-lang-supported objc || return 1
2079 use_if_iuse objc
2080 }
2081
2082 is_objcxx() {
2083 gcc-lang-supported 'obj-c++' || return 1
2084 use cxx && use_if_iuse objc++
2085 }
2086
2087 is_ada() {
2088 gcc-lang-supported ada || return 1
2089 use ada
2090 }
2091
2092 is_treelang() {
2093 use_if_iuse boundschecking && return 1 #260532
2094 is_crosscompile && return 1 #199924
2095 gcc-lang-supported treelang || return 1
2096 #use treelang
2097 return 0
2098 }

  ViewVC Help
Powered by ViewVC 1.1.20