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

Diff of /eclass/toolchain-funcs.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.111 Revision 1.133
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2014 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.111 2012/06/09 06:56:14 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.133 2015/03/10 17:56:30 vapier Exp $
4 4
5# @ECLASS: toolchain-funcs.eclass 5# @ECLASS: toolchain-funcs.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Toolchain Ninjas <toolchain@gentoo.org> 7# Toolchain Ninjas <toolchain@gentoo.org>
8# @BLURB: functions to query common info about the toolchain 8# @BLURB: functions to query common info about the toolchain
11# for gleaning useful information about the toolchain and to simplify 11# for gleaning useful information about the toolchain and to simplify
12# ugly things like cross-compiling and multilib. All of this is done 12# ugly things like cross-compiling and multilib. All of this is done
13# in such a way that you can rely on the function always returning 13# in such a way that you can rely on the function always returning
14# something sane. 14# something sane.
15 15
16if [[ ${___ECLASS_ONCE_TOOLCHAIN_FUNCS} != "recur -_+^+_- spank" ]] ; then 16if [[ -z ${_TOOLCHAIN_FUNCS_ECLASS} ]]; then
17___ECLASS_ONCE_TOOLCHAIN_FUNCS="recur -_+^+_- spank" 17_TOOLCHAIN_FUNCS_ECLASS=1
18 18
19inherit multilib 19inherit multilib
20
21DESCRIPTION="Based on the ${ECLASS} eclass"
22 20
23# tc-getPROG <VAR [search vars]> <default> [tuple] 21# tc-getPROG <VAR [search vars]> <default> [tuple]
24_tc-getPROG() { 22_tc-getPROG() {
25 local tuple=$1 23 local tuple=$1
26 local v var vars=$2 24 local v var vars=$2
169} 167}
170 168
171# @FUNCTION: tc-is-cross-compiler 169# @FUNCTION: tc-is-cross-compiler
172# @RETURN: Shell true if we are using a cross-compiler, shell false otherwise 170# @RETURN: Shell true if we are using a cross-compiler, shell false otherwise
173tc-is-cross-compiler() { 171tc-is-cross-compiler() {
174 return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]]) 172 [[ ${CBUILD:-${CHOST}} != ${CHOST} ]]
175} 173}
176 174
177# @FUNCTION: tc-is-softfloat 175# @FUNCTION: tc-is-softfloat
178# @DESCRIPTION: 176# @DESCRIPTION:
179# See if this toolchain is a softfloat based one. 177# See if this toolchain is a softfloat based one.
210# otherwise. 208# otherwise.
211tc-is-static-only() { 209tc-is-static-only() {
212 local host=${CTARGET:-${CHOST}} 210 local host=${CTARGET:-${CHOST}}
213 211
214 # *MiNT doesn't have shared libraries, only platform so far 212 # *MiNT doesn't have shared libraries, only platform so far
215 return $([[ ${host} == *-mint* ]]) 213 [[ ${host} == *-mint* ]]
214}
215
216# @FUNCTION: tc-export_build_env
217# @USAGE: [compiler variables]
218# @DESCRIPTION:
219# Export common build related compiler settings.
220tc-export_build_env() {
221 tc-export "$@"
222 : ${BUILD_CFLAGS:=-O1 -pipe}
223 : ${BUILD_CXXFLAGS:=-O1 -pipe}
224 : ${BUILD_CPPFLAGS:=}
225 : ${BUILD_LDFLAGS:=}
226 export BUILD_{C,CXX,CPP,LD}FLAGS
227
228 # Some packages use XXX_FOR_BUILD.
229 local v
230 for v in BUILD_{C,CXX,CPP,LD}FLAGS ; do
231 export ${v#BUILD_}_FOR_BUILD="${!v}"
232 done
216} 233}
217 234
218# @FUNCTION: tc-env_build 235# @FUNCTION: tc-env_build
219# @USAGE: <command> [command args] 236# @USAGE: <command> [command args]
220# @INTERNAL 237# @INTERNAL
222# Setup the compile environment to the build tools and then execute the 239# Setup the compile environment to the build tools and then execute the
223# specified command. We use tc-getBUILD_XX here so that we work with 240# specified command. We use tc-getBUILD_XX here so that we work with
224# all of the semi-[non-]standard env vars like $BUILD_CC which often 241# all of the semi-[non-]standard env vars like $BUILD_CC which often
225# the target build system does not check. 242# the target build system does not check.
226tc-env_build() { 243tc-env_build() {
244 tc-export_build_env
227 CFLAGS=${BUILD_CFLAGS:--O1 -pipe} \ 245 CFLAGS=${BUILD_CFLAGS} \
228 CXXFLAGS=${BUILD_CXXFLAGS:--O1 -pipe} \ 246 CXXFLAGS=${BUILD_CXXFLAGS} \
229 CPPFLAGS=${BUILD_CPPFLAGS} \ 247 CPPFLAGS=${BUILD_CPPFLAGS} \
230 LDFLAGS=${BUILD_LDFLAGS} \ 248 LDFLAGS=${BUILD_LDFLAGS} \
231 AR=$(tc-getBUILD_AR) \ 249 AR=$(tc-getBUILD_AR) \
232 AS=$(tc-getBUILD_AS) \ 250 AS=$(tc-getBUILD_AS) \
233 CC=$(tc-getBUILD_CC) \ 251 CC=$(tc-getBUILD_CC) \
277# fi 295# fi
278# ... normal build paths ... 296# ... normal build paths ...
279# } 297# }
280# @CODE 298# @CODE
281econf_build() { 299econf_build() {
300 local CBUILD=${CBUILD:-${CHOST}}
282 tc-env_build econf --build=${CBUILD:-${CHOST}} "$@" 301 tc-env_build econf --build=${CBUILD} --host=${CBUILD} "$@"
283} 302}
284 303
285# @FUNCTION: tc-has-openmp 304# @FUNCTION: tc-has-openmp
286# @USAGE: [toolchain prefix] 305# @USAGE: [toolchain prefix]
287# @DESCRIPTION: 306# @DESCRIPTION:
343 362
344 local type=$1 363 local type=$1
345 local host=$2 364 local host=$2
346 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}} 365 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
347 366
367 local KV=${KV:-${KV_FULL}}
368 [[ ${type} == "kern" ]] && [[ -z ${KV} ]] && \
369 ewarn "QA: Kernel version could not be determined, please inherit kernel-2 or linux-info"
370
348 case ${host} in 371 case ${host} in
372 aarch64*) echo arm64;;
349 alpha*) echo alpha;; 373 alpha*) echo alpha;;
350 arm*) echo arm;; 374 arm*) echo arm;;
351 avr*) ninj avr32 avr;; 375 avr*) ninj avr32 avr;;
352 bfin*) ninj blackfin bfin;; 376 bfin*) ninj blackfin bfin;;
377 c6x*) echo c6x;;
353 cris*) echo cris;; 378 cris*) echo cris;;
379 frv*) echo frv;;
380 hexagon*) echo hexagon;;
354 hppa*) ninj parisc hppa;; 381 hppa*) ninj parisc hppa;;
355 i?86*) 382 i?86*)
356 # Starting with linux-2.6.24, the 'x86_64' and 'i386' 383 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
357 # trees have been unified into 'x86'. 384 # trees have been unified into 'x86'.
358 # FreeBSD still uses i386 385 # FreeBSD still uses i386
362 echo x86 389 echo x86
363 fi 390 fi
364 ;; 391 ;;
365 ia64*) echo ia64;; 392 ia64*) echo ia64;;
366 m68*) echo m68k;; 393 m68*) echo m68k;;
394 metag*) echo metag;;
395 microblaze*) echo microblaze;;
367 mips*) echo mips;; 396 mips*) echo mips;;
368 nios2*) echo nios2;; 397 nios2*) echo nios2;;
369 nios*) echo nios;; 398 nios*) echo nios;;
399 or32*) echo openrisc;;
370 powerpc*) 400 powerpc*)
371 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees 401 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees
372 # have been unified into simply 'powerpc', but until 2.6.16, 402 # have been unified into simply 'powerpc', but until 2.6.16,
373 # ppc32 is still using ARCH="ppc" as default 403 # ppc32 is still using ARCH="ppc" as default
374 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]] ; then 404 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]] ; then
385 ninj ppc64 ppc 415 ninj ppc64 ppc
386 else 416 else
387 echo ppc 417 echo ppc
388 fi 418 fi
389 ;; 419 ;;
420 riscv*) echo riscv;;
390 s390*) echo s390;; 421 s390*) echo s390;;
422 score*) echo score;;
391 sh64*) ninj sh64 sh;; 423 sh64*) ninj sh64 sh;;
392 sh*) echo sh;; 424 sh*) echo sh;;
393 sparc64*) ninj sparc64 sparc;; 425 sparc64*) ninj sparc64 sparc;;
394 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \ 426 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \
395 && ninj sparc64 sparc \ 427 && ninj sparc64 sparc \
396 || echo sparc 428 || echo sparc
397 ;; 429 ;;
430 tile*) echo tile;;
398 vax*) echo vax;; 431 vax*) echo vax;;
399 x86_64*freebsd*) echo amd64;; 432 x86_64*freebsd*) echo amd64;;
400 x86_64*) 433 x86_64*)
401 # Starting with linux-2.6.24, the 'x86_64' and 'i386' 434 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
402 # trees have been unified into 'x86'. 435 # trees have been unified into 'x86'.
404 echo x86 437 echo x86
405 else 438 else
406 ninj x86_64 amd64 439 ninj x86_64 amd64
407 fi 440 fi
408 ;; 441 ;;
442 xtensa*) echo xtensa;;
409 443
410 # since our usage of tc-arch is largely concerned with 444 # since our usage of tc-arch is largely concerned with
411 # normalizing inputs for testing ${CTARGET}, let's filter 445 # normalizing inputs for testing ${CTARGET}, let's filter
412 # other cross targets (mingw and such) into the unknown. 446 # other cross targets (mingw and such) into the unknown.
413 *) echo unknown;; 447 *) echo unknown;;
430 local host=$1 464 local host=$1
431 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}} 465 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
432 host=${host%%-*} 466 host=${host%%-*}
433 467
434 case ${host} in 468 case ${host} in
469 aarch64*be) echo big;;
470 aarch64) echo little;;
435 alpha*) echo big;; 471 alpha*) echo big;;
436 arm*b*) echo big;; 472 arm*b*) echo big;;
437 arm*) echo little;; 473 arm*) echo little;;
438 cris*) echo little;; 474 cris*) echo little;;
439 hppa*) echo big;; 475 hppa*) echo big;;
440 i?86*) echo little;; 476 i?86*) echo little;;
441 ia64*) echo little;; 477 ia64*) echo little;;
442 m68*) echo big;; 478 m68*) echo big;;
443 mips*l*) echo little;; 479 mips*l*) echo little;;
444 mips*) echo big;; 480 mips*) echo big;;
481 powerpc*le) echo little;;
445 powerpc*) echo big;; 482 powerpc*) echo big;;
446 s390*) echo big;; 483 s390*) echo big;;
447 sh*b*) echo big;; 484 sh*b*) echo big;;
448 sh*) echo little;; 485 sh*) echo little;;
449 sparc*) echo big;; 486 sparc*) echo big;;
542 579
543# Returns true if gcc sets relro 580# Returns true if gcc sets relro
544gcc-specs-relro() { 581gcc-specs-relro() {
545 local directive 582 local directive
546 directive=$(gcc-specs-directive link_command) 583 directive=$(gcc-specs-directive link_command)
547 return $([[ "${directive/\{!norelro:}" != "${directive}" ]]) 584 [[ "${directive/\{!norelro:}" != "${directive}" ]]
548} 585}
549# Returns true if gcc sets now 586# Returns true if gcc sets now
550gcc-specs-now() { 587gcc-specs-now() {
551 local directive 588 local directive
552 directive=$(gcc-specs-directive link_command) 589 directive=$(gcc-specs-directive link_command)
553 return $([[ "${directive/\{!nonow:}" != "${directive}" ]]) 590 [[ "${directive/\{!nonow:}" != "${directive}" ]]
554} 591}
555# Returns true if gcc builds PIEs 592# Returns true if gcc builds PIEs
556gcc-specs-pie() { 593gcc-specs-pie() {
557 local directive 594 local directive
558 directive=$(gcc-specs-directive cc1) 595 directive=$(gcc-specs-directive cc1)
559 return $([[ "${directive/\{!nopie:}" != "${directive}" ]]) 596 [[ "${directive/\{!nopie:}" != "${directive}" ]]
560} 597}
561# Returns true if gcc builds with the stack protector 598# Returns true if gcc builds with the stack protector
562gcc-specs-ssp() { 599gcc-specs-ssp() {
563 local directive 600 local directive
564 directive=$(gcc-specs-directive cc1) 601 directive=$(gcc-specs-directive cc1)
565 return $([[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]]) 602 [[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]]
566} 603}
567# Returns true if gcc upgrades fstack-protector to fstack-protector-all 604# Returns true if gcc upgrades fstack-protector to fstack-protector-all
568gcc-specs-ssp-to-all() { 605gcc-specs-ssp-to-all() {
569 local directive 606 local directive
570 directive=$(gcc-specs-directive cc1) 607 directive=$(gcc-specs-directive cc1)
571 return $([[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]]) 608 [[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]]
572} 609}
573# Returns true if gcc builds with fno-strict-overflow 610# Returns true if gcc builds with fno-strict-overflow
574gcc-specs-nostrict() { 611gcc-specs-nostrict() {
575 local directive 612 local directive
576 directive=$(gcc-specs-directive cc1) 613 directive=$(gcc-specs-directive cc1)
577 return $([[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]]) 614 [[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]]
615}
616# Returns true if gcc builds with fstack-check
617gcc-specs-stack-check() {
618 local directive
619 directive=$(gcc-specs-directive cc1)
620 [[ "${directive/\{!fno-stack-check:}" != "${directive}" ]]
578} 621}
579 622
580 623
581# @FUNCTION: gen_usr_ldscript 624# @FUNCTION: gen_usr_ldscript
582# @USAGE: [-a] <list of libs to create linker scripts for> 625# @USAGE: [-a] <list of libs to create linker scripts for>
596 local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname) 639 local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname)
597 [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/ 640 [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/
598 641
599 tc-is-static-only && return 642 tc-is-static-only && return
600 643
644 # Eventually we'd like to get rid of this func completely #417451
645 case ${CTARGET:-${CHOST}} in
646 *-darwin*) ;;
647 *linux*|*-freebsd*|*-openbsd*|*-netbsd*)
648 use prefix && return 0 ;;
649 *) return 0 ;;
650 esac
651
601 # Just make sure it exists 652 # Just make sure it exists
602 dodir /usr/${libdir} 653 dodir /usr/${libdir}
603 654
604 if [[ $1 == "-a" ]] ; then 655 if [[ $1 == "-a" ]] ; then
605 auto=true 656 auto=true
607 dodir /${libdir} 658 dodir /${libdir}
608 fi 659 fi
609 660
610 # OUTPUT_FORMAT gives hints to the linker as to what binary format 661 # OUTPUT_FORMAT gives hints to the linker as to what binary format
611 # is referenced ... makes multilib saner 662 # is referenced ... makes multilib saner
663 local flags=( ${CFLAGS} ${LDFLAGS} -Wl,--verbose )
664 if $(tc-getLD) --version | grep -q 'GNU gold' ; then
665 # If they're using gold, manually invoke the old bfd. #487696
666 local d="${T}/bfd-linker"
667 mkdir -p "${d}"
668 ln -sf $(which ${CHOST}-ld.bfd) "${d}"/ld
669 flags+=( -B"${d}" )
670 fi
612 output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p') 671 output_format=$($(tc-getCC) "${flags[@]}" 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
613 [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )" 672 [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
614 673
615 for lib in "$@" ; do 674 for lib in "$@" ; do
616 local tlib 675 local tlib
617 if ${auto} ; then 676 if ${auto} ; then
662 # understand linker scripts, just create a symlink. 721 # understand linker scripts, just create a symlink.
663 pushd "${ED}/usr/${libdir}" > /dev/null 722 pushd "${ED}/usr/${libdir}" > /dev/null
664 ln -snf "../../${libdir}/${tlib}" "${lib}" 723 ln -snf "../../${libdir}/${tlib}" "${lib}"
665 popd > /dev/null 724 popd > /dev/null
666 ;; 725 ;;
667 *-aix*|*-irix*|*64*-hpux*|*-interix*|*-winnt*)
668 if ${auto} ; then
669 mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die
670 # no way to retrieve soname on these platforms (?)
671 tlib=$(readlink "${ED}"/${libdir}/${lib})
672 tlib=${tlib##*/}
673 if [[ -z ${tlib} ]] ; then
674 # ok, apparently was not a symlink, don't remove it and
675 # just link to it
676 tlib=${lib}
677 else
678 rm -f "${ED}"/${libdir}/${lib}
679 fi
680 else
681 tlib=${lib}
682 fi
683
684 # we don't have GNU binutils on these platforms, so we symlink
685 # instead, which seems to work fine. Keep it relative, otherwise
686 # we break some QA checks in Portage
687 # on interix, the linker scripts would work fine in _most_
688 # situations. if a library links to such a linker script the
689 # absolute path to the correct library is inserted into the binary,
690 # which is wrong, since anybody linking _without_ libtool will miss
691 # some dependencies, since the stupid linker cannot find libraries
692 # hardcoded with absolute paths (as opposed to the loader, which
693 # seems to be able to do this).
694 # this has been seen while building shared-mime-info which needs
695 # libxml2, but links without libtool (and does not add libz to the
696 # command line by itself).
697 pushd "${ED}/usr/${libdir}" > /dev/null
698 ln -snf "../../${libdir}/${tlib}" "${lib}"
699 popd > /dev/null
700 ;;
701 hppa*-hpux*) # PA-RISC 32bit (SOM) only, others (ELF) match *64*-hpux* above.
702 if ${auto} ; then
703 tlib=$(chatr "${ED}"/usr/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}')
704 [[ -z ${tlib} ]] && tlib=${lib}
705 tlib=${tlib##*/} # 'internal name' can have a path component
706 mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die
707 # some SONAMEs are funky: they encode a version before the .so
708 if [[ ${tlib} != ${lib}* ]] ; then
709 mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die
710 fi
711 [[ ${tlib} != ${lib} ]] &&
712 rm -f "${ED}"/${libdir}/${lib}
713 else
714 tlib=$(chatr "${ED}"/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}')
715 [[ -z ${tlib} ]] && tlib=${lib}
716 tlib=${tlib##*/} # 'internal name' can have a path component
717 fi
718 pushd "${ED}"/usr/${libdir} >/dev/null
719 ln -snf "../../${libdir}/${tlib}" "${lib}"
720 # need the internal name in usr/lib too, to be available at runtime
721 # when linked with /path/to/lib.sl (hardcode_direct_absolute=yes)
722 [[ ${tlib} != ${lib} ]] &&
723 ln -snf "../../${libdir}/${tlib}" "${tlib}"
724 popd >/dev/null
725 ;;
726 *) 726 *)
727 if ${auto} ; then 727 if ${auto} ; then
728 tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib}) 728 tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib})
729 [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}" 729 [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}"
730 mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die 730 mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die

Legend:
Removed from v.1.111  
changed lines
  Added in v.1.133

  ViewVC Help
Powered by ViewVC 1.1.20