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

Contents of /eclass/toolchain.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.568 - (show annotations) (download)
Thu Jan 24 01:27:27 2013 UTC (22 months, 3 weeks ago) by vapier
Branch: MAIN
Changes since 1.567: +5 -12 lines
drop USE="bootstrap build" as it does very little and the existing logic should handle things correctly #440224

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

  ViewVC Help
Powered by ViewVC 1.1.20