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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1375 - (show annotations) (download)
Thu Sep 7 18:55:24 2006 UTC (7 years, 10 months ago) by grobian
File size: 77165 byte(s)
Ok, finally get all paths right (or it looks like so)


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=\"${BINPATH}\"" > ${gcc_envd_file}
628 echo "ROOTPATH=\"${BINPATH}\"" >> ${gcc_envd_file}
629
630 if use multilib && ! has_multilib_profile; then
631 LDPATH="${LIBPATH}"
632 for path in 32 64 ; do
633 [[ -d ${LIBPATH}/${path} ]] && LDPATH="${LDPATH}:${LIBPATH}/${path}"
634 done
635 else
636 local MULTIDIR
637 LDPATH="${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=${LIBPATH}
648 else
649 LDPATH=${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}:${LIBPATH}
658 else
659 LDPATH=${LDPATH}:${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=\"${DATAPATH}/man\"" >> ${gcc_envd_file}
672 echo "INFOPATH=\"${DATAPATH}/info\"" >> ${gcc_envd_file}
673 echo "STDCXX_INCDIR=\"${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=${PREFIX}/${CTARGET}"
1270 else
1271 confgcc="${confgcc} --with-sysroot=${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 "PREFIX: ${PREFIX}"
1304 einfo "BINPATH: ${BINPATH}"
1305 einfo "LIBPATH: ${LIBPATH}"
1306 einfo "DATAPATH: ${DATAPATH}"
1307 einfo "STDCXX_INCDIR: ${STDCXX_INCDIR}"
1308 echo
1309 einfo "Configuring GCC with: ${confgcc//--/\n\t--} ${@} ${EXTRA_ECONF}"
1310 echo
1311
1312 # Build in a separate build tree
1313 mkdir -p "${WORKDIR}"/build
1314 pushd "${WORKDIR}"/build > /dev/null
1315
1316 # and now to do the actual configuration
1317 addwrite /dev/zero
1318 "${S}"/configure ${confgcc} $@ ${EXTRA_ECONF} \
1319 || die "failed to run configure"
1320
1321 # return to whatever directory we were in before
1322 popd > /dev/null
1323 }
1324
1325 # This function accepts one optional argument, the make target to be used.
1326 # If ommitted, gcc_do_make will try to guess whether it should use all,
1327 # profiledbootstrap, or bootstrap-lean depending on CTARGET and arch. An
1328 # example of how to use this function:
1329 #
1330 # gcc_do_make all-target-libstdc++-v3
1331 #
1332 # In addition to the target to be used, the following variables alter the
1333 # behavior of this function:
1334 #
1335 # LDFLAGS
1336 # Flags to pass to ld
1337 #
1338 # STAGE1_CFLAGS
1339 # CFLAGS to use during stage1 of a gcc bootstrap
1340 #
1341 # BOOT_CFLAGS
1342 # CFLAGS to use during stages 2+3 of a gcc bootstrap.
1343 #
1344 # Travis Tilley <lv@gentoo.org> (04 Sep 2004)
1345 #
1346 gcc_do_make() {
1347 # Fix for libtool-portage.patch
1348 local OLDS=${S}
1349 S=${WORKDIR}/build
1350
1351 # Set make target to $1 if passed
1352 [[ -n $1 ]] && GCC_MAKE_TARGET=$1
1353 # default target
1354 if is_crosscompile || tc-is-cross-compiler ; then
1355 # 3 stage bootstrapping doesnt quite work when you cant run the
1356 # resulting binaries natively ^^;
1357 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-all}
1358 elif [[ $(tc-arch) == "x86" || $(tc-arch) == "amd64" || $(tc-arch) == "ppc64" ]] \
1359 && [[ ${GCCMAJOR}.${GCCMINOR} > 3.3 ]]
1360 then
1361 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-profiledbootstrap}
1362 else
1363 GCC_MAKE_TARGET=${GCC_MAKE_TARGET-bootstrap-lean}
1364 fi
1365
1366 # the gcc docs state that parallel make isnt supported for the
1367 # profiledbootstrap target, as collisions in profile collecting may occur.
1368 [[ ${GCC_MAKE_TARGET} == "profiledbootstrap" ]] && export MAKEOPTS="${MAKEOPTS} -j1"
1369
1370 # boundschecking seems to introduce parallel build issues
1371 want_boundschecking && export MAKEOPTS="${MAKEOPTS} -j1"
1372
1373 if [[ ${GCC_MAKE_TARGET} == "all" ]] ; then
1374 STAGE1_CFLAGS=${STAGE1_CFLAGS-"${CFLAGS}"}
1375 elif [[ $(gcc-version) == "3.4" && ${GCC_BRANCH_VER} == "3.4" ]] && gcc-specs-ssp ; then
1376 # See bug #79852
1377 STAGE1_CFLAGS=${STAGE1_CFLAGS-"-O2"}
1378 else
1379 STAGE1_CFLAGS=${STAGE1_CFLAGS-"-O"}
1380 fi
1381
1382 if is_crosscompile; then
1383 # In 3.4, BOOT_CFLAGS is never used on a crosscompile...
1384 # but I'll leave this in anyways as someone might have had
1385 # some reason for putting it in here... --eradicator
1386 BOOT_CFLAGS=${BOOT_CFLAGS-"-O2"}
1387 else
1388 # we only want to use the system's CFLAGS if not building a
1389 # cross-compiler.
1390 BOOT_CFLAGS=${BOOT_CFLAGS-"$(get_abi_CFLAGS) ${CFLAGS}"}
1391 fi
1392
1393 pushd "${WORKDIR}"/build
1394 einfo "Running make LDFLAGS=\"${LDFLAGS}\" STAGE1_CFLAGS=\"${STAGE1_CFLAGS}\" LIBPATH=\"${LIBPATH}\" BOOT_CFLAGS=\"${BOOT_CFLAGS}\" ${GCC_MAKE_TARGET}"
1395
1396 emake \
1397 LDFLAGS="${LDFLAGS}" \
1398 STAGE1_CFLAGS="${STAGE1_CFLAGS}" \
1399 LIBPATH="${LIBPATH}" \
1400 BOOT_CFLAGS="${BOOT_CFLAGS}" \
1401 ${GCC_MAKE_TARGET} \
1402 || die "emake failed with ${GCC_MAKE_TARGET}"
1403
1404 if ! use build && ! is_crosscompile && ! use nocxx && use doc ; then
1405 if type -p doxygen > /dev/null ; then
1406 cd "${CTARGET}"/libstdc++-v3
1407 make doxygen-man || ewarn "failed to make docs"
1408 else
1409 ewarn "Skipping libstdc++ manpage generation since you don't have doxygen installed"
1410 fi
1411 fi
1412
1413 popd
1414 }
1415
1416 # This function will add ${GCC_CONFIG_VER} to the names of all shared libraries in the
1417 # directory specified to avoid filename collisions between multiple slotted
1418 # non-versioned gcc targets. If no directory is specified, it is assumed that
1419 # you want -all- shared objects to have ${GCC_CONFIG_VER} added. Example
1420 #
1421 # add_version_to_shared ${D}/usr/$(get_libdir)
1422 #
1423 # Travis Tilley <lv@gentoo.org> (05 Sep 2004)
1424 #
1425 add_version_to_shared() {
1426 local sharedlib sharedlibdir
1427 [[ -z $1 ]] \
1428 && sharedlibdir=${D} \
1429 || sharedlibdir=$1
1430
1431 for sharedlib in $(find ${sharedlibdir} -name *.so.*) ; do
1432 if [[ ! -L ${sharedlib} ]] ; then
1433 einfo "Renaming `basename "${sharedlib}"` to `basename "${sharedlib/.so*/}-${GCC_CONFIG_VER}.so.${sharedlib/*.so./}"`"
1434 mv "${sharedlib}" "${sharedlib/.so*/}-${GCC_CONFIG_VER}.so.${sharedlib/*.so./}" \
1435 || die
1436 pushd `dirname "${sharedlib}"` > /dev/null || die
1437 ln -sf "`basename "${sharedlib/.so*/}-${GCC_CONFIG_VER}.so.${sharedlib/*.so./}"`" \
1438 "`basename "${sharedlib}"`" || die
1439 popd > /dev/null || die
1440 fi
1441 done
1442 }
1443
1444 # This is mostly a stub function to be overwritten in an ebuild
1445 gcc_do_filter_flags() {
1446 strip-flags
1447
1448 # In general gcc does not like optimization, and add -O2 where
1449 # it is safe. This is especially true for gcc 3.3 + 3.4
1450 replace-flags -O? -O2
1451
1452 # ... sure, why not?
1453 strip-unsupported-flags
1454
1455 # dont want to funk ourselves
1456 filter-flags '-mabi*' -m31 -m32 -m64
1457
1458 case ${GCC_BRANCH_VER} in
1459 3.2|3.3)
1460 case $(tc-arch) in
1461 x86) filter-flags '-mtune=*';;
1462 amd64) filter-flags '-mtune=*'
1463 replace-cpu-flags k8 athlon64 opteron i686;;
1464 esac
1465 ;;
1466 3.4|4.*)
1467 case $(tc-arch) in
1468 x86|amd64) filter-flags '-mcpu=*';;
1469 esac
1470 ;;
1471 esac
1472
1473 # Compile problems with these (bug #6641 among others)...
1474 #filter-flags "-fno-exceptions -fomit-frame-pointer -fforce-addr"
1475
1476 # CFLAGS logic (verified with 3.4.3):
1477 # CFLAGS:
1478 # This conflicts when creating a crosscompiler, so set to a sane
1479 # default in this case:
1480 # used in ./configure and elsewhere for the native compiler
1481 # used by gcc when creating libiberty.a
1482 # used by xgcc when creating libstdc++ (and probably others)!
1483 # this behavior should be removed...
1484 #
1485 # CXXFLAGS:
1486 # used by xgcc when creating libstdc++
1487 #
1488 # STAGE1_CFLAGS (not used in creating a crosscompile gcc):
1489 # used by ${CHOST}-gcc for building stage1 compiler
1490 #
1491 # BOOT_CFLAGS (not used in creating a crosscompile gcc):
1492 # used by xgcc for building stage2/3 compiler
1493
1494 if is_crosscompile ; then
1495 # Set this to something sane for both native and target
1496 CFLAGS="-O2 -pipe"
1497
1498 local VAR="CFLAGS_"${CTARGET//-/_}
1499 CXXFLAGS=${!VAR}
1500 fi
1501
1502 export GCJFLAGS=${GCJFLAGS:-${CFLAGS}}
1503 }
1504
1505 gcc_src_compile() {
1506 gcc_do_filter_flags
1507 einfo "CFLAGS=\"${CFLAGS}\""
1508 einfo "CXXFLAGS=\"${CXXFLAGS}\""
1509
1510 # Build in a separate build tree
1511 mkdir -p "${WORKDIR}"/build
1512 pushd "${WORKDIR}"/build > /dev/null
1513
1514 # Install our pre generated manpages if we do not have perl ...
1515 [[ ! -x /usr/bin/perl ]] && [[ -n ${MAN_VER} ]] && \
1516 unpack gcc-${MAN_VER}-manpages.tar.bz2
1517
1518 einfo "Configuring ${PN} ..."
1519 gcc_do_configure
1520
1521 touch "${S}"/gcc/c-gperf.h
1522
1523 # Do not make manpages if we do not have perl ...
1524 [[ ! -x /usr/bin/perl ]] \
1525 && find "${WORKDIR}"/build -name '*.[17]' | xargs touch
1526
1527 einfo "Compiling ${PN} ..."
1528 gcc_do_make ${GCC_MAKE_TARGET}
1529
1530 # Do not create multiple specs files for PIE+SSP if boundschecking is in
1531 # USE, as we disable PIE+SSP when it is.
1532 if [[ ${ETYPE} == "gcc-compiler" ]] && want_split_specs ; then
1533 split_out_specs_files || die "failed to split out specs"
1534 fi
1535
1536 popd > /dev/null
1537 }
1538
1539 gcc_src_test() {
1540 cd "${WORKDIR}"/build
1541 make check || ewarn "check failed and that sucks :("
1542 }
1543
1544 gcc-library_src_install() {
1545 einfo "Installing ${PN} ..."
1546 # Do the 'make install' from the build directory
1547 cd "${WORKDIR}"/build
1548 S=${WORKDIR}/build \
1549 make DESTDIR="${EDEST}" \
1550 prefix=${PREFIX} \
1551 bindir=${BINPATH} \
1552 includedir=${LIBPATH}/include \
1553 datadir=${DATAPATH} \
1554 mandir=${DATAPATH}/man \
1555 infodir=${DATAPATH}/info \
1556 LIBPATH="${LIBPATH}" \
1557 ${GCC_INSTALL_TARGET} || die
1558
1559 if [[ ${GCC_LIB_COMPAT_ONLY} == "true" ]] ; then
1560 rm -rf "${D}"${INCLUDEPATH}
1561 rm -rf "${D}"${DATAPATH}
1562 pushd "${D}"${LIBPATH}/
1563 rm *.a *.la *.so
1564 popd
1565 fi
1566
1567 if [[ -n ${GCC_LIB_USE_SUBDIR} ]] ; then
1568 mkdir -p "${WORKDIR}"/${GCC_LIB_USE_SUBDIR}/
1569 mv "${D}"${LIBPATH}/* "${WORKDIR}"/${GCC_LIB_USE_SUBDIR}/
1570 mv "${WORKDIR}"/${GCC_LIB_USE_SUBDIR}/ "${D}"${LIBPATH}
1571
1572 dodir /etc/env.d
1573 echo "LDPATH=\"${LIBPATH}/${GCC_LIB_USE_SUBDIR}/\"" >> "${D}"/etc/env.d/99${PN}
1574 fi
1575
1576 if [[ ${GCC_VAR_TYPE} == "non-versioned" ]] ; then
1577 # if we're not using versioned directories, we need to use versioned
1578 # filenames.
1579 add_version_to_shared
1580 fi
1581 }
1582
1583 gcc-compiler_src_install() {
1584 local x=
1585
1586 # Do allow symlinks in ${PREFIX}/lib/gcc-lib/${CHOST}/${GCC_CONFIG_VER}/include as
1587 # this can break the build.
1588 for x in "${WORKDIR}"/build/gcc/include/* ; do
1589 [[ -L ${x} ]] && rm -f "${x}"
1590 done
1591 # Remove generated headers, as they can cause things to break
1592 # (ncurses, openssl, etc).
1593 for x in $(find "${WORKDIR}"/build/gcc/include/ -name '*.h') ; do
1594 grep -q 'It has been auto-edited by fixincludes from' "${x}" \
1595 && rm -f "${x}"
1596 done
1597 einfo "Installing GCC..."
1598 # Do the 'make install' from the build directory
1599 cd "${WORKDIR}"/build
1600 S=${WORKDIR}/build \
1601 make DESTDIR="${EDEST}" install || die
1602 # Punt some tools which are really only useful while building gcc
1603 rm -r "${D}${LIBEXECPATH}"/install-tools
1604 # This one comes with binutils
1605 find "${D}" -name libiberty.a -exec rm -f {} \;
1606
1607 # Move the libraries to the proper location
1608 gcc_movelibs
1609
1610 # Basic sanity check
1611 is_crosscompile || [[ -r ${D}${BINPATH}/gcc ]] || die "gcc not found in ${D}"
1612
1613 dodir /etc/env.d/gcc
1614 create_gcc_env_entry
1615
1616 if want_split_specs ; then
1617 if use hardened ; then
1618 create_gcc_env_entry vanilla
1619 fi
1620 ! use hardened && hardened_gcc_works && create_gcc_env_entry hardened
1621 if hardened_gcc_works || hardened_gcc_works pie ; then
1622 create_gcc_env_entry hardenednossp
1623 fi
1624 if hardened_gcc_works || hardened_gcc_works ssp ; then
1625 create_gcc_env_entry hardenednopie
1626 fi
1627 create_gcc_env_entry hardenednopiessp
1628
1629 insinto ${LIBPATH}
1630 doins "${WORKDIR}"/build/*.specs || die "failed to install specs"
1631 fi
1632
1633 # Make sure we dont have stuff lying around that
1634 # can nuke multiple versions of gcc
1635 if ! use build ; then
1636 cd ${D}${LIBPATH}
1637
1638 # Move Java headers to compiler-specific dir
1639 for x in ${D}${PREFIX}/include/gc*.h ${D}${PREFIX}/include/j*.h ; do
1640 [[ -f ${x} ]] && mv -f "${x}" ${D}${LIBPATH}/include/
1641 done
1642 for x in gcj gnu java javax org ; do
1643 if [[ -d ${D}${PREFIX}/include/${x} ]] ; then
1644 dodir /${LIBPATH}/include/${x}
1645 mv -f ${D}${PREFIX}/include/${x}/* ${D}${LIBPATH}/include/${x}/
1646 rm -rf ${D}${PREFIX}/include/${x}
1647 fi
1648 done
1649
1650 if [[ -d ${D}${PREFIX}/lib/security ]] ; then
1651 dodir /${LIBPATH}/security
1652 mv -f ${D}${PREFIX}/lib/security/* ${D}${LIBPATH}/security
1653 rm -rf ${D}${PREFIX}/lib/security
1654 fi
1655
1656 # Move libgcj.spec to compiler-specific directories
1657 [[ -f ${D}${PREFIX}/lib/libgcj.spec ]] && \
1658 mv -f ${D}${PREFIX}/lib/libgcj.spec ${D}${LIBPATH}/libgcj.spec
1659
1660 # Rename jar because it could clash with Kaffe's jar if this gcc is
1661 # primary compiler (aka don't have the -<version> extension)
1662 cd ${D}${BINPATH}
1663 [[ -f jar ]] && mv -f jar gcj-jar
1664
1665 # Move <cxxabi.h> to compiler-specific directories
1666 [[ -f ${D}${STDCXX_INCDIR}/cxxabi.h ]] && \
1667 mv -f ${D}${STDCXX_INCDIR}/cxxabi.h ${D}${LIBPATH}/include/
1668
1669 # These should be symlinks
1670 dodir /usr/bin
1671 cd "${D}"${BINPATH}
1672 for x in cpp gcc g++ c++ g77 gcj gcjh gfortran ; do
1673 # For some reason, g77 gets made instead of ${CTARGET}-g77...
1674 # this should take care of that
1675 [[ -f ${x} ]] && mv ${x} ${CTARGET}-${x}
1676
1677 if [[ -f ${CTARGET}-${x} ]] && ! is_crosscompile ; then
1678 ln -sf ${CTARGET}-${x} ${x}
1679
1680 # Create version-ed symlinks
1681 dosym ${BINPATH}/${CTARGET}-${x} \
1682 /usr/bin/${CTARGET}-${x}-${GCC_CONFIG_VER}
1683 dosym ${BINPATH}/${CTARGET}-${x} \
1684 /usr/bin/${x}-${GCC_CONFIG_VER}
1685 fi
1686
1687 if [[ -f ${CTARGET}-${x}-${GCC_CONFIG_VER} ]] ; then
1688 rm -f ${CTARGET}-${x}-${GCC_CONFIG_VER}
1689 ln -sf ${CTARGET}-${x} ${CTARGET}-${x}-${GCC_CONFIG_VER}
1690 fi
1691 done
1692
1693 # I do not know if this will break gcj stuff, so I'll only do it for
1694 # objc for now; basically "ffi.h" is the correct file to include,
1695 # but it gets installed in .../GCCVER/include and yet it does
1696 # "#include <ffitarget.h>" which (correctly, as it's an "extra" file)
1697 # is installed in .../GCCVER/include/libffi; the following fixes
1698 # ffi.'s include of ffitarget.h - Armando Di Cianno <fafhrd@gentoo.org>
1699 if is_objc && ! is_gcj ; then
1700 #dosed "s:<ffitarget.h>:<libffi/ffitarget.h>:g" /${LIBPATH}/include/ffi.h
1701 mv "${D}"${LIBPATH}/include/libffi/* "${D}"${LIBPATH}/include
1702 rm -Rf "${D}"${LIBPATH}/include/libffi
1703 fi
1704 fi
1705
1706 # Now do the fun stripping stuff
1707 env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${BINPATH}" "${D}${LIBEXECPATH}"
1708 env RESTRICT="" CHOST=${CTARGET} prepstrip "${D}${LIBPATH}"
1709
1710 cd "${S}"
1711 if use build || is_crosscompile; then
1712 rm -rf "${D}"/usr/share/{man,info}
1713 rm -rf "${D}"${DATAPATH}/{man,info}
1714 else
1715 local cxx_mandir=${WORKDIR}/build/${CTARGET}/libstdc++-v3/docs/doxygen/man
1716 if [[ -d ${cxx_mandir} ]] ; then
1717 # clean bogus manpages #113902
1718 find "${cxx_mandir}" -name '*_build_*' -exec rm {} \;
1719 cp -r "${cxx_mandir}"/man? "${D}/${DATAPATH}"/man/
1720 fi
1721 has noinfo ${FEATURES} \
1722 && rm -r "${D}/${DATAPATH}"/info \
1723 || prepinfo "${DATAPATH}"
1724 has noman ${FEATURES} \
1725 && rm -r "${D}/${DATAPATH}"/man \
1726 || prepman "${DATAPATH}"
1727 fi
1728 # prune empty dirs left behind
1729 find "${D}" -type d | xargs rmdir >& /dev/null
1730
1731 # Rather install the script, else portage with changing $FILESDIR
1732 # between binary and source package borks things ....
1733 if ! is_crosscompile ; then
1734 insinto "${DATAPATH}"
1735 if tc_version_is_at_least 4.0 ; then
1736 newins "${GCC_FILESDIR}"/awk/fixlafiles.awk-no_gcc_la fixlafiles.awk || die
1737 find "${D}/${LIBPATH}" -name libstdc++.la -type f -exec rm "{}" \;
1738 else
1739 doins "${GCC_FILESDIR}"/awk/fixlafiles.awk || die
1740 fi
1741 exeinto "${DATAPATH}"
1742 doexe "${GCC_FILESDIR}"/fix_libtool_files.sh || die
1743 doexe "${GCC_FILESDIR}"/c{89,99} || die
1744 fi
1745
1746 # use gid of 0 because some stupid ports don't have
1747 # the group 'root' set to gid 0
1748 chown -R ${PORTAGE_INST_UID:-0}:${PORTAGE_INST_GID:-0} "${D}"${LIBPATH}
1749
1750 # Create config files for eselect-compiler
1751 create_eselect_conf
1752 }
1753
1754 # Move around the libs to the right location. For some reason,
1755 # when installing gcc, it dumps internal libraries into /usr/lib
1756 # instead of the private gcc lib path
1757 gcc_movelibs() {
1758 local multiarg removedirs=""
1759 for multiarg in $($(XGCC) -print-multi-lib) ; do
1760 multiarg=${multiarg#*;}
1761 multiarg=${multiarg//@/ -}
1762
1763 local OS_MULTIDIR=$($(XGCC) ${multiarg} --print-multi-os-directory)
1764 local MULTIDIR=$($(XGCC) ${multiarg} --print-multi-directory)
1765 local TODIR=${D}${LIBPATH}/${MULTIDIR}
1766 local FROMDIR=
1767
1768 [[ -d ${TODIR} ]] || mkdir -p ${TODIR}
1769
1770 for FROMDIR in \
1771 ${LIBPATH}/${OS_MULTIDIR} \
1772 ${LIBPATH}/../${MULTIDIR} \
1773 ${PREFIX}/lib/${OS_MULTIDIR} \
1774 ${PREFIX}/${CTARGET}/lib/${OS_MULTIDIR} \
1775 ${PREFIX}/lib/${MULTIDIR}
1776 do
1777 removedirs="${removedirs} ${FROMDIR}"
1778 FROMDIR=${D}${FROMDIR}
1779 if [[ ${FROMDIR} != "${TODIR}" && -d ${FROMDIR} ]] ; then
1780 local files=$(find "${FROMDIR}" -maxdepth 1 ! -type d 2>/dev/null)
1781 if [[ -n ${files} ]] ; then
1782 mv ${files} "${TODIR}"
1783 fi
1784 fi
1785 done
1786 done
1787
1788 # We remove directories separately to avoid this case:
1789 # mv SRC/lib/../lib/*.o DEST
1790 # rmdir SRC/lib/../lib/
1791 # mv SRC/lib/../lib32/*.o DEST # Bork
1792 for FROMDIR in ${removedirs} ; do
1793 rmdir "${D}"${FROMDIR} >& /dev/null
1794 done
1795 find "${D}" -type d | xargs rmdir >& /dev/null
1796
1797 # make sure the libtool archives have libdir set to where they actually
1798 # -are-, and not where they -used- to be.
1799 fix_libtool_libdir_paths "$(find ${D}${LIBPATH} -name *.la)"
1800 }
1801
1802 #----<< src_* >>----
1803
1804 #---->> unorganized crap in need of refactoring follows
1805
1806 # gcc_quick_unpack will unpack the gcc tarball and patches in a way that is
1807 # consistant with the behavior of get_gcc_src_uri. The only patch it applies
1808 # itself is the branch update if present.
1809 #
1810 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
1811 #
1812 gcc_quick_unpack() {
1813 pushd "${WORKDIR}" > /dev/null
1814 export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
1815 export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
1816 export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
1817 export PP_GCC_VER=${PP_GCC_VER:-${GCC_RELEASE_VER}}
1818 export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
1819
1820 if [[ -n ${GCC_A_FAKEIT} ]] ; then
1821 unpack ${GCC_A_FAKEIT}
1822 elif [[ -n ${PRERELEASE} ]] ; then
1823 unpack gcc-${PRERELEASE}.tar.bz2
1824 elif [[ -n ${SNAPSHOT} ]] ; then
1825 unpack gcc-${SNAPSHOT}.tar.bz2
1826 else
1827 unpack gcc-${GCC_RELEASE_VER}.tar.bz2
1828 # We want branch updates to be against a release tarball
1829 if [[ -n ${BRANCH_UPDATE} ]] ; then
1830 pushd ${S:-"$(gcc_get_s_dir)"} > /dev/null
1831 epatch ${DISTDIR}/gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2
1832 popd > /dev/null
1833 fi
1834 fi
1835
1836 [[ -n ${PATCH_VER} ]] && \
1837 unpack gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2
1838
1839 [[ -n ${UCLIBC_VER} ]] && \
1840 unpack gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2
1841
1842 if want_ssp ; then
1843 if [[ -n ${PP_FVER} ]] ; then
1844 # The gcc 3.4 propolice versions are meant to be unpacked to ${S}
1845 pushd ${S:-$(gcc_get_s_dir)} > /dev/null
1846 unpack protector-${PP_FVER}.tar.gz
1847 popd > /dev/null
1848 else
1849 unpack gcc-${PP_GCC_VER}-ssp-${PP_VER}.tar.bz2
1850 fi
1851 fi
1852
1853 if want_pie ; then
1854 if [[ -n ${PIE_CORE} ]] ; then
1855 unpack ${PIE_CORE}
1856 else
1857 unpack gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2
1858 fi
1859 fi
1860
1861 # pappy@gentoo.org - Fri Oct 1 23:24:39 CEST 2004
1862 want_boundschecking && \
1863 unpack "bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
1864
1865 popd > /dev/null
1866 }
1867
1868 # Exclude any unwanted patches, as specified by the following variables:
1869 #
1870 # GENTOO_PATCH_EXCLUDE
1871 # List of filenames, relative to ${WORKDIR}/patch/
1872 #
1873 # PIEPATCH_EXCLUDE
1874 # List of filenames, relative to ${WORKDIR}/piepatch/
1875 #
1876 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
1877 #
1878 exclude_gcc_patches() {
1879 local i
1880 for i in ${GENTOO_PATCH_EXCLUDE} ; do
1881 if [[ -f ${WORKDIR}/patch/${i} ]] ; then
1882 einfo "Excluding patch ${i}"
1883 rm -f "${WORKDIR}"/patch/${i} || die "failed to delete ${i}"
1884 fi
1885 done
1886 for i in ${PIEPATCH_EXCLUDE} ; do
1887 if [[ -f ${WORKDIR}/piepatch/${i} ]] ; then
1888 einfo "Excluding piepatch ${i}"
1889 rm -f "${WORKDIR}"/piepatch/${i} || die "failed to delete ${i}"
1890 fi
1891 done
1892 }
1893
1894 # Try to apply some stub patches so that gcc won't error out when
1895 # passed parameters like -fstack-protector but no ssp is found
1896 do_gcc_stub() {
1897 local v stub_patch=""
1898 for v in ${GCC_RELEASE_VER} ${GCC_BRANCH_VER} ; do
1899 stub_patch=${GCC_FILESDIR}/stubs/gcc-${v}-$1-stub.patch
1900 if [[ -e ${stub_patch} ]] ; then
1901 EPATCH_SINGLE_MSG="Applying stub patch for $1 ..." \
1902 epatch "${stub_patch}"
1903 return 0
1904 fi
1905 done
1906 }
1907
1908 do_gcc_HTB_patches() {
1909 if ! want_boundschecking || \
1910 (want_ssp && [[ ${HTB_EXCLUSIVE} == "true" ]])
1911 then
1912 do_gcc_stub htb
1913 return 0
1914 fi
1915
1916 # modify the bounds checking patch with a regression patch
1917 epatch "${WORKDIR}/bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch"
1918 release_version="${release_version}, HTB-${HTB_GCC_VER}-${HTB_VER}"
1919 }
1920
1921 # patch in ProPolice Stack Smashing protection
1922 do_gcc_SSP_patches() {
1923 # PARISC has no love ... it's our stack :(
1924 if [[ $(tc-arch) == "hppa" ]] || \
1925 ! want_ssp || \
1926 (want_boundschecking && [[ ${HTB_EXCLUSIVE} == "true" ]])
1927 then
1928 do_gcc_stub ssp
1929 return 0
1930 fi
1931
1932 local ssppatch
1933 local sspdocs
1934
1935 if [[ -n ${PP_FVER} ]] ; then
1936 # Etoh keeps changing where files are and what the patch is named
1937 if tc_version_is_at_least 3.4.1 ; then
1938 # >3.4.1 uses version in patch name, and also includes docs
1939 ssppatch="${S}/gcc_${PP_VER}.dif"
1940 sspdocs="yes"
1941 elif tc_version_is_at_least 3.4.0 ; then
1942 # >3.4 put files where they belong and 3_4 uses old patch name
1943 ssppatch="${S}/protector.dif"
1944 sspdocs="no"
1945 elif tc_version_is_at_least 3.2.3 ; then
1946 # earlier versions have no directory structure or docs
1947 mv "${S}"/protector.{c,h} "${S}"/gcc
1948 ssppatch="${S}/protector.dif"
1949 sspdocs="no"
1950 fi
1951 else
1952 # Just start packaging the damn thing ourselves
1953 mv "${WORKDIR}"/ssp/protector.{c,h} "${S}"/gcc/
1954 ssppatch=${WORKDIR}/ssp/gcc-${PP_GCC_VER}-ssp.patch
1955 # allow boundschecking and ssp to get along
1956 (want_boundschecking && [[ -e ${WORKDIR}/ssp/htb-ssp.patch ]]) \
1957 && patch -s "${ssppatch}" "${WORKDIR}"/ssp/htb-ssp.patch
1958 fi
1959
1960 [[ -z ${ssppatch} ]] && die "Sorry, SSP is not supported in this version"
1961 epatch ${ssppatch}
1962
1963 if [[ ${PN} == "gcc" && ${sspdocs} == "no" ]] ; then
1964 epatch "${GCC_FILESDIR}"/pro-police-docs.patch
1965 fi
1966
1967 # Don't build crtbegin/end with ssp
1968 sed -e 's|^CRTSTUFF_CFLAGS = |CRTSTUFF_CFLAGS = -fno-stack-protector |'\
1969 -i gcc/Makefile.in || die "Failed to update crtstuff!"
1970
1971 # if gcc in a stage3 defaults to ssp, is version 3.4.0 and a stage1 is built
1972 # the build fails building timevar.o w/:
1973 # cc1: stack smashing attack in function ix86_split_to_parts()
1974 if use build && tc_version_is_at_least 3.4.0 ; then
1975 if gcc -dumpspecs | grep -q "fno-stack-protector:" ; then
1976 epatch "${GCC_FILESDIR}"/3.4.0/gcc-3.4.0-cc1-no-stack-protector.patch
1977 fi
1978 fi
1979
1980 release_version="${release_version}, ssp-${PP_FVER:-${PP_GCC_VER}-${PP_VER}}"
1981 if want_libssp ; then
1982 update_gcc_for_libssp
1983 else
1984 update_gcc_for_libc_ssp
1985 fi
1986
1987 # Don't build libgcc with ssp
1988 sed -e 's|^\(LIBGCC2_CFLAGS.*\)$|\1 -fno-stack-protector|' \
1989 -i gcc/Makefile.in || die "Failed to update gcc!"
1990 }
1991
1992 # If glibc or uclibc has been patched to provide the necessary symbols itself,
1993 # then lets use those for SSP instead of libgcc.
1994 update_gcc_for_libc_ssp() {
1995 if libc_has_ssp ; then
1996 einfo "Updating gcc to use SSP from libc ..."
1997 sed -e 's|^\(LIBGCC2_CFLAGS.*\)$|\1 -D_LIBC_PROVIDES_SSP_|' \
1998 -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!"
1999 fi
2000 }
2001
2002 # a split out non-libc non-libgcc ssp requires additional spec logic changes
2003 update_gcc_for_libssp() {
2004 einfo "Updating gcc to use SSP from libssp..."
2005 sed -e 's|^\(INTERNAL_CFLAGS.*\)$|\1 -D_LIBSSP_PROVIDES_SSP_|' \
2006 -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!"
2007 }
2008
2009 # do various updates to PIE logic
2010 do_gcc_PIE_patches() {
2011 if ! want_pie || \
2012 (want_boundschecking && [[ ${HTB_EXCLUSIVE} == "true" ]])
2013 then
2014 return 0
2015 fi
2016
2017 want_boundschecking \
2018 && rm -f "${WORKDIR}"/piepatch/*/*-boundschecking-no.patch* \
2019 || rm -f "${WORKDIR}"/piepatch/*/*-boundschecking-yes.patch*
2020
2021 use vanilla && rm -f "${WORKDIR}"/piepatch/*/*uclibc*
2022
2023 guess_patch_type_in_dir "${WORKDIR}"/piepatch/upstream
2024
2025 # corrects startfile/endfile selection and shared/static/pie flag usage
2026 EPATCH_MULTI_MSG="Applying upstream pie patches ..." \
2027 epatch "${WORKDIR}"/piepatch/upstream
2028 # adds non-default pie support (rs6000)
2029 EPATCH_MULTI_MSG="Applying non-default pie patches ..." \
2030 epatch "${WORKDIR}"/piepatch/nondef
2031 # adds default pie support (rs6000 too) if DEFAULT_PIE[_SSP] is defined
2032 EPATCH_MULTI_MSG="Applying default pie patches ..." \
2033 epatch "${WORKDIR}"/piepatch/def
2034
2035 # we want to be able to control the pie patch logic via something other
2036 # than ALL_CFLAGS...
2037 sed -e '/^ALL_CFLAGS/iHARD_CFLAGS = ' \
2038 -e 's|^ALL_CFLAGS = |ALL_CFLAGS = $(HARD_CFLAGS) |' \
2039 -i "${S}"/gcc/Makefile.in
2040
2041 release_version="${release_version}, pie-${PIE_VER}"
2042 }
2043
2044 should_we_gcc_config() {
2045 # we only want to switch compilers if installing to / or /tmp/stage1root
2046 [[ ${ROOT} == "/" || ${ROOT} == "/tmp/stage1root" ]] || return 1
2047
2048 # we always want to run gcc-config if we're bootstrapping, otherwise
2049 # we might get stuck with the c-only stage1 compiler
2050 use bootstrap && return 0
2051 use build && return 0
2052
2053 # if the current config is invalid, we definitely want a new one
2054 # Note: due to bash quirkiness, the following must not be 1 line
2055 local curr_config
2056 curr_config=$(env -i gcc-config -c ${CTARGET} 2>&1) || return 0
2057
2058 # if the previously selected config has the same major.minor (branch) as
2059 # the version we are installing, then it will probably be uninstalled
2060 # for being in the same SLOT, make sure we run gcc-config.
2061 local curr_config_ver=$(env -i gcc-config -S ${curr_config} | awk '{print $2}')
2062
2063 local curr_branch_ver=$(get_version_component_range 1-2 ${curr_config_ver})
2064
2065 # If we're using multislot, just run gcc-config if we're installing
2066 # to the same profile as the current one.
2067 use multislot && return $([[ ${curr_config_ver} == ${GCC_CONFIG_VER} ]])
2068
2069 if [[ ${curr_branch_ver} == ${GCC_BRANCH_VER} ]] ; then
2070 return 0
2071 else
2072 # if we're installing a genuinely different compiler version,
2073 # we should probably tell the user -how- to switch to the new
2074 # gcc version, since we're not going to do it for him/her.
2075 # We don't want to switch from say gcc-3.3 to gcc-3.4 right in
2076 # the middle of an emerge operation (like an 'emerge -e world'
2077 # which could install multiple gcc versions).
2078 einfo "The current gcc config appears valid, so it will not be"
2079 einfo "automatically switched for you. If you would like to"
2080 einfo "switch to the newly installed gcc version, do the"
2081 einfo "following:"
2082 echo
2083 einfo "gcc-config ${CTARGET}-${GCC_CONFIG_VER}"
2084 einfo "source /etc/profile"
2085 echo
2086 ebeep
2087 return 1
2088 fi
2089 }
2090
2091 do_gcc_config() {
2092 if ! should_we_gcc_config ; then
2093 env -i gcc-config --use-old --force
2094 return 0
2095 fi
2096
2097 local current_gcc_config="" current_specs="" use_specs=""
2098
2099 # We grep out any possible errors
2100 current_gcc_config=$(env -i gcc-config -c ${CTARGET} | grep -v '^ ')
2101 if [[ -n ${current_gcc_config} ]] ; then
2102 # figure out which specs-specific config is active
2103 current_specs=$(gcc-config -S ${current_gcc_config} | awk '{print $3}')
2104 [[ -n ${current_specs} ]] && use_specs=-${current_specs}
2105 fi
2106 if [[ -n ${use_specs} ]] && \
2107 [[ ! -e ${ROOT}/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}${use_specs} ]]
2108 then
2109 ewarn "The currently selected specs-specific gcc config,"
2110 ewarn "${current_specs}, doesn't exist anymore. This is usually"
2111 ewarn "due to enabling/disabling hardened or switching to a version"
2112 ewarn "of gcc that doesnt create multiple specs files. The default"
2113 ewarn "config will be used, and the previous preference forgotten."
2114 ebeep
2115 epause
2116 use_specs=""
2117 fi
2118
2119 gcc-config ${CTARGET}-${GCC_CONFIG_VER}${use_specs}
2120 }
2121
2122 should_we_eselect_compiler() {
2123 # we only want to switch compilers if installing to / or /tmp/stage1root
2124 [[ ${ROOT} == "/" || ${ROOT} == "/tmp/stage1root" ]] || return 1
2125
2126 # we always want to run gcc-config if we're bootstrapping, otherwise
2127 # we might get stuck with the c-only stage1 compiler
2128 use bootstrap && return 0
2129 use build && return 0
2130
2131 # if the current config is invalid, we definitely want a new one
2132 # Note: due to bash quirkiness, the following must not be 1 line
2133 local curr_config
2134 curr_config=$(env -i eselect compiler show ${CTARGET} 2>&1) || return 0
2135 [[ -z ${curr_config} || ${curr_config} == "(none)" ]] && return 0
2136
2137 # if the previously selected config has the same major.minor (branch) as
2138 # the version we are installing, then it will probably be uninstalled
2139 # for being in the same SLOT, make sure we run gcc-config.
2140 local curr_config_ver=$(echo ${curr_config} | cut -f1 -d/ | awk -F - '{ print $5 }')
2141 local curr_branch_ver=$(get_version_component_range 1-2 ${curr_config_ver})
2142
2143 # If we're using multislot, just run gcc-config if we're installing
2144 # to the same profile as the current one.
2145 use multislot && return $([[ ${curr_config_ver} == ${GCC_CONFIG_VER} ]])
2146
2147 if [[ ${curr_branch_ver} == ${GCC_BRANCH_VER} ]] ; then
2148 return 0
2149 else
2150 # if we're installing a genuinely different compiler version,
2151 # we should probably tell the user -how- to switch to the new
2152 # gcc version, since we're not going to do it for him/her.
2153 # We don't want to switch from say gcc-3.3 to gcc-3.4 right in
2154 # the middle of an emerge operation (like an 'emerge -e world'
2155 # which could install multiple gcc versions).
2156 einfo "The current gcc config appears valid, so it will not be"
2157 einfo "automatically switched for you. If you would like to"
2158 einfo "switch to the newly installed gcc version, do the"
2159 einfo "following:"
2160 echo
2161 einfo "eselect compiler set <profile>"
2162 echo
2163 ebeep
2164 return 1
2165 fi
2166 }
2167
2168 do_eselect_compiler() {
2169 if ! should_we_eselect_compiler; then
2170 eselect compiler update
2171 return 0
2172 fi
2173
2174 for abi in $(get_all_abis) ; do
2175 local ctarget=$(get_abi_CHOST ${abi})
2176 local current_specs=$(env -i eselect compiler show ${ctarget} | cut -f2 -d/)
2177
2178 if [[ -n ${current_specs} && ${current_specs} != "(none)" ]] && eselect compiler set ${CTARGET}-${GCC_CONFIG_VER}/${current_specs} &> /dev/null; then
2179 einfo "The following compiler profile has been activated based on your previous profile:"
2180 einfo "${CTARGET}-${GCC_CONFIG_VER}/${current_specs}"
2181 else
2182 # We couldn't choose based on the old specs, so fall back on vanilla/hardened based on USE
2183
2184 local spec
2185 if use hardened ; then
2186 spec="hardened"
2187 else
2188 spec="vanilla"
2189 fi
2190
2191 local profile
2192 local isset=0
2193 for profile in "${current_specs%-*}-${spec}" "${abi}-${spec}" "${spec}" ; do
2194 if eselect compiler set ${CTARGET}-${GCC_CONFIG_VER}/${profile} &> /dev/null ; then
2195 ewarn "The newly installed version of gcc does not have a profile that matches the name of your"
2196 ewarn "currently selected profile for ${ctarget}, so we have enabled the following instead:"
2197 ewarn "${CTARGET}-${GCC_CONFIG_VER}/${profile}"
2198 ewarn "If this is incorrect, please use 'eselect compiler set' to"
2199 ewarn "select another profile."
2200
2201 isset=1
2202 break
2203 fi
2204 done
2205
2206 if [[ ${isset} == 0 ]] ; then
2207 eerror "We were not able to automatically set the current compiler for ${ctarget}"
2208 eerror "to your newly emerged gcc. Please use 'eselect compiler set'"
2209 eerror "to select your compiler."
2210 fi
2211 fi
2212 done
2213 }
2214
2215 # This function allows us to gentoo-ize gcc's version number and bugzilla
2216 # URL without needing to use patches.
2217 #
2218 # Travis Tilley <lv@gentoo.org> (02 Sep 2004)
2219 #
2220 gcc_version_patch() {
2221 [[ -z $1 ]] && die "no arguments to gcc_version_patch"
2222
2223 if grep -qs VERSUFFIX "${S}"/gcc/version.c ; then
2224 sed -i -e "s~VERSUFFIX \"\"~VERSUFFIX \" ($2)\"~" \
2225 "${S}"/gcc/version.c || die "failed to update VERSUFFIX with Gentoo branding"
2226 else
2227 version_string="$1 ($2)"
2228 sed -i -e "s~\(const char version_string\[\] = \"\).*\(\".*\)~\1$version_string\2~" \
2229 "${S}"/gcc/version.c || die "failed to update version.c with Gentoo branding."
2230 fi
2231 sed -i -e 's~gcc\.gnu\.org\/bugs\.html~bugs\.gentoo\.org\/~' \
2232 "${S}"/gcc/version.c || die "Failed to change the bug URL"
2233 }
2234
2235 # The purpose of this DISGUSTING gcc multilib hack is to allow 64bit libs
2236 # to live in lib instead of lib64 where they belong, with 32bit libraries
2237 # in lib32. This hack has been around since the beginning of the amd64 port,
2238 # and we're only now starting to fix everything that's broken. Eventually
2239 # this should go away.
2240 #
2241 # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
2242 #
2243 disgusting_gcc_multilib_HACK() {
2244 local config
2245 local libdirs
2246 if has_multilib_profile ; then
2247 case $(tc-arch) in
2248 amd64)
2249 config="i386/t-linux64"
2250 libdirs="../$(get_abi_LIBDIR amd64) ../$(get_abi_LIBDIR x86)" \
2251 ;;
2252 ppc64)
2253 config="rs6000/t-linux64"
2254 libdirs="../$(get_abi_LIBDIR ppc64) ../$(get_abi_LIBDIR ppc)" \
2255 ;;
2256 esac
2257 else
2258 # Remove this hunk when amd64's 2004.3 is purged from portage.
2259 use amd64 || die "Your profile is no longer supported by portage."
2260 config="i386/t-linux64"
2261 libdirs="../$(get_libdir) ../$(get_multilibdir)"
2262 fi
2263
2264 einfo "updating multilib directories to be: ${libdirs}"
2265 sed -i -e "s:^MULTILIB_OSDIRNAMES.*:MULTILIB_OSDIRNAMES = ${libdirs}:" "${S}"/gcc/config/${config}
2266 }
2267
2268 disable_multilib_libjava() {
2269 if is_gcj ; then
2270 # We dont want a multilib libjava, so lets use this hack taken from fedora
2271 pushd "${S}" > /dev/null
2272 sed -i -e 's/^all: all-redirect/ifeq (\$(MULTISUBDIR),)\nall: all-redirect\nelse\nall:\n\techo Multilib libjava build disabled\nendif/' libjava/Makefile.in
2273 sed -i -e 's/^install: install-redirect/ifeq (\$(MULTISUBDIR),)\ninstall: install-redirect\nelse\ninstall:\n\techo Multilib libjava install disabled\nendif/' libjava/Makefile.in
2274 sed -i -e 's/^check: check-redirect/ifeq (\$(MULTISUBDIR),)\ncheck: check-redirect\nelse\ncheck:\n\techo Multilib libjava check disabled\nendif/' libjava/Makefile.in
2275 sed -i -e 's/^all: all-recursive/ifeq (\$(MULTISUBDIR),)\nall: all-recursive\nelse\nall:\n\techo Multilib libjava build disabled\nendif/' libjava/Makefile.in
2276 sed -i -e 's/^install: install-recursive/ifeq (\$(MULTISUBDIR),)\ninstall: install-recursive\nelse\ninstall:\n\techo Multilib libjava install disabled\nendif/' libjava/Makefile.in
2277 sed -i -e 's/^check: check-recursive/ifeq (\$(MULTISUBDIR),)\ncheck: check-recursive\nelse\ncheck:\n\techo Multilib libjava check disabled\nendif/' libjava/Makefile.in
2278 popd > /dev/null
2279 fi
2280 }
2281
2282 fix_libtool_libdir_paths() {
2283 local dirpath
2284 for archive in $* ; do
2285 dirpath=$(dirname ${archive} | sed -e "s:^${D}::")
2286 sed -i ${archive} -e "s:^libdir.*:libdir=\'${dirpath}\':"
2287 done
2288 }
2289
2290 is_multilib() {
2291 [[ ${GCCMAJOR} < 3 ]] && return 1
2292 case ${CTARGET} in
2293 mips64*|powerpc64*|s390x*|sparc64*|x86_64*)
2294 has_multilib_profile || use multilib ;;
2295 *) false ;;
2296 esac
2297 }
2298
2299 is_uclibc() {
2300 [[ ${GCCMAJOR} -lt 3 ]] && return 1
2301 [[ ${CTARGET} == *-uclibc ]]
2302 }
2303
2304 is_cxx() {
2305 gcc-lang-supported 'c++' || return 1
2306 use build && return 1
2307 ! use nocxx
2308 }
2309
2310 is_f77() {
2311 gcc-lang-supported f77 || return 1
2312 use build && return 1
2313 use fortran
2314 }
2315
2316 is_f95() {
2317 gcc-lang-supported f95 || return 1
2318 use build && return 1
2319 use fortran
2320 }
2321
2322 is_fortran() {
2323 gcc-lang-supported fortran || return 1
2324 use build && return 1
2325 use fortran
2326 }
2327
2328 is_gcj() {
2329 gcc-lang-supported java || return 1
2330 use build && return 1
2331 use gcj
2332 }
2333
2334 is_objc() {
2335 gcc-lang-supported objc || return 1
2336 use build && return 1
2337 use objc
2338 }
2339
2340 is_objcxx() {
2341 gcc-lang-supported 'obj-c++' || return 1
2342 use build && return 1
2343 use objc++
2344 }
2345
2346 is_ada() {
2347 gcc-lang-supported ada || return 1
2348 use build && return 1
2349 use ada
2350 }

  ViewVC Help
Powered by ViewVC 1.1.20