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

Contents of /eclass/toolchain.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.676 - (show annotations) (download)
Fri Jul 17 07:36:00 2015 UTC (2 years, 1 month ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Changes since 1.675: +4 -2 lines
use --enable-checking=no w/gcc-3.4 as "release" was not added until gcc-4.0 #551636 by Samuel Bauer

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

  ViewVC Help
Powered by ViewVC 1.1.20