/[gentoo-alt]/trunk/prefix/eclass/toolchain.eclass
Gentoo

Contents of /trunk/prefix/eclass/toolchain.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1377 - (show annotations) (download)
Thu Sep 7 20:42:47 2006 UTC (7 years, 10 months ago) by grobian
File size: 77382 byte(s)
use prefix in the generated env.d file


1 # Copyright 1999-2006 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.305 2006/08/27 20:53:11 vapier Exp $
4
5 HOMEPAGE="http://gcc.gnu.org/"
6 LICENSE="GPL-2 LGPL-2.1"
7 RESTRICT="nostrip" # cross-compilers need controlled stripping
8
9 #---->> eclass stuff <<----
10 inherit eutils versionator libtool toolchain-funcs flag-o-matic gnuconfig multilib fixheadtails
11
12 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_test pkg_preinst src_install pkg_postinst pkg_prerm pkg_postrm
13 DESCRIPTION="Based on the ${ECLASS} eclass"
14
15 FEATURES=${FEATURES/multilib-strict/}
16
17 toolchain_pkg_setup() {
18 gcc_pkg_setup
19 }
20 toolchain_src_unpack() {
21 gcc_src_unpack
22 }
23 toolchain_src_compile() {
24 gcc_src_compile
25 }
26 toolchain_src_test() {
27 gcc_src_test
28 }
29 toolchain_pkg_preinst() {
30 ${ETYPE}_pkg_preinst
31 }
32 toolchain_src_install() {
33 ${ETYPE}_src_install
34 }
35 toolchain_pkg_postinst() {
36 ${ETYPE}_pkg_postinst
37 }
38 toolchain_pkg_prerm() {
39 ${ETYPE}_pkg_prerm
40 }
41 toolchain_pkg_postrm() {
42 ${ETYPE}_pkg_postrm
43 }
44 #----<< eclass stuff >>----
45
46
47 #---->> globals <<----
48 export CTARGET=${CTARGET:-${CHOST}}
49 if [[ ${CTARGET} = ${CHOST} ]] ; then
50 if [[ ${CATEGORY/cross-} != ${CATEGORY} ]] ; then
51 export CTARGET=${CATEGORY/cross-}
52 fi
53 fi
54 is_crosscompile() {
55 [[ ${CHOST} != ${CTARGET} ]]
56 }
57
58 tc_version_is_at_least() { version_is_at_least "$1" "${2:-${GCC_PV}}" ; }
59
60
61 GCC_PV=${TOOLCHAIN_GCC_PV:-${PV}}
62 GCC_PVR=${GCC_PV}
63 [[ ${PR} != "r0" ]] && GCC_PVR=${GCC_PVR}-${PR}
64 GCC_RELEASE_VER=$(get_version_component_range 1-3 ${GCC_PV})
65 GCC_BRANCH_VER=$(get_version_component_range 1-2 ${GCC_PV})
66 GCCMAJOR=$(get_version_component_range 1 ${GCC_PV})
67 GCCMINOR=$(get_version_component_range 2 ${GCC_PV})
68 GCCMICRO=$(get_version_component_range 3 ${GCC_PV})
69 [[ ${BRANCH_UPDATE-notset} == "notset" ]] && BRANCH_UPDATE=$(get_version_component_range 4 ${GCC_PV})
70
71 # According to gcc/c-cppbuiltin.c, GCC_CONFIG_VER MUST match this regex.
72 # ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)?
73 GCC_CONFIG_VER=${GCC_CONFIG_VER:-$(replace_version_separator 3 '-' ${GCC_PV})}
74
75 # Pre-release support
76 if [[ ${GCC_PV} != ${GCC_PV/_pre/-} ]] ; then
77 PRERELEASE=${GCC_PV/_pre/-}
78 fi
79 # make _alpha and _beta ebuilds automatically use a snapshot
80 if [[ ${GCC_PV} != ${GCC_PV/_alpha/} ]] ; then
81 SNAPSHOT=${GCC_BRANCH_VER}-${GCC_PV##*_alpha}
82 elif [[ ${GCC_PV} != ${GCC_PV/_beta/} ]] ; then
83 SNAPSHOT=${GCC_BRANCH_VER}-${GCC_PV##*_beta}
84 fi
85 export GCC_FILESDIR=${GCC_FILESDIR:-${FILESDIR}}
86
87 if [[ ${ETYPE} == "gcc-library" ]] ; then
88 GCC_VAR_TYPE=${GCC_VAR_TYPE:-non-versioned}
89 GCC_LIB_COMPAT_ONLY=${GCC_LIB_COMPAT_ONLY:-true}
90 GCC_TARGET_NO_MULTILIB=${GCC_TARGET_NO_MULTILIB:-true}
91 else
92 GCC_VAR_TYPE=${GCC_VAR_TYPE:-versioned}
93 GCC_LIB_COMPAT_ONLY="false"
94 GCC_TARGET_NO_MULTILIB=${GCC_TARGET_NO_MULTILIB:-false}
95 fi
96
97 PREFIX=${TOOLCHAIN_PREFIX:-/usr}
98
99 if [[ ${GCC_VAR_TYPE} == "versioned" ]] ; then
100 if tc_version_is_at_least 3.4.0 ; then
101 LIBPATH=${TOOLCHAIN_LIBPATH:-${PREFIX}/lib/gcc/${CTARGET}/${GCC_CONFIG_VER}}
102 else
103 LIBPATH=${TOOLCHAIN_LIBPATH:-${PREFIX}/lib/gcc-lib/${CTARGET}/${GCC_CONFIG_VER}}
104 fi
105 LIBEXECPATH=${TOOLCHAIN_LIBEXE:-${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}}
106 INCLUDEPATH=${TOOLCHAIN_INCLUDEPATH:-${LIBPATH}/include}
107 if is_crosscompile ; then
108 BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/${CHOST}/${CTARGET}/gcc-bin/${GCC_CONFIG_VER}}
109 else
110 BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/${CTARGET}/gcc-bin/${GCC_CONFIG_VER}}
111 fi
112 DATAPATH=${TOOLCHAIN_DATAPATH:-${PREFIX}/share/gcc-data/${CTARGET}/${GCC_CONFIG_VER}}
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 elif [[ ${GCC_VAR_TYPE} == "non-versioned" ]] ; then
117 # using non-versioned directories to install gcc, like what is currently
118 # done for ppc64 and 3.3.3_pre, is a BAD IDEA. DO NOT do it!! However...
119 # setting up variables for non-versioned directories might be useful for
120 # specific gcc targets, like libffi. Note that we dont override the value
121 # returned by get_libdir here.
122 LIBPATH=${TOOLCHAIN_LIBPATH:-${PREFIX}/$(get_libdir)}
123 LIBEXECPATH=${TOOLCHAIN_LIBEXE:-${PREFIX}/libexec/gcc}
124 INCLUDEPATH=${TOOLCHAIN_INCLUDEPATH:-${PREFIX}/include}
125 BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/bin}
126 DATAPATH=${TOOLCHAIN_DATAPATH:-${PREFIX}/share}
127 STDCXX_INCDIR=${TOOLCHAIN_STDCXX_INCDIR:-${PREFIX}/include/g++-v3}
128 fi
129
130 #----<< globals >>----
131
132
133 #---->> SLOT+IUSE logic <<----
134 if [[ ${ETYPE} == "gcc-library" ]] ; then
135 IUSE="nls build test"
136 SLOT="${CTARGET}-${SO_VERSION_SLOT:-5}"
137 else
138 IUSE="multislot test"
139
140 if [[ ${PN} != "kgcc64" ]] ; then
141 IUSE="${IUSE} altivec bootstrap build doc fortran gcj gtk hardened multilib nls nocxx objc vanilla"
142 [[ -n ${PIE_VER} ]] && IUSE="${IUSE} nopie"
143 [[ -n ${PP_VER} ]] && IUSE="${IUSE} nossp"
144 [[ -n ${HTB_VER} ]] && IUSE="${IUSE} boundschecking"
145
146 # gcc-{nios2,bfin} don't accept these
147 if [[ ${PN} == "gcc" ]] ; then
148 IUSE="${IUSE} ip28 ip32r10k n32 n64"
149 fi
150
151 # these are features introduced in 4.0
152 if tc_version_is_at_least "4.0" ; then
153 IUSE="${IUSE} objc-gc mudflap"
154
155 if tc_version_is_at_least "4.1" ; then
156 IUSE="${IUSE} objc++"
157 fi
158 fi
159 fi
160
161 # Support upgrade paths here or people get pissed
162 if use multislot ; then
163 SLOT="${CTARGET}-${GCC_CONFIG_VER}"
164 elif is_crosscompile; then
165 SLOT="${CTARGET}-${GCC_BRANCH_VER}"
166 else
167 SLOT="${GCC_BRANCH_VER}"
168 fi
169 fi
170 #----<< SLOT+IUSE logic >>----
171
172
173 #---->> S + SRC_URI essentials <<----
174
175 # This function sets the source directory depending on whether we're using
176 # a prerelease, snapshot, or release tarball. To use it, just set S with:
177 #
178 # S="$(gcc_get_s_dir)"
179 #
180 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
181 #
182 gcc_get_s_dir() {
183 if [[ -n ${PRERELEASE} ]] ; then
184 GCC_S=${WORKDIR}/gcc-${PRERELEASE}
185 elif [[ -n ${SNAPSHOT} ]] ; then
186 GCC_S=${WORKDIR}/gcc-${SNAPSHOT}
187 else
188 GCC_S=${WORKDIR}/gcc-${GCC_RELEASE_VER}
189 fi
190
191 echo "${GCC_S}"
192 }
193
194 # This function handles the basics of setting the SRC_URI for a gcc ebuild.
195 # To use, set SRC_URI with:
196 #
197 # SRC_URI="$(get_gcc_src_uri)"
198 #
199 # Other than the variables normally set by portage, this function's behavior
200 # can be altered by setting the following:
201 #
202 # SNAPSHOT
203 # If set, this variable signals that we should be using a snapshot
204 # of gcc from ftp://sources.redhat.com/pub/gcc/snapshots/. It is
205 # expected to be in the format "YYYY-MM-DD". Note that if the ebuild
206 # has a _pre suffix, this variable is ignored and the prerelease
207 # tarball is used instead.
208 #
209 # BRANCH_UPDATE
210 # If set, this variable signals that we should be using the main
211 # release tarball (determined by ebuild version) and applying a
212 # CVS branch update patch against it. The location of this branch
213 # update patch is assumed to be in ${GENTOO_TOOLCHAIN_BASE_URI}.
214 # Just like with SNAPSHOT, this variable is ignored if the ebuild
215 # has a _pre suffix.
216 #
217 # PATCH_VER
218 # PATCH_GCC_VER
219 # This should be set to the version of the gentoo patch tarball.
220 # The resulting filename of this tarball will be:
221 # gcc-${PATCH_GCC_VER:-${GCC_RELEASE_VER}}-patches-${PATCH_VER}.tar.bz2
222 #
223 # PIE_VER
224 # PIE_GCC_VER
225 # obsoleted: PIE_CORE
226 # These variables control patching in various updates for the logic
227 # controlling Position Independant Executables. PIE_VER is expected
228 # to be the version of this patch, PIE_GCC_VER the gcc version of
229 # the patch, and PIE_CORE (obsoleted) the actual filename of the patch.
230 # An example:
231 # PIE_VER="8.7.6.5"
232 # PIE_GCC_VER="3.4.0"
233 # The resulting filename of this tarball will be:
234 # gcc-${PIE_GCC_VER:-${GCC_RELEASE_VER}}-piepatches-v${PIE_VER}.tar.bz2
235 # old syntax (do not define PIE_CORE anymore):
236 # PIE_CORE="gcc-3.4.0-piepatches-v${PIE_VER}.tar.bz2"
237 #
238 # PP_VER
239 # PP_GCC_VER
240 # obsoleted: PP_FVER
241 # These variables control patching in stack smashing protection
242 # support. They both control the version of ProPolice to download.
243 #
244 # PP_VER / PP_GCC_VER
245 # Used to roll our own custom tarballs of ssp.
246 # PP_FVER / PP_VER
247 # Used for mirroring ssp straight from IBM.
248 # PP_VER sets the version of the directory in which to find the
249 # patch, and PP_FVER sets the version of the patch itself. For
250 # example:
251 # PP_VER="3_4"
252 # PP_FVER="${PP_VER//_/.}-2"
253 # would download gcc3_4/protector-3.4-2.tar.gz
254 #
255 # HTB_VER
256 # HTB_GCC_VER
257 # These variables control whether or not an ebuild supports Herman
258 # ten Brugge's bounds-checking patches. If you want to use a patch
259 # for an older gcc version with a new gcc, make sure you set
260 # HTB_GCC_VER to that version of gcc.
261 #
262 # MAN_VER
263 # The version of gcc for which we will download manpages. This will
264 # default to ${GCC_RELEASE_VER}, but we may not want to pre-generate man pages
265 # for prerelease test ebuilds for example. This allows you to
266 # continue using pre-generated manpages from the last stable release.
267 # If set to "none", this will prevent the downloading of manpages,
268 # which is useful for individual library targets.
269 #
270 gentoo_urls() {
271 local devspace="HTTP~lv/GCC/URI HTTP~eradicator/gcc/URI HTTP~vapier/dist/URI
272 HTTP~halcy0n/patches/URI"
273 devspace=${devspace//HTTP/http:\/\/dev.gentoo.org\/}
274 echo mirror://gentoo/$1 ${devspace//URI/$1}
275 }
276 get_gcc_src_uri() {
277 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
278 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
279 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
280 export PP_GCC_VER=${PP_GCC_VER:-${GCC_RELEASE_VER}}
281 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
282
283 [[ -n ${PIE_VER} ]] && \
284 PIE_CORE=${PIE_CORE:-gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2}
285
286 # Set where to download gcc itself depending on whether we're using a
287 # prerelease, snapshot, or release tarball.
288 if [[ -n ${PRERELEASE} ]] ; then
289 GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/prerelease-${PRERELEASE}/gcc-${PRERELEASE}.tar.bz2"
290 elif [[ -n ${SNAPSHOT} ]] ; then
291 GCC_SRC_URI="ftp://sources.redhat.com/pub/gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.bz2"
292 else
293 GCC_SRC_URI="mirror://gnu/gcc/gcc-${GCC_PV}/gcc-${GCC_RELEASE_VER}.tar.bz2"
294 # we want all branch updates to be against the main release
295 [[ -n ${BRANCH_UPDATE} ]] && \
296 GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2)"
297 fi
298
299 # propolice aka stack smashing protection
300 if [[ -n ${PP_VER} ]] ; then
301 if [[ -n ${PP_FVER} ]] ; then
302 GCC_SRC_URI="${GCC_SRC_URI}
303 !nossp? (
304 http://www.research.ibm.com/trl/projects/security/ssp/gcc${PP_VER}/protector-${PP_FVER}.tar.gz
305 $(gentoo_urls protector-${PP_FVER}.tar.gz)
306 )"
307 else
308 GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${PP_GCC_VER}-ssp-${PP_VER}.tar.bz2)"
309 fi
310 fi
311
312 # uclibc lovin
313 [[ -n ${UCLIBC_VER} ]] && \
314 GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2)"
315
316 # PERL cannot be present at bootstrap, and is used to build the man pages.
317 # So... lets include some pre-generated ones, shall we?
318 [[ -n ${MAN_VER} ]] && \
319 GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${MAN_VER}-manpages.tar.bz2)"
320
321 # various gentoo patches
322 [[ -n ${PATCH_VER} ]] && \
323 GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2)"
324
325 # strawberry pie, Cappuccino and a Gauloises (it's a good thing)
326 [[ -n ${PIE_VER} ]] && \
327 GCC_SRC_URI="${GCC_SRC_URI} !nopie? ( $(gentoo_urls ${PIE_CORE}) )"
328
329 # gcc bounds checking patch
330 if [[ -n ${HTB_VER} ]] ; then
331 local HTBFILE="bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
332 GCC_SRC_URI="${GCC_SRC_URI}
333 boundschecking? (
334 mirror://sourceforge/boundschecking/${HTBFILE}
335 http://web.inter.nl.net/hcc/Haj.Ten.Brugge/${HTBFILE}
336 $(gentoo_urls ${HTBFILE})
337 )"
338 fi
339
340 echo "${GCC_SRC_URI}"
341 }
342 S=$(gcc_get_s_dir)
343 SRC_URI=$(get_gcc_src_uri)
344 #---->> S + SRC_URI essentials >>----
345
346
347 #---->> support checks <<----
348
349 # Grab a variable from the build system (taken from linux-info.eclass)
350 get_make_var() {
351 local var=$1 makefile=${2:-${WORKDIR}/build/Makefile}
352 echo -e "e:\\n\\t@echo \$(${var})\\ninclude ${makefile}" | \
353 r=${makefile%/*} emake --no-print-directory -s -f - 2>/dev/null
354 }
355 XGCC() { get_make_var GCC_FOR_TARGET ; }
356
357 # The gentoo piessp patches allow for 3 configurations:
358 # 1) PIE+SSP by default
359 # 2) PIE by default
360 # 3) SSP by default
361 hardened_gcc_works() {
362 if [[ $1 == "pie" ]] ; then
363 # $gcc_cv_ld_pie is unreliable as it simply take the output of
364 # `ld --help | grep -- -pie`, that reports the option in all cases, also if
365 # the loader doesn't actually load the resulting executables.
366 # To avoid breakage, blacklist FreeBSD here at least
367 [[ ${CTARGET} == *-freebsd* ]] && return 1
368
369 want_pie || return 1
370 hardened_gcc_is_stable pie && return 0
371 if has ~$(tc-arch) ${ACCEPT_KEYWORDS} ; then
372 hardened_gcc_check_unsupported pie && return 1
373 ewarn "Allowing pie-by-default for an unstable arch ($(tc-arch))"
374 return 0
375 fi
376 return 1
377 elif [[ $1 == "ssp" ]] ; then
378 [[ -z ${PP_VER} ]] && return 1
379 hardened_gcc_is_stable ssp && return 0
380 if has ~$(tc-arch) ${ACCEPT_KEYWORDS} ; then
381 hardened_gcc_check_unsupported ssp && return 1
382 ewarn "Allowing ssp-by-default for an unstable arch ($(tc-arch))"
383 return 0
384 fi
385 return 1
386 else
387 # laziness ;)
388 hardened_gcc_works pie || return 1
389 hardened_gcc_works ssp || return 1
390 return 0
391 fi
392 }
393
394 hardened_gcc_is_stable() {
395 if [[ $1 == "pie" ]] ; then
396 # HARDENED_* variables are deprecated and here for compatibility
397 local tocheck="${HARDENED_PIE_WORKS} ${HARDENED_GCC_WORKS}"
398 if is_uclibc ; then
399 tocheck="${tocheck} ${PIE_UCLIBC_STABLE}"
400 else
401 tocheck="${tocheck} ${PIE_GLIBC_STABLE}"
402 fi
403 elif [[ $1 == "ssp" ]] ; then
404 # ditto
405 local tocheck="${HARDENED_SSP_WORKS} ${HARDENED_GCC_WORKS}"
406 if is_uclibc ; then
407 tocheck="${tocheck} ${SSP_UCLIBC_STABLE}"
408 else
409 tocheck="${tocheck} ${SSP_STABLE}"
410 fi
411 else
412 die "hardened_gcc_stable needs to be called with pie or ssp"
413 fi
414
415 hasq $(tc-arch) ${tocheck} && return 0
416 return 1
417 }
418
419 hardened_gcc_check_unsupported() {
420 local tocheck=""
421 # if a variable is unset, we assume that all archs are unsupported. since
422 # this function is never called if hardened_gcc_is_stable returns true,
423 # this shouldn't cause problems... however, allowing this logic to work
424 # even with the variables unset will break older ebuilds that dont use them.
425 if [[ $1 == "pie" ]] ; then
426 if is_uclibc ; then
427 [[ -z ${PIE_UCLIBC_UNSUPPORTED} ]] && return 0
428 tocheck="${tocheck} ${PIE_UCLIBC_UNSUPPORTED}"
429 else
430 [[ -z ${PIE_GLIBC_UNSUPPORTED} ]] && return 0
431 tocheck="${tocheck} ${PIE_GLIBC_UNSUPPORTED}"
432 fi
433 elif [[ $1 == "ssp" ]] ; then
434 if is_uclibc ; then
435 [[ -z ${SSP_UCLIBC_UNSUPPORTED} ]] && return 0
436 tocheck="${tocheck} ${SSP_UCLIBC_UNSUPPORTED}"
437 else
438 [[ -z ${SSP_UNSUPPORTED} ]] && return 0
439 tocheck="${tocheck} ${SSP_UNSUPPORTED}"
440 fi
441 else
442 die "hardened_gcc_check_unsupported needs to be called with pie or ssp"
443 fi
444
445 hasq $(tc-arch) ${tocheck} && return 0
446 return 1
447 }
448
449 has_libssp() {
450 [[ -e /$(get_libdir)/libssp.so ]] && return 0
451 return 1
452 }
453
454 want_libssp() {
455 [[ ${GCC_LIBSSP_SUPPORT} == "true" ]] || return 1
456 has_libssp || return 1
457 [[ -n ${PP_VER} ]] || return 1
458 return 0
459 }
460
461 _want_stuff() {
462 local var=$1 flag=$2
463 [[ -z ${!var} ]] && return 1
464 use ${flag} && return 0
465 return 1
466 }
467 want_boundschecking() { _want_stuff HTB_VER boundschecking ; }
468 want_pie() { _want_stuff PIE_VER !nopie ; }
469 want_ssp() { _want_stuff PP_VER !nossp ; }
470
471 want_split_specs() {
472 [[ ${SPLIT_SPECS} == "true" ]] && want_pie
473 }
474
475 # This function checks whether or not glibc has the support required to build
476 # Position Independant Executables with gcc.
477 glibc_have_pie() {
478 if [[ ! -f ${ROOT}/usr/$(get_libdir)/Scrt1.o ]] ; then
479 echo
480 ewarn "Your glibc does not have support for pie, the file Scrt1.o is missing"
481 ewarn "Please update your glibc to a proper version or disable hardened"
482 echo
483 return 1
484 fi
485 }
486
487 # This function determines whether or not libc has been patched with stack
488 # smashing protection support.
489 libc_has_ssp() {
490 [[ ${ROOT} != "/" ]] && return 0
491
492 # lib hacks taken from sandbox configure
493 echo 'int main(){}' > "${T}"/libctest.c
494 LC_ALL=C gcc "${T}"/libctest.c -lc -o libctest -Wl,-verbose &> "${T}"/libctest.log || return 1
495 local libc_file=$(awk '/attempt to open/ { if (($4 ~ /\/libc\.so/) && ($5 == "succeeded")) LIBC = $4; }; END {print LIBC}' "${T}"/libctest.log)
496
497 [[ -z ${libc_file} ]] && die "Unable to find a libc !?"
498
499 # Check for gcc-4.x style ssp support
500 if [[ -n $(readelf -s "${libc_file}" 2>/dev/null | \
501 grep 'FUNC.*GLOBAL.*__stack_chk_fail') ]]
502 then
503 return 0
504 else
505 # Check for gcc-3.x style ssp support
506 if [[ -n $(readelf -s "${libc_file}" 2>/dev/null | \
507 grep 'OBJECT.*GLOBAL.*__guard') ]] && \
508 [[ -n $(readelf -s "${libc_file}" 2>/dev/null | \
509 grep 'FUNC.*GLOBAL.*__stack_smash_handler') ]]
510 then
511 return 0
512 elif is_crosscompile ; then
513 die "'${libc_file}' was detected w/out ssp, that sucks (a lot)"
514 else
515 return 1
516 fi
517 fi
518 }
519
520 # This is to make sure we don't accidentally try to enable support for a
521 # language that doesnt exist. GCC 3.4 supports f77, while 4.0 supports f95, etc.
522 #
523 # Also add a hook so special ebuilds (kgcc64) can control which languages
524 # exactly get enabled
525 gcc-lang-supported() {
526 grep ^language=\"${1}\" "${S}"/gcc/*/config-lang.in > /dev/null || return 1
527 [[ -z ${TOOLCHAIN_ALLOWED_LANGS} ]] && return 0
528 has $1 ${TOOLCHAIN_ALLOWED_LANGS}
529 }
530
531 #----<< support checks >>----
532
533 #---->> specs + env.d logic <<----
534
535 # defaults to enable for all hardened toolchains
536 gcc_common_hard="-DEFAULT_RELRO -DEFAULT_BIND_NOW"
537
538 # configure to build with the hardened GCC specs as the default
539 make_gcc_hard() {
540 if hardened_gcc_works ; then
541 einfo "Updating gcc to use automatic PIE + SSP building ..."
542 sed -e "s|^HARD_CFLAGS = |HARD_CFLAGS = -DEFAULT_PIE_SSP ${gcc_common_hard} |" \
543 -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!"
544 elif hardened_gcc_works pie ; then
545 einfo "Updating gcc to use automatic PIE building ..."
546 ewarn "SSP has not been enabled by default"
547 sed -e "s|^HARD_CFLAGS = |HARD_CFLAGS = -DEFAULT_PIE ${gcc_common_hard} |" \
548 -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!"
549 elif hardened_gcc_works ssp ; then
550 einfo "Updating gcc to use automatic SSP building ..."
551 ewarn "PIE has not been enabled by default"
552 sed -e "s|^HARD_CFLAGS = |HARD_CFLAGS = -DEFAULT_SSP ${gcc_common_hard} |" \
553 -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!"
554 else
555 # do nothing if hardened isnt supported, but dont die either
556 ewarn "hardened is not supported for this arch in this gcc version"
557 ebeep
558 return 0
559 fi
560
561 # rebrand to make bug reports easier
562 release_version="${release_version/Gentoo/Gentoo Hardened}"
563 }
564
565 # now we generate different spec files so that the user can select a compiler
566 # that enforces certain features in gcc itself and so we don't have to worry
567 # about a certain package ignoring CFLAGS/LDFLAGS
568 _create_specs_file() {
569 # Usage: _create_specs_file <USE flag> <specs name> <CFLAGS>
570 local uflag=$1 name=$2 flags=${*:3}
571 ebegin "Creating a ${name} gcc specs file"
572 pushd "${WORKDIR}"/build/gcc > /dev/null
573 if [[ -z ${uflag} ]] || use ${uflag} ; then
574 # backup the compiler first
575 cp Makefile Makefile.orig
576 sed -i -e '/^HARD_CFLAGS/s:=.*:='"${flags}"':' Makefile
577 mv xgcc xgcc.foo
578 mv gcc.o gcc.o.foo
579 emake -s xgcc
580 $(XGCC) -dumpspecs > "${WORKDIR}"/build/${name}.specs
581 # restore everything to normal
582 mv gcc.o.foo gcc.o
583 mv xgcc.foo xgcc
584 mv Makefile.orig Makefile
585 else
586 $(XGCC) -dumpspecs > "${WORKDIR}"/build/${name}.specs
587 fi
588 popd > /dev/null
589 eend $([[ -s ${WORKDIR}/build/${name}.specs ]] ; echo $?)
590 }
591 create_vanilla_specs_file() { _create_specs_file hardened vanilla ; }
592 create_hardened_specs_file() { _create_specs_file !hardened hardened ${gcc_common_hard} -DEFAULT_PIE_SSP ; }
593 create_hardenednossp_specs_file() { _create_specs_file "" hardenednossp ${gcc_common_hard} -DEFAULT_PIE ; }
594 create_hardenednopie_specs_file() { _create_specs_file "" hardenednopie ${gcc_common_hard} -DEFAULT_SSP ; }
595 create_hardenednopiessp_specs_file() { _create_specs_file "" hardenednopiessp ${gcc_common_hard} ; }
596
597 split_out_specs_files() {
598 local s spec_list="hardenednopiessp vanilla"
599 if hardened_gcc_works ; then
600 spec_list="${spec_list} hardened hardenednossp hardenednopie"
601 elif hardened_gcc_works pie ; then
602 spec_list="${spec_list} hardenednossp"
603 elif hardened_gcc_works ssp ; then
604 spec_list="${spec_list} hardenednopie"
605 fi
606 for s in ${spec_list} ; do
607 create_${s}_specs_file || return 1
608 done
609 }
610
611 create_gcc_env_entry() {
612 dodir /etc/env.d/gcc
613 local gcc_envd_base="/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}"
614
615 if [[ -z $1 ]] ; then
616 gcc_envd_file="${D}${gcc_envd_base}"
617 # I'm leaving the following commented out to remind me that it
618 # was an insanely -bad- idea. Stuff broke. GCC_SPECS isnt unset
619 # on chroot or in non-toolchain.eclass gcc ebuilds!
620 #gcc_specs_file="${LIBPATH}/specs"
621 gcc_specs_file=""
622 else
623 gcc_envd_file="${D}${gcc_envd_base}-$1"
624 gcc_specs_file="${LIBPATH}/$1.specs"
625 fi
626
627 echo "PATH=\"${EPREFIX}/${BINPATH}\"" > ${gcc_envd_file}
628 echo "ROOTPATH=\"${EPREFIX}/${BINPATH}\"" >> ${gcc_envd_file}
629
630 if use multilib && ! has_multilib_profile; then
631 LDPATH="${EPREFIX}/${LIBPATH}"
632 for path in 32 64 ; do
633 [[ -d ${EPREFIX}/${LIBPATH}/${path} ]] && LDPATH="${LDPATH}:${EPREFIX}/${LIBPATH}/${path}"
634 done
635 else
636 local MULTIDIR
637 LDPATH="${EPREFIX}/${LIBPATH}"
638
639 # We want to list the default ABI's LIBPATH first so libtool
640 # searches that directory first. This is a temporary
641 # workaround for libtool being stupid and using .la's from
642 # conflicting ABIs by using the first one in the search path
643
644 local abi=${DEFAULT_ABI}
645 local MULTIDIR=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory)
646 if [[ ${MULTIDIR} == "." ]] ; then
647 LDPATH="${EPREFIX}/${LIBPATH}"
648 else
649 LDPATH="${EPREFIX}/${LIBPATH}/${MULTIDIR}"
650 fi
651
652 for abi in $(get_all_abis) ; do
653 [[ ${abi} == ${DEFAULT_ABI} ]] && continue
654
655 MULTIDIR=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory)
656 if [[ ${MULTIDIR} == "." ]] ; then
657 LDPATH=${LDPATH}:${EPREFIX}/${LIBPATH}
658 else
659 LDPATH=${LDPATH}:${EPREFIX}/${LIBPATH}/${MULTIDIR}
660 fi
661 done
662 fi
663
664 echo "LDPATH=\"${LDPATH}\"" >> ${gcc_envd_file}
665
666 local mbits
667 CC=$(XGCC) has_m32 && mbits="${mbits:+${mbits} }32"
668 CC=$(XGCC) has_m64 && mbits="${mbits:+${mbits} }64"
669 echo "GCCBITS=\"${mbits}\"" >> ${gcc_envd_file}
670
671 echo "MANPATH=\"${EPREFIX}/${DATAPATH}/man\"" >> ${gcc_envd_file}
672 echo "INFOPATH=\"${EPREFIX}/${DATAPATH}/info\"" >> ${gcc_envd_file}
673 echo "STDCXX_INCDIR=\"${EPREFIX}/${STDCXX_INCDIR##*/}\"" >> ${gcc_envd_file}
674
675 is_crosscompile && echo "CTARGET=${CTARGET}" >> ${gcc_envd_file}
676
677 # Set which specs file to use
678 [[ -n ${gcc_specs_file} ]] && echo "GCC_SPECS=\"${gcc_specs_file}\"" >> ${gcc_envd_file}
679 }
680
681 add_profile_eselect_conf() {
682 local compiler_config_file=$1
683 local abi=$2
684 local specs=$3
685 local gcc_specs_file
686 local var
687
688 if [[ -z ${specs} ]] ; then
689 # I'm leaving the following commented out to remind me that it
690 # was an insanely -bad- idea. Stuff broke. GCC_SPECS isnt unset
691 # on chroot or in non-toolchain.eclass gcc ebuilds!
692 #gcc_specs_file="${LIBPATH}/specs"
693 gcc_specs_file=""
694
695 if use hardened ; then
696 specs="hardened"
697 else
698 specs="vanilla"
699 fi
700 else
701 gcc_specs_file="${LIBPATH}/${specs}.specs"
702 fi
703
704 echo >> ${compiler_config_file}
705 if ! is_multilib ; then
706 echo "[${specs}]" >> ${compiler_config_file}
707 echo " ctarget=${CTARGET}" >> ${compiler_config_file}
708 else
709 echo "[${abi}-${specs}]" >> ${compiler_config_file}
710 var="CTARGET_${abi}"
711 if [[ -n ${!var} ]] ; then
712 echo " ctarget=${!var}" >> ${compiler_config_file}
713 else
714 var="CHOST_${abi}"
715 if [[ -n ${!var} ]] ; then
716 echo " ctarget=${!var}" >> ${compiler_config_file}
717 else
718 echo " ctarget=${CTARGET}" >> ${compiler_config_file}
719 fi
720 fi
721 fi
722
723 local MULTIDIR=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory)
724 local LDPATH=${LIBPATH}
725 if [[ ${MULTIDIR} != "." ]] ; then
726 LDPATH="${LIBPATH}/${MULTIDIR}"
727 fi
728
729 echo " ldpath=${LDPATH}" >> ${compiler_config_file}
730
731 if [[ -n ${gcc_specs_file} ]] ; then
732 echo " specs=${gcc_specs_file}" >> ${compiler_config_file}
733 fi
734
735 var="CFLAGS_${abi}"
736 if [[ -n ${!var} ]] ; then
737 echo " cflags=${!var}" >> ${compiler_config_file}
738 fi
739 }
740
741 create_eselect_conf() {
742 local config_dir="/etc/eselect/compiler"
743 local compiler_config_file="${D}/${config_dir}/${CTARGET}-${GCC_CONFIG_VER}.conf"
744 local abi
745
746 dodir ${config_dir}
747
748 echo "[global]" > ${compiler_config_file}
749 echo " version=${CTARGET}-${GCC_CONFIG_VER}" >> ${compiler_config_file}
750 echo " binpath=${BINPATH}" >> ${compiler_config_file}
751 echo " manpath=${DATAPATH}/man" >> ${compiler_config_file}
752 echo " infopath=${DATAPATH}/info" >> ${compiler_config_file}
753 echo " alias_cc=gcc" >> ${compiler_config_file}
754 echo " stdcxx_incdir=${STDCXX_INCDIR##*/}" >> ${compiler_config_file}
755 echo " bin_prefix=${CTARGET}" >> ${compiler_config_file}
756
757 # Per spyderous, it is best not to alias the fortran compilers
758 #if [[ -x "${D}/${BINPATH}/${CTARGET}-g77" ]] ; then
759 # echo " alias_gfortran=g77" >> ${compiler_config_file}
760 #elif [[ -x "${D}/${BINPATH}/${CTARGET}-gfortran" ]] ; then
761 # echo " alias_g77=gfortran" >> ${compiler_config_file}
762 #fi
763
764 for abi in $(get_all_abis) ; do
765 add_profile_eselect_conf "${compiler_config_file}" "${abi}"
766
767 if want_split_specs ; then
768 if use hardened ; then
769 add_profile_eselect_conf "${compiler_config_file}" "${abi}" vanilla
770 elif hardened_gcc_works ; then
771 add_profile_eselect_conf "${compiler_config_file}" "${abi}" hardened
772 fi
773
774 if hardened_gcc_works || hardened_gcc_works pie ; then
775 add_profile_eselect_conf "${compiler_config_file}" "${abi}" hardenednossp
776 fi
777
778 if hardened_gcc_works || hardened_gcc_works ssp ; then
779 add_profile_eselect_conf "${compiler_config_file}" "${abi}" hardenednopie
780 fi
781
782 add_profile_eselect_conf "${compiler_config_file}" "${abi}" hardenednopiessp
783 fi
784 done
785 }
786
787 #----<< specs + env.d logic >>----
788
789 #---->> pkg_* <<----
790 gcc_pkg_setup() {
791 [[ -z ${ETYPE} ]] && die "Your ebuild needs to set the ETYPE variable"
792
793 if [[ ( $(tc-arch) == "amd64" || $(tc-arch) == "ppc64" ) && ( ${LD_PRELOAD} == "/lib/libsandbox.so" || ${LD_PRELOAD} == "/usr/lib/libsandbox.so" ) ]] && is_multilib ; then
794 eerror "Sandbox in your installed portage does not support compilation."
795 eerror "of a multilib gcc. Please set FEATURES=-sandbox and try again."
796 eerror "After you have a multilib gcc, re-emerge portage to have a working sandbox."
797 die "No 32bit sandbox. Retry with FEATURES=-sandbox."
798 fi
799
800 if [[ ${ETYPE} == "gcc-compiler" ]] ; then
801 case $(tc-arch) in
802 mips)
803 # Must compile for mips64-linux target if we want n32/n64 support
804 case "${CTARGET}" in
805 mips64*) ;;
806 *)
807 if use n32 || use n64; then
808 eerror "n32/n64 can only be used when target host is mips64*-*-linux-*";
809 die "Invalid USE flags for CTARGET ($CTARGET)";
810 fi
811 ;;
812 esac
813
814 #cannot have both n32 & n64 without multilib
815 if use n32 && use n64 && ! is_multilib; then
816 eerror "Please enable multilib if you want to use both n32 & n64";
817 die "Invalid USE flag combination";
818 fi
819 ;;
820 esac
821
822 # Setup variables which would normally be in the profile
823 if is_crosscompile ; then
824 multilib_env ${CTARGET}
825 if ! use multilib ; then
826 MULTILIB_ABIS=${DEFAULT_ABI}
827 fi
828 fi
829
830 # we dont want to use the installed compiler's specs to build gcc!
831 unset GCC_SPECS
832 fi
833
834 want_libssp && libc_has_ssp && \
835 die "libssp cannot be used with a glibc that has been patched to provide ssp symbols"
836 }
837
838 gcc-compiler_pkg_preinst() {
839 :
840 }
841
842 gcc-compiler_pkg_postinst() {
843 export LD_LIBRARY_PATH=${LIBPATH}:${LD_LIBRARY_PATH}
844
845 if has_version 'app-admin/eselect-compiler' ; then
846 do_eselect_compiler
847 else
848 do_gcc_config
849 fi
850
851 if ! is_crosscompile ; then
852 echo
853 ewarn "If you have issues with packages unable to locate libstdc++.la,"
854 ewarn "then try running 'fix_libtool_files.sh' on the old gcc versions."
855 echo
856 fi
857
858 # If our gcc-config version doesn't like '-' in it's version string,
859 # tell our users that gcc-config will yell at them, but it's all good.
860 if ! has_version '>=sys-devel/gcc-config-1.3.10-r1' && [[ ${GCC_CONFIG_VER/-/} != ${GCC_CONFIG_VER} ]] ; then
861 ewarn "Your version of gcc-config will issue about having an invalid profile"
862 ewarn "when switching to this profile. It is safe to ignore this warning,"
863 ewarn "and this problem has been corrected in >=sys-devel/gcc-config-1.3.10-r1."
864 fi
865
866 if ! is_crosscompile && ! use multislot && [[ ${GCCMAJOR}.${GCCMINOR} == 3.4 ]] ; then
867 echo
868 ewarn "You should make sure to rebuild all your C++ packages when"
869 ewarn "upgrading between different versions of gcc. For example,"
870 ewarn "when moving to gcc-3.4 from gcc-3.3, emerge gentoolkit and run:"
871 ewarn " # revdep-rebuild --library libstdc++.so.5"
872 echo
873 ewarn "For more information on the steps to take when upgrading "
874 ewarn "from gcc-3.3 please refer to: "
875 ewarn "http://www.gentoo.org/doc/en/gcc-upgrading.xml"
876 echo
877 fi
878
879 if ! is_crosscompile ; then
880 # hack to prevent collisions between SLOT
881 [[ ! -d ${ROOT}/lib/rcscripts/awk ]] \
882 && mkdir -p "${ROOT}"/lib/rcscripts/awk
883 [[ ! -d ${ROOT}/sbin ]] \
884 && mkdir -p "${ROOT}"/sbin
885 cp "${ROOT}/${DATAPATH}"/fixlafiles.awk "${ROOT}"/lib/rcscripts/awk/ || die "installing fixlafiles.awk"
886 cp "${ROOT}/${DATAPATH}"/fix_libtool_files.sh "${ROOT}"/sbin/ || die "installing fix_libtool_files.sh"
887
888 # These don't seem to exist when using the -K option and a hardened compiler and probably other cases also.
889 for x in "${ROOT}/${DATAPATH}"/c{89,99} ; do
890 if [[ -e ${x} ]]; then
891 cp ${x} "${ROOT}"/usr/sbin/ || die "installing c89/c99"
892 fi
893 done
894 fi
895 }
896
897 gcc-compiler_pkg_prerm() {
898 # Don't let these files be uninstalled #87647
899 touch -c "${ROOT}"/sbin/fix_libtool_files.sh \
900 "${ROOT}"/lib/rcscripts/awk/fixlafiles.awk
901 }
902
903 gcc-compiler_pkg_postrm() {
904 # to make our lives easier (and saner), we do the fix_libtool stuff here.
905 # rather than checking SLOT's and trying in upgrade paths, we just see if
906 # the common libstdc++.la exists in the ${LIBPATH} of the gcc that we are
907 # unmerging. if it does, that means this was a simple re-emerge.
908
909 # clean up the cruft left behind by cross-compilers
910 if is_crosscompile ; then
911 if [[ -z $(ls "${ROOT}"/etc/env.d/gcc/${CTARGET}* 2>/dev/null) ]] ; then
912 rm -f "${ROOT}"/etc/env.d/gcc/config-${CTARGET}
913 rm -f "${ROOT}"/etc/env.d/??gcc-${CTARGET}
914 rm -f "${ROOT}"/usr/bin/${CTARGET}-{gcc,{g,c}++}{,32,64}
915 fi
916 return 0
917 fi
918
919 # ROOT isnt handled by the script
920 [[ ${ROOT} != "/" ]] && return 0
921
922 if [[ ! -e ${LIBPATH}/libstdc++.so ]] ; then
923 einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}'"
924 ${EPREFIX}/sbin/fix_libtool_files.sh ${GCC_RELEASE_VER}
925 if [[ -n ${BRANCH_UPDATE} ]] ; then
926 einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE}'"
927 ${EPREFIX}/sbin/fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE}
928 fi
929 fi
930
931 return 0
932 }
933
934 #---->> pkg_* <<----
935
936 #---->> src_* <<----
937
938 # generic GCC src_unpack, to be called from the ebuild's src_unpack.
939 # BIG NOTE regarding hardened support: ebuilds with support for hardened are
940 # expected to export the following variable:
941 #
942 # HARDENED_GCC_WORKS
943 # This variable should be set to the archs on which hardened should
944 # be allowed. For example: HARDENED_GCC_WORKS="x86 sparc amd64"
945 # This allows for additional archs to be supported by hardened when
946 # ready.
947 #
948 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
949 #
950 gcc-compiler_src_unpack() {
951 # fail if using pie patches, building hardened, and glibc doesnt have
952 # the necessary support
953 want_pie && use hardened && glibc_have_pie
954
955 if use hardened ; then
956 einfo "updating configuration to build hardened GCC"
957 make_gcc_hard || die "failed to make gcc hard"
958 fi
959 }
960 gcc-library_src_unpack() {
961 :
962 }
963 guess_patch_type_in_dir() {
964 [[ -n $(ls "$1"/*.bz2 2>/dev/null) ]] \
965 && EPATCH_SUFFIX="patch.bz2" \
966 || EPATCH_SUFFIX="patch"
967 }
968 do_gcc_rename_java_bins() {
969 # bug #139918 - conflict between gcc and java-config-2 for ownership of
970 # /usr/bin/rmi{c,registry}. Done with mv & sed rather than a patch
971 # because patches would be large (thanks to the rename of man files),
972 # and it's clear from the sed invocations that all that changes is the
973 # rmi{c,registry} names to grmi{c,registry} names.
974 # Kevin F. Quinn 2006-07-12
975 einfo "Renaming jdk executables rmic and rmiregistry to grmic and grmiregistry."
976 # 1) Move the man files if present (missing prior to gcc-3.4)
977 for manfile in rmic rmiregistry; do
978 [[ -f ${S}/gcc/doc/${manfile}.1 ]] || continue
979 mv ${S}/gcc/doc/${manfile}.1 ${S}/gcc/doc/g${manfile}.1
980 done
981 # 2) Fixup references in the docs if present (mission prior to gcc-3.4)
982 for jfile in gcc/doc/gcj.info gcc/doc/grmic.1 gcc/doc/grmiregistry.1 gcc/java/gcj.texi; do
983 [[ -f ${S}/${jfile} ]] || continue
984 sed -i -e 's:rmiregistry:grmiregistry:g' ${S}/${jfile} ||
985 die "Failed to fixup file ${jfile} for rename to grmiregistry"
986 sed -i -e 's:rmic:grmic:g' ${S}/${jfile} ||
987 die "Failed to fixup file ${jfile} for rename to grmic"
988 done
989 # 3) Fixup Makefiles to build the changed executable names
990 # These are present in all 3.x versions, and are the important bit
991 # to get gcc to build with the new names.
992 for jfile in libjava/Makefile.am libjava/Makefile.in gcc/java/Make-lang.in; do
993 sed -i -e 's:rmiregistry:grmiregistry:g' ${S}/${jfile} ||
994 die "Failed to fixup file ${jfile} for rename to grmiregistry"
995 # Careful with rmic on these files; it's also the name of a directory
996 # which should be left unchanged. Replace occurrences of 'rmic$',
997 # 'rmic_' and 'rmic '.
998 sed -i -e 's:rmic\([$_ ]\):grmic\1:g' ${S}/${jfile} ||
999 die "Failed to fixup file ${jfile} for rename to grmic"
1000 done
1001 }
1002 gcc_src_unpack() {
1003 local release_version="Gentoo ${GCC_PVR}"
1004
1005 [[ -z ${UCLIBC_VER} ]] && is_uclibc && die "Sorry, this version does not support uClibc"
1006
1007 gcc_quick_unpack
1008 exclude_gcc_patches
1009
1010 cd ${S:=$(gcc_get_s_dir)}
1011
1012 if ! use vanilla ; then
1013 if [[ -n ${PATCH_VER} ]] ; then
1014 guess_patch_type_in_dir "${WORKDIR}"/patch
1015 EPATCH_MULTI_MSG="Applying Gentoo patches ..." \
1016 epatch "${WORKDIR}"/patch
1017 fi
1018 if [[ -n ${UCLIBC_VER} ]] ; then
1019 guess_patch_type_in_dir "${WORKDIR}"/uclibc
1020 EPATCH_MULTI_MSG="Applying uClibc patches ..." \
1021 epatch "${WORKDIR}"/uclibc
1022 fi
1023 fi
1024 do_gcc_HTB_patches
1025 do_gcc_SSP_patches
1026 do_gcc_PIE_patches
1027
1028 ${ETYPE}_src_unpack || die "failed to ${ETYPE}_src_unpack"
1029
1030 if ! is_crosscompile ; then
1031 # enable protoize / unprotoize
1032 sed -i -e '/^LANGUAGES =/s:$: proto:' "${S}"/gcc/Makefile.in
1033 fi
1034
1035 fix_files=""
1036 for x in contrib/test_summary libstdc++-v3/scripts/check_survey.in ; do
1037 [[ -e ${x} ]] && fix_files="${fix_files} ${x}"
1038 done
1039 ht_fix_file ${fix_files} */configure *.sh */Makefile.in
1040
1041 if ! is_crosscompile && is_multilib && \
1042 [[ ( $(tc-arch) == "amd64" || $(tc-arch) == "ppc64" ) && -z ${SKIP_MULTILIB_HACK} ]] ; then
1043 disgusting_gcc_multilib_HACK || die "multilib hack failed"
1044 fi
1045
1046 local version_string=${GCC_CONFIG_VER}
1047
1048 # Backwards support... add the BRANCH_UPDATE for 3.3.5-r1 and 3.4.3-r1
1049 # which set it directly rather than using ${GCC_PV}
1050 if [[ ${GCC_PVR} == "3.3.5-r1" || ${GCC_PVR} = "3.4.3-r1" ]] ; then
1051 version_string="${version_string} ${BRANCH_UPDATE}"
1052 fi
1053
1054
1055 einfo "patching gcc version: ${version_string} (${release_version})"
1056 gcc_version_patch "${version_string}" "${release_version}"
1057
1058 if [[ ${GCCMAJOR}.${GCCMINOR} > 4.0 ]] ; then
1059 if [[ -n ${SNAPSHOT} || -n ${PRERELEASE} ]] ; then
1060 echo ${PV/_/-} > "${S}"/gcc/BASE-VER
1061 echo "" > "${S}"/gcc/DATESTAMP
1062 fi
1063 fi
1064
1065 # Misdesign in libstdc++ (Redhat)
1066 if [[ ${GCCMAJOR} -ge 3 ]] && [[ -e ${S}/libstdc++-v3/config/cpu/i486/atomicity.h ]] ; then
1067 cp -pPR "${S}"/libstdc++-v3/config/cpu/i{4,3}86/atomicity.h
1068 fi
1069
1070 # disable --as-needed from being compiled into gcc specs
1071 # natively when using a gcc version < 3.4.4
1072 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14992
1073 if [[ ${GCCMAJOR} < 3 ]] || \
1074 [[ ${GCCMAJOR}.${GCCMINOR} < 3.4 ]] || \
1075 [[ ${GCCMAJOR}.${GCCMINOR}.${GCCMICRO} < 3.4.4 ]]
1076 then
1077 sed -i -e s/HAVE_LD_AS_NEEDED/USE_LD_AS_NEEDED/g "${S}"/gcc/config.in
1078 fi
1079
1080 # In gcc 3.3.x and 3.4.x, rename the java bins to gcc-specific names
1081 # in line with gcc-4.
1082 if [[ ${GCCMAJOR} == 3 ]] &&
1083 [[ ${GCCMINOR} -ge 3 ]]
1084 then
1085 do_gcc_rename_java_bins
1086 fi
1087
1088 # Fixup libtool to correctly generate .la files with portage
1089 cd "${S}"
1090 elibtoolize --portage --shallow --no-uclibc
1091
1092 gnuconfig_update
1093
1094 # update configure files
1095 local f
1096 einfo "Fixing misc issues in configure files"
1097 for f in $(grep -l 'autoconf version 2.13' $(find "${S}" -name configure)) ; do
1098 ebegin " Updating ${f/${S}\/}"
1099 patch "${f}" "${GCC_FILESDIR}"/gcc-configure-LANG.patch >& "${T}"/configure-patch.log \
1100 || eerror "Please file a bug about this"
1101 eend $?
1102 done
1103
1104 einfo "Touching generated files"
1105 ./contrib/gcc_update --touch | \
1106 while read f ; do
1107 einfo " ${f%%...}"
1108 done
1109
1110 disable_multilib_libjava || die "failed to disable multilib java"
1111 }
1112
1113 gcc-library-configure() {
1114 # multilib support
1115 [[ ${GCC_TARGET_NO_MULTILIB} == "true" ]] \
1116 && confgcc="${confgcc} --disable-multilib" \
1117 || confgcc="${confgcc} --enable-multilib"
1118 }
1119
1120 gcc-compiler-configure() {
1121 # multilib support
1122 if is_multilib ; then
1123 confgcc="${confgcc} --enable-multilib"
1124 elif [[ ${CTARGET} == *-linux* ]] ; then
1125 confgcc="${confgcc} --disable-multilib"
1126 fi
1127
1128 if tc_version_is_at_least "4.0" ; then
1129 confgcc="${confgcc} $(use_enable mudflap libmudflap)"
1130
1131 if want_libssp ; then
1132 confgcc="${confgcc} --enable-libssp"
1133 else
1134 export gcc_cv_libc_provides_ssp=yes
1135 confgcc="${confgcc} --disable-libssp"
1136 fi
1137 fi
1138
1139 # GTK+ is preferred over xlib in 3.4.x (xlib is unmaintained
1140 # right now). Much thanks to <csm@gnu.org> for the heads up.
1141 # Travis Tilley <lv@gentoo.org> (11 Jul 2004)
1142 if ! is_gcj ; then
1143 confgcc="${confgcc} --disable-libgcj"
1144 elif use gtk ; then
1145 confgcc="${confgcc} --enable-java-awt=gtk"
1146 fi
1147
1148 case $(tc-arch) in
1149 # Add --with-abi flags to set default MIPS ABI
1150 mips)
1151 local mips_abi=""
1152 use n64 && mips_abi="--with-abi=64"
1153 use n32 && mips_abi="--with-abi=n32"
1154 [[ -n ${mips_abi} ]] && confgcc="${confgcc} ${mips_abi}"
1155 ;;
1156 # Enable sjlj exceptions for backward compatibility on hppa
1157 hppa)
1158 [[ ${GCC_PV:0:1} == "3" ]] && \
1159 confgcc="${confgcc} --enable-sjlj-exceptions"
1160 ;;
1161 esac
1162
1163 GCC_LANG="c"
1164 is_cxx && GCC_LANG="${GCC_LANG},c++"
1165 is_gcj && GCC_LANG="${GCC_LANG},java"
1166 if is_objc || is_objcxx ; then
1167 GCC_LANG="${GCC_LANG},objc"
1168 use objc-gc && confgcc="${confgcc} --enable-objc-gc"
1169 is_objcxx && GCC_LANG="${GCC_LANG},obj-c++"
1170 fi
1171
1172 # fortran support just got sillier! the lang value can be f77 for
1173 # fortran77, f95 for fortran95, or just plain old fortran for the
1174 # currently supported standard depending on gcc version.
1175 is_fortran && GCC_LANG="${GCC_LANG},fortran"
1176 is_f77 && GCC_LANG="${GCC_LANG},f77"
1177 is_f95 && GCC_LANG="${GCC_LANG},f95"
1178
1179 # We do NOT want 'ADA support' in here!
1180 # is_ada && GCC_LANG="${GCC_LANG},ada"
1181
1182 einfo "configuring for GCC_LANG: ${GCC_LANG}"
1183 }
1184
1185 # Other than the variables described for gcc_setup_variables, the following
1186 # will alter tha behavior of gcc_do_configure:
1187 #
1188 # CTARGET
1189 # CBUILD
1190 # Enable building for a target that differs from CHOST
1191 #
1192 # GCC_TARGET_NO_MULTILIB
1193 # Disable multilib. Useful when building single library targets.
1194 #
1195 # GCC_LANG
1196 # Enable support for ${GCC_LANG} languages. defaults to just "c"
1197 #
1198 # Travis Tilley <lv@gentoo.org> (04 Sep 2004)
1199 #
1200 gcc_do_configure() {
1201 local confgcc
1202
1203 # Set configuration based on path variables
1204 confgcc="${confgcc} \
1205 --prefix=${EPREFIX}/${PREFIX} \
1206 --bindir=${EPREFIX}/${BINPATH} \
1207 --includedir=${EPREFIX}/${INCLUDEPATH} \
1208 --datadir=${EPREFIX}/${DATAPATH} \
1209 --mandir=${EPREFIX}/${DATAPATH}/man \
1210 --infodir=${EPREFIX}/${DATAPATH}/info \
1211 --with-gxx-include-dir=${EPREFIX}/${STDCXX_INCDIR}"
1212
1213 # All our cross-compile logic goes here ! woo !
1214 confgcc="${confgcc} --host=${CHOST}"
1215 if is_crosscompile || tc-is-cross-compiler ; then
1216 # Straight from the GCC install doc:
1217 # "GCC has code to correctly determine the correct value for target
1218 # for nearly all native systems. Therefore, we highly recommend you
1219 # not provide a configure target when configuring a native compiler."
1220 confgcc="${confgcc} --target=${CTARGET}"
1221 fi
1222 [[ -n ${CBUILD} ]] && confgcc="${confgcc} --build=${CBUILD}"
1223
1224 # ppc altivec support
1225 confgcc="${confgcc} $(use_enable altivec)"
1226
1227 [[ ${CTARGET} == *-softfloat-* ]] && confgcc="${confgcc} --with-float=soft"
1228
1229 # Native Language Support
1230 if use nls && ! use build ; then
1231 confgcc="${confgcc} --enable-nls --without-included-gettext"
1232 else
1233 confgcc="${confgcc} --disable-nls"
1234 fi
1235
1236 # reasonably sane globals (hopefully)
1237 # --disable-libunwind-exceptions needed till unwind sections get fixed. see ps.m for details
1238 confgcc="${confgcc} \
1239 --with-system-zlib \
1240 --disable-checking \
1241 --disable-werror \
1242 --disable-libunwind-exceptions"
1243
1244 # etype specific configuration
1245 einfo "running ${ETYPE}-configure"
1246 ${ETYPE}-configure || die
1247
1248 # if not specified, assume we are building for a target that only
1249 # requires C support
1250 GCC_LANG=${GCC_LANG:-c}
1251 confgcc="${confgcc} --enable-languages=${GCC_LANG}"
1252
1253 if is_crosscompile ; then
1254 # When building a stage1 cross-compiler (just C compiler), we have to
1255 # disable a bunch of features or gcc goes boom
1256 local needed_libc=""
1257 case ${CTARGET} in
1258 *-dietlibc) needed_libc=dietlibc;;
1259 *-freebsd*) needed_libc=freebsd-lib;;
1260 *-gnu*) needed_libc=glibc;;
1261 *-klibc) needed_libc=klibc;;
1262 *-uclibc) needed_libc=uclibc;;
1263 avr) confgcc="${confgcc} --enable-shared --disable-threads";;
1264 esac
1265 if [[ -n ${needed_libc} ]] ; then
1266 if ! has_version ${CATEGORY}/${needed_libc} ; then
1267 confgcc="${confgcc} --disable-shared --disable-threads --without-headers"
1268 elif built_with_use ${CATEGORY}/${needed_libc} crosscompile_opts_headers-only ; then
1269 confgcc="${confgcc} --disable-shared --with-sysroot=${EPREFIX}/${PREFIX}/${CTARGET}"
1270 else
1271 confgcc="${confgcc} --with-sysroot=${EPREFIX}/${PREFIX}/${CTARGET}"
1272 fi
1273 fi
1274
1275 if [[ ${GCCMAJOR}.${GCCMINOR} > 4.1 ]] ; then
1276 confgcc="${confgcc} --disable-bootstrap"
1277 fi
1278 else
1279 confgcc="${confgcc} --enable-shared --enable-threads=posix"
1280
1281 if [[ ${GCCMAJOR}.${GCCMINOR} > 4.1 ]] ; then
1282 confgcc="${confgcc} --enable-bootstrap"
1283 fi
1284 fi
1285 # __cxa_atexit is "essential for fully standards-compliant handling of
1286 # destructors", but apparently requires glibc.
1287 # --enable-sjlj-exceptions : currently the unwind stuff seems to work
1288 # for statically linked apps but not dynamic
1289 # so use setjmp/longjmp exceptions by default
1290 if is_uclibc ; then
1291 confgcc="${confgcc} --disable-__cxa_atexit --enable-target-optspace"
1292 [[ ${GCCMAJOR}.${GCCMINOR} == 3.3 ]] && \
1293 confgcc="${confgcc} --enable-sjlj-exceptions"
1294 else
1295 confgcc="${confgcc} --enable-__cxa_atexit"
1296 fi
1297 [[ ${CTARGET} == *-gnu* ]] && confgcc="${confgcc} --enable-clocale=gnu"
1298 [[ ${CTARGET} == *-uclibc* ]] && [[ ${GCCMAJOR}.${GCCMINOR} > 3.3 ]] \
1299 && confgcc="${confgcc} --enable-clocale=uclibc"
1300
1301 # Nothing wrong with a good dose of verbosity
1302 echo
1303 einfo "EPREFIX: ${EPREFIX}"
1304 einfo "PREFIX: ${PREFIX}"
1305 einfo "BINPATH: ${BINPATH}"
1306 einfo "LIBPATH: ${LIBPATH}"
1307 einfo "DATAPATH: ${DATAPATH}"
1308 einfo "STDCXX_INCDIR: ${STDCXX_INCDIR}"
1309 echo
1310 einfo "Configuring GCC with: ${confgcc//--/\n\t--} ${@} ${EXTRA_ECONF}"
1311 echo
1312
1313 # Build in a separate build tree
1314 mkdir -p "${WORKDIR}"/build
1315 pushd "${WORKDIR}"/build > /dev/null
1316
1317 # and now to do the actual configuration
1318 addwrite /dev/zero
1319 "${S}"/configure ${confgcc} $@ ${EXTRA_ECONF} \
1320 || die "failed to run configure"
1321
1322 # return to whatever directory we were in before
1323 popd > /dev/null
1324 }
1325
1326 # This function accepts one optional argument, the make target to be used.
1327 # If ommitted, gcc_do_make will try to guess whether it should use all,
1328 # profiledbootstrap, or bootstrap-lean depending on CTARGET and arch. An
1329 # example of how to use this function:
1330 #
1331 # gcc_do_make all-target-libstdc++-v3
1332 #
1333 # In addition to the target to be used, the following variables alter the
1334 # behavior of this function:
1335 #
1336 # LDFLAGS
1337 # Flags to pass to ld
1338 #
1339 # STAGE1_CFLAGS
1340 # CFLAGS to use during stage1 of a gcc bootstrap
1341 #
1342 # BOOT_CFLAGS
1343 # CFLAGS to use during stages 2+3 of a gcc bootstrap.
1344 #
1345 # Travis Tilley <lv@gentoo.org> (04 Sep 2004)
1346 #
1347 gcc_do_make() {
1348 # Fix for libtool-portage.patch
1349 local OLDS=${S}
1350 S=${WORKDIR}/build
1351
1352 # Set make target to $1 if passed
1353 [[ -n $1 ]] && GCC_MAKE_TARGET=$1
1354 # default target
1355 if is_crosscompile || tc-is-cross-compiler ; then
1356 # 3 stage bootstrapping doesnt quite work when you cant run the
1357 # resulting binaries natively ^^;
1358 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-all}
1359 elif [[ $(tc-arch) == "x86" || $(tc-arch) == "amd64" || $(tc-arch) == "ppc64" ]] \
1360 && [[ ${GCCMAJOR}.${GCCMINOR} > 3.3 ]]
1361 then
1362 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-profiledbootstrap}
1363 else
1364 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-bootstrap-lean}
1365 fi
1366
1367 # the gcc docs state that parallel make isnt supported for the
1368 # profiledbootstrap target, as collisions in profile collecting may occur.
1369 [[ ${GCC_MAKE_TARGET} == "profiledbootstrap" ]] && export MAKEOPTS="${MAKEOPTS} -j1"
1370
1371 # boundschecking seems to introduce parallel build issues
1372 want_boundschecking && export MAKEOPTS="${MAKEOPTS} -j1"
1373
1374 if [[ ${GCC_MAKE_TARGET} == "all" ]] ; then
1375 STAGE1_CFLAGS=${STAGE1_CFLAGS-"${CFLAGS}"}
1376 elif [[ $(gcc-version) == "3.4" && ${GCC_BRANCH_VER} == "3.4" ]] && gcc-specs-ssp ; then
1377 # See bug #79852
1378 STAGE1_CFLAGS=${STAGE1_CFLAGS-"-O2"}
1379 else
1380 STAGE1_CFLAGS=${STAGE1_CFLAGS-"-O"}
1381 fi
1382
1383 if is_crosscompile; then
1384 # In 3.4, BOOT_CFLAGS is never used on a crosscompile...
1385 # but I'll leave this in anyways as someone might have had
1386 # some reason for putting it in here... --eradicator
1387 BOOT_CFLAGS=${BOOT_CFLAGS-"-O2"}
1388 else
1389 # we only want to use the system's CFLAGS if not building a
1390 # cross-compiler.
1391 BOOT_CFLAGS=${BOOT_CFLAGS-"$(get_abi_CFLAGS) ${CFLAGS}"}
1392 fi
1393
1394 pushd "${WORKDIR}"/build
1395 einfo "Running make LDFLAGS=\"${LDFLAGS}\" STAGE1_CFLAGS=\"${STAGE1_CFLAGS}\" LIBPATH=\"${LIBPATH}\" BOOT_CFLAGS=\"${BOOT_CFLAGS}\" ${GCC_MAKE_TARGET}"
1396
1397 emake \
1398 LDFLAGS="${LDFLAGS}" \
1399 STAGE1_CFLAGS="${STAGE1_CFLAGS}" \
1400 LIBPATH="${LIBPATH}" \
1401 BOOT_CFLAGS="${BOOT_CFLAGS}" \
1402 ${GCC_MAKE_TARGET} \
1403 || die "emake failed with ${GCC_MAKE_TARGET}"
1404
1405 if ! use build && ! is_crosscompile && ! use nocxx && use doc ; then
1406 if type -p doxygen > /dev/null ; then
1407 cd "${CTARGET}"/libstdc++-v3
1408 make doxygen-man || ewarn "failed to make docs"
1409 else
1410 ewarn "Skipping libstdc++ manpage generation since you don't have doxygen installed"
1411 fi
1412 fi
1413
1414 popd
1415 }
1416
1417 # This function will add ${GCC_CONFIG_VER} to the names of all shared libraries in the
1418 # directory specified to avoid filename collisions between multiple slotted
1419 # non-versioned gcc targets. If no directory is specified, it is assumed that
1420 # you want -all- shared objects to have ${GCC_CONFIG_VER} added. Example
1421 #
1422 # add_version_to_shared ${D}/usr/$(get_libdir)
1423 #
1424 # Travis Tilley <lv@gentoo.org> (05 Sep 2004)
1425 #
1426 add_version_to_shared() {
1427 local sharedlib sharedlibdir
1428 [[ -z $1 ]] \
1429 && sharedlibdir=${D} \
1430 || sharedlibdir=$1
1431
1432 for sharedlib in $(find ${sharedlibdir} -name *.so.*) ; do
1433 if [[ ! -L ${sharedlib} ]] ; then
1434 einfo "Renaming `basename "${sharedlib}"` to `basename "${sharedlib/.so*/}-${GCC_CONFIG_VER}.so.${sharedlib/*.so./}"`"
1435 mv "${sharedlib}" "${sharedlib/.so*/}-${GCC_CONFIG_VER}.so.${sharedlib/*.so./}" \
1436 || die
1437 pushd `dirname "${sharedlib}"` > /dev/null || die
1438 ln -sf "`basename "${sharedlib/.so*/}-${GCC_CONFIG_VER}.so.${sharedlib/*.so./}"`" \
1439 "`basename "${sharedlib}"`" || die
1440 popd > /dev/null || die
1441 fi
1442 done
1443 }
1444
1445 # This is mostly a stub function to be overwritten in an ebuild
1446 gcc_do_filter_flags() {
1447 strip-flags
1448
1449 # In general gcc does not like optimization, and add -O2 where
1450 # it is safe. This is especially true for gcc 3.3 + 3.4
1451 replace-flags -O? -O2
1452
1453 # ... sure, why not?
1454 strip-unsupported-flags
1455
1456 # dont want to funk ourselves
1457 filter-flags '-mabi*' -m31 -m32 -m64
1458
1459 case ${GCC_BRANCH_VER} in
1460 3.2|3.3)
1461 case $(tc-arch) in
1462 x86) filter-flags '-mtune=*';;
1463 amd64) filter-flags '-mtune=*'
1464 replace-cpu-flags k8 athlon64 opteron i686;;
1465 esac
1466 ;;
1467 3.4|4.*)
1468 case $(tc-arch) in
1469 x86|amd64) filter-flags '-mcpu=*';;
1470 esac
1471 ;;
1472 esac
1473
1474 # Compile problems with these (bug #6641 among others)...
1475 #filter-flags "-fno-exceptions -fomit-frame-pointer -fforce-addr"
1476
1477 # CFLAGS logic (verified with 3.4.3):
1478 # CFLAGS:
1479 # This conflicts when creating a crosscompiler, so set to a sane
1480 # default in this case:
1481 # used in ./configure and elsewhere for the native compiler
1482 # used by gcc when creating libiberty.a
1483 # used by xgcc when creating libstdc++ (and probably others)!
1484 # this behavior should be removed...
1485 #
1486 # CXXFLAGS:
1487 # used by xgcc when creating libstdc++
1488 #
1489 # STAGE1_CFLAGS (not used in creating a crosscompile gcc):
1490 # used by ${CHOST}-gcc for building stage1 compiler
1491 #
1492 # BOOT_CFLAGS (not used in creating a crosscompile gcc):
1493 # used by xgcc for building stage2/3 compiler
1494
1495 if is_crosscompile ; then
1496 # Set this to something sane for both native and target
1497 CFLAGS="-O2 -pipe"
1498
1499 local VAR="CFLAGS_"${CTARGET//-/_}
1500 CXXFLAGS=${!VAR}
1501 fi
1502
1503 export GCJFLAGS=${GCJFLAGS:-${CFLAGS}}
1504 }
1505
1506 gcc_src_compile() {
1507 gcc_do_filter_flags
1508 einfo "CFLAGS=\"${CFLAGS}\""
1509 einfo "CXXFLAGS=\"${CXXFLAGS}\""
1510
1511 # Build in a separate build tree
1512 mkdir -p "${WORKDIR}"/build
1513 pushd "${WORKDIR}"/build > /dev/null
1514
1515 # Install our pre generated manpages if we do not have perl ...
1516 [[ ! -x /usr/bin/perl ]] && [[ -n ${MAN_VER} ]] && \
1517 unpack gcc-${MAN_VER}-manpages.tar.bz2
1518
1519 einfo "Configuring ${PN} ..."
1520 gcc_do_configure
1521
1522 touch "${S}"/gcc/c-gperf.h
1523
1524 # Do not make manpages if we do not have perl ...
1525 [[ ! -x /usr/bin/perl ]] \
1526 && find "${WORKDIR}"/build -name '*.[17]' | xargs touch
1527
1528 einfo "Compiling ${PN} ..."
1529 gcc_do_make ${GCC_MAKE_TARGET}
1530
1531 # Do not create multiple specs files for PIE+SSP if boundschecking is in
1532 # USE, as we disable PIE+SSP when it is.
1533 if [[ ${ETYPE} == "gcc-compiler" ]] && want_split_specs ; then
1534 split_out_specs_files || die "failed to split out specs"
1535 fi
1536
1537 popd > /dev/null
1538 }
1539
1540 gcc_src_test() {
1541 cd "${WORKDIR}"/build
1542 make check || ewarn "check failed and that sucks :("
1543 }
1544
1545 gcc-library_src_install() {
1546 einfo "Installing ${PN} ..."
1547 # Do the 'make install' from the build directory
1548 cd "${WORKDIR}"/build
1549 S=${WORKDIR}/build \
1550 make DESTDIR="${EDEST}" \
1551 prefix=${PREFIX} \
1552 bindir=${BINPATH} \
1553 includedir=${LIBPATH}/include \
1554 datadir=${DATAPATH} \
1555 mandir=${DATAPATH}/man \
1556 infodir=${DATAPATH}/info \
1557 LIBPATH="${LIBPATH}" \
1558 ${GCC_INSTALL_TARGET} || die
1559
1560 if [[ ${GCC_LIB_COMPAT_ONLY} == "true" ]] ; then
1561 rm -rf "${D}"${INCLUDEPATH}
1562 rm -rf "${D}"${DATAPATH}
1563 pushd "${D}"${LIBPATH}/
1564 rm *.a *.la *.so
1565 popd
1566 fi
1567
1568 if [[ -n ${GCC_LIB_USE_SUBDIR} ]] ; then
1569 mkdir -p "${WORKDIR}"/${GCC_LIB_USE_SUBDIR}/
1570 mv "${D}"${LIBPATH}/* "${WORKDIR}"/${GCC_LIB_USE_SUBDIR}/
1571 mv "${WORKDIR}"/${GCC_LIB_USE_SUBDIR}/ "${D}"${LIBPATH}
1572
1573 dodir /etc/env.d
1574 echo "LDPATH=\"${EPREFIX}/${LIBPATH}/${GCC_LIB_USE_SUBDIR}/\"" >> "${D}"/etc/env.d/99${PN}
1575 fi
1576
1577 if [[ ${GCC_VAR_TYPE} == "non-versioned" ]] ; then
1578 # if we're not using versioned directories, we need to use versioned
1579 # filenames.
1580 add_version_to_shared
1581 fi
1582 }
1583
1584 gcc-compiler_src_install() {
1585 local x=
1586
1587 # Do allow symlinks in ${PREFIX}/lib/gcc-lib/${CHOST}/${GCC_CONFIG_VER}/include as
1588 # this can break the build.
1589 for x in "${WORKDIR}"/build/gcc/include/* ; do
1590 [[ -L ${x} ]] && rm -f "${x}"
1591 done
1592 # Remove generated headers, as they can cause things to break
1593 # (ncurses, openssl, etc).
1594 for x in $(find "${WORKDIR}"/build/gcc/include/ -name '*.h') ; do
1595 grep -q 'It has been auto-edited by fixincludes from' "${x}" \
1596 && rm -f "${x}"
1597 done
1598 einfo "Installing GCC..."
1599 # Do the 'make install' from the build directory
1600 cd "${WORKDIR}"/build
1601 S=${WORKDIR}/build \
1602 make DESTDIR="${EDEST}" install || die
1603 # Punt some tools which are really only useful while building gcc
1604 rm -r "${D}${LIBEXECPATH}"/install-tools
1605 # This one comes with binutils
1606 find "${D}" -name libiberty.a -exec rm -f {} \;
1607
1608 # Move the libraries to the proper location
1609 gcc_movelibs
1610
1611 # Basic sanity check
1612 is_crosscompile || [[ -r ${D}${BINPATH}/gcc ]] || die "gcc not found in ${D}"
1613
1614 dodir /etc/env.d/gcc
1615 create_gcc_env_entry
1616
1617 if want_split_specs ; then
1618 if use hardened ; then
1619 create_gcc_env_entry vanilla
1620 fi
1621 ! use hardened && hardened_gcc_works && create_gcc_env_entry hardened
1622 if hardened_gcc_works || hardened_gcc_works pie ; then
1623 create_gcc_env_entry hardenednossp
1624 fi
1625 if hardened_gcc_works || hardened_gcc_works ssp ; then
1626 create_gcc_env_entry hardenednopie
1627 fi
1628 create_gcc_env_entry hardenednopiessp
1629
1630 insinto ${LIBPATH}
1631 doins "${WORKDIR}"/build/*.specs || die "failed to install specs"
1632 fi
1633
1634 # Make sure we dont have stuff lying around that
1635 # can nuke multiple versions of gcc
1636 if ! use build ; then
1637 cd ${D}${LIBPATH}
1638
1639 # Move Java headers to compiler-specific dir
1640 for x in ${D}${PREFIX}/include/gc*.h ${D}${PREFIX}/include/j*.h ; do
1641 [[ -f ${x} ]] && mv -f "${x}" ${D}${LIBPATH}/include/
1642 done
1643 for x in gcj gnu java javax org ; do
1644 if [[ -d ${D}${PREFIX}/include/${x} ]] ; then
1645 dodir /${LIBPATH}/include/${x}
1646 mv -f ${D}${PREFIX}/include/${x}/* ${D}${LIBPATH}/include/${x}/
1647 rm -rf ${D}${PREFIX}/include/${x}
1648 fi
1649 done
1650
1651 if [[ -d ${D}${PREFIX}/lib/security ]] ; then
1652 dodir /${LIBPATH}/security
1653 mv -f ${D}${PREFIX}/lib/security/* ${D}${LIBPATH}/security
1654 rm -rf ${D}${PREFIX}/lib/security
1655 fi
1656
1657 # Move libgcj.spec to compiler-specific directories
1658 [[ -f ${D}${PREFIX}/lib/libgcj.spec ]] && \
1659 mv -f ${D}${PREFIX}/lib/libgcj.spec ${D}${LIBPATH}/libgcj.spec
1660
1661 # Rename jar because it could clash with Kaffe's jar if this gcc is
1662 # primary compiler (aka don't have the -<version> extension)
1663 cd ${D}${BINPATH}
1664 [[ -f jar ]] && mv -f jar gcj-jar
1665
1666 # Move <cxxabi.h> to compiler-specific directories
1667 [[ -f ${D}${STDCXX_INCDIR}/cxxabi.h ]] && \
1668 mv -f ${D}${STDCXX_INCDIR}/cxxabi.h ${D}${LIBPATH}/include/
1669
1670 # These should be symlinks
1671 dodir /usr/bin
1672 cd "${D}"${BINPATH}
1673 for x in cpp gcc g++ c++ g77 gcj gcjh gfortran ; do
1674 # For some reason, g77 gets made instead of ${CTARGET}-g77...
1675 # this should take care of that
1676 [[ -f ${x} ]] && mv ${x} ${CTARGET}-${x}
1677
1678 if [[ -f ${CTARGET}-${x} ]] && ! is_crosscompile ; then
1679 ln -sf ${CTARGET}-${x} ${x}
1680
1681 # Create version-ed symlinks
1682 dosym ${BINPATH}/${CTARGET}-${x} \
1683 /usr/bin/${CTARGET}-${x}-${GCC_CONFIG_VER}
1684 dosym ${BINPATH}/${CTARGET}-${x} \
1685 /usr/bin/${x}-${GCC_CONFIG_VER}
1686 fi
1687
1688 if [[ -f ${CTARGET}-${x}-${GCC_CONFIG_VER} ]] ; then
1689 rm -f ${CTARGET}-${x}-${GCC_CONFIG_VER}
1690 ln -sf ${CTARGET}-${x} ${CTARGET}-${x}-${GCC_CONFIG_VER}
1691 fi
1692 done
1693
1694 # I do not know if this will break gcj stuff, so I'll only do it for
1695 # objc for now; basically "ffi.h" is the correct file to include,
1696 # but it gets installed in .../GCCVER/include and yet it does
1697 # "#include <ffitarget.h>" which (correctly, as it's an "extra" file)
1698 # is installed in .../GCCVER/include/libffi; the following fixes
1699 # ffi.'s include of ffitarget.h - Armando Di Cianno <fafhrd@gentoo.org>
1700 if is_objc && ! is_gcj ; then
1701 #dosed "s:<ffitarget.h>:<libffi/ffitarget.h>:g" /${LIBPATH}/include/ffi.h
1702 mv "${D}"${LIBPATH}/include/libffi/* "${D}"${LIBPATH}/include
1703 rm -Rf "${D}"${LIBPATH}/include/libffi
1704 fi
1705 fi
1706
1707 # Now do the fun stripping stuff
1708 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${BINPATH}" "${D}${LIBEXECPATH}"
1709 env RESTRICT="" CHOST=${CTARGET} prepstrip "${D}${LIBPATH}"
1710
1711 cd "${S}"
1712 if use build || is_crosscompile; then
1713 rm -rf "${D}"/usr/share/{man,info}
1714 rm -rf "${D}"${DATAPATH}/{man,info}
1715 else
1716 local cxx_mandir=${WORKDIR}/build/${CTARGET}/libstdc++-v3/docs/doxygen/man
1717 if [[ -d ${cxx_mandir} ]] ; then
1718 # clean bogus manpages #113902
1719 find "${cxx_mandir}" -name '*_build_*' -exec rm {} \;
1720 cp -r "${cxx_mandir}"/man? "${D}/${DATAPATH}"/man/
1721 fi
1722 has noinfo ${FEATURES} \
1723 && rm -r "${D}/${DATAPATH}"/info \
1724 || prepinfo "${DATAPATH}"
1725 has noman ${FEATURES} \
1726 && rm -r "${D}/${DATAPATH}"/man \
1727 || prepman "${DATAPATH}"
1728 fi
1729 # prune empty dirs left behind
1730 find "${D}" -type d | xargs rmdir >& /dev/null
1731
1732 # Rather install the script, else portage with changing $FILESDIR
1733 # between binary and source package borks things ....
1734 if ! is_crosscompile ; then
1735 insinto "${DATAPATH}"
1736 if tc_version_is_at_least 4.0 ; then
1737 newins "${GCC_FILESDIR}"/awk/fixlafiles.awk-no_gcc_la fixlafiles.awk || die
1738 find "${D}/${LIBPATH}" -name libstdc++.la -type f -exec rm "{}" \;
1739 else
1740 doins "${GCC_FILESDIR}"/awk/fixlafiles.awk || die
1741 fi
1742 exeinto "${DATAPATH}"
1743 doexe "${GCC_FILESDIR}"/fix_libtool_files.sh || die
1744 doexe "${GCC_FILESDIR}"/c{89,99} || die
1745 fi
1746
1747 # use gid of 0 because some stupid ports don't have
1748 # the group 'root' set to gid 0
1749 chown -R ${PORTAGE_INST_UID:-0}:${PORTAGE_INST_GID:-0} "${D}"${LIBPATH}
1750
1751 # Create config files for eselect-compiler
1752 create_eselect_conf
1753 }
1754
1755 # Move around the libs to the right location. For some reason,
1756 # when installing gcc, it dumps internal libraries into /usr/lib
1757 # instead of the private gcc lib path
1758 gcc_movelibs() {
1759 local multiarg removedirs=""
1760 for multiarg in $($(XGCC) -print-multi-lib) ; do
1761 multiarg=${multiarg#*;}
1762 multiarg=${multiarg//@/ -}
1763
1764 local OS_MULTIDIR=$($(XGCC) ${multiarg} --print-multi-os-directory)
1765 local MULTIDIR=$($(XGCC) ${multiarg} --print-multi-directory)
1766 local TODIR=${D}${LIBPATH}/${MULTIDIR}
1767 local FROMDIR=
1768
1769 [[ -d ${TODIR} ]] || mkdir -p ${TODIR}
1770
1771 for FROMDIR in \
1772 ${LIBPATH}/${OS_MULTIDIR} \
1773 ${LIBPATH}/../${MULTIDIR} \
1774 ${PREFIX}/lib/${OS_MULTIDIR} \
1775 ${PREFIX}/${CTARGET}/lib/${OS_MULTIDIR} \
1776 ${PREFIX}/lib/${MULTIDIR}
1777 do
1778 removedirs="${removedirs} ${FROMDIR}"
1779 FROMDIR=${D}${FROMDIR}
1780 if [[ ${FROMDIR} != "${TODIR}" && -d ${FROMDIR} ]] ; then
1781 local files=$(find "${FROMDIR}" -maxdepth 1 ! -type d 2>/dev/null)
1782 if [[ -n ${files} ]] ; then
1783 mv ${files} "${TODIR}"
1784 fi
1785 fi
1786 done
1787 done
1788
1789 # We remove directories separately to avoid this case:
1790 # mv SRC/lib/../lib/*.o DEST
1791 # rmdir SRC/lib/../lib/
1792 # mv SRC/lib/../lib32/*.o DEST # Bork
1793 for FROMDIR in ${removedirs} ; do
1794 rmdir "${D}"${FROMDIR} >& /dev/null
1795 done
1796 find "${D}" -type d | xargs rmdir >& /dev/null
1797
1798 # make sure the libtool archives have libdir set to where they actually
1799 # -are-, and not where they -used- to be.
1800 fix_libtool_libdir_paths "$(find ${D}${LIBPATH} -name *.la)"
1801 }
1802
1803 #----<< src_* >>----
1804
1805 #---->> unorganized crap in need of refactoring follows
1806
1807 # gcc_quick_unpack will unpack the gcc tarball and patches in a way that is
1808 # consistant with the behavior of get_gcc_src_uri. The only patch it applies
1809 # itself is the branch update if present.
1810 #
1811 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
1812 #
1813 gcc_quick_unpack() {
1814 pushd "${WORKDIR}" > /dev/null
1815 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
1816 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
1817 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
1818 export PP_GCC_VER=${PP_GCC_VER:-${GCC_RELEASE_VER}}
1819 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
1820
1821 if [[ -n ${GCC_A_FAKEIT} ]] ; then
1822 unpack ${GCC_A_FAKEIT}
1823 elif [[ -n ${PRERELEASE} ]] ; then
1824 unpack gcc-${PRERELEASE}.tar.bz2
1825 elif [[ -n ${SNAPSHOT} ]] ; then
1826 unpack gcc-${SNAPSHOT}.tar.bz2
1827 else
1828 unpack gcc-${GCC_RELEASE_VER}.tar.bz2
1829 # We want branch updates to be against a release tarball
1830 if [[ -n ${BRANCH_UPDATE} ]] ; then
1831 pushd ${S:-"$(gcc_get_s_dir)"} > /dev/null
1832 epatch ${DISTDIR}/gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2
1833 popd > /dev/null
1834 fi
1835 fi
1836
1837 [[ -n ${PATCH_VER} ]] && \
1838 unpack gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2
1839
1840 [[ -n ${UCLIBC_VER} ]] && \
1841 unpack gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2
1842
1843 if want_ssp ; then
1844 if [[ -n ${PP_FVER} ]] ; then
1845 # The gcc 3.4 propolice versions are meant to be unpacked to ${S}
1846 pushd ${S:-$(gcc_get_s_dir)} > /dev/null
1847 unpack protector-${PP_FVER}.tar.gz
1848 popd > /dev/null
1849 else
1850 unpack gcc-${PP_GCC_VER}-ssp-${PP_VER}.tar.bz2
1851 fi
1852 fi
1853
1854 if want_pie ; then
1855 if [[ -n ${PIE_CORE} ]] ; then
1856 unpack ${PIE_CORE}
1857 else
1858 unpack gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2
1859 fi
1860 fi
1861
1862 # pappy@gentoo.org - Fri Oct 1 23:24:39 CEST 2004
1863 want_boundschecking && \
1864 unpack "bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
1865
1866 popd > /dev/null
1867 }
1868
1869 # Exclude any unwanted patches, as specified by the following variables:
1870 #
1871 # GENTOO_PATCH_EXCLUDE
1872 # List of filenames, relative to ${WORKDIR}/patch/
1873 #
1874 # PIEPATCH_EXCLUDE
1875 # List of filenames, relative to ${WORKDIR}/piepatch/
1876 #
1877 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
1878 #
1879 exclude_gcc_patches() {
1880 local i
1881 for i in ${GENTOO_PATCH_EXCLUDE} ; do
1882 if [[ -f ${WORKDIR}/patch/${i} ]] ; then
1883 einfo "Excluding patch ${i}"
1884 rm -f "${WORKDIR}"/patch/${i} || die "failed to delete ${i}"
1885 fi
1886 done
1887 for i in ${PIEPATCH_EXCLUDE} ; do
1888 if [[ -f ${WORKDIR}/piepatch/${i} ]] ; then
1889 einfo "Excluding piepatch ${i}"
1890 rm -f "${WORKDIR}"/piepatch/${i} || die "failed to delete ${i}"
1891 fi
1892 done
1893 }
1894
1895 # Try to apply some stub patches so that gcc won't error out when
1896 # passed parameters like -fstack-protector but no ssp is found
1897 do_gcc_stub() {
1898 local v stub_patch=""
1899 for v in ${GCC_RELEASE_VER} ${GCC_BRANCH_VER} ; do
1900 stub_patch=${GCC_FILESDIR}/stubs/gcc-${v}-$1-stub.patch
1901 if [[ -e ${stub_patch} ]] ; then
1902 EPATCH_SINGLE_MSG="Applying stub patch for $1 ..." \
1903 epatch "${stub_patch}"
1904 return 0
1905 fi
1906 done
1907 }
1908
1909 do_gcc_HTB_patches() {
1910 if ! want_boundschecking || \
1911 (want_ssp && [[ ${HTB_EXCLUSIVE} == "true" ]])
1912 then
1913 do_gcc_stub htb
1914 return 0
1915 fi
1916
1917 # modify the bounds checking patch with a regression patch
1918 epatch "${WORKDIR}/bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch"
1919 release_version="${release_version}, HTB-${HTB_GCC_VER}-${HTB_VER}"
1920 }
1921
1922 # patch in ProPolice Stack Smashing protection
1923 do_gcc_SSP_patches() {
1924 # PARISC has no love ... it's our stack :(
1925 if [[ $(tc-arch) == "hppa" ]] || \
1926 ! want_ssp || \
1927 (want_boundschecking && [[ ${HTB_EXCLUSIVE} == "true" ]])
1928 then
1929 do_gcc_stub ssp
1930 return 0
1931 fi
1932
1933 local ssppatch
1934 local sspdocs
1935
1936 if [[ -n ${PP_FVER} ]] ; then
1937 # Etoh keeps changing where files are and what the patch is named
1938 if tc_version_is_at_least 3.4.1 ; then
1939 # >3.4.1 uses version in patch name, and also includes docs
1940 ssppatch="${S}/gcc_${PP_VER}.dif"
1941 sspdocs="yes"
1942 elif tc_version_is_at_least 3.4.0 ; then
1943 # >3.4 put files where they belong and 3_4 uses old patch name
1944 ssppatch="${S}/protector.dif"
1945 sspdocs="no"
1946 elif tc_version_is_at_least 3.2.3 ; then
1947 # earlier versions have no directory structure or docs
1948 mv "${S}"/protector.{c,h} "${S}"/gcc
1949 ssppatch="${S}/protector.dif"
1950 sspdocs="no"
1951 fi
1952 else
1953 # Just start packaging the damn thing ourselves
1954 mv "${WORKDIR}"/ssp/protector.{c,h} "${S}"/gcc/
1955 ssppatch=${WORKDIR}/ssp/gcc-${PP_GCC_VER}-ssp.patch
1956 # allow boundschecking and ssp to get along
1957 (want_boundschecking && [[ -e ${WORKDIR}/ssp/htb-ssp.patch ]]) \
1958 && patch -s "${ssppatch}" "${WORKDIR}"/ssp/htb-ssp.patch
1959 fi
1960
1961 [[ -z ${ssppatch} ]] && die "Sorry, SSP is not supported in this version"
1962 epatch ${ssppatch}
1963
1964 if [[ ${PN} == "gcc" && ${sspdocs} == "no" ]] ; then
1965 epatch "${GCC_FILESDIR}"/pro-police-docs.patch
1966 fi
1967
1968 # Don't build crtbegin/end with ssp
1969 sed -e 's|^CRTSTUFF_CFLAGS = |CRTSTUFF_CFLAGS = -fno-stack-protector |'\
1970 -i gcc/Makefile.in || die "Failed to update crtstuff!"
1971
1972 # if gcc in a stage3 defaults to ssp, is version 3.4.0 and a stage1 is built
1973 # the build fails building timevar.o w/:
1974 # cc1: stack smashing attack in function ix86_split_to_parts()
1975 if use build && tc_version_is_at_least 3.4.0 ; then
1976 if gcc -dumpspecs | grep -q "fno-stack-protector:" ; then
1977 epatch "${GCC_FILESDIR}"/3.4.0/gcc-3.4.0-cc1-no-stack-protector.patch
1978 fi
1979 fi
1980
1981 release_version="${release_version}, ssp-${PP_FVER:-${PP_GCC_VER}-${PP_VER}}"
1982 if want_libssp ; then
1983 update_gcc_for_libssp
1984 else
1985 update_gcc_for_libc_ssp
1986 fi
1987
1988 # Don't build libgcc with ssp
1989 sed -e 's|^\(LIBGCC2_CFLAGS.*\)$|\1 -fno-stack-protector|' \
1990 -i gcc/Makefile.in || die "Failed to update gcc!"
1991 }
1992
1993 # If glibc or uclibc has been patched to provide the necessary symbols itself,
1994 # then lets use those for SSP instead of libgcc.
1995 update_gcc_for_libc_ssp() {
1996 if libc_has_ssp ; then
1997 einfo "Updating gcc to use SSP from libc ..."
1998 sed -e 's|^\(LIBGCC2_CFLAGS.*\)$|\1 -D_LIBC_PROVIDES_SSP_|' \
1999 -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!"
2000 fi
2001 }
2002
2003 # a split out non-libc non-libgcc ssp requires additional spec logic changes
2004 update_gcc_for_libssp() {
2005 einfo "Updating gcc to use SSP from libssp..."
2006 sed -e 's|^\(INTERNAL_CFLAGS.*\)$|\1 -D_LIBSSP_PROVIDES_SSP_|' \
2007 -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!"
2008 }
2009
2010 # do various updates to PIE logic
2011 do_gcc_PIE_patches() {
2012 if ! want_pie || \
2013 (want_boundschecking && [[ ${HTB_EXCLUSIVE} == "true" ]])
2014 then
2015 return 0
2016 fi
2017
2018 want_boundschecking \
2019 && rm -f "${WORKDIR}"/piepatch/*/*-boundschecking-no.patch* \
2020 || rm -f "${WORKDIR}"/piepatch/*/*-boundschecking-yes.patch*
2021
2022 use vanilla && rm -f "${WORKDIR}"/piepatch/*/*uclibc*
2023
2024 guess_patch_type_in_dir "${WORKDIR}"/piepatch/upstream
2025
2026 # corrects startfile/endfile selection and shared/static/pie flag usage
2027 EPATCH_MULTI_MSG="Applying upstream pie patches ..." \
2028 epatch "${WORKDIR}"/piepatch/upstream
2029 # adds non-default pie support (rs6000)
2030 EPATCH_MULTI_MSG="Applying non-default pie patches ..." \
2031 epatch "${WORKDIR}"/piepatch/nondef
2032 # adds default pie support (rs6000 too) if DEFAULT_PIE[_SSP] is defined
2033 EPATCH_MULTI_MSG="Applying default pie patches ..." \
2034 epatch "${WORKDIR}"/piepatch/def
2035
2036 # we want to be able to control the pie patch logic via something other
2037 # than ALL_CFLAGS...
2038 sed -e '/^ALL_CFLAGS/iHARD_CFLAGS = ' \
2039 -e 's|^ALL_CFLAGS = |ALL_CFLAGS = $(HARD_CFLAGS) |' \
2040 -i "${S}"/gcc/Makefile.in
2041
2042 release_version="${release_version}, pie-${PIE_VER}"
2043 }
2044
2045 should_we_gcc_config() {
2046 # we only want to switch compilers if installing to / or /tmp/stage1root
2047 [[ ${ROOT} == "/" || ${ROOT} == "/tmp/stage1root" ]] || return 1
2048
2049 # we always want to run gcc-config if we're bootstrapping, otherwise
2050 # we might get stuck with the c-only stage1 compiler
2051 use bootstrap && return 0
2052 use build && return 0
2053
2054 # if the current config is invalid, we definitely want a new one
2055 # Note: due to bash quirkiness, the following must not be 1 line
2056 local curr_config
2057 curr_config=$(env -i gcc-config -c ${CTARGET} 2>&1) || return 0
2058
2059 # if the previously selected config has the same major.minor (branch) as
2060 # the version we are installing, then it will probably be uninstalled
2061 # for being in the same SLOT, make sure we run gcc-config.
2062 local curr_config_ver=$(env -i gcc-config -S ${curr_config} | awk '{print $2}')
2063
2064 local curr_branch_ver=$(get_version_component_range 1-2 ${curr_config_ver})
2065
2066 # If we're using multislot, just run gcc-config if we're installing
2067 # to the same profile as the current one.
2068 use multislot && return $([[ ${curr_config_ver} == ${GCC_CONFIG_VER} ]])
2069
2070 if [[ ${curr_branch_ver} == ${GCC_BRANCH_VER} ]] ; then
2071 return 0
2072 else
2073 # if we're installing a genuinely different compiler version,
2074 # we should probably tell the user -how- to switch to the new
2075 # gcc version, since we're not going to do it for him/her.
2076 # We don't want to switch from say gcc-3.3 to gcc-3.4 right in
2077 # the middle of an emerge operation (like an 'emerge -e world'
2078 # which could install multiple gcc versions).
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 ebeep
2088 return 1
2089 fi
2090 }
2091
2092 do_gcc_config() {
2093 if ! should_we_gcc_config ; then
2094 env -i gcc-config --use-old --force
2095 return 0
2096 fi
2097
2098 local current_gcc_config="" current_specs="" use_specs=""
2099
2100 # We grep out any possible errors
2101 current_gcc_config=$(env -i gcc-config -c ${CTARGET} | grep -v '^ ')
2102 if [[ -n ${current_gcc_config} ]] ; then
2103 # figure out which specs-specific config is active
2104 current_specs=$(gcc-config -S ${current_gcc_config} | awk '{print $3}')
2105 [[ -n ${current_specs} ]] && use_specs=-${current_specs}
2106 fi
2107 if [[ -n ${use_specs} ]] && \
2108 [[ ! -e ${ROOT}/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}${use_specs} ]]
2109 then
2110 ewarn "The currently selected specs-specific gcc config,"
2111 ewarn "${current_specs}, doesn't exist anymore. This is usually"
2112 ewarn "due to enabling/disabling hardened or switching to a version"
2113 ewarn "of gcc that doesnt create multiple specs files. The default"
2114 ewarn "config will be used, and the previous preference forgotten."
2115 ebeep
2116 epause
2117 use_specs=""
2118 fi
2119
2120 gcc-config ${CTARGET}-${GCC_CONFIG_VER}${use_specs}
2121 }
2122
2123 should_we_eselect_compiler() {
2124 # we only want to switch compilers if installing to / or /tmp/stage1root
2125 [[ ${ROOT} == "/" || ${ROOT} == "/tmp/stage1root" ]] || return 1
2126
2127 # we always want to run gcc-config if we're bootstrapping, otherwise
2128 # we might get stuck with the c-only stage1 compiler
2129 use bootstrap && return 0
2130 use build && return 0
2131
2132 # if the current config is invalid, we definitely want a new one
2133 # Note: due to bash quirkiness, the following must not be 1 line
2134 local curr_config
2135 curr_config=$(env -i eselect compiler show ${CTARGET} 2>&1) || return 0
2136 [[ -z ${curr_config} || ${curr_config} == "(none)" ]] && return 0
2137
2138 # if the previously selected config has the same major.minor (branch) as
2139 # the version we are installing, then it will probably be uninstalled
2140 # for being in the same SLOT, make sure we run gcc-config.
2141 local curr_config_ver=$(echo ${curr_config} | cut -f1 -d/ | awk -F - '{ print $5 }')
2142 local curr_branch_ver=$(get_version_component_range 1-2 ${curr_config_ver})
2143
2144 # If we're using multislot, just run gcc-config if we're installing
2145 # to the same profile as the current one.
2146 use multislot && return $([[ ${curr_config_ver} == ${GCC_CONFIG_VER} ]])
2147
2148 if [[ ${curr_branch_ver} == ${GCC_BRANCH_VER} ]] ; then
2149 return 0
2150 else
2151 # if we're installing a genuinely different compiler version,
2152 # we should probably tell the user -how- to switch to the new
2153 # gcc version, since we're not going to do it for him/her.
2154 # We don't want to switch from say gcc-3.3 to gcc-3.4 right in
2155 # the middle of an emerge operation (like an 'emerge -e world'
2156 # which could install multiple gcc versions).
2157 einfo "The current gcc config appears valid, so it will not be"
2158 einfo "automatically switched for you. If you would like to"
2159 einfo "switch to the newly installed gcc version, do the"
2160 einfo "following:"
2161 echo
2162 einfo "eselect compiler set <profile>"
2163 echo
2164 ebeep
2165 return 1
2166 fi
2167 }
2168
2169 do_eselect_compiler() {
2170 if ! should_we_eselect_compiler; then
2171 eselect compiler update
2172 return 0
2173 fi
2174
2175 for abi in $(get_all_abis) ; do
2176 local ctarget=$(get_abi_CHOST ${abi})
2177 local current_specs=$(env -i eselect compiler show ${ctarget} | cut -f2 -d/)
2178
2179 if [[ -n ${current_specs} && ${current_specs} != "(none)" ]] && eselect compiler set ${CTARGET}-${GCC_CONFIG_VER}/${current_specs} &> /dev/null; then
2180 einfo "The following compiler profile has been activated based on your previous profile:"
2181 einfo "${CTARGET}-${GCC_CONFIG_VER}/${current_specs}"
2182 else
2183 # We couldn't choose based on the old specs, so fall back on vanilla/hardened based on USE
2184
2185 local spec
2186 if use hardened ; then
2187 spec="hardened"
2188 else
2189 spec="vanilla"
2190 fi
2191
2192 local profile
2193 local isset=0
2194 for profile in "${current_specs%-*}-${spec}" "${abi}-${spec}" "${spec}" ; do
2195 if eselect compiler set ${CTARGET}-${GCC_CONFIG_VER}/${profile} &> /dev/null ; then
2196 ewarn "The newly installed version of gcc does not have a profile that matches the name of your"
2197 ewarn "currently selected profile for ${ctarget}, so we have enabled the following instead:"
2198 ewarn "${CTARGET}-${GCC_CONFIG_VER}/${profile}"
2199 ewarn "If this is incorrect, please use 'eselect compiler set' to"
2200 ewarn "select another profile."
2201
2202 isset=1
2203 break
2204 fi
2205 done
2206
2207 if [[ ${isset} == 0 ]] ; then
2208 eerror "We were not able to automatically set the current compiler for ${ctarget}"
2209 eerror "to your newly emerged gcc. Please use 'eselect compiler set'"
2210 eerror "to select your compiler."
2211 fi
2212 fi
2213 done
2214 }
2215
2216 # This function allows us to gentoo-ize gcc's version number and bugzilla
2217 # URL without needing to use patches.
2218 #
2219 # Travis Tilley <lv@gentoo.org> (02 Sep 2004)
2220 #
2221 gcc_version_patch() {
2222 [[ -z $1 ]] && die "no arguments to gcc_version_patch"
2223
2224 if grep -qs VERSUFFIX "${S}"/gcc/version.c ; then
2225 sed -i -e "s~VERSUFFIX \"\"~VERSUFFIX \" ($2)\"~" \
2226 "${S}"/gcc/version.c || die "failed to update VERSUFFIX with Gentoo branding"
2227 else
2228 version_string="$1 ($2)"
2229 sed -i -e "s~\(const char version_string\[\] = \"\).*\(\".*\)~\1$version_string\2~" \
2230 "${S}"/gcc/version.c || die "failed to update version.c with Gentoo branding."
2231 fi
2232 sed -i -e 's~gcc\.gnu\.org\/bugs\.html~bugs\.gentoo\.org\/~' \
2233 "${S}"/gcc/version.c || die "Failed to change the bug URL"
2234 }
2235
2236 # The purpose of this DISGUSTING gcc multilib hack is to allow 64bit libs
2237 # to live in lib instead of lib64 where they belong, with 32bit libraries
2238 # in lib32. This hack has been around since the beginning of the amd64 port,
2239 # and we're only now starting to fix everything that's broken. Eventually
2240 # this should go away.
2241 #
2242 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
2243 #
2244 disgusting_gcc_multilib_HACK() {
2245 local config
2246 local libdirs
2247 if has_multilib_profile ; then
2248 case $(tc-arch) in
2249 amd64)
2250 config="i386/t-linux64"
2251 libdirs="../$(get_abi_LIBDIR amd64) ../$(get_abi_LIBDIR x86)" \
2252 ;;
2253 ppc64)
2254 config="rs6000/t-linux64"
2255 libdirs="../$(get_abi_LIBDIR ppc64) ../$(get_abi_LIBDIR ppc)" \
2256 ;;
2257 esac
2258 else
2259 # Remove this hunk when amd64's 2004.3 is purged from portage.
2260 use amd64 || die "Your profile is no longer supported by portage."
2261 config="i386/t-linux64"
2262 libdirs="../$(get_libdir) ../$(get_multilibdir)"
2263 fi
2264
2265 einfo "updating multilib directories to be: ${libdirs}"
2266 sed -i -e "s:^MULTILIB_OSDIRNAMES.*:MULTILIB_OSDIRNAMES = ${libdirs}:" "${S}"/gcc/config/${config}
2267 }
2268
2269 disable_multilib_libjava() {
2270 if is_gcj ; then
2271 # We dont want a multilib libjava, so lets use this hack taken from fedora
2272 pushd "${S}" > /dev/null
2273 sed -i -e 's/^all: all-redirect/ifeq (\$(MULTISUBDIR),)\nall: all-redirect\nelse\nall:\n\techo Multilib libjava build disabled\nendif/' libjava/Makefile.in
2274 sed -i -e 's/^install: install-redirect/ifeq (\$(MULTISUBDIR),)\ninstall: install-redirect\nelse\ninstall:\n\techo Multilib libjava install disabled\nendif/' libjava/Makefile.in
2275 sed -i -e 's/^check: check-redirect/ifeq (\$(MULTISUBDIR),)\ncheck: check-redirect\nelse\ncheck:\n\techo Multilib libjava check disabled\nendif/' libjava/Makefile.in
2276 sed -i -e 's/^all: all-recursive/ifeq (\$(MULTISUBDIR),)\nall: all-recursive\nelse\nall:\n\techo Multilib libjava build disabled\nendif/' libjava/Makefile.in
2277 sed -i -e 's/^install: install-recursive/ifeq (\$(MULTISUBDIR),)\ninstall: install-recursive\nelse\ninstall:\n\techo Multilib libjava install disabled\nendif/' libjava/Makefile.in
2278 sed -i -e 's/^check: check-recursive/ifeq (\$(MULTISUBDIR),)\ncheck: check-recursive\nelse\ncheck:\n\techo Multilib libjava check disabled\nendif/' libjava/Makefile.in
2279 popd > /dev/null
2280 fi
2281 }
2282
2283 fix_libtool_libdir_paths() {
2284 local dirpath
2285 for archive in $* ; do
2286 dirpath=$(dirname ${archive} | sed -e "s:^${D}::")
2287 sed -i ${archive} -e "s:^libdir.*:libdir=\'${dirpath}\':"
2288 done
2289 }
2290
2291 is_multilib() {
2292 [[ ${GCCMAJOR} < 3 ]] && return 1
2293 case ${CTARGET} in
2294 mips64*|powerpc64*|s390x*|sparc64*|x86_64*)
2295 has_multilib_profile || use multilib ;;
2296 *) false ;;
2297 esac
2298 }
2299
2300 is_uclibc() {
2301 [[ ${GCCMAJOR} -lt 3 ]] && return 1
2302 [[ ${CTARGET} == *-uclibc ]]
2303 }
2304
2305 is_cxx() {
2306 gcc-lang-supported 'c++' || return 1
2307 use build && return 1
2308 ! use nocxx
2309 }
2310
2311 is_f77() {
2312 gcc-lang-supported f77 || return 1
2313 use build && return 1
2314 use fortran
2315 }
2316
2317 is_f95() {
2318 gcc-lang-supported f95 || return 1
2319 use build && return 1
2320 use fortran
2321 }
2322
2323 is_fortran() {
2324 gcc-lang-supported fortran || return 1
2325 use build && return 1
2326 use fortran
2327 }
2328
2329 is_gcj() {
2330 gcc-lang-supported java || return 1
2331 use build && return 1
2332 use gcj
2333 }
2334
2335 is_objc() {
2336 gcc-lang-supported objc || return 1
2337 use build && return 1
2338 use objc
2339 }
2340
2341 is_objcxx() {
2342 gcc-lang-supported 'obj-c++' || return 1
2343 use build && return 1
2344 use objc++
2345 }
2346
2347 is_ada() {
2348 gcc-lang-supported ada || return 1
2349 use build && return 1
2350 use ada
2351 }

  ViewVC Help
Powered by ViewVC 1.1.20