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

Contents of /eclass/toolchain.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.624 - (show annotations) (download)
Sun Mar 16 18:38:37 2014 UTC (5 months, 1 week ago) by rhill
Branch: MAIN
Changes since 1.623: +2 -2 lines
Update my src_uri.

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.623 2014/02/05 06:18:29 dirtyepic 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? ( sys-devel/gettext )"
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 regression-test? (
186 >=dev-util/dejagnu-1.4.4
187 >=sys-devel/autogen-5.5.4
188 )"
189
190 if in_iuse gcj ; then
191 GCJ_DEPS=">=media-libs/libart_lgpl-2.1"
192 GCJ_GTK_DEPS="
193 x11-libs/libXt
194 x11-libs/libX11
195 x11-libs/libXtst
196 x11-proto/xproto
197 x11-proto/xextproto
198 =x11-libs/gtk+-2*
199 virtual/pkgconfig
200 amd64? ( multilib? (
201 app-emulation/emul-linux-x86-gtklibs
202 app-emulation/emul-linux-x86-xlibs
203 ) )
204 "
205 tc_version_is_at_least 3.4 && GCJ_GTK_DEPS+=" x11-libs/pango"
206 tc_version_is_at_least 4.2 && GCJ_DEPS+=" app-arch/zip app-arch/unzip"
207 DEPEND+=" gcj? ( awt? ( ${GCJ_GTK_DEPS} ) ${GCJ_DEPS} )"
208 fi
209
210 PDEPEND=">=sys-devel/gcc-config-1.7"
211
212 #---->> S + SRC_URI essentials <<----
213
214 # Set the source directory depending on whether we're using
215 # a prerelease, snapshot, or release tarball.
216 S=$(
217 if [[ -n ${PRERELEASE} ]] ; then
218 echo ${WORKDIR}/gcc-${PRERELEASE}
219 elif [[ -n ${SNAPSHOT} ]] ; then
220 echo ${WORKDIR}/gcc-${SNAPSHOT}
221 else
222 echo ${WORKDIR}/gcc-${GCC_RELEASE_VER}
223 fi
224 )
225
226 gentoo_urls() {
227 local devspace="HTTP~vapier/dist/URI HTTP~rhill/dist/URI
228 HTTP~halcy0n/patches/URI HTTP~zorry/patches/gcc/URI"
229 devspace=${devspace//HTTP/http:\/\/dev.gentoo.org\/}
230 echo mirror://gentoo/$1 ${devspace//URI/$1}
231 }
232
233 # This function handles the basics of setting the SRC_URI for a gcc ebuild.
234 # To use, set SRC_URI with:
235 #
236 # SRC_URI="$(get_gcc_src_uri)"
237 #
238 # Other than the variables normally set by portage, this function's behavior
239 # can be altered by setting the following:
240 #
241 # SNAPSHOT
242 # If set, this variable signals that we should be using a snapshot of
243 # gcc. It is expected to be in the format "YYYY-MM-DD". Note that if
244 # the ebuild has a _pre suffix, this variable is ignored and the
245 # prerelease tarball is used instead.
246 #
247 # BRANCH_UPDATE
248 # If set, this variable signals that we should be using the main
249 # release tarball (determined by ebuild version) and applying a
250 # CVS branch update patch against it. The location of this branch
251 # update patch is assumed to be in ${GENTOO_TOOLCHAIN_BASE_URI}.
252 # Just like with SNAPSHOT, this variable is ignored if the ebuild
253 # has a _pre suffix.
254 #
255 # PATCH_VER
256 # PATCH_GCC_VER
257 # This should be set to the version of the gentoo patch tarball.
258 # The resulting filename of this tarball will be:
259 # gcc-${PATCH_GCC_VER:-${GCC_RELEASE_VER}}-patches-${PATCH_VER}.tar.bz2
260 #
261 # PIE_VER
262 # PIE_GCC_VER
263 # These variables control patching in various updates for the logic
264 # controlling Position Independant Executables. PIE_VER is expected
265 # to be the version of this patch, and PIE_GCC_VER the gcc version of
266 # the patch:
267 # An example:
268 # PIE_VER="8.7.6.5"
269 # PIE_GCC_VER="3.4.0"
270 # The resulting filename of this tarball will be:
271 # gcc-${PIE_GCC_VER:-${GCC_RELEASE_VER}}-piepatches-v${PIE_VER}.tar.bz2
272 #
273 # SPECS_VER
274 # SPECS_GCC_VER
275 # This is for the minispecs files included in the hardened gcc-4.x
276 # The specs files for hardenedno*, vanilla and for building the "specs" file.
277 # SPECS_VER is expected to be the version of this patch, SPECS_GCC_VER
278 # the gcc version of the patch.
279 # An example:
280 # SPECS_VER="8.7.6.5"
281 # SPECS_GCC_VER="3.4.0"
282 # The resulting filename of this tarball will be:
283 # gcc-${SPECS_GCC_VER:-${GCC_RELEASE_VER}}-specs-${SPECS_VER}.tar.bz2
284 #
285 # HTB_VER
286 # HTB_GCC_VER
287 # These variables control whether or not an ebuild supports Herman
288 # ten Brugge's bounds-checking patches. If you want to use a patch
289 # for an older gcc version with a new gcc, make sure you set
290 # HTB_GCC_VER to that version of gcc.
291 get_gcc_src_uri() {
292 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
293 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
294 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
295 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
296 export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}}
297
298 # Set where to download gcc itself depending on whether we're using a
299 # prerelease, snapshot, or release tarball.
300 if [[ -n ${PRERELEASE} ]] ; then
301 GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/prerelease-${PRERELEASE}/gcc-${PRERELEASE}.tar.bz2"
302 elif [[ -n ${SNAPSHOT} ]] ; then
303 GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.bz2"
304 elif [[ ${PV} != *9999* ]] ; then
305 GCC_SRC_URI="mirror://gnu/gcc/gcc-${GCC_PV}/gcc-${GCC_RELEASE_VER}.tar.bz2"
306 # we want all branch updates to be against the main release
307 [[ -n ${BRANCH_UPDATE} ]] && \
308 GCC_SRC_URI+=" $(gentoo_urls gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2)"
309 fi
310
311 [[ -n ${UCLIBC_VER} ]] && \
312 GCC_SRC_URI+=" $(gentoo_urls gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2)"
313 [[ -n ${PATCH_VER} ]] && \
314 GCC_SRC_URI+=" $(gentoo_urls gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2)"
315
316 # strawberry pie, Cappuccino and a Gauloises (it's a good thing)
317 [[ -n ${PIE_VER} ]] && \
318 PIE_CORE=${PIE_CORE:-gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2} && \
319 GCC_SRC_URI+=" $(gentoo_urls ${PIE_CORE})"
320
321 # gcc minispec for the hardened gcc 4 compiler
322 [[ -n ${SPECS_VER} ]] && \
323 GCC_SRC_URI+=" $(gentoo_urls gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2)"
324
325 # gcc bounds checking patch
326 if [[ -n ${HTB_VER} ]] ; then
327 local HTBFILE="bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
328 GCC_SRC_URI+="
329 boundschecking? (
330 mirror://sourceforge/boundschecking/${HTBFILE}
331 $(gentoo_urls ${HTBFILE})
332 )"
333 fi
334
335 [[ -n ${D_VER} ]] && \
336 GCC_SRC_URI+=" d? ( mirror://sourceforge/dgcc/gdc-${D_VER}-src.tar.bz2 )"
337
338 if in_iuse gcj ; then
339 if tc_version_is_at_least 4.5 ; then
340 GCC_SRC_URI+=" gcj? ( ftp://sourceware.org/pub/java/ecj-4.5.jar )"
341 elif tc_version_is_at_least 4.3 ; then
342 GCC_SRC_URI+=" gcj? ( ftp://sourceware.org/pub/java/ecj-4.3.jar )"
343 fi
344 fi
345
346 echo "${GCC_SRC_URI}"
347 }
348
349 SRC_URI=$(get_gcc_src_uri)
350
351 #---->> pkg_pretend <<----
352
353 toolchain_pkg_pretend() {
354 if [[ -n ${PRERELEASE}${SNAPSHOT} || ${PV} == *9999* ]] &&
355 [[ -z ${I_PROMISE_TO_SUPPLY_PATCHES_WITH_BUGS} ]] ; then
356 die "Please \`export I_PROMISE_TO_SUPPLY_PATCHES_WITH_BUGS=1\` or define it" \
357 "in your make.conf if you want to use this version."
358 fi
359
360 [[ -z ${UCLIBC_VER} ]] && [[ ${CTARGET} == *-uclibc* ]] && \
361 die "Sorry, this version does not support uClibc"
362
363 if ! use_if_iuse cxx ; then
364 use_if_iuse go && ewarn 'Go requires a C++ compiler, disabled due to USE="-cxx"'
365 use_if_iuse objc++ && ewarn 'Obj-C++ requires a C++ compiler, disabled due to USE="-cxx"'
366 use_if_iuse gcj && ewarn 'GCJ requires a C++ compiler, disabled due to USE="-cxx"'
367 fi
368
369 want_minispecs
370 }
371
372 #---->> pkg_setup <<----
373
374 toolchain_pkg_setup() {
375 case "${EAPI:-0}" in
376 0|1|2|3) toolchain_pkg_pretend ;;
377 esac
378
379 # we dont want to use the installed compiler's specs to build gcc
380 unset GCC_SPECS
381 unset LANGUAGES #265283
382 }
383
384 #---->> src_unpack <<----
385
386 toolchain_src_unpack() {
387 if [[ ${PV} == *9999* ]]; then
388 git-2_src_unpack
389 else
390 gcc_quick_unpack
391 fi
392
393 case ${EAPI:-0} in
394 0|1) toolchain_src_prepare ;;
395 esac
396 }
397
398 gcc_quick_unpack() {
399 pushd "${WORKDIR}" > /dev/null
400 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
401 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
402 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
403 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
404 export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}}
405
406 if [[ -n ${GCC_A_FAKEIT} ]] ; then
407 unpack ${GCC_A_FAKEIT}
408 elif [[ -n ${PRERELEASE} ]] ; then
409 unpack gcc-${PRERELEASE}.tar.bz2
410 elif [[ -n ${SNAPSHOT} ]] ; then
411 unpack gcc-${SNAPSHOT}.tar.bz2
412 elif [[ ${PV} != *9999* ]] ; then
413 unpack gcc-${GCC_RELEASE_VER}.tar.bz2
414 # We want branch updates to be against a release tarball
415 if [[ -n ${BRANCH_UPDATE} ]] ; then
416 pushd "${S}" > /dev/null
417 epatch "${DISTDIR}"/gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2
418 popd > /dev/null
419 fi
420 fi
421
422 if [[ -n ${D_VER} ]] && use d ; then
423 pushd "${S}"/gcc > /dev/null
424 unpack gdc-${D_VER}-src.tar.bz2
425 cd ..
426 ebegin "Adding support for the D language"
427 ./gcc/d/setup-gcc.sh >& "${T}"/dgcc.log
428 if ! eend $? ; then
429 eerror "The D GCC package failed to apply"
430 eerror "Please include this log file when posting a bug report:"
431 eerror " ${T}/dgcc.log"
432 die "failed to include the D language"
433 fi
434 popd > /dev/null
435 fi
436
437 [[ -n ${PATCH_VER} ]] && \
438 unpack gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2
439
440 [[ -n ${UCLIBC_VER} ]] && \
441 unpack gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2
442
443 if want_pie ; then
444 if [[ -n ${PIE_CORE} ]] ; then
445 unpack ${PIE_CORE}
446 else
447 unpack gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2
448 fi
449 [[ -n ${SPECS_VER} ]] && \
450 unpack gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2
451 fi
452
453 use_if_iuse boundschecking && unpack "bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
454
455 popd > /dev/null
456 }
457
458 #---->> src_prepare <<----
459
460 toolchain_src_prepare() {
461 export BRANDING_GCC_PKGVERSION="Gentoo ${GCC_PVR}"
462 cd "${S}"
463
464 if ! use vanilla ; then
465 if [[ -n ${PATCH_VER} ]] ; then
466 guess_patch_type_in_dir "${WORKDIR}"/patch
467 EPATCH_MULTI_MSG="Applying Gentoo patches ..." \
468 epatch "${WORKDIR}"/patch
469 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION} p${PATCH_VER}"
470 fi
471 if [[ -n ${UCLIBC_VER} ]] ; then
472 guess_patch_type_in_dir "${WORKDIR}"/uclibc
473 EPATCH_MULTI_MSG="Applying uClibc patches ..." \
474 epatch "${WORKDIR}"/uclibc
475 fi
476 fi
477 do_gcc_HTB_patches
478 do_gcc_PIE_patches
479 epatch_user
480
481 if ( tc_version_is_at_least 4.8.2 || use hardened ) && ! use vanilla ; then
482 make_gcc_hard
483 fi
484
485 # install the libstdc++ python into the right location
486 # http://gcc.gnu.org/PR51368
487 if tc_version_is_between 4.5 4.7 ; then
488 sed -i \
489 '/^pythondir =/s:=.*:= $(datadir)/python:' \
490 "${S}"/libstdc++-v3/python/Makefile.in || die
491 fi
492
493 # make sure the pkg config files install into multilib dirs.
494 # since we configure with just one --libdir, we can't use that
495 # (as gcc itself takes care of building multilibs). #435728
496 find "${S}" -name Makefile.in \
497 -exec sed -i '/^pkgconfigdir/s:=.*:=$(toolexeclibdir)/pkgconfig:' {} +
498
499 # No idea when this first started being fixed, but let's go with 4.3.x for now
500 if ! tc_version_is_at_least 4.3 ; then
501 fix_files=""
502 for x in contrib/test_summary libstdc++-v3/scripts/check_survey.in ; do
503 [[ -e ${x} ]] && fix_files="${fix_files} ${x}"
504 done
505 ht_fix_file ${fix_files} */configure *.sh */Makefile.in
506 fi
507
508 setup_multilib_osdirnames
509 gcc_version_patch
510
511 if tc_version_is_at_least 4.1 ; then
512 if [[ -n ${SNAPSHOT} || -n ${PRERELEASE} ]] ; then
513 # BASE-VER must be a three-digit version number
514 # followed by an optional -pre string
515 # eg. 4.5.1, 4.6.2-pre20120213, 4.7.0-pre9999
516 # If BASE-VER differs from ${PV/_/-} then libraries get installed in
517 # the wrong directory.
518 echo ${PV/_/-} > "${S}"/gcc/BASE-VER
519 fi
520 fi
521
522 # >= gcc-4.3 doesn't bundle ecj.jar, so copy it
523 if tc_version_is_at_least 4.3 && use gcj ; then
524 if tc_version_is_at_least 4.5 ; then
525 einfo "Copying ecj-4.5.jar"
526 cp -pPR "${DISTDIR}/ecj-4.5.jar" "${S}/ecj.jar" || die
527 else
528 einfo "Copying ecj-4.3.jar"
529 cp -pPR "${DISTDIR}/ecj-4.3.jar" "${S}/ecj.jar" || die
530 fi
531 fi
532
533 # disable --as-needed from being compiled into gcc specs
534 # natively when using a gcc version < 3.4.4
535 # http://gcc.gnu.org/PR14992
536 if ! tc_version_is_at_least 3.4.4 ; then
537 sed -i -e s/HAVE_LD_AS_NEEDED/USE_LD_AS_NEEDED/g "${S}"/gcc/config.in
538 fi
539
540 # In gcc 3.3.x and 3.4.x, rename the java bins to gcc-specific names
541 # in line with gcc-4.
542 if tc_version_is_between 3.3 4.0 ; then
543 do_gcc_rename_java_bins
544 fi
545
546 # Prevent libffi from being installed
547 if tc_version_is_between 3.0 4.8 ; then
548 sed -i -e 's/\(install.*:\) install-.*recursive/\1/' "${S}"/libffi/Makefile.in || die
549 sed -i -e 's/\(install-data-am:\).*/\1/' "${S}"/libffi/include/Makefile.in || die
550 fi
551
552 # Fixup libtool to correctly generate .la files with portage
553 elibtoolize --portage --shallow --no-uclibc
554
555 gnuconfig_update
556
557 # update configure files
558 local f
559 einfo "Fixing misc issues in configure files"
560 for f in $(grep -l 'autoconf version 2.13' $(find "${S}" -name configure)) ; do
561 ebegin " Updating ${f/${S}\/} [LANG]"
562 patch "${f}" "${GCC_FILESDIR}"/gcc-configure-LANG.patch >& "${T}"/configure-patch.log \
563 || eerror "Please file a bug about this"
564 eend $?
565 done
566 sed -i 's|A-Za-z0-9|[:alnum:]|g' "${S}"/gcc/*.awk #215828
567
568 # Prevent new texinfo from breaking old versions (see #198182, #464008)
569 tc_version_is_at_least 4.1 && epatch "${GCC_FILESDIR}"/gcc-configure-texinfo.patch
570
571 if [[ -x contrib/gcc_update ]] ; then
572 einfo "Touching generated files"
573 ./contrib/gcc_update --touch | \
574 while read f ; do
575 einfo " ${f%%...}"
576 done
577 fi
578 }
579
580 guess_patch_type_in_dir() {
581 [[ -n $(ls "$1"/*.bz2 2>/dev/null) ]] \
582 && EPATCH_SUFFIX="patch.bz2" \
583 || EPATCH_SUFFIX="patch"
584 }
585
586 do_gcc_HTB_patches() {
587 use_if_iuse boundschecking || return 0
588
589 # modify the bounds checking patch with a regression patch
590 epatch "${WORKDIR}/bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch"
591 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, HTB-${HTB_GCC_VER}-${HTB_VER}"
592 }
593
594 do_gcc_PIE_patches() {
595 want_pie || return 0
596 use vanilla && return 0
597
598 if tc_version_is_at_least 4.3.2 ; then
599 guess_patch_type_in_dir "${WORKDIR}"/piepatch/
600 EPATCH_MULTI_MSG="Applying pie patches ..." \
601 epatch "${WORKDIR}"/piepatch/
602 else
603 guess_patch_type_in_dir "${WORKDIR}"/piepatch/upstream
604
605 # corrects startfile/endfile selection and shared/static/pie flag usage
606 EPATCH_MULTI_MSG="Applying upstream pie patches ..." \
607 epatch "${WORKDIR}"/piepatch/upstream
608 # adds non-default pie support (rs6000)
609 EPATCH_MULTI_MSG="Applying non-default pie patches ..." \
610 epatch "${WORKDIR}"/piepatch/nondef
611 # adds default pie support (rs6000 too) if DEFAULT_PIE[_SSP] is defined
612 EPATCH_MULTI_MSG="Applying default pie patches ..." \
613 epatch "${WORKDIR}"/piepatch/def
614 fi
615
616 BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, pie-${PIE_VER}"
617 }
618
619 # configure to build with the hardened GCC specs as the default
620 make_gcc_hard() {
621
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 is_treelang && GCC_LANG+=",treelang"
839
840 # fortran support just got sillier! the lang value can be f77 for
841 # fortran77, f95 for fortran95, or just plain old fortran for the
842 # currently supported standard depending on gcc version.
843 is_fortran && GCC_LANG+=",fortran"
844 is_f77 && GCC_LANG+=",f77"
845 is_f95 && GCC_LANG+=",f95"
846
847 # We do NOT want 'ADA support' in here!
848 # is_ada && GCC_LANG+=",ada"
849
850 confgcc+=( --enable-languages=${GCC_LANG} )
851
852 ### general options
853
854 confgcc+=(
855 --enable-obsolete
856 --enable-secureplt
857 --disable-werror
858 --with-system-zlib
859 )
860
861 if use nls ; then
862 confgcc+=( --enable-nls --without-included-gettext )
863 else
864 confgcc+=( --disable-nls )
865 fi
866
867 tc_version_is_at_least 3.4 || confgcc+=( --disable-libunwind-exceptions )
868
869 # Use the default ("release") checking because upstream usually neglects
870 # to test "disabled" so it has a history of breaking. #317217
871 if tc_version_is_at_least 4 || [[ -n ${GCC_CHECKS_LIST} ]] ; then
872 confgcc+=( --enable-checking=${GCC_CHECKS_LIST:-release} )
873 else
874 confgcc+=( --disable-checking )
875 fi
876
877 # Branding
878 tc_version_is_at_least 4.3 && confgcc+=(
879 --with-bugurl=https://bugs.gentoo.org/
880 --with-pkgversion="${BRANDING_GCC_PKGVERSION}"
881 )
882
883 # If we want hardened support with the newer piepatchset for >=gcc 4.4
884 if tc_version_is_at_least 4.4 && want_minispecs ; then
885 confgcc+=( $(use_enable hardened esp) )
886 fi
887
888 # allow gcc to search for clock funcs in the main C lib.
889 # if it can't find them, then tough cookies -- we aren't
890 # going to link in -lrt to all C++ apps. #411681
891 if tc_version_is_at_least 4.4 && is_cxx ; then
892 confgcc+=( --enable-libstdcxx-time )
893 fi
894
895 # newer gcc versions like to bootstrap themselves with C++,
896 # so we need to manually disable it ourselves
897 if tc_version_is_between 4.7 4.8 && ! is_cxx ; then
898 confgcc+=( --disable-build-with-cxx --disable-build-poststage1-with-cxx )
899 fi
900
901 ### Cross-compiler options
902 if is_crosscompile ; then
903 # Enable build warnings by default with cross-compilers when system
904 # paths are included (e.g. via -I flags).
905 confgcc+=( --enable-poison-system-directories )
906
907 # When building a stage1 cross-compiler (just C compiler), we have to
908 # disable a bunch of features or gcc goes boom
909 local needed_libc=""
910 case ${CTARGET} in
911 *-linux) needed_libc=no-fucking-clue;;
912 *-dietlibc) needed_libc=dietlibc;;
913 *-elf|*-eabi) needed_libc=newlib;;
914 *-freebsd*) needed_libc=freebsd-lib;;
915 *-gnu*) needed_libc=glibc;;
916 *-klibc) needed_libc=klibc;;
917 *-musl*) needed_libc=musl;;
918 *-uclibc*)
919 if ! echo '#include <features.h>' | \
920 $(tc-getCPP ${CTARGET}) -E -dD - 2>/dev/null | \
921 grep -q __HAVE_SHARED__
922 then #291870
923 confgcc+=( --disable-shared )
924 fi
925 needed_libc=uclibc
926 ;;
927 *-cygwin) needed_libc=cygwin;;
928 x86_64-*-mingw*|\
929 *-w64-mingw*) needed_libc=mingw64-runtime;;
930 mingw*|*-mingw*) needed_libc=mingw-runtime;;
931 avr) confgcc+=( --enable-shared --disable-threads );;
932 esac
933 if [[ -n ${needed_libc} ]] ; then
934 local confgcc_no_libc=( --disable-shared )
935 tc_version_is_at_least 4.8 && confgcc_no_libc+=( --disable-libatomic )
936 if ! has_version ${CATEGORY}/${needed_libc} ; then
937 confgcc+=(
938 "${confgcc_no_libc[@]}"
939 --disable-threads
940 --without-headers
941 )
942 elif built_with_use --hidden --missing false ${CATEGORY}/${needed_libc} crosscompile_opts_headers-only ; then
943 confgcc+=(
944 "${confgcc_no_libc[@]}"
945 --with-sysroot=${PREFIX}/${CTARGET}
946 )
947 else
948 confgcc+=( --with-sysroot=${PREFIX}/${CTARGET} )
949 fi
950 fi
951
952 tc_version_is_at_least 4.2 && confgcc+=( --disable-bootstrap )
953 else
954 if tc-is-static-only ; then
955 confgcc+=( --disable-shared )
956 else
957 confgcc+=( --enable-shared )
958 fi
959 case ${CHOST} in
960 mingw*|*-mingw*|*-cygwin)
961 confgcc+=( --enable-threads=win32 ) ;;
962 *)
963 confgcc+=( --enable-threads=posix ) ;;
964 esac
965 fi
966
967 # __cxa_atexit is "essential for fully standards-compliant handling of
968 # destructors", but apparently requires glibc.
969 case ${CTARGET} in
970 *-uclibc*)
971 confgcc+=(
972 --disable-__cxa_atexit
973 $(use_enable nptl tls)
974 )
975 tc_version_is_between 3.3 3.4 && confgcc+=( --enable-sjlj-exceptions )
976 if tc_version_is_between 3.4 4.3 ; then
977 confgcc+=( --enable-clocale=uclibc )
978 fi
979 ;;
980 *-elf|*-eabi)
981 confgcc+=( --with-newlib )
982 ;;
983 *-gnu*)
984 confgcc+=(
985 --enable-__cxa_atexit
986 --enable-clocale=gnu
987 )
988 ;;
989 *-freebsd*)
990 confgcc+=( --enable-__cxa_atexit )
991 ;;
992 *-solaris*)
993 confgcc+=( --enable-__cxa_atexit )
994 ;;
995 esac
996
997 ### arch options
998
999 gcc-multilib-configure
1000
1001 # ppc altivec support
1002 confgcc+=( $(use_enable altivec) )
1003
1004 # gcc has fixed-point arithmetic support in 4.3 for mips targets that can
1005 # significantly increase compile time by several hours. This will allow
1006 # users to control this feature in the event they need the support.
1007 tc_version_is_at_least 4.3 && confgcc+=( $(use_enable fixed-point) )
1008
1009 case $(tc-is-softfloat) in
1010 yes) confgcc+=( --with-float=soft ) ;;
1011 softfp) confgcc+=( --with-float=softfp ) ;;
1012 *)
1013 # If they've explicitly opt-ed in, do hardfloat,
1014 # otherwise let the gcc default kick in.
1015 [[ ${CTARGET//_/-} == *-hardfloat-* ]] \
1016 && confgcc+=( --with-float=hard )
1017 ;;
1018 esac
1019
1020 local with_abi_map=()
1021 case $(tc-arch) in
1022 arm) #264534 #414395
1023 local a arm_arch=${CTARGET%%-*}
1024 # Remove trailing endian variations first: eb el be bl b l
1025 for a in e{b,l} {b,l}e b l ; do
1026 if [[ ${arm_arch} == *${a} ]] ; then
1027 arm_arch=${arm_arch%${a}}
1028 break
1029 fi
1030 done
1031 # Convert armv7{a,r,m} to armv7-{a,r,m}
1032 [[ ${arm_arch} == armv7? ]] && arm_arch=${arm_arch/7/7-}
1033 # See if this is a valid --with-arch flag
1034 if (srcdir=${S}/gcc target=${CTARGET} with_arch=${arm_arch};
1035 . "${srcdir}"/config.gcc) &>/dev/null
1036 then
1037 confgcc+=( --with-arch=${arm_arch} )
1038 fi
1039
1040 # Make default mode thumb for microcontroller classes #418209
1041 [[ ${arm_arch} == *-m ]] && confgcc+=( --with-mode=thumb )
1042
1043 # Enable hardvfp
1044 if [[ $(tc-is-softfloat) == "no" ]] && \
1045 [[ ${CTARGET} == armv[67]* ]] && \
1046 tc_version_is_at_least 4.5
1047 then
1048 # Follow the new arm hardfp distro standard by default
1049 confgcc+=( --with-float=hard )
1050 case ${CTARGET} in
1051 armv6*) confgcc+=( --with-fpu=vfp ) ;;
1052 armv7*) confgcc+=( --with-fpu=vfpv3-d16 ) ;;
1053 esac
1054 fi
1055 ;;
1056 mips)
1057 # Add --with-abi flags to set default ABI
1058 confgcc+=( --with-abi=$(gcc-abi-map ${TARGET_DEFAULT_ABI}) )
1059 ;;
1060 amd64)
1061 # drop the older/ABI checks once this get's merged into some
1062 # version of gcc upstream
1063 if tc_version_is_at_least 4.7 && has x32 $(get_all_abis TARGET) ; then
1064 confgcc+=( --with-abi=$(gcc-abi-map ${TARGET_DEFAULT_ABI}) )
1065 fi
1066 ;;
1067 x86)
1068 # Default arch for x86 is normally i386, lets give it a bump
1069 # since glibc will do so based on CTARGET anyways
1070 confgcc+=( --with-arch=${CTARGET%%-*} )
1071 ;;
1072 hppa)
1073 # Enable sjlj exceptions for backward compatibility on hppa
1074 [[ ${GCCMAJOR} == "3" ]] && confgcc+=( --enable-sjlj-exceptions )
1075 ;;
1076 ppc)
1077 # Set up defaults based on current CFLAGS
1078 is-flagq -mfloat-gprs=double && confgcc+=( --enable-e500-double )
1079 [[ ${CTARGET//_/-} == *-e500v2-* ]] && confgcc+=( --enable-e500-double )
1080 ;;
1081 esac
1082
1083 # if the target can do biarch (-m32/-m64), enable it. overhead should
1084 # be small, and should simplify building of 64bit kernels in a 32bit
1085 # userland by not needing sys-devel/kgcc64. #349405
1086 case $(tc-arch) in
1087 ppc|ppc64) tc_version_is_at_least 3.4 && confgcc+=( --enable-targets=all ) ;;
1088 sparc) tc_version_is_at_least 4.4 && confgcc+=( --enable-targets=all ) ;;
1089 amd64|x86) tc_version_is_at_least 4.3 && confgcc+=( --enable-targets=all ) ;;
1090 esac
1091
1092 # On Darwin we need libdir to be set in order to get correct install names
1093 # for things like libobjc-gnu, libgcj and libfortran. If we enable it on
1094 # non-Darwin we screw up the behaviour this eclass relies on. We in
1095 # particular need this over --libdir for bug #255315.
1096 [[ ${CTARGET} == *-darwin* ]] && \
1097 confgcc+=( --enable-version-specific-runtime-libs )
1098
1099 ### library options
1100
1101 if ! is_gcj ; then
1102 confgcc+=( --disable-libgcj )
1103 elif use awt ; then
1104 confgcc+=( --enable-java-awt=gtk )
1105 fi
1106
1107 if tc_version_is_at_least 4.2 ; then
1108 if in_iuse openmp ; then
1109 # Make sure target has pthreads support. #326757 #335883
1110 # There shouldn't be a chicken & egg problem here as openmp won't
1111 # build without a C library, and you can't build that w/out
1112 # already having a compiler ...
1113 if ! is_crosscompile || \
1114 $(tc-getCPP ${CTARGET}) -E - <<<"#include <pthread.h>" >& /dev/null
1115 then
1116 confgcc+=( $(use_enable openmp libgomp) )
1117 else
1118 # Force disable as the configure script can be dumb #359855
1119 confgcc+=( --disable-libgomp )
1120 fi
1121 else
1122 # For gcc variants where we don't want openmp (e.g. kgcc)
1123 confgcc+=( --disable-libgomp )
1124 fi
1125 fi
1126
1127 if tc_version_is_at_least 4.0 ; then
1128 if in_iuse mudflap ; then
1129 confgcc+=( $(use_enable mudflap libmudflap) )
1130 else
1131 confgcc+=( --disable-libmudflap )
1132 fi
1133
1134 if use_if_iuse libssp ; then
1135 confgcc+=( --enable-libssp )
1136 else
1137 export gcc_cv_libc_provides_ssp=yes
1138 confgcc+=( --disable-libssp )
1139 fi
1140
1141 fi
1142
1143 # newer gcc's come with libquadmath, but only fortran uses
1144 # it, so auto punt it when we don't care
1145 if tc_version_is_at_least 4.6 && ! is_fortran ; then
1146 confgcc+=( --disable-libquadmath )
1147 fi
1148
1149 if tc_version_is_at_least 4.6 ; then
1150 confgcc+=( --enable-lto )
1151 elif tc_version_is_at_least 4.5 ; then
1152 confgcc+=( --disable-lto )
1153 fi
1154
1155 # graphite was added in 4.4 but we only support it in 4.6+ due to external
1156 # library issues. 4.6/4.7 uses cloog-ppl which is a fork of CLooG with a
1157 # PPL backend. 4.8+ uses upstream CLooG with the ISL backend. We install
1158 # cloog-ppl into a non-standard location to prevent collisions.
1159 if tc_version_is_at_least 4.8 ; then
1160 confgcc+=( $(use_with graphite cloog) )
1161 use graphite && confgcc+=( --disable-isl-version-check )
1162 elif tc_version_is_at_least 4.6 ; then
1163 confgcc+=( $(use_with graphite cloog) )
1164 confgcc+=( $(use_with graphite ppl) )
1165 use graphite && confgcc+=( --with-cloog-include=/usr/include/cloog-ppl )
1166 use graphite && confgcc+=( --disable-ppl-version-check )
1167 elif tc_version_is_at_least 4.4 ; then
1168 confgcc+=( --without-cloog )
1169 confgcc+=( --without-ppl )
1170 fi
1171
1172 # Disable gcc info regeneration -- it ships with generated info pages
1173 # already. Our custom version/urls/etc... trigger it. #464008
1174 export gcc_cv_prog_makeinfo_modern=no
1175
1176 # Do not let the X detection get in our way. We know things can be found
1177 # via system paths, so no need to hardcode things that'll break multilib.
1178 # Older gcc versions will detect ac_x_libraries=/usr/lib64 which ends up
1179 # killing the 32bit builds which want /usr/lib.
1180 export ac_cv_have_x='have_x=yes ac_x_includes= ac_x_libraries='
1181
1182 confgcc+=( "$@" ${EXTRA_ECONF} )
1183
1184 # Nothing wrong with a good dose of verbosity
1185 echo
1186 einfo "PREFIX: ${PREFIX}"
1187 einfo "BINPATH: ${BINPATH}"
1188 einfo "LIBPATH: ${LIBPATH}"
1189 einfo "DATAPATH: ${DATAPATH}"
1190 einfo "STDCXX_INCDIR: ${STDCXX_INCDIR}"
1191 echo
1192 einfo "Languages: ${GCC_LANG}"
1193 echo
1194 einfo "Configuring GCC with: ${confgcc[@]//--/\n\t--}"
1195 echo
1196
1197 # Build in a separate build tree
1198 mkdir -p "${WORKDIR}"/build
1199 pushd "${WORKDIR}"/build > /dev/null
1200
1201 # and now to do the actual configuration
1202 addwrite /dev/zero
1203 echo "${S}"/configure "${confgcc[@]}"
1204 "${S}"/configure "${confgcc[@]}" || die "failed to run configure"
1205
1206 # return to whatever directory we were in before
1207 popd > /dev/null
1208 }
1209
1210 # Replace -m flags unsupported by the version being built with the best
1211 # available equivalent
1212 downgrade_arch_flags() {
1213 local arch bver i isa myarch mytune rep ver
1214
1215 bver=${1:-${GCC_BRANCH_VER}}
1216 [[ $(gcc-version) < ${bver} ]] && return 0
1217 [[ $(tc-arch) != amd64 && $(tc-arch) != x86 ]] && return 0
1218
1219 myarch=$(get-flag march)
1220 mytune=$(get-flag mtune)
1221
1222 # If -march=native isn't supported we have to tease out the actual arch
1223 if [[ ${myarch} == native || ${mytune} == native ]] ; then
1224 if [[ ${bver} < 4.2 ]] ; then
1225 arch=$(echo "" | $(tc-getCC) -march=native -v -E - 2>&1 \
1226 | grep cc1 | sed -e 's:.*-march=\([^ ]*\).*:\1:')
1227 replace-cpu-flags native ${arch}
1228 fi
1229 fi
1230
1231 # Handle special -mtune flags
1232 [[ ${mytune} == intel && ${bver} < 4.9 ]] && replace-cpu-flags intel generic
1233 [[ ${mytune} == generic && ${bver} < 4.2 ]] && filter-flags '-mtune=*'
1234 [[ ${mytune} == x86-64 ]] && filter-flags '-mtune=*'
1235 [[ ${bver} < 3.4 ]] && filter-flags '-mtune=*'
1236
1237 declare -a archlist
1238 # "arch" "added" "replacement"
1239 archlist=("bdver4 4.9 bdver3")
1240 archlist+=("bonnell 4.9 atom")
1241 archlist+=("broadwell 4.9 core-avx2")
1242 archlist+=("haswell 4.9 core-avx2")
1243 archlist+=("ivybridge 4.9 core-avx-i")
1244 archlist+=("nehalem 4.9 corei7")
1245 archlist+=("sandybridge 4.9 corei7-avx")
1246 archlist+=("silvermont 4.9 corei7")
1247 archlist+=("westmere 4.9 corei7")
1248 archlist+=("bdver3 4.8 bdver2")
1249 archlist+=("btver2 4.8 btver1")
1250 archlist+=("bdver2 4.7 bdver1")
1251 archlist+=("core-avx2 4.7 core-avx-i")
1252 archlist+=("bdver1 4.6 amdfam10")
1253 archlist+=("btver1 4.6 amdfam10")
1254 archlist+=("core-avx-i 4.6 core2")
1255 archlist+=("corei7 4.6 core2")
1256 archlist+=("corei7-avx 4.6 core2")
1257 archlist+=("atom 4.5 core2")
1258 archlist+=("amdfam10 4.3 k8")
1259 archlist+=("athlon64-sse3 4.3 k8")
1260 archlist+=("barcelona 4.3 k8")
1261 archlist+=("core2 4.3 nocona")
1262 archlist+=("geode 4.3 k6-2") # gcc.gnu.org/PR41989#c22
1263 archlist+=("k8-sse3 4.3 k8")
1264 archlist+=("opteron-sse3 4.3 k8")
1265 archlist+=("athlon-fx 3.4 x86-64")
1266 archlist+=("athlon64 3.4 x86-64")
1267 archlist+=("c3-2 3.4 c3")
1268 archlist+=("k8 3.4 x86-64")
1269 archlist+=("opteron 3.4 x86-64")
1270 archlist+=("pentium-m 3.4 pentium3")
1271 archlist+=("pentium3m 3.4 pentium3")
1272 archlist+=("pentium4m 3.4 pentium4")
1273
1274 myarch=$(get-flag march)
1275 mytune=$(get-flag mtune)
1276
1277 for ((i=0; i < ${#archlist[@]}; i++)) ; do
1278 arch=${archlist[i]%% *}
1279 ver=${archlist[i]#* } ver=${ver% *}
1280 rep=${archlist[i]##* }
1281
1282 [[ ${myarch} != ${arch} && ${mytune} != ${arch} ]] && continue
1283
1284 if [[ ${ver} > ${bver} ]] ; then
1285 einfo "Replacing ${myarch} (added in ${ver}) with ${rep}..."
1286 [[ ${myarch} == ${arch} ]] && replace-cpu-flags ${myarch} ${rep}
1287 [[ ${mytune} == ${arch} ]] && replace-cpu-flags ${mytune} ${rep}
1288 downgrade_arch_flags ${1:-${GCC_BRANCH_VER}}
1289 break
1290 else
1291 break
1292 fi
1293 done
1294
1295 declare -a isalist
1296 # we only check -mno* here since -m* get removed by strip-flags later on
1297 isalist=("-mno-sha 4.9")
1298 isalist+=("-mno-avx512pf 4.9")
1299 isalist+=("-mno-avx512f 4.9")
1300 isalist+=("-mno-avx512er 4.9")
1301 isalist+=("-mno-avx512cd 4.9")
1302 isalist+=("-mno-xsaveopt 4.8")
1303 isalist+=("-mno-xsave 4.8")
1304 isalist+=("-mno-rtm 4.8")
1305 isalist+=("-mno-fxsr 4.8")
1306 isalist+=("-mno-lzcnt 4.7")
1307 isalist+=("-mno-bmi2 4.7")
1308 isalist+=("-mno-avx2 4.7")
1309 isalist+=("-mno-tbm 4.6")
1310 isalist+=("-mno-rdrnd 4.6")
1311 isalist+=("-mno-fsgsbase 4.6")
1312 isalist+=("-mno-f16c 4.6")
1313 isalist+=("-mno-bmi 4.6")
1314 isalist+=("-mno-xop 4.5")
1315 isalist+=("-mno-movbe 4.5")
1316 isalist+=("-mno-lwp 4.5")
1317 isalist+=("-mno-fma4 4.5")
1318 isalist+=("-mno-pclmul 4.4")
1319 isalist+=("-mno-fma 4.4")
1320 isalist+=("-mno-avx 4.4")
1321 isalist+=("-mno-aes 4.4")
1322 isalist+=("-mno-ssse3 4.3")
1323 isalist+=("-mno-sse4a 4.3")
1324 isalist+=("-mno-sse4 4.3")
1325 isalist+=("-mno-sse4.2 4.3")
1326 isalist+=("-mno-sse4.1 4.3")
1327 isalist+=("-mno-popcnt 4.3")
1328 isalist+=("-mno-abm 4.3")
1329
1330 for ((i=0; i < ${#isalist[@]}; i++)) ; do
1331 isa=${isalist[i]%% *}
1332 ver=${isalist[i]##* }
1333 [[ ${ver} > ${bver} ]] && filter-flags ${isa}
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
1346 if tc_version_is_between 3.2 3.4 ; then
1347 # XXX: this is so outdated it's barely useful, but it don't hurt...
1348 replace-cpu-flags G3 750
1349 replace-cpu-flags G4 7400
1350 replace-cpu-flags G5 7400
1351
1352 # XXX: should add a sed or something to query all supported flags
1353 # from the gcc source and trim everything else ...
1354 filter-flags -f{no-,}unit-at-a-time -f{no-,}web -mno-tls-direct-seg-refs
1355 filter-flags -f{no-,}stack-protector{,-all}
1356 filter-flags -fvisibility-inlines-hidden -fvisibility=hidden
1357 fi
1358
1359 if tc_version_is_at_least 3.4 ; then
1360 case $(tc-arch) in
1361 amd64|x86)
1362 filter-flags '-mcpu=*'
1363
1364 tc_version_is_between 4.4 4.5 && append-flags -mno-avx # 357287
1365
1366 if tc_version_is_between 4.6 4.7 ; then
1367 # https://bugs.gentoo.org/411333
1368 # https://bugs.gentoo.org/466454
1369 replace-cpu-flags c3-2 pentium2 pentium3 pentium3m pentium-m i686
1370 fi
1371 ;;
1372 alpha)
1373 # https://bugs.gentoo.org/454426
1374 append-ldflags -Wl,--no-relax
1375 ;;
1376 sparc)
1377 # temporary workaround for random ICEs reproduced by multiple users
1378 # https://bugs.gentoo.org/457062
1379 tc_version_is_between 4.6 4.8 && MAKEOPTS+=" -j1"
1380 ;;
1381 *-macos)
1382 # http://gcc.gnu.org/PR25127
1383 tc_version_is_between 4.0 4.2 && \
1384 filter-flags '-mcpu=*' '-march=*' '-mtune=*'
1385 ;;
1386 esac
1387 fi
1388
1389 strip-unsupported-flags
1390
1391 # these are set here so we have something sane at configure time
1392 if is_crosscompile ; then
1393 # Set this to something sane for both native and target
1394 CFLAGS="-O2 -pipe"
1395 FFLAGS=${CFLAGS}
1396 FCFLAGS=${CFLAGS}
1397
1398 local VAR="CFLAGS_"${CTARGET//-/_}
1399 CXXFLAGS=${!VAR}
1400 fi
1401
1402 export GCJFLAGS=${GCJFLAGS:-${CFLAGS}}
1403 }
1404
1405 setup_minispecs_gcc_build_specs() {
1406 # Setup the "build.specs" file for gcc 4.3 to use when building.
1407 if hardened_gcc_works pie ; then
1408 cat "${WORKDIR}"/specs/pie.specs >> "${WORKDIR}"/build.specs
1409 fi
1410 if hardened_gcc_works ssp ; then
1411 for s in ssp sspall ; do
1412 cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs
1413 done
1414 fi
1415 for s in nostrict znow ; do
1416 cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs
1417 done
1418 export GCC_SPECS="${WORKDIR}"/build.specs
1419 }
1420
1421 gcc-multilib-configure() {
1422 if ! is_multilib ; then
1423 confgcc+=( --disable-multilib )
1424 # Fun times: if we are building for a target that has multiple
1425 # possible ABI formats, and the user has told us to pick one
1426 # that isn't the default, then not specifying it via the list
1427 # below will break that on us.
1428 else
1429 confgcc+=( --enable-multilib )
1430 fi
1431
1432 # translate our notion of multilibs into gcc's
1433 local abi list
1434 for abi in $(get_all_abis TARGET) ; do
1435 local l=$(gcc-abi-map ${abi})
1436 [[ -n ${l} ]] && list+=",${l}"
1437 done
1438 if [[ -n ${list} ]] ; then
1439 case ${CTARGET} in
1440 x86_64*)
1441 tc_version_is_at_least 4.7 && confgcc+=( --with-multilib-list=${list:1} )
1442 ;;
1443 esac
1444 fi
1445 }
1446
1447 gcc-abi-map() {
1448 # Convert the ABI name we use in Gentoo to what gcc uses
1449 local map=()
1450 case ${CTARGET} in
1451 mips*) map=("o32 32" "n32 n32" "n64 64") ;;
1452 x86_64*) map=("amd64 m64" "x86 m32" "x32 mx32") ;;
1453 esac
1454
1455 local m
1456 for m in "${map[@]}" ; do
1457 l=( ${m} )
1458 [[ $1 == ${l[0]} ]] && echo ${l[1]} && break
1459 done
1460 }
1461
1462 #----> src_compile <----
1463
1464 toolchain_src_compile() {
1465 case ${EAPI:-0} in
1466 0|1) toolchain_src_configure ;;
1467 esac
1468
1469 touch "${S}"/gcc/c-gperf.h
1470
1471 # Do not make manpages if we do not have perl ...
1472 [[ ! -x /usr/bin/perl ]] \
1473 && find "${WORKDIR}"/build -name '*.[17]' | xargs touch
1474
1475 einfo "Compiling ${PN} ..."
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 # profiledbootstrap, or bootstrap-lean depending on CTARGET and arch. An
1483 # example of how to use this function:
1484 #
1485 # gcc_do_make all-target-libstdc++-v3
1486 #
1487 # Set make target to $1 if passed
1488 [[ -n ${1} ]] && GCC_MAKE_TARGET=${1}
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 # the gcc docs state that parallel make isnt supported for the
1499 # profiledbootstrap target, as collisions in profile collecting may occur.
1500 # boundschecking also seems to introduce parallel build issues.
1501 if [[ ${GCC_MAKE_TARGET} == "profiledbootstrap" ]] ||
1502 use_if_iuse boundschecking
1503 then
1504 export MAKEOPTS="${MAKEOPTS} -j1"
1505 fi
1506
1507 if [[ ${GCC_MAKE_TARGET} == "all" ]] ; then
1508 STAGE1_CFLAGS=${STAGE1_CFLAGS-"${CFLAGS}"}
1509 elif [[ $(gcc-version) == "3.4" && ${GCC_BRANCH_VER} == "3.4" ]] && gcc-specs-ssp ; then
1510 # See bug #79852
1511 STAGE1_CFLAGS=${STAGE1_CFLAGS-"-O2"}
1512 fi
1513
1514 if is_crosscompile; then
1515 # In 3.4, BOOT_CFLAGS is never used on a crosscompile...
1516 # but I'll leave this in anyways as someone might have had
1517 # some reason for putting it in here... --eradicator
1518 BOOT_CFLAGS=${BOOT_CFLAGS-"-O2"}
1519 else
1520 # we only want to use the system's CFLAGS if not building a
1521 # cross-compiler.
1522 BOOT_CFLAGS=${BOOT_CFLAGS-"$(get_abi_CFLAGS ${TARGET_DEFAULT_ABI}) ${CFLAGS}"}
1523 fi
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 is_treelang() {
2116 use_if_iuse boundschecking && return 1 #260532
2117 is_crosscompile && return 1 #199924
2118 gcc-lang-supported treelang || return 1
2119 #use treelang
2120 return 0
2121 }
2122
2123 # Grab a variable from the build system (taken from linux-info.eclass)
2124 get_make_var() {
2125 local var=$1 makefile=${2:-${WORKDIR}/build/Makefile}
2126 echo -e "e:\\n\\t@echo \$(${var})\\ninclude ${makefile}" | \
2127 r=${makefile%/*} emake --no-print-directory -s -f - 2>/dev/null
2128 }
2129
2130 XGCC() { get_make_var GCC_FOR_TARGET ; }
2131
2132 # The gentoo piessp patches allow for 3 configurations:
2133 # 1) PIE+SSP by default
2134 # 2) PIE by default
2135 # 3) SSP by default
2136 hardened_gcc_works() {
2137 if [[ $1 == "pie" ]] ; then
2138 # $gcc_cv_ld_pie is unreliable as it simply take the output of
2139 # `ld --help | grep -- -pie`, that reports the option in all cases, also if
2140 # the loader doesn't actually load the resulting executables.
2141 # To avoid breakage, blacklist FreeBSD here at least
2142 [[ ${CTARGET} == *-freebsd* ]] && return 1
2143
2144 want_pie || return 1
2145 use_if_iuse nopie && return 1
2146 hardened_gcc_is_stable pie
2147 return $?
2148 elif [[ $1 == "ssp" ]] ; then
2149 [[ -n ${SPECS_VER} ]] || return 1
2150 use_if_iuse nossp && return 1
2151 hardened_gcc_is_stable ssp
2152 return $?
2153 else
2154 # laziness ;)
2155 hardened_gcc_works pie || return 1
2156 hardened_gcc_works ssp || return 1
2157 return 0
2158 fi
2159 }
2160
2161 hardened_gcc_is_stable() {
2162 local tocheck
2163 if [[ $1 == "pie" ]] ; then
2164 if [[ ${CTARGET} == *-uclibc* ]] ; then
2165 tocheck=${PIE_UCLIBC_STABLE}
2166 else
2167 tocheck=${PIE_GLIBC_STABLE}
2168 fi
2169 elif [[ $1 == "ssp" ]] ; then
2170 if [[ ${CTARGET} == *-uclibc* ]] ; then
2171 tocheck=${SSP_UCLIBC_STABLE}
2172 else
2173 tocheck=${SSP_STABLE}
2174 fi
2175 else
2176 die "hardened_gcc_stable needs to be called with pie or ssp"
2177 fi
2178
2179 has $(tc-arch) ${tocheck} && return 0
2180 return 1
2181 }
2182
2183 want_minispecs() {
2184 if tc_version_is_at_least 4.3.2 && use hardened ; then
2185 if ! want_pie ; then
2186 ewarn "PIE_VER or SPECS_VER is not defined in the GCC ebuild."
2187 elif use vanilla ; then
2188 ewarn "You will not get hardened features if you have the vanilla USE-flag."
2189 elif use nopie && use nossp ; then
2190 ewarn "You will not get hardened features if you have the nopie and nossp USE-flag."
2191 elif ! hardened_gcc_works ; then
2192 ewarn "Your $(tc-arch) arch is not supported."
2193 else
2194 return 0
2195 fi
2196 ewarn "Hope you know what you are doing. Hardened will not work."
2197 return 0
2198 fi
2199 return 1
2200 }
2201
2202 want_pie() {
2203 ! use hardened && [[ -n ${PIE_VER} ]] && use nopie && return 1
2204 [[ -n ${PIE_VER} ]] && [[ -n ${SPECS_VER} ]] && return 0
2205 tc_version_is_at_least 4.3.2 && return 1
2206 [[ -z ${PIE_VER} ]] && return 1
2207 use !nopie && return 0
2208 return 1
2209 }
2210
2211 has toolchain_death_notice ${EBUILD_DEATH_HOOKS} || EBUILD_DEATH_HOOKS+=" toolchain_death_notice"
2212 toolchain_death_notice() {
2213 if [[ -e "${WORKDIR}"/build ]] ; then
2214 pushd "${WORKDIR}"/build >/dev/null
2215 (echo '' | $(tc-getCC ${CTARGET}) ${CFLAGS} -v -E - 2>&1) > gccinfo.log
2216 [[ -e "${T}"/build.log ]] && cp "${T}"/build.log .
2217 tar jcf "${WORKDIR}"/gcc-build-logs.tar.bz2 \
2218 gccinfo.log build.log $(find -name config.log)
2219 rm gccinfo.log build.log
2220 eerror
2221 eerror "Please include ${WORKDIR}/gcc-build-logs.tar.bz2 in your bug report."
2222 eerror
2223 popd >/dev/null
2224 fi
2225 }

  ViewVC Help
Powered by ViewVC 1.1.20