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

Contents of /eclass/toolchain.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.632 - (show annotations) (download)
Sun Jun 1 23:00:45 2014 UTC (7 months, 4 weeks ago) by rhill
Branch: MAIN
Changes since 1.631: +7 -8 lines
If we keep the flag list sorted by version there's no need for this function
to be recursive. This shaves a couple seconds off the worst-case runtime.

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

  ViewVC Help
Powered by ViewVC 1.1.20