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

Contents of /eclass/toolchain.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.569 - (show annotations) (download)
Sat Feb 9 04:34:32 2013 UTC (20 months, 2 weeks ago) by vapier
Branch: MAIN
Changes since 1.568: +6 -7 lines
update snapshot location to use gcc.gnu.org #455152

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

  ViewVC Help
Powered by ViewVC 1.1.20