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

Contents of /eclass/toolchain.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.594 - (show annotations) (download)
Mon Jun 17 02:23:45 2013 UTC (10 months ago) by vapier
Branch: MAIN
Changes since 1.593: +2 -1 lines
handle musl C library #473328 by Anthony Basile

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.593 2013/05/24 21:07:21 vapier Exp $
4 #
5 # Maintainer: Toolchain Ninjas <toolchain@gentoo.org>
6
7 #---->> eclass stuff <<----
8 HOMEPAGE="http://gcc.gnu.org/"
9 LICENSE="GPL-2 LGPL-2.1"
10 RESTRICT="strip" # cross-compilers need controlled stripping
11
12 inherit eutils versionator libtool toolchain-funcs flag-o-matic gnuconfig multilib fixheadtails pax-utils
13
14 if [[ ${PV} == *_pre9999* ]] ; then
15 EGIT_REPO_URI="git://gcc.gnu.org/git/gcc.git"
16 # naming style:
17 # gcc-4.7.1_pre9999 -> gcc-4_7-branch
18 # Note that the micro version is required or lots of stuff will break.
19 # To checkout master set gcc_LIVE_BRANCH="master" in the ebuild before
20 # inheriting this eclass.
21 EGIT_BRANCH="${PN}-${PV%.?_pre9999}-branch"
22 EGIT_BRANCH=${EGIT_BRANCH//./_}
23 inherit git-2
24 fi
25
26 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_test src_install pkg_postinst pkg_postrm
27 DESCRIPTION="The GNU Compiler Collection"
28
29 FEATURES=${FEATURES/multilib-strict/}
30 #----<< eclass stuff >>----
31
32
33 #---->> globals <<----
34 export CTARGET=${CTARGET:-${CHOST}}
35 if [[ ${CTARGET} = ${CHOST} ]] ; then
36 if [[ ${CATEGORY/cross-} != ${CATEGORY} ]] ; then
37 export CTARGET=${CATEGORY/cross-}
38 fi
39 fi
40 : ${TARGET_ABI:=${ABI}}
41 : ${TARGET_MULTILIB_ABIS:=${MULTILIB_ABIS}}
42 : ${TARGET_DEFAULT_ABI:=${DEFAULT_ABI}}
43
44 is_crosscompile() {
45 [[ ${CHOST} != ${CTARGET} ]]
46 }
47
48 tc_version_is_at_least() { version_is_at_least "$1" "${2:-${GCC_RELEASE_VER}}" ; }
49
50 GCC_PV=${TOOLCHAIN_GCC_PV:-${PV}}
51 GCC_PVR=${GCC_PV}
52 [[ ${PR} != "r0" ]] && GCC_PVR=${GCC_PVR}-${PR}
53 GCC_RELEASE_VER=$(get_version_component_range 1-3 ${GCC_PV})
54 GCC_BRANCH_VER=$(get_version_component_range 1-2 ${GCC_PV})
55 GCCMAJOR=$(get_version_component_range 1 ${GCC_PV})
56 GCCMINOR=$(get_version_component_range 2 ${GCC_PV})
57 GCCMICRO=$(get_version_component_range 3 ${GCC_PV})
58 [[ ${BRANCH_UPDATE-notset} == "notset" ]] && BRANCH_UPDATE=$(get_version_component_range 4 ${GCC_PV})
59
60 # According to gcc/c-cppbuiltin.c, GCC_CONFIG_VER MUST match this regex.
61 # ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)?
62 GCC_CONFIG_VER=${GCC_CONFIG_VER:-$(replace_version_separator 3 '-' ${GCC_PV})}
63
64 # Pre-release support
65 if [[ ${GCC_PV} != ${GCC_PV/_pre/-} ]] ; then
66 PRERELEASE=${GCC_PV/_pre/-}
67 fi
68 # make _alpha and _beta ebuilds automatically use a snapshot
69 if [[ ${GCC_PV} == *_alpha* ]] ; then
70 SNAPSHOT=${GCC_BRANCH_VER}-${GCC_PV##*_alpha}
71 elif [[ ${GCC_PV} == *_beta* ]] ; then
72 SNAPSHOT=${GCC_BRANCH_VER}-${GCC_PV##*_beta}
73 elif [[ ${GCC_PV} == *_rc* ]] ; then
74 SNAPSHOT=${GCC_PV%_rc*}-RC-${GCC_PV##*_rc}
75 fi
76 export GCC_FILESDIR=${GCC_FILESDIR:-${FILESDIR}}
77
78 PREFIX=${TOOLCHAIN_PREFIX:-/usr}
79
80 if tc_version_is_at_least 3.4.0 ; then
81 LIBPATH=${TOOLCHAIN_LIBPATH:-${PREFIX}/lib/gcc/${CTARGET}/${GCC_CONFIG_VER}}
82 else
83 LIBPATH=${TOOLCHAIN_LIBPATH:-${PREFIX}/lib/gcc-lib/${CTARGET}/${GCC_CONFIG_VER}}
84 fi
85 INCLUDEPATH=${TOOLCHAIN_INCLUDEPATH:-${LIBPATH}/include}
86 if is_crosscompile ; then
87 BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/${CHOST}/${CTARGET}/gcc-bin/${GCC_CONFIG_VER}}
88 else
89 BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/${CTARGET}/gcc-bin/${GCC_CONFIG_VER}}
90 fi
91 DATAPATH=${TOOLCHAIN_DATAPATH:-${PREFIX}/share/gcc-data/${CTARGET}/${GCC_CONFIG_VER}}
92 # Dont install in /usr/include/g++-v3/, but in gcc internal directory.
93 # We will handle /usr/include/g++-v3/ with gcc-config ...
94 STDCXX_INCDIR=${TOOLCHAIN_STDCXX_INCDIR:-${LIBPATH}/include/g++-v${GCC_BRANCH_VER/\.*/}}
95
96 #----<< globals >>----
97
98
99 #---->> SLOT+IUSE logic <<----
100 IUSE="multislot nls nptl regression-test vanilla"
101
102 if [[ ${PN} != "kgcc64" && ${PN} != gcc-* ]] ; then
103 IUSE+=" altivec cxx fortran"
104 [[ -n ${PIE_VER} ]] && IUSE+=" nopie"
105 [[ -n ${HTB_VER} ]] && IUSE+=" boundschecking"
106 [[ -n ${D_VER} ]] && IUSE+=" d"
107 [[ -n ${SPECS_VER} ]] && IUSE+=" nossp"
108
109 if tc_version_is_at_least 3 ; then
110 IUSE+=" doc gcj gtk hardened multilib objc"
111
112 tc_version_is_at_least "4.0" && IUSE+=" objc-gc mudflap"
113 tc_version_is_at_least "4.1" && IUSE+=" libssp objc++"
114 tc_version_is_at_least "4.2" && IUSE+=" openmp"
115 tc_version_is_at_least "4.3" && IUSE+=" fixed-point"
116 tc_version_is_at_least "4.6" && IUSE+=" graphite"
117 tc_version_is_at_least "4.6" && IUSE+=" lto"
118 tc_version_is_at_least "4.7" && IUSE+=" go"
119 fi
120 fi
121
122 # Support upgrade paths here or people get pissed
123 if use multislot ; then
124 SLOT="${GCC_CONFIG_VER}"
125 else
126 SLOT="${GCC_BRANCH_VER}"
127 fi
128 #----<< SLOT+IUSE logic >>----
129
130 #---->> DEPEND <<----
131
132 RDEPEND="sys-libs/zlib
133 nls? ( sys-devel/gettext )"
134 if tc_version_is_at_least 3 ; then
135 RDEPEND+=" virtual/libiconv"
136 fi
137 if tc_version_is_at_least 4 ; then
138 GMP_MPFR_DEPS=">=dev-libs/gmp-4.3.2 >=dev-libs/mpfr-2.4.2"
139 if tc_version_is_at_least 4.3 ; then
140 RDEPEND+=" ${GMP_MPFR_DEPS}"
141 elif in_iuse fortran ; then
142 RDEPEND+=" fortran? ( ${GMP_MPFR_DEPS} )"
143 fi
144 if tc_version_is_at_least 4.5 ; then
145 RDEPEND+=" >=dev-libs/mpc-0.8.1"
146 fi
147 fi
148 if in_iuse graphite ; then
149 if tc_version_is_at_least 4.8 ; then
150 RDEPEND+="
151 graphite? (
152 >=dev-libs/cloog-0.18.0
153 >=dev-libs/isl-0.11.1
154 )"
155 else
156 RDEPEND+="
157 graphite? (
158 >=dev-libs/cloog-ppl-0.15.10
159 >=dev-libs/ppl-0.11
160 )"
161 fi
162 fi
163
164 DEPEND="${RDEPEND}
165 >=sys-devel/bison-1.875
166 >=sys-devel/flex-2.5.4
167 regression-test? (
168 >=dev-util/dejagnu-1.4.4
169 >=sys-devel/autogen-5.5.4
170 )"
171 if in_iuse gcj ; then
172 GCJ_GTK_DEPS="
173 x11-libs/libXt
174 x11-libs/libX11
175 x11-libs/libXtst
176 x11-proto/xproto
177 x11-proto/xextproto
178 =x11-libs/gtk+-2*
179 virtual/pkgconfig
180 amd64? ( multilib? (
181 app-emulation/emul-linux-x86-gtklibs
182 app-emulation/emul-linux-x86-xlibs
183 ) )
184 "
185 tc_version_is_at_least 3.4 && GCJ_GTK_DEPS+=" x11-libs/pango"
186 GCJ_DEPS=">=media-libs/libart_lgpl-2.1"
187 tc_version_is_at_least 4.2 && GCJ_DEPS+=" app-arch/zip app-arch/unzip"
188 DEPEND+=" gcj? ( gtk? ( ${GCJ_GTK_DEPS} ) ${GCJ_DEPS} )"
189 fi
190
191 PDEPEND=">=sys-devel/gcc-config-1.7"
192
193 #----<< DEPEND >>----
194
195 #---->> S + SRC_URI essentials <<----
196
197 # Set the source directory depending on whether we're using
198 # a prerelease, snapshot, or release tarball.
199 S=$(
200 if [[ -n ${PRERELEASE} ]] ; then
201 echo ${WORKDIR}/gcc-${PRERELEASE}
202 elif [[ -n ${SNAPSHOT} ]] ; then
203 echo ${WORKDIR}/gcc-${SNAPSHOT}
204 else
205 echo ${WORKDIR}/gcc-${GCC_RELEASE_VER}
206 fi
207 )
208
209 # This function handles the basics of setting the SRC_URI for a gcc ebuild.
210 # To use, set SRC_URI with:
211 #
212 # SRC_URI="$(get_gcc_src_uri)"
213 #
214 # Other than the variables normally set by portage, this function's behavior
215 # can be altered by setting the following:
216 #
217 # SNAPSHOT
218 # If set, this variable signals that we should be using a snapshot of
219 # gcc. It is expected to be in the format "YYYY-MM-DD". Note that if
220 # the ebuild has a _pre suffix, this variable is ignored and the
221 # prerelease tarball is used instead.
222 #
223 # BRANCH_UPDATE
224 # If set, this variable signals that we should be using the main
225 # release tarball (determined by ebuild version) and applying a
226 # CVS branch update patch against it. The location of this branch
227 # update patch is assumed to be in ${GENTOO_TOOLCHAIN_BASE_URI}.
228 # Just like with SNAPSHOT, this variable is ignored if the ebuild
229 # has a _pre suffix.
230 #
231 # PATCH_VER
232 # PATCH_GCC_VER
233 # This should be set to the version of the gentoo patch tarball.
234 # The resulting filename of this tarball will be:
235 # gcc-${PATCH_GCC_VER:-${GCC_RELEASE_VER}}-patches-${PATCH_VER}.tar.bz2
236 #
237 # PIE_VER
238 # PIE_GCC_VER
239 # These variables control patching in various updates for the logic
240 # controlling Position Independant Executables. PIE_VER is expected
241 # to be the version of this patch, and PIE_GCC_VER the gcc version of
242 # the patch:
243 # An example:
244 # PIE_VER="8.7.6.5"
245 # PIE_GCC_VER="3.4.0"
246 # The resulting filename of this tarball will be:
247 # gcc-${PIE_GCC_VER:-${GCC_RELEASE_VER}}-piepatches-v${PIE_VER}.tar.bz2
248 #
249 # SPECS_VER
250 # SPECS_GCC_VER
251 # This is for the minispecs files included in the hardened gcc-4.x
252 # The specs files for hardenedno*, vanilla and for building the "specs" file.
253 # SPECS_VER is expected to be the version of this patch, SPECS_GCC_VER
254 # the gcc version of the patch.
255 # An example:
256 # SPECS_VER="8.7.6.5"
257 # SPECS_GCC_VER="3.4.0"
258 # The resulting filename of this tarball will be:
259 # gcc-${SPECS_GCC_VER:-${GCC_RELEASE_VER}}-specs-${SPECS_VER}.tar.bz2
260 #
261 # HTB_VER
262 # HTB_GCC_VER
263 # These variables control whether or not an ebuild supports Herman
264 # ten Brugge's bounds-checking patches. If you want to use a patch
265 # for an older gcc version with a new gcc, make sure you set
266 # HTB_GCC_VER to that version of gcc.
267 #
268 gentoo_urls() {
269 local devspace="HTTP~vapier/dist/URI HTTP~dirtyepic/dist/URI
270 HTTP~halcy0n/patches/URI HTTP~zorry/patches/gcc/URI"
271 devspace=${devspace//HTTP/http:\/\/dev.gentoo.org\/}
272 echo mirror://gentoo/$1 ${devspace//URI/$1}
273 }
274
275 get_gcc_src_uri() {
276 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
277 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
278 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
279 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
280 export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}}
281
282 # Set where to download gcc itself depending on whether we're using a
283 # prerelease, snapshot, or release tarball.
284 if [[ -n ${PRERELEASE} ]] ; then
285 GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/prerelease-${PRERELEASE}/gcc-${PRERELEASE}.tar.bz2"
286 elif [[ -n ${SNAPSHOT} ]] ; then
287 GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.bz2"
288 elif [[ ${PV} != *9999* ]] ; then
289 GCC_SRC_URI="mirror://gnu/gcc/gcc-${GCC_PV}/gcc-${GCC_RELEASE_VER}.tar.bz2"
290 # we want all branch updates to be against the main release
291 [[ -n ${BRANCH_UPDATE} ]] && \
292 GCC_SRC_URI+=" $(gentoo_urls gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2)"
293 fi
294
295 [[ -n ${UCLIBC_VER} ]] && GCC_SRC_URI+=" $(gentoo_urls gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2)"
296 [[ -n ${PATCH_VER} ]] && GCC_SRC_URI+=" $(gentoo_urls gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2)"
297
298 # strawberry pie, Cappuccino and a Gauloises (it's a good thing)
299 [[ -n ${PIE_VER} ]] && \
300 PIE_CORE=${PIE_CORE:-gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2} && \
301 GCC_SRC_URI+=" $(gentoo_urls ${PIE_CORE})"
302
303 # gcc minispec for the hardened gcc 4 compiler
304 [[ -n ${SPECS_VER} ]] && GCC_SRC_URI+=" $(gentoo_urls gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2)"
305
306 # gcc bounds checking patch
307 if [[ -n ${HTB_VER} ]] ; then
308 local HTBFILE="bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
309 GCC_SRC_URI+="
310 boundschecking? (
311 mirror://sourceforge/boundschecking/${HTBFILE}
312 $(gentoo_urls ${HTBFILE})
313 )"
314 fi
315
316 [[ -n ${D_VER} ]] && GCC_SRC_URI+=" d? ( mirror://sourceforge/dgcc/gdc-${D_VER}-src.tar.bz2 )"
317
318 # >= gcc-4.3 uses ecj.jar and we only add gcj as a use flag under certain
319 # conditions
320 if [[ ${PN} != "kgcc64" && ${PN} != gcc-* ]] ; then
321 if tc_version_is_at_least "4.5" ; then
322 GCC_SRC_URI+=" gcj? ( ftp://sourceware.org/pub/java/ecj-4.5.jar )"
323 elif tc_version_is_at_least "4.3" ; then
324 GCC_SRC_URI+=" gcj? ( ftp://sourceware.org/pub/java/ecj-4.3.jar )"
325 fi
326 fi
327
328 echo "${GCC_SRC_URI}"
329 }
330 SRC_URI=$(get_gcc_src_uri)
331 #---->> S + SRC_URI essentials >>----
332
333
334 #---->> support checks <<----
335
336 # Grab a variable from the build system (taken from linux-info.eclass)
337 get_make_var() {
338 local var=$1 makefile=${2:-${WORKDIR}/build/Makefile}
339 echo -e "e:\\n\\t@echo \$(${var})\\ninclude ${makefile}" | \
340 r=${makefile%/*} emake --no-print-directory -s -f - 2>/dev/null
341 }
342 XGCC() { get_make_var GCC_FOR_TARGET ; }
343
344 # The gentoo piessp patches allow for 3 configurations:
345 # 1) PIE+SSP by default
346 # 2) PIE by default
347 # 3) SSP by default
348 hardened_gcc_works() {
349 if [[ $1 == "pie" ]] ; then
350 # $gcc_cv_ld_pie is unreliable as it simply take the output of
351 # `ld --help | grep -- -pie`, that reports the option in all cases, also if
352 # the loader doesn't actually load the resulting executables.
353 # To avoid breakage, blacklist FreeBSD here at least
354 [[ ${CTARGET} == *-freebsd* ]] && return 1
355
356 want_pie || return 1
357 use_if_iuse nopie && return 1
358 hardened_gcc_is_stable pie
359 return $?
360 elif [[ $1 == "ssp" ]] ; then
361 [[ -n ${SPECS_VER} ]] || return 1
362 use_if_iuse nossp && return 1
363 hardened_gcc_is_stable ssp
364 return $?
365 else
366 # laziness ;)
367 hardened_gcc_works pie || return 1
368 hardened_gcc_works ssp || return 1
369 return 0
370 fi
371 }
372
373 hardened_gcc_is_stable() {
374 local tocheck
375 if [[ $1 == "pie" ]] ; then
376 if [[ ${CTARGET} == *-uclibc* ]] ; then
377 tocheck=${PIE_UCLIBC_STABLE}
378 else
379 tocheck=${PIE_GLIBC_STABLE}
380 fi
381 elif [[ $1 == "ssp" ]] ; then
382 if [[ ${CTARGET} == *-uclibc* ]] ; then
383 tocheck=${SSP_UCLIBC_STABLE}
384 else
385 tocheck=${SSP_STABLE}
386 fi
387 else
388 die "hardened_gcc_stable needs to be called with pie or ssp"
389 fi
390
391 has $(tc-arch) ${tocheck} && return 0
392 return 1
393 }
394
395 want_pie() {
396 ! use hardened && [[ -n ${PIE_VER} ]] && use nopie && return 1
397 [[ -n ${PIE_VER} ]] && [[ -n ${SPECS_VER} ]] && return 0
398 tc_version_is_at_least 4.3.2 && return 1
399 [[ -z ${PIE_VER} ]] && return 1
400 use !nopie && return 0
401 return 1
402 }
403
404 want_minispecs() {
405 if tc_version_is_at_least 4.3.2 && use hardened ; then
406 if ! want_pie ; then
407 ewarn "PIE_VER or SPECS_VER is not defiend in the GCC ebuild."
408 elif use vanilla ; then
409 ewarn "You will not get hardened features if you have the vanilla USE-flag."
410 elif use nopie && use nossp ; then
411 ewarn "You will not get hardened features if you have the nopie and nossp USE-flag."
412 elif ! hardened_gcc_works ; then
413 ewarn "Your $(tc-arch) arch is not supported."
414 else
415 return 0
416 fi
417 ewarn "Hope you know what you are doing. Hardened will not work."
418 return 0
419 fi
420 return 1
421 }
422
423 # This is to make sure we don't accidentally try to enable support for a
424 # language that doesnt exist. GCC 3.4 supports f77, while 4.0 supports f95, etc.
425 #
426 # Also add a hook so special ebuilds (kgcc64) can control which languages
427 # exactly get enabled
428 gcc-lang-supported() {
429 grep ^language=\"${1}\" "${S}"/gcc/*/config-lang.in > /dev/null || return 1
430 [[ -z ${TOOLCHAIN_ALLOWED_LANGS} ]] && return 0
431 has $1 ${TOOLCHAIN_ALLOWED_LANGS}
432 }
433
434 #----<< support checks >>----
435
436 #---->> specs + env.d logic <<----
437
438 # configure to build with the hardened GCC specs as the default
439 make_gcc_hard() {
440 # defaults to enable for all hardened toolchains
441 local gcc_hard_flags="-DEFAULT_RELRO -DEFAULT_BIND_NOW"
442
443 if hardened_gcc_works ; then
444 einfo "Updating gcc to use automatic PIE + SSP building ..."
445 gcc_hard_flags+=" -DEFAULT_PIE_SSP"
446 elif hardened_gcc_works pie ; then
447 einfo "Updating gcc to use automatic PIE building ..."
448 ewarn "SSP has not been enabled by default"
449 gcc_hard_flags+=" -DEFAULT_PIE"
450 elif hardened_gcc_works ssp ; then
451 einfo "Updating gcc to use automatic SSP building ..."
452 ewarn "PIE has not been enabled by default"
453 gcc_hard_flags+=" -DEFAULT_SSP"
454 else
455 # do nothing if hardened isnt supported, but dont die either
456 ewarn "hardened is not supported for this arch in this gcc version"
457 ebeep
458 return 0
459 fi
460
461 sed -i \
462 -e "/^HARD_CFLAGS = /s|=|= ${gcc_hard_flags} |" \
463 "${S}"/gcc/Makefile.in || die
464
465 # rebrand to make bug reports easier
466 BRANDING_GCC_PKGVERSION=${BRANDING_GCC_PKGVERSION/Gentoo/Gentoo Hardened}
467 }
468
469 create_gcc_env_entry() {
470 dodir /etc/env.d/gcc
471 local gcc_envd_base="/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}"
472
473 local gcc_specs_file
474 local gcc_envd_file="${D}${gcc_envd_base}"
475 if [[ -z $1 ]] ; then
476 # I'm leaving the following commented out to remind me that it
477 # was an insanely -bad- idea. Stuff broke. GCC_SPECS isnt unset
478 # on chroot or in non-toolchain.eclass gcc ebuilds!
479 #gcc_specs_file="${LIBPATH}/specs"
480 gcc_specs_file=""
481 else
482 gcc_envd_file+="-$1"
483 gcc_specs_file="${LIBPATH}/$1.specs"
484 fi
485
486 # We want to list the default ABI's LIBPATH first so libtool
487 # searches that directory first. This is a temporary
488 # workaround for libtool being stupid and using .la's from
489 # conflicting ABIs by using the first one in the search path
490 local ldpaths mosdirs
491 if tc_version_is_at_least 3.2 ; then
492 local mdir mosdir abi ldpath
493 for abi in $(get_all_abis TARGET) ; do
494 mdir=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory)
495 ldpath=${LIBPATH}
496 [[ ${mdir} != "." ]] && ldpath+="/${mdir}"
497 ldpaths="${ldpath}${ldpaths:+:${ldpaths}}"
498
499 mosdir=$($(XGCC) $(get_abi_CFLAGS ${abi}) -print-multi-os-directory)
500 mosdirs="${mosdir}${mosdirs:+:${mosdirs}}"
501 done
502 else
503 # Older gcc's didn't do multilib, so logic is simple.
504 ldpaths=${LIBPATH}
505 fi
506
507 cat <<-EOF > ${gcc_envd_file}
508 PATH="${BINPATH}"
509 ROOTPATH="${BINPATH}"
510 GCC_PATH="${BINPATH}"
511 LDPATH="${ldpaths}"
512 MANPATH="${DATAPATH}/man"
513 INFOPATH="${DATAPATH}/info"
514 STDCXX_INCDIR="${STDCXX_INCDIR##*/}"
515 CTARGET="${CTARGET}"
516 GCC_SPECS="${gcc_specs_file}"
517 MULTIOSDIRS="${mosdirs}"
518 EOF
519 }
520 setup_minispecs_gcc_build_specs() {
521 # Setup the "build.specs" file for gcc 4.3 to use when building.
522 if hardened_gcc_works pie ; then
523 cat "${WORKDIR}"/specs/pie.specs >> "${WORKDIR}"/build.specs
524 fi
525 if hardened_gcc_works ssp ; then
526 for s in ssp sspall ; do
527 cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs
528 done
529 fi
530 for s in nostrict znow ; do
531 cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs
532 done
533 export GCC_SPECS="${WORKDIR}"/build.specs
534 }
535 copy_minispecs_gcc_specs() {
536 # setup the hardenedno* specs files and the vanilla specs file.
537 if hardened_gcc_works ; then
538 create_gcc_env_entry hardenednopiessp
539 fi
540 if hardened_gcc_works pie ; then
541 create_gcc_env_entry hardenednopie
542 fi
543 if hardened_gcc_works ssp ; then
544 create_gcc_env_entry hardenednossp
545 fi
546 create_gcc_env_entry vanilla
547 insinto ${LIBPATH}
548 doins "${WORKDIR}"/specs/*.specs || die "failed to install specs"
549 # Build system specs file which, if it exists, must be a complete set of
550 # specs as it completely and unconditionally overrides the builtin specs.
551 # For gcc 4.3
552 if ! tc_version_is_at_least 4.4 ; then
553 $(XGCC) -dumpspecs > "${WORKDIR}"/specs/specs
554 cat "${WORKDIR}"/build.specs >> "${WORKDIR}"/specs/specs
555 doins "${WORKDIR}"/specs/specs || die "failed to install the specs file"
556 fi
557 }
558
559 #----<< specs + env.d logic >>----
560
561 #---->> pkg_* <<----
562 toolchain_pkg_setup() {
563 if [[ -n ${PRERELEASE}${SNAPSHOT} || ${PV} == *9999* ]] &&
564 [[ -z ${I_PROMISE_TO_SUPPLY_PATCHES_WITH_BUGS} ]]
565 then
566 die "Please \`export I_PROMISE_TO_SUPPLY_PATCHES_WITH_BUGS=1\` or define it in your make.conf if you want to use this version." \
567 "This is to try and cut down on people filing bugs for a compiler we do not currently support."
568 fi
569
570 # we dont want to use the installed compiler's specs to build gcc!
571 unset GCC_SPECS
572
573 if ! use_if_iuse cxx ; then
574 use_if_iuse go && ewarn 'Go requires a C++ compiler, disabled due to USE="-cxx"'
575 use_if_iuse objc++ && ewarn 'Obj-C++ requires a C++ compiler, disabled due to USE="-cxx"'
576 use_if_iuse gcj && ewarn 'GCJ requires a C++ compiler, disabled due to USE="-cxx"'
577 fi
578
579 want_minispecs
580
581 unset LANGUAGES #265283
582 }
583
584 toolchain_pkg_postinst() {
585 do_gcc_config
586
587 if ! is_crosscompile ; then
588 echo
589 ewarn "If you have issues with packages unable to locate libstdc++.la,"
590 ewarn "then try running 'fix_libtool_files.sh' on the old gcc versions."
591 echo
592 ewarn "You might want to review the GCC upgrade guide when moving between"
593 ewarn "major versions (like 4.2 to 4.3):"
594 ewarn "http://www.gentoo.org/doc/en/gcc-upgrading.xml"
595 echo
596 fi
597
598 if ! is_crosscompile ; then
599 # hack to prevent collisions between SLOTs
600
601 # Clean up old paths
602 rm -f "${ROOT}"/*/rcscripts/awk/fixlafiles.awk "${ROOT}"/sbin/fix_libtool_files.sh
603 rmdir "${ROOT}"/*/rcscripts{/awk,} 2>/dev/null
604
605 mkdir -p "${ROOT}"/usr/{share/gcc-data,sbin,bin}
606 cp "${ROOT}/${DATAPATH}"/fixlafiles.awk "${ROOT}"/usr/share/gcc-data/ || die
607 cp "${ROOT}/${DATAPATH}"/fix_libtool_files.sh "${ROOT}"/usr/sbin/ || die
608
609 # Since these aren't critical files and portage sucks with
610 # handling of binpkgs, don't require these to be found
611 cp "${ROOT}/${DATAPATH}"/c{89,99} "${ROOT}"/usr/bin/ 2>/dev/null
612 fi
613
614 if use regression-test ; then
615 elog "Testsuite results have been installed into /usr/share/doc/${PF}/testsuite"
616 echo
617 fi
618 }
619
620 toolchain_pkg_postrm() {
621 # to make our lives easier (and saner), we do the fix_libtool stuff here.
622 # rather than checking SLOT's and trying in upgrade paths, we just see if
623 # the common libstdc++.la exists in the ${LIBPATH} of the gcc that we are
624 # unmerging. if it does, that means this was a simple re-emerge.
625
626 # clean up the cruft left behind by cross-compilers
627 if is_crosscompile ; then
628 if [[ -z $(ls "${ROOT}"/etc/env.d/gcc/${CTARGET}* 2>/dev/null) ]] ; then
629 rm -f "${ROOT}"/etc/env.d/gcc/config-${CTARGET}
630 rm -f "${ROOT}"/etc/env.d/??gcc-${CTARGET}
631 rm -f "${ROOT}"/usr/bin/${CTARGET}-{gcc,{g,c}++}{,32,64}
632 fi
633 return 0
634 fi
635
636 # ROOT isnt handled by the script
637 [[ ${ROOT} != "/" ]] && return 0
638
639 if [[ ! -e ${LIBPATH}/libstdc++.so ]] ; then
640 # make sure the profile is sane during same-slot upgrade #289403
641 do_gcc_config
642
643 einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}'"
644 /usr/sbin/fix_libtool_files.sh ${GCC_RELEASE_VER}
645 if [[ -n ${BRANCH_UPDATE} ]] ; then
646 einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE}'"
647 /usr/sbin/fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE}
648 fi
649 fi
650
651 return 0
652 }
653
654 #---->> pkg_* <<----
655
656 #---->> src_* <<----
657
658 guess_patch_type_in_dir() {
659 [[ -n $(ls "$1"/*.bz2 2>/dev/null) ]] \
660 && EPATCH_SUFFIX="patch.bz2" \
661 || EPATCH_SUFFIX="patch"
662 }
663 do_gcc_rename_java_bins() {
664 # bug #139918 - conflict between gcc and java-config-2 for ownership of
665 # /usr/bin/rmi{c,registry}. Done with mv & sed rather than a patch
666 # because patches would be large (thanks to the rename of man files),
667 # and it's clear from the sed invocations that all that changes is the
668 # rmi{c,registry} names to grmi{c,registry} names.
669 # Kevin F. Quinn 2006-07-12
670 einfo "Renaming jdk executables rmic and rmiregistry to grmic and grmiregistry."
671 # 1) Move the man files if present (missing prior to gcc-3.4)
672 for manfile in rmic rmiregistry; do
673 [[ -f ${S}/gcc/doc/${manfile}.1 ]] || continue
674 mv "${S}"/gcc/doc/${manfile}.1 "${S}"/gcc/doc/g${manfile}.1
675 done
676 # 2) Fixup references in the docs if present (mission prior to gcc-3.4)
677 for jfile in gcc/doc/gcj.info gcc/doc/grmic.1 gcc/doc/grmiregistry.1 gcc/java/gcj.texi; do
678 [[ -f ${S}/${jfile} ]] || continue
679 sed -i -e 's:rmiregistry:grmiregistry:g' "${S}"/${jfile} ||
680 die "Failed to fixup file ${jfile} for rename to grmiregistry"
681 sed -i -e 's:rmic:grmic:g' "${S}"/${jfile} ||
682 die "Failed to fixup file ${jfile} for rename to grmic"
683 done
684 # 3) Fixup Makefiles to build the changed executable names
685 # These are present in all 3.x versions, and are the important bit
686 # to get gcc to build with the new names.
687 for jfile in libjava/Makefile.am libjava/Makefile.in gcc/java/Make-lang.in; do
688 sed -i -e 's:rmiregistry:grmiregistry:g' "${S}"/${jfile} ||
689 die "Failed to fixup file ${jfile} for rename to grmiregistry"
690 # Careful with rmic on these files; it's also the name of a directory
691 # which should be left unchanged. Replace occurrences of 'rmic$',
692 # 'rmic_' and 'rmic '.
693 sed -i -e 's:rmic\([$_ ]\):grmic\1:g' "${S}"/${jfile} ||
694 die "Failed to fixup file ${jfile} for rename to grmic"
695 done
696 }
697 toolchain_src_unpack() {
698 [[ -z ${UCLIBC_VER} ]] && [[ ${CTARGET} == *-uclibc* ]] && 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
753 gcc_version_patch
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 elif tc_version_is_at_least "4.3" ; then
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 ; 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 cd "${S}"
797 elibtoolize --portage --shallow --no-uclibc
798
799 gnuconfig_update
800
801 # update configure files
802 local f
803 einfo "Fixing misc issues in configure files"
804 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.0" ; 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 tc_version_is_at_least 3.4 || confgcc+=( --disable-libunwind-exceptions )
1229
1230 # if the target can do biarch (-m32/-m64), enable it. overhead should
1231 # be small, and should simplify building of 64bit kernels in a 32bit
1232 # userland by not needing sys-devel/kgcc64. #349405
1233 case $(tc-arch) in
1234 ppc|ppc64) tc_version_is_at_least 3.4 && confgcc+=( --enable-targets=all ) ;;
1235 sparc) tc_version_is_at_least 4.4 && confgcc+=( --enable-targets=all ) ;;
1236 amd64|x86) tc_version_is_at_least 4.3 && confgcc+=( --enable-targets=all ) ;;
1237 esac
1238
1239 tc_version_is_at_least 4.3 && confgcc+=(
1240 --with-bugurl=http://bugs.gentoo.org/
1241 --with-pkgversion="${BRANDING_GCC_PKGVERSION}"
1242 )
1243 confgcc+=(
1244 "$@"
1245 ${EXTRA_ECONF}
1246 )
1247
1248 # Disable gcc info regeneration -- it ships with generated info pages
1249 # already. Our custom version/urls/etc... trigger it. #464008
1250 export gcc_cv_prog_makeinfo_modern=no
1251
1252 # Do not let the X detection get in our way. We know things can be found
1253 # via system paths, so no need to hardcode things that'll break multilib.
1254 # Older gcc versions will detect ac_x_libraries=/usr/lib64 which ends up
1255 # killing the 32bit builds which want /usr/lib.
1256 export ac_cv_have_x='have_x=yes ac_x_includes= ac_x_libraries='
1257
1258 # Nothing wrong with a good dose of verbosity
1259 echo
1260 einfo "PREFIX: ${PREFIX}"
1261 einfo "BINPATH: ${BINPATH}"
1262 einfo "LIBPATH: ${LIBPATH}"
1263 einfo "DATAPATH: ${DATAPATH}"
1264 einfo "STDCXX_INCDIR: ${STDCXX_INCDIR}"
1265 echo
1266 einfo "Configuring GCC with: ${confgcc[@]//--/\n\t--}"
1267 echo
1268
1269 # Build in a separate build tree
1270 mkdir -p "${WORKDIR}"/build
1271 pushd "${WORKDIR}"/build > /dev/null
1272
1273 # and now to do the actual configuration
1274 addwrite /dev/zero
1275 echo "${S}"/configure "${confgcc[@]}"
1276 "${S}"/configure "${confgcc[@]}" || die "failed to run configure"
1277
1278 # return to whatever directory we were in before
1279 popd > /dev/null
1280 }
1281
1282 has toolchain_death_notice ${EBUILD_DEATH_HOOKS} || EBUILD_DEATH_HOOKS+=" toolchain_death_notice"
1283 toolchain_death_notice() {
1284 pushd "${WORKDIR}"/build >/dev/null
1285 tar jcf gcc-build-logs.tar.bz2 $(find -name config.log)
1286 eerror
1287 eerror "Please include ${PWD}/gcc-build-logs.tar.bz2 in your bug report"
1288 eerror
1289 popd >/dev/null
1290 }
1291
1292 # This function accepts one optional argument, the make target to be used.
1293 # If ommitted, gcc_do_make will try to guess whether it should use all,
1294 # profiledbootstrap, or bootstrap-lean depending on CTARGET and arch. An
1295 # example of how to use this function:
1296 #
1297 # gcc_do_make all-target-libstdc++-v3
1298 #
1299 # In addition to the target to be used, the following variables alter the
1300 # behavior of this function:
1301 #
1302 # LDFLAGS
1303 # Flags to pass to ld
1304 #
1305 # STAGE1_CFLAGS
1306 # CFLAGS to use during stage1 of a gcc bootstrap
1307 #
1308 # BOOT_CFLAGS
1309 # CFLAGS to use during stages 2+3 of a gcc bootstrap.
1310 #
1311 # Travis Tilley <lv@gentoo.org> (04 Sep 2004)
1312 #
1313 gcc_do_make() {
1314 # Set make target to $1 if passed
1315 [[ -n $1 ]] && GCC_MAKE_TARGET=$1
1316 # default target
1317 if is_crosscompile || tc-is-cross-compiler ; then
1318 # 3 stage bootstrapping doesnt quite work when you cant run the
1319 # resulting binaries natively ^^;
1320 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-all}
1321 else
1322 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-bootstrap-lean}
1323 fi
1324
1325 # the gcc docs state that parallel make isnt supported for the
1326 # profiledbootstrap target, as collisions in profile collecting may occur.
1327 # boundschecking also seems to introduce parallel build issues.
1328 if [[ ${GCC_MAKE_TARGET} == "profiledbootstrap" ]] ||
1329 use_if_iuse boundschecking
1330 then
1331 export MAKEOPTS="${MAKEOPTS} -j1"
1332 fi
1333
1334 if [[ ${GCC_MAKE_TARGET} == "all" ]] ; then
1335 STAGE1_CFLAGS=${STAGE1_CFLAGS-"${CFLAGS}"}
1336 elif [[ $(gcc-version) == "3.4" && ${GCC_BRANCH_VER} == "3.4" ]] && gcc-specs-ssp ; then
1337 # See bug #79852
1338 STAGE1_CFLAGS=${STAGE1_CFLAGS-"-O2"}
1339 fi
1340
1341 if is_crosscompile; then
1342 # In 3.4, BOOT_CFLAGS is never used on a crosscompile...
1343 # but I'll leave this in anyways as someone might have had
1344 # some reason for putting it in here... --eradicator
1345 BOOT_CFLAGS=${BOOT_CFLAGS-"-O2"}
1346 else
1347 # we only want to use the system's CFLAGS if not building a
1348 # cross-compiler.
1349 BOOT_CFLAGS=${BOOT_CFLAGS-"$(get_abi_CFLAGS ${TARGET_DEFAULT_ABI}) ${CFLAGS}"}
1350 fi
1351
1352 pushd "${WORKDIR}"/build >/dev/null
1353
1354 emake \
1355 LDFLAGS="${LDFLAGS}" \
1356 STAGE1_CFLAGS="${STAGE1_CFLAGS}" \
1357 LIBPATH="${LIBPATH}" \
1358 BOOT_CFLAGS="${BOOT_CFLAGS}" \
1359 ${GCC_MAKE_TARGET} \
1360 || die "emake failed with ${GCC_MAKE_TARGET}"
1361
1362 if ! is_crosscompile && use cxx && use_if_iuse doc ; then
1363 if type -p doxygen > /dev/null ; then
1364 if tc_version_is_at_least 4.3 ; then
1365 cd "${CTARGET}"/libstdc++-v3/doc
1366 emake doc-man-doxygen || ewarn "failed to make docs"
1367 elif tc_version_is_at_least 3.0 ; then
1368 cd "${CTARGET}"/libstdc++-v3
1369 emake doxygen-man || ewarn "failed to make docs"
1370 fi
1371 else
1372 ewarn "Skipping libstdc++ manpage generation since you don't have doxygen installed"
1373 fi
1374 fi
1375
1376 popd >/dev/null
1377 }
1378
1379 # This is mostly a stub function to be overwritten in an ebuild
1380 gcc_do_filter_flags() {
1381
1382 strip-flags
1383
1384 # In general gcc does not like optimization, and add -O2 where
1385 # it is safe. This is especially true for gcc 3.3 + 3.4
1386 replace-flags -O? -O2
1387
1388 # ... sure, why not?
1389 strip-unsupported-flags
1390
1391 # dont want to funk ourselves
1392 filter-flags '-mabi*' -m31 -m32 -m64
1393
1394 case ${GCC_BRANCH_VER} in
1395 3.2|3.3)
1396 replace-cpu-flags k8 athlon64 opteron i686 x86-64
1397 replace-cpu-flags pentium-m pentium3m pentium3
1398 case $(tc-arch) in
1399 amd64|x86) filter-flags '-mtune=*' ;;
1400 # in gcc 3.3 there is a bug on ppc64 where if -mcpu is used,
1401 # the compiler wrongly assumes a 32bit target
1402 ppc64) filter-flags "-mcpu=*";;
1403 esac
1404 case $(tc-arch) in
1405 amd64) replace-cpu-flags core2 nocona;;
1406 x86) replace-cpu-flags core2 prescott;;
1407 esac
1408
1409 replace-cpu-flags G3 750
1410 replace-cpu-flags G4 7400
1411 replace-cpu-flags G5 7400
1412
1413 # XXX: should add a sed or something to query all supported flags
1414 # from the gcc source and trim everything else ...
1415 filter-flags -f{no-,}unit-at-a-time -f{no-,}web -mno-tls-direct-seg-refs
1416 filter-flags -f{no-,}stack-protector{,-all}
1417 filter-flags -fvisibility-inlines-hidden -fvisibility=hidden
1418 ;;
1419 3.4|4.*)
1420 case $(tc-arch) in
1421 x86|amd64) filter-flags '-mcpu=*';;
1422 *-macos)
1423 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25127
1424 [[ ${GCC_BRANCH_VER} == 4.0 || ${GCC_BRANCH_VER} == 4.1 ]] && \
1425 filter-flags '-mcpu=*' '-march=*' '-mtune=*'
1426 ;;
1427 esac
1428 ;;
1429 esac
1430
1431 case ${GCC_BRANCH_VER} in
1432 4.6)
1433 # https://bugs.gentoo.org/411333
1434 # https://bugs.gentoo.org/466454
1435 replace-cpu-flags c3-2 pentium2 pentium3 pentium3m pentium-m i686
1436 ;;
1437 esac
1438
1439 # CFLAGS logic (verified with 3.4.3):
1440 # CFLAGS:
1441 # This conflicts when creating a crosscompiler, so set to a sane
1442 # default in this case:
1443 # used in ./configure and elsewhere for the native compiler
1444 # used by gcc when creating libiberty.a
1445 # used by xgcc when creating libstdc++ (and probably others)!
1446 # this behavior should be removed...
1447 #
1448 # CXXFLAGS:
1449 # used by xgcc when creating libstdc++
1450 #
1451 # STAGE1_CFLAGS (not used in creating a crosscompile gcc):
1452 # used by ${CHOST}-gcc for building stage1 compiler
1453 #
1454 # BOOT_CFLAGS (not used in creating a crosscompile gcc):
1455 # used by xgcc for building stage2/3 compiler
1456
1457 if is_crosscompile ; then
1458 # Set this to something sane for both native and target
1459 CFLAGS="-O2 -pipe"
1460 FFLAGS=${CFLAGS}
1461 FCFLAGS=${CFLAGS}
1462
1463 local VAR="CFLAGS_"${CTARGET//-/_}
1464 CXXFLAGS=${!VAR}
1465 fi
1466
1467 export GCJFLAGS=${GCJFLAGS:-${CFLAGS}}
1468 }
1469
1470 toolchain_src_compile() {
1471 gcc_do_filter_flags
1472 einfo "CFLAGS=\"${CFLAGS}\""
1473 einfo "CXXFLAGS=\"${CXXFLAGS}\""
1474
1475 # Force internal zip based jar script to avoid random
1476 # issues with 3rd party jar implementations. #384291
1477 export JAR=no
1478
1479 # For hardened gcc 4.3 piepatchset to build the hardened specs
1480 # file (build.specs) to use when building gcc.
1481 if ! tc_version_is_at_least 4.4 && want_minispecs ; then
1482 setup_minispecs_gcc_build_specs
1483 fi
1484 # Build in a separate build tree
1485 mkdir -p "${WORKDIR}"/build
1486 pushd "${WORKDIR}"/build > /dev/null
1487
1488 einfo "Configuring ${PN} ..."
1489 gcc_do_configure
1490
1491 touch "${S}"/gcc/c-gperf.h
1492
1493 # Do not make manpages if we do not have perl ...
1494 [[ ! -x /usr/bin/perl ]] \
1495 && find "${WORKDIR}"/build -name '*.[17]' | xargs touch
1496
1497 einfo "Compiling ${PN} ..."
1498 gcc_do_make ${GCC_MAKE_TARGET}
1499
1500 popd > /dev/null
1501 }
1502
1503 toolchain_src_test() {
1504 if use regression-test ; then
1505 cd "${WORKDIR}"/build
1506 emake -k check
1507 fi
1508 }
1509
1510 toolchain_src_install() {
1511 local x=
1512
1513 cd "${WORKDIR}"/build
1514 # Do allow symlinks in private gcc include dir as this can break the build
1515 find gcc/include*/ -type l -delete
1516 # Copy over the info pages. We disabled their generation earlier, but the
1517 # build system only expects to install out of the build dir, not the source. #464008
1518 mkdir -p gcc/doc
1519 for x in "${S}"/gcc/doc/*.info* ; do
1520 if [[ -f ${x} ]] ; then
1521 cp "${x}" gcc/doc/ || die
1522 fi
1523 done
1524 # Remove generated headers, as they can cause things to break
1525 # (ncurses, openssl, etc).
1526 while read x ; do
1527 grep -q 'It has been auto-edited by fixincludes from' "${x}" \
1528 && rm -f "${x}"
1529 done < <(find gcc/include*/ -name '*.h')
1530 # Do the 'make install' from the build directory
1531 S=${WORKDIR}/build \
1532 emake -j1 DESTDIR="${D}" install || die
1533 # Punt some tools which are really only useful while building gcc
1534 find "${D}" -name install-tools -prune -type d -exec rm -rf "{}" \;
1535 # This one comes with binutils
1536 find "${D}" -name libiberty.a -delete
1537
1538 # Move the libraries to the proper location
1539 gcc_movelibs
1540
1541 # Basic sanity check
1542 if ! is_crosscompile ; then
1543 local EXEEXT
1544 eval $(grep ^EXEEXT= "${WORKDIR}"/build/gcc/config.log)
1545 [[ -r ${D}${BINPATH}/gcc${EXEEXT} ]] || die "gcc not found in ${D}"
1546 fi
1547
1548 dodir /etc/env.d/gcc
1549 create_gcc_env_entry
1550
1551 # Setup the gcc_env_entry for hardened gcc 4 with minispecs
1552 if want_minispecs ; then
1553 copy_minispecs_gcc_specs
1554 fi
1555 # Make sure we dont have stuff lying around that
1556 # can nuke multiple versions of gcc
1557
1558 gcc_slot_java
1559
1560 # These should be symlinks
1561 dodir /usr/bin
1562 cd "${D}"${BINPATH}
1563 # Ugh: we really need to auto-detect this list.
1564 # It's constantly out of date.
1565 for x in cpp gcc g++ c++ gcov g77 gcj gcjh gfortran gccgo ; do
1566 # For some reason, g77 gets made instead of ${CTARGET}-g77...
1567 # this should take care of that
1568 [[ -f ${x} ]] && mv ${x} ${CTARGET}-${x}
1569
1570 if [[ -f ${CTARGET}-${x} ]] ; then
1571 if ! is_crosscompile ; then
1572 ln -sf ${CTARGET}-${x} ${x}
1573 dosym ${BINPATH}/${CTARGET}-${x} \
1574 /usr/bin/${x}-${GCC_CONFIG_VER}
1575 fi
1576
1577 # Create version-ed symlinks
1578 dosym ${BINPATH}/${CTARGET}-${x} \
1579 /usr/bin/${CTARGET}-${x}-${GCC_CONFIG_VER}
1580 fi
1581
1582 if [[ -f ${CTARGET}-${x}-${GCC_CONFIG_VER} ]] ; then
1583 rm -f ${CTARGET}-${x}-${GCC_CONFIG_VER}
1584 ln -sf ${CTARGET}-${x} ${CTARGET}-${x}-${GCC_CONFIG_VER}
1585 fi
1586 done
1587
1588 # Now do the fun stripping stuff
1589 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${BINPATH}"
1590 env RESTRICT="" CHOST=${CTARGET} prepstrip "${D}${LIBPATH}"
1591 # gcc used to install helper binaries in lib/ but then moved to libexec/
1592 [[ -d ${D}${PREFIX}/libexec/gcc ]] && \
1593 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}"
1594
1595 cd "${S}"
1596 if is_crosscompile; then
1597 rm -rf "${D}"/usr/share/{man,info}
1598 rm -rf "${D}"${DATAPATH}/{man,info}
1599 else
1600 if tc_version_is_at_least 3.0 ; then
1601 local cxx_mandir=$(find "${WORKDIR}/build/${CTARGET}/libstdc++-v3" -name man)
1602 if [[ -d ${cxx_mandir} ]] ; then
1603 # clean bogus manpages #113902
1604 find "${cxx_mandir}" -name '*_build_*' -exec rm {} \;
1605 cp -r "${cxx_mandir}"/man? "${D}/${DATAPATH}"/man/
1606 fi
1607 fi
1608 has noinfo ${FEATURES} \
1609 && rm -r "${D}/${DATAPATH}"/info \
1610 || prepinfo "${DATAPATH}"
1611 has noman ${FEATURES} \
1612 && rm -r "${D}/${DATAPATH}"/man \
1613 || prepman "${DATAPATH}"
1614 fi
1615 # prune empty dirs left behind
1616 find "${D}" -depth -type d -delete 2>/dev/null
1617
1618 # install testsuite results
1619 if use regression-test; then
1620 docinto testsuite
1621 find "${WORKDIR}"/build -type f -name "*.sum" -print0 | xargs -0 dodoc
1622 find "${WORKDIR}"/build -type f -path "*/testsuite/*.log" -print0 \
1623 | xargs -0 dodoc
1624 fi
1625
1626 # Rather install the script, else portage with changing $FILESDIR
1627 # between binary and source package borks things ....
1628 if ! is_crosscompile ; then
1629 insinto "${DATAPATH}"
1630 if tc_version_is_at_least 4.0 ; then
1631 newins "${GCC_FILESDIR}"/awk/fixlafiles.awk-no_gcc_la fixlafiles.awk || die
1632 find "${D}/${LIBPATH}" -name libstdc++.la -type f -exec rm "{}" \;
1633 else
1634 doins "${GCC_FILESDIR}"/awk/fixlafiles.awk || die
1635 fi
1636 exeinto "${DATAPATH}"
1637 doexe "${GCC_FILESDIR}"/fix_libtool_files.sh || die
1638 doexe "${GCC_FILESDIR}"/c{89,99} || die
1639 fi
1640
1641 # Use gid of 0 because some stupid ports don't have
1642 # the group 'root' set to gid 0. Send to /dev/null
1643 # for people who are testing as non-root.
1644 chown -R root:0 "${D}"${LIBPATH} 2>/dev/null
1645
1646 # Move pretty-printers to gdb datadir to shut ldconfig up
1647 local py gdbdir=/usr/share/gdb/auto-load${LIBPATH/\/lib\//\/$(get_libdir)\/}
1648 pushd "${D}"${LIBPATH} >/dev/null
1649 for py in $(find . -name '*-gdb.py') ; do
1650 local multidir=${py%/*}
1651 insinto "${gdbdir}/${multidir}"
1652 sed -i "/^libdir =/s:=.*:= '${LIBPATH}/${multidir}':" "${py}" || die #348128
1653 doins "${py}" || die
1654 rm "${py}" || die
1655 done
1656 popd >/dev/null
1657
1658 # Don't scan .gox files for executable stacks - false positives
1659 export QA_EXECSTACK="usr/lib*/go/*/*.gox"
1660 export QA_WX_LOAD="usr/lib*/go/*/*.gox"
1661
1662 # Disable RANDMMAP so PCH works. #301299
1663 if tc_version_is_at_least 4.3 ; then
1664 pax-mark -r "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}/cc1"
1665 pax-mark -r "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}/cc1plus"
1666 fi
1667 }
1668
1669 gcc_slot_java() {
1670 local x
1671
1672 # Move Java headers to compiler-specific dir
1673 for x in "${D}"${PREFIX}/include/gc*.h "${D}"${PREFIX}/include/j*.h ; do
1674 [[ -f ${x} ]] && mv -f "${x}" "${D}"${LIBPATH}/include/
1675 done
1676 for x in gcj gnu java javax org ; do
1677 if [[ -d ${D}${PREFIX}/include/${x} ]] ; then
1678 dodir /${LIBPATH}/include/${x}
1679 mv -f "${D}"${PREFIX}/include/${x}/* "${D}"${LIBPATH}/include/${x}/
1680 rm -rf "${D}"${PREFIX}/include/${x}
1681 fi
1682 done
1683
1684 if [[ -d ${D}${PREFIX}/lib/security ]] || [[ -d ${D}${PREFIX}/$(get_libdir)/security ]] ; then
1685 dodir /${LIBPATH}/security
1686 mv -f "${D}"${PREFIX}/lib*/security/* "${D}"${LIBPATH}/security
1687 rm -rf "${D}"${PREFIX}/lib*/security
1688 fi
1689
1690 # Move random gcj files to compiler-specific directories
1691 for x in libgcj.spec logging.properties ; do
1692 x="${D}${PREFIX}/lib/${x}"
1693 [[ -f ${x} ]] && mv -f "${x}" "${D}"${LIBPATH}/
1694 done
1695
1696 # Rename jar because it could clash with Kaffe's jar if this gcc is
1697 # primary compiler (aka don't have the -<version> extension)
1698 cd "${D}"${BINPATH}
1699 [[ -f jar ]] && mv -f jar gcj-jar
1700 }
1701
1702 # Move around the libs to the right location. For some reason,
1703 # when installing gcc, it dumps internal libraries into /usr/lib
1704 # instead of the private gcc lib path
1705 gcc_movelibs() {
1706 # older versions of gcc did not support --print-multi-os-directory
1707 tc_version_is_at_least 3.2 || return 0
1708
1709 local x multiarg removedirs=""
1710 for multiarg in $($(XGCC) -print-multi-lib) ; do
1711 multiarg=${multiarg#*;}
1712 multiarg=${multiarg//@/ -}
1713
1714 local OS_MULTIDIR=$($(XGCC) ${multiarg} --print-multi-os-directory)
1715 local MULTIDIR=$($(XGCC) ${multiarg} --print-multi-directory)
1716 local TODIR=${D}${LIBPATH}/${MULTIDIR}
1717 local FROMDIR=
1718
1719 [[ -d ${TODIR} ]] || mkdir -p ${TODIR}
1720
1721 for FROMDIR in \
1722 ${LIBPATH}/${OS_MULTIDIR} \
1723 ${LIBPATH}/../${MULTIDIR} \
1724 ${PREFIX}/lib/${OS_MULTIDIR} \
1725 ${PREFIX}/${CTARGET}/lib/${OS_MULTIDIR}
1726 do
1727 removedirs="${removedirs} ${FROMDIR}"
1728 FROMDIR=${D}${FROMDIR}
1729 if [[ ${FROMDIR} != "${TODIR}" && -d ${FROMDIR} ]] ; then
1730 local files=$(find "${FROMDIR}" -maxdepth 1 ! -type d 2>/dev/null)
1731 if [[ -n ${files} ]] ; then
1732 mv ${files} "${TODIR}"
1733 fi
1734 fi
1735 done
1736 fix_libtool_libdir_paths "${LIBPATH}/${MULTIDIR}"
1737
1738 # SLOT up libgcj.pc if it's available (and let gcc-config worry about links)
1739 FROMDIR="${PREFIX}/lib/${OS_MULTIDIR}"
1740 for x in "${D}${FROMDIR}"/pkgconfig/libgcj*.pc ; do
1741 [[ -f ${x} ]] || continue
1742 sed -i "/^libdir=/s:=.*:=${LIBPATH}/${MULTIDIR}:" "${x}"
1743 mv "${x}" "${D}${FROMDIR}"/pkgconfig/libgcj-${GCC_PV}.pc || die
1744 done
1745 done
1746
1747 # We remove directories separately to avoid this case:
1748 # mv SRC/lib/../lib/*.o DEST
1749 # rmdir SRC/lib/../lib/
1750 # mv SRC/lib/../lib32/*.o DEST # Bork
1751 for FROMDIR in ${removedirs} ; do
1752 rmdir "${D}"${FROMDIR} >& /dev/null
1753 done
1754 find "${D}" -type d | xargs rmdir >& /dev/null
1755 }
1756
1757 #----<< src_* >>----
1758
1759 #---->> unorganized crap in need of refactoring follows
1760
1761 # gcc_quick_unpack will unpack the gcc tarball and patches in a way that is
1762 # consistant with the behavior of get_gcc_src_uri. The only patch it applies
1763 # itself is the branch update if present.
1764 #
1765 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
1766 #
1767 gcc_quick_unpack() {
1768 pushd "${WORKDIR}" > /dev/null
1769 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
1770 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
1771 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
1772 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
1773 export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}}
1774
1775 if [[ -n ${GCC_A_FAKEIT} ]] ; then
1776 unpack ${GCC_A_FAKEIT}
1777 elif [[ -n ${PRERELEASE} ]] ; then
1778 unpack gcc-${PRERELEASE}.tar.bz2
1779 elif [[ -n ${SNAPSHOT} ]] ; then
1780 unpack gcc-${SNAPSHOT}.tar.bz2
1781 elif [[ ${PV} != *9999* ]] ; then
1782 unpack gcc-${GCC_RELEASE_VER}.tar.bz2
1783 # We want branch updates to be against a release tarball
1784 if [[ -n ${BRANCH_UPDATE} ]] ; then
1785 pushd "${S}" > /dev/null
1786 epatch "${DISTDIR}"/gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2
1787 popd > /dev/null
1788 fi
1789 fi
1790
1791 if [[ -n ${D_VER} ]] && use d ; then
1792 pushd "${S}"/gcc > /dev/null
1793 unpack gdc-${D_VER}-src.tar.bz2
1794 cd ..
1795 ebegin "Adding support for the D language"
1796 ./gcc/d/setup-gcc.sh >& "${T}"/dgcc.log
1797 if ! eend $? ; then
1798 eerror "The D gcc package failed to apply"
1799 eerror "Please include this log file when posting a bug report:"
1800 eerror " ${T}/dgcc.log"
1801 die "failed to include the D language"
1802 fi
1803 popd > /dev/null
1804 fi
1805
1806 [[ -n ${PATCH_VER} ]] && \
1807 unpack gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2
1808
1809 [[ -n ${UCLIBC_VER} ]] && \
1810 unpack gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2
1811
1812 if want_pie ; then
1813 if [[ -n ${PIE_CORE} ]] ; then
1814 unpack ${PIE_CORE}
1815 else
1816 unpack gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2
1817 fi
1818 [[ -n ${SPECS_VER} ]] && \
1819 unpack gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2
1820 fi
1821
1822 use_if_iuse boundschecking && unpack "bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
1823
1824 popd > /dev/null
1825 }
1826
1827 do_gcc_HTB_patches() {
1828 use_if_iuse boundschecking || return 0
1829
1830 # modify the bounds checking patch with a regression patch
1831 epatch "${WORKDIR}/bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch"
1832 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, HTB-${HTB_GCC_VER}-${HTB_VER}"
1833 }
1834
1835 # do various updates to PIE logic
1836 do_gcc_PIE_patches() {
1837 want_pie || return 0
1838
1839 use vanilla && return 0
1840
1841 if tc_version_is_at_least 4.3.2; then
1842 guess_patch_type_in_dir "${WORKDIR}"/piepatch/
1843 EPATCH_MULTI_MSG="Applying pie patches ..." \
1844 epatch "${WORKDIR}"/piepatch/
1845 else
1846 guess_patch_type_in_dir "${WORKDIR}"/piepatch/upstream
1847
1848 # corrects startfile/endfile selection and shared/static/pie flag usage
1849 EPATCH_MULTI_MSG="Applying upstream pie patches ..." \
1850 epatch "${WORKDIR}"/piepatch/upstream
1851 # adds non-default pie support (rs6000)
1852 EPATCH_MULTI_MSG="Applying non-default pie patches ..." \
1853 epatch "${WORKDIR}"/piepatch/nondef
1854 # adds default pie support (rs6000 too) if DEFAULT_PIE[_SSP] is defined
1855 EPATCH_MULTI_MSG="Applying default pie patches ..." \
1856 epatch "${WORKDIR}"/piepatch/def
1857 fi
1858
1859 # we want to be able to control the pie patch logic via something other
1860 # than ALL_CFLAGS...
1861 sed -e '/^ALL_CFLAGS/iHARD_CFLAGS = ' \
1862 -e 's|^ALL_CFLAGS = |ALL_CFLAGS = $(HARD_CFLAGS) |' \
1863 -i "${S}"/gcc/Makefile.in
1864 # Need to add HARD_CFLAGS to ALL_CXXFLAGS on >= 4.7
1865 if tc_version_is_at_least 4.7.0 ; then
1866 sed -e '/^ALL_CXXFLAGS/iHARD_CFLAGS = ' \
1867 -e 's|^ALL_CXXFLAGS = |ALL_CXXFLAGS = $(HARD_CFLAGS) |' \
1868 -i "${S}"/gcc/Makefile.in
1869 fi
1870
1871 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, pie-${PIE_VER}"
1872 }
1873
1874 should_we_gcc_config() {
1875 # if the current config is invalid, we definitely want a new one
1876 # Note: due to bash quirkiness, the following must not be 1 line
1877 local curr_config
1878 curr_config=$(env -i ROOT="${ROOT}" gcc-config -c ${CTARGET} 2>&1) || return 0
1879
1880 # if the previously selected config has the same major.minor (branch) as
1881 # the version we are installing, then it will probably be uninstalled
1882 # for being in the same SLOT, make sure we run gcc-config.
1883 local curr_config_ver=$(env -i ROOT="${ROOT}" gcc-config -S ${curr_config} | awk '{print $2}')
1884
1885 local curr_branch_ver=$(get_version_component_range 1-2 ${curr_config_ver})
1886
1887 # If we're using multislot, just run gcc-config if we're installing
1888 # to the same profile as the current one.
1889 use multislot && return $([[ ${curr_config_ver} == ${GCC_CONFIG_VER} ]])
1890
1891 if [[ ${curr_branch_ver} == ${GCC_BRANCH_VER} ]] ; then
1892 return 0
1893 else
1894 # if we're installing a genuinely different compiler version,
1895 # we should probably tell the user -how- to switch to the new
1896 # gcc version, since we're not going to do it for him/her.
1897 # We don't want to switch from say gcc-3.3 to gcc-3.4 right in
1898 # the middle of an emerge operation (like an 'emerge -e world'
1899 # which could install multiple gcc versions).
1900 # Only warn if we're installing a pkg as we might be called from
1901 # the pkg_{pre,post}rm steps. #446830
1902 if [[ ${EBUILD_PHASE} == *"inst" ]] ; then
1903 einfo "The current gcc config appears valid, so it will not be"
1904 einfo "automatically switched for you. If you would like to"
1905 einfo "switch to the newly installed gcc version, do the"
1906 einfo "following:"
1907 echo
1908 einfo "gcc-config ${CTARGET}-${GCC_CONFIG_VER}"
1909 einfo "source /etc/profile"
1910 echo
1911 fi
1912 return 1
1913 fi
1914 }
1915
1916 do_gcc_config() {
1917 if ! should_we_gcc_config ; then
1918 env -i ROOT="${ROOT}" gcc-config --use-old --force
1919 return 0
1920 fi
1921
1922 local current_gcc_config="" current_specs="" use_specs=""
1923
1924 current_gcc_config=$(env -i ROOT="${ROOT}" gcc-config -c ${CTARGET} 2>/dev/null)
1925 if [[ -n ${current_gcc_config} ]] ; then
1926 # figure out which specs-specific config is active
1927 current_specs=$(gcc-config -S ${current_gcc_config} | awk '{print $3}')
1928 [[ -n ${current_specs} ]] && use_specs=-${current_specs}
1929 fi
1930 if [[ -n ${use_specs} ]] && \
1931 [[ ! -e ${ROOT}/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}${use_specs} ]]
1932 then
1933 ewarn "The currently selected specs-specific gcc config,"
1934 ewarn "${current_specs}, doesn't exist anymore. This is usually"
1935 ewarn "due to enabling/disabling hardened or switching to a version"
1936 ewarn "of gcc that doesnt create multiple specs files. The default"
1937 ewarn "config will be used, and the previous preference forgotten."
1938 ebeep
1939 epause
1940 use_specs=""
1941 fi
1942
1943 gcc-config ${CTARGET}-${GCC_CONFIG_VER}${use_specs}
1944 }
1945
1946 # This function allows us to gentoo-ize gcc's version number and bugzilla
1947 # URL without needing to use patches.
1948 gcc_version_patch() {
1949 # gcc-4.3+ has configure flags (whoo!)
1950 tc_version_is_at_least 4.3 && return 0
1951
1952 local version_string=${GCC_CONFIG_VER}
1953 [[ -n ${BRANCH_UPDATE} ]] && version_string+=" ${BRANCH_UPDATE}"
1954
1955 einfo "patching gcc version: ${version_string} (${BRANDING_GCC_PKGVERSION})"
1956
1957 local gcc_sed=( -e 's:gcc\.gnu\.org/bugs\.html:bugs\.gentoo\.org/:' )
1958 if grep -qs VERSUFFIX "${S}"/gcc/version.c ; then
1959 gcc_sed+=( -e "/VERSUFFIX \"\"/s:\"\":\" (${BRANDING_GCC_PKGVERSION})\":" )
1960 else
1961 version_string="${version_string} (${BRANDING_GCC_PKGVERSION})"
1962 gcc_sed+=( -e "/const char version_string\[\] = /s:= \".*\":= \"${version_string}\":" )
1963 fi
1964 sed -i "${gcc_sed[@]}" "${S}"/gcc/version.c || die
1965 }
1966
1967 # This is a historical wart. The original Gentoo/amd64 port used:
1968 # lib32 - 32bit binaries (x86)
1969 # lib64 - 64bit binaries (x86_64)
1970 # lib - "native" binaries (a symlink to lib64)
1971 # Most other distros use the logic (including mainline gcc):
1972 # lib - 32bit binaries (x86)
1973 # lib64 - 64bit binaries (x86_64)
1974 # Over time, Gentoo is migrating to the latter form.
1975 #
1976 # Unfortunately, due to distros picking the lib32 behavior, newer gcc
1977 # versions will dynamically detect whether to use lib or lib32 for its
1978 # 32bit multilib. So, to keep the automagic from getting things wrong
1979 # while people are transitioning from the old style to the new style,
1980 # we always set the MULTILIB_OSDIRNAMES var for relevant targets.
1981 setup_multilib_osdirnames() {
1982 is_multilib || return 0
1983
1984 local config
1985 local libdirs="../lib64 ../lib32"
1986
1987 # this only makes sense for some Linux targets
1988 case ${CTARGET} in
1989 x86_64*-linux*) config="i386" ;;
1990 powerpc64*-linux*) config="rs6000" ;;
1991 sparc64*-linux*) config="sparc" ;;
1992 s390x*-linux*) config="s390" ;;
1993 *) return 0 ;;
1994 esac
1995 config+="/t-linux64"
1996
1997 local sed_args=()
1998 if tc_version_is_at_least 4.6 ; then
1999 sed_args+=( -e 's:$[(]call if_multiarch[^)]*[)]::g' )
2000 fi
2001 if [[ ${SYMLINK_LIB} == "yes" ]] ; then
2002 einfo "updating multilib directories to be: ${libdirs}"
2003 if tc_version_is_at_least 4.6.4 || tc_version_is_at_least 4.7 ; then
2004 sed_args+=( -e '/^MULTILIB_OSDIRNAMES.*lib32/s:[$][(]if.*):../lib32:' )
2005 else
2006 sed_args+=( -e "/^MULTILIB_OSDIRNAMES/s:=.*:= ${libdirs}:" )
2007 fi
2008 else
2009 einfo "using upstream multilib; disabling lib32 autodetection"
2010 sed_args+=( -r -e 's:[$][(]if.*,(.*)[)]:\1:' )
2011 fi
2012 sed -i "${sed_args[@]}" "${S}"/gcc/config/${config} || die
2013 }
2014
2015 # make sure the libtool archives have libdir set to where they actually
2016 # -are-, and not where they -used- to be. also, any dependencies we have
2017 # on our own .la files need to be updated.
2018 fix_libtool_libdir_paths() {
2019 pushd "${D}" >/dev/null
2020
2021 pushd "./${1}" >/dev/null
2022 local dir="${PWD#${D%/}}"
2023 local allarchives=$(echo *.la)
2024 allarchives="\(${allarchives// /\\|}\)"
2025 popd >/dev/null
2026
2027 sed -i \
2028 -e "/^libdir=/s:=.*:='${dir}':" \
2029 ./${dir}/*.la
2030 sed -i \
2031 -e "/^dependency_libs=/s:/[^ ]*/${allarchives}:${LIBPATH}/\1:g" \
2032 $(find ./${PREFIX}/lib* -maxdepth 3 -name '*.la') \
2033 ./${dir}/*.la
2034
2035 popd >/dev/null
2036 }
2037
2038 is_multilib() {
2039 tc_version_is_at_least 3 || return 1
2040 use multilib
2041 }
2042
2043 is_cxx() {
2044 gcc-lang-supported 'c++' || return 1
2045 use cxx
2046 }
2047
2048 is_d() {
2049 gcc-lang-supported d || return 1
2050 use_if_iuse d
2051 }
2052
2053 is_f77() {
2054 gcc-lang-supported f77 || return 1
2055 use fortran
2056 }
2057
2058 is_f95() {
2059 gcc-lang-supported f95 || return 1
2060 use fortran
2061 }
2062
2063 is_fortran() {
2064 gcc-lang-supported fortran || return 1
2065 use fortran
2066 }
2067
2068 is_gcj() {
2069 gcc-lang-supported java || return 1
2070 use cxx && use_if_iuse gcj
2071 }
2072
2073 is_go() {
2074 gcc-lang-supported go || return 1
2075 use cxx && use_if_iuse go
2076 }
2077
2078 is_objc() {
2079 gcc-lang-supported objc || return 1
2080 use_if_iuse objc
2081 }
2082
2083 is_objcxx() {
2084 gcc-lang-supported 'obj-c++' || return 1
2085 use cxx && use_if_iuse objc++
2086 }
2087
2088 is_ada() {
2089 gcc-lang-supported ada || return 1
2090 use ada
2091 }
2092
2093 is_treelang() {
2094 use_if_iuse boundschecking && return 1 #260532
2095 is_crosscompile && return 1 #199924
2096 gcc-lang-supported treelang || return 1
2097 #use treelang
2098 return 0
2099 }
2100
2101 # should kill these off once all the ebuilds are migrated
2102 gcc_pkg_setup() { toolchain_pkg_setup ; }
2103 gcc_src_unpack() { toolchain_src_unpack ; }
2104 gcc_src_compile() { toolchain_src_compile ; }
2105 gcc_src_test() { toolchain_src_test ; }

  ViewVC Help
Powered by ViewVC 1.1.20