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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1233 - (show annotations) (download)
Tue Apr 11 19:13:40 2006 UTC (8 years, 3 months ago) by grobian
File size: 73811 byte(s)
Adding a missing quote, spotted by matt (sesquile)


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

  ViewVC Help
Powered by ViewVC 1.1.20