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

Contents of /eclass/toolchain.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.554 - (show annotations) (download)
Mon Nov 19 02:59:49 2012 UTC (2 years, 1 month ago) by vapier
Branch: MAIN
Changes since 1.553: +3 -1 lines
set FCFLAGS/FFLAGS when cross-compiling

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

  ViewVC Help
Powered by ViewVC 1.1.20