/[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.115 Revision 1.137
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2015 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.115 2012/07/26 16:43:59 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.137 2015/04/13 05:38:17 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
84tc-getRANLIB() { tc-getPROG RANLIB ranlib "$@"; } 82tc-getRANLIB() { tc-getPROG RANLIB ranlib "$@"; }
85# @FUNCTION: tc-getOBJCOPY 83# @FUNCTION: tc-getOBJCOPY
86# @USAGE: [toolchain prefix] 84# @USAGE: [toolchain prefix]
87# @RETURN: name of the object copier 85# @RETURN: name of the object copier
88tc-getOBJCOPY() { tc-getPROG OBJCOPY objcopy "$@"; } 86tc-getOBJCOPY() { tc-getPROG OBJCOPY objcopy "$@"; }
87# @FUNCTION: tc-getOBJDUMP
88# @USAGE: [toolchain prefix]
89# @RETURN: name of the object dumper
90tc-getOBJDUMP() { tc-getPROG OBJDUMP objdump "$@"; }
89# @FUNCTION: tc-getF77 91# @FUNCTION: tc-getF77
90# @USAGE: [toolchain prefix] 92# @USAGE: [toolchain prefix]
91# @RETURN: name of the Fortran 77 compiler 93# @RETURN: name of the Fortran 77 compiler
92tc-getF77() { tc-getPROG F77 gfortran "$@"; } 94tc-getF77() { tc-getPROG F77 gfortran "$@"; }
93# @FUNCTION: tc-getFC 95# @FUNCTION: tc-getFC
169} 171}
170 172
171# @FUNCTION: tc-is-cross-compiler 173# @FUNCTION: tc-is-cross-compiler
172# @RETURN: Shell true if we are using a cross-compiler, shell false otherwise 174# @RETURN: Shell true if we are using a cross-compiler, shell false otherwise
173tc-is-cross-compiler() { 175tc-is-cross-compiler() {
174 return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]]) 176 [[ ${CBUILD:-${CHOST}} != ${CHOST} ]]
175} 177}
176 178
177# @FUNCTION: tc-is-softfloat 179# @FUNCTION: tc-is-softfloat
178# @DESCRIPTION: 180# @DESCRIPTION:
179# See if this toolchain is a softfloat based one. 181# See if this toolchain is a softfloat based one.
210# otherwise. 212# otherwise.
211tc-is-static-only() { 213tc-is-static-only() {
212 local host=${CTARGET:-${CHOST}} 214 local host=${CTARGET:-${CHOST}}
213 215
214 # *MiNT doesn't have shared libraries, only platform so far 216 # *MiNT doesn't have shared libraries, only platform so far
215 return $([[ ${host} == *-mint* ]]) 217 [[ ${host} == *-mint* ]]
216} 218}
217 219
218# @FUNCTION: tc-export_build_env 220# @FUNCTION: tc-export_build_env
219# @USAGE: [compiler variables] 221# @USAGE: [compiler variables]
220# @DESCRIPTION: 222# @DESCRIPTION:
221# Export common build related compiler settings. 223# Export common build related compiler settings.
222tc-export_build_env() { 224tc-export_build_env() {
223 tc-export "$@" 225 tc-export "$@"
226 # Some build envs will initialize vars like:
227 # : ${BUILD_LDFLAGS:-${LDFLAGS}}
228 # So make sure all variables are non-empty. #526734
224 : ${BUILD_CFLAGS:=-O1 -pipe} 229 : ${BUILD_CFLAGS:=-O1 -pipe}
225 : ${BUILD_CXXFLAGS:=-O1 -pipe} 230 : ${BUILD_CXXFLAGS:=-O1 -pipe}
226 : ${BUILD_CPPFLAGS:=} 231 : ${BUILD_CPPFLAGS:= }
227 : ${BUILD_LDFLAGS:=} 232 : ${BUILD_LDFLAGS:= }
228 export BUILD_{C,CXX,CPP,LD}FLAGS 233 export BUILD_{C,CXX,CPP,LD}FLAGS
234
235 # Some packages use XXX_FOR_BUILD.
236 local v
237 for v in BUILD_{C,CXX,CPP,LD}FLAGS ; do
238 export ${v#BUILD_}_FOR_BUILD="${!v}"
239 done
229} 240}
230 241
231# @FUNCTION: tc-env_build 242# @FUNCTION: tc-env_build
232# @USAGE: <command> [command args] 243# @USAGE: <command> [command args]
233# @INTERNAL 244# @INTERNAL
291# fi 302# fi
292# ... normal build paths ... 303# ... normal build paths ...
293# } 304# }
294# @CODE 305# @CODE
295econf_build() { 306econf_build() {
307 local CBUILD=${CBUILD:-${CHOST}}
296 tc-env_build econf --build=${CBUILD:-${CHOST}} "$@" 308 tc-env_build econf --build=${CBUILD} --host=${CBUILD} "$@"
309}
310
311# @FUNCTION: tc-ld-is-gold
312# @USAGE: [toolchain prefix]
313# @DESCRIPTION:
314# Return true if the current linker is set to gold.
315tc-ld-is-gold() {
316 local out
317
318 # First check the linker directly.
319 out=$($(tc-getLD "$@") --version 2>&1)
320 if [[ ${out} == *"GNU gold"* ]] ; then
321 return 0
322 fi
323
324 # Then see if they're selecting gold via compiler flags.
325 # Note: We're assuming they're using LDFLAGS to hold the
326 # options and not CFLAGS/CXXFLAGS.
327 local base="${T}/test-tc-gold"
328 cat <<-EOF > "${base}.c"
329 int main() { return 0; }
330 EOF
331 out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version "${base}.c" -o "${base}" 2>&1)
332 rm -f "${base}"*
333 if [[ ${out} == *"GNU gold"* ]] ; then
334 return 0
335 fi
336
337 # No gold here!
338 return 1
339}
340
341# @FUNCTION: tc-ld-disable-gold
342# @USAGE: [toolchain prefix]
343# @DESCRIPTION:
344# If the gold linker is currently selected, configure the compilation
345# settings so that we use the older bfd linker instead.
346tc-ld-disable-gold() {
347 if ! tc-ld-is-gold "$@" ; then
348 # They aren't using gold, so nothing to do!
349 return
350 fi
351
352 ewarn "Forcing usage of the BFD linker instead of GOLD"
353
354 # Set up LD to point directly to bfd if it's available.
355 # We need to extract the first word in case there are flags appended
356 # to its value (like multilib). #545218
357 local ld=$(tc-getLD "$@")
358 local bfd_ld="${ld%% *}.bfd"
359 local path_ld=$(which "${bfd_ld}" 2>/dev/null)
360 [[ -e ${path_ld} ]] && export LD=${bfd_ld}
361
362 # Set up LDFLAGS to select gold based on the gcc version.
363 local major=$(gcc-major-version "$@")
364 local minor=$(gcc-minor-version "$@")
365 if [[ ${major} -lt 4 ]] || [[ ${major} -eq 4 && ${minor} -lt 8 ]] ; then
366 # <=gcc-4.7 requires some coercion. Only works if bfd exists.
367 if [[ -e ${path_ld} ]] ; then
368 local d="${T}/bfd-linker"
369 mkdir -p "${d}"
370 ln -sf "${path_ld}" "${d}"/ld
371 export LDFLAGS="${LDFLAGS} -B${d}"
372 else
373 die "unable to locate a BFD linker to bypass gold"
374 fi
375 else
376 # gcc-4.8+ supports -fuse-ld directly.
377 export LDFLAGS="${LDFLAGS} -fuse-ld=bfd"
378 fi
297} 379}
298 380
299# @FUNCTION: tc-has-openmp 381# @FUNCTION: tc-has-openmp
300# @USAGE: [toolchain prefix] 382# @USAGE: [toolchain prefix]
301# @DESCRIPTION: 383# @DESCRIPTION:
357 439
358 local type=$1 440 local type=$1
359 local host=$2 441 local host=$2
360 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}} 442 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
361 443
444 local KV=${KV:-${KV_FULL}}
445 [[ ${type} == "kern" ]] && [[ -z ${KV} ]] && \
446 ewarn "QA: Kernel version could not be determined, please inherit kernel-2 or linux-info"
447
362 case ${host} in 448 case ${host} in
449 aarch64*) echo arm64;;
363 alpha*) echo alpha;; 450 alpha*) echo alpha;;
364 arm*) echo arm;; 451 arm*) echo arm;;
365 avr*) ninj avr32 avr;; 452 avr*) ninj avr32 avr;;
366 bfin*) ninj blackfin bfin;; 453 bfin*) ninj blackfin bfin;;
454 c6x*) echo c6x;;
367 cris*) echo cris;; 455 cris*) echo cris;;
456 frv*) echo frv;;
457 hexagon*) echo hexagon;;
368 hppa*) ninj parisc hppa;; 458 hppa*) ninj parisc hppa;;
369 i?86*) 459 i?86*)
370 # Starting with linux-2.6.24, the 'x86_64' and 'i386' 460 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
371 # trees have been unified into 'x86'. 461 # trees have been unified into 'x86'.
372 # FreeBSD still uses i386 462 # FreeBSD still uses i386
376 echo x86 466 echo x86
377 fi 467 fi
378 ;; 468 ;;
379 ia64*) echo ia64;; 469 ia64*) echo ia64;;
380 m68*) echo m68k;; 470 m68*) echo m68k;;
471 metag*) echo metag;;
472 microblaze*) echo microblaze;;
381 mips*) echo mips;; 473 mips*) echo mips;;
382 nios2*) echo nios2;; 474 nios2*) echo nios2;;
383 nios*) echo nios;; 475 nios*) echo nios;;
476 or32*) echo openrisc;;
384 powerpc*) 477 powerpc*)
385 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees 478 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees
386 # have been unified into simply 'powerpc', but until 2.6.16, 479 # have been unified into simply 'powerpc', but until 2.6.16,
387 # ppc32 is still using ARCH="ppc" as default 480 # ppc32 is still using ARCH="ppc" as default
388 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]] ; then 481 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]] ; then
399 ninj ppc64 ppc 492 ninj ppc64 ppc
400 else 493 else
401 echo ppc 494 echo ppc
402 fi 495 fi
403 ;; 496 ;;
497 riscv*) echo riscv;;
404 s390*) echo s390;; 498 s390*) echo s390;;
499 score*) echo score;;
405 sh64*) ninj sh64 sh;; 500 sh64*) ninj sh64 sh;;
406 sh*) echo sh;; 501 sh*) echo sh;;
407 sparc64*) ninj sparc64 sparc;; 502 sparc64*) ninj sparc64 sparc;;
408 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \ 503 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \
409 && ninj sparc64 sparc \ 504 && ninj sparc64 sparc \
410 || echo sparc 505 || echo sparc
411 ;; 506 ;;
507 tile*) echo tile;;
412 vax*) echo vax;; 508 vax*) echo vax;;
413 x86_64*freebsd*) echo amd64;; 509 x86_64*freebsd*) echo amd64;;
414 x86_64*) 510 x86_64*)
415 # Starting with linux-2.6.24, the 'x86_64' and 'i386' 511 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
416 # trees have been unified into 'x86'. 512 # trees have been unified into 'x86'.
418 echo x86 514 echo x86
419 else 515 else
420 ninj x86_64 amd64 516 ninj x86_64 amd64
421 fi 517 fi
422 ;; 518 ;;
519 xtensa*) echo xtensa;;
423 520
424 # since our usage of tc-arch is largely concerned with 521 # since our usage of tc-arch is largely concerned with
425 # normalizing inputs for testing ${CTARGET}, let's filter 522 # normalizing inputs for testing ${CTARGET}, let's filter
426 # other cross targets (mingw and such) into the unknown. 523 # other cross targets (mingw and such) into the unknown.
427 *) echo unknown;; 524 *) echo unknown;;
444 local host=$1 541 local host=$1
445 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}} 542 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
446 host=${host%%-*} 543 host=${host%%-*}
447 544
448 case ${host} in 545 case ${host} in
546 aarch64*be) echo big;;
547 aarch64) echo little;;
449 alpha*) echo big;; 548 alpha*) echo big;;
450 arm*b*) echo big;; 549 arm*b*) echo big;;
451 arm*) echo little;; 550 arm*) echo little;;
452 cris*) echo little;; 551 cris*) echo little;;
453 hppa*) echo big;; 552 hppa*) echo big;;
454 i?86*) echo little;; 553 i?86*) echo little;;
455 ia64*) echo little;; 554 ia64*) echo little;;
456 m68*) echo big;; 555 m68*) echo big;;
457 mips*l*) echo little;; 556 mips*l*) echo little;;
458 mips*) echo big;; 557 mips*) echo big;;
558 powerpc*le) echo little;;
459 powerpc*) echo big;; 559 powerpc*) echo big;;
460 s390*) echo big;; 560 s390*) echo big;;
461 sh*b*) echo big;; 561 sh*b*) echo big;;
462 sh*) echo little;; 562 sh*) echo little;;
463 sparc*) echo big;; 563 sparc*) echo big;;
556 656
557# Returns true if gcc sets relro 657# Returns true if gcc sets relro
558gcc-specs-relro() { 658gcc-specs-relro() {
559 local directive 659 local directive
560 directive=$(gcc-specs-directive link_command) 660 directive=$(gcc-specs-directive link_command)
561 return $([[ "${directive/\{!norelro:}" != "${directive}" ]]) 661 [[ "${directive/\{!norelro:}" != "${directive}" ]]
562} 662}
563# Returns true if gcc sets now 663# Returns true if gcc sets now
564gcc-specs-now() { 664gcc-specs-now() {
565 local directive 665 local directive
566 directive=$(gcc-specs-directive link_command) 666 directive=$(gcc-specs-directive link_command)
567 return $([[ "${directive/\{!nonow:}" != "${directive}" ]]) 667 [[ "${directive/\{!nonow:}" != "${directive}" ]]
568} 668}
569# Returns true if gcc builds PIEs 669# Returns true if gcc builds PIEs
570gcc-specs-pie() { 670gcc-specs-pie() {
571 local directive 671 local directive
572 directive=$(gcc-specs-directive cc1) 672 directive=$(gcc-specs-directive cc1)
573 return $([[ "${directive/\{!nopie:}" != "${directive}" ]]) 673 [[ "${directive/\{!nopie:}" != "${directive}" ]]
574} 674}
575# Returns true if gcc builds with the stack protector 675# Returns true if gcc builds with the stack protector
576gcc-specs-ssp() { 676gcc-specs-ssp() {
577 local directive 677 local directive
578 directive=$(gcc-specs-directive cc1) 678 directive=$(gcc-specs-directive cc1)
579 return $([[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]]) 679 [[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]]
580} 680}
581# Returns true if gcc upgrades fstack-protector to fstack-protector-all 681# Returns true if gcc upgrades fstack-protector to fstack-protector-all
582gcc-specs-ssp-to-all() { 682gcc-specs-ssp-to-all() {
583 local directive 683 local directive
584 directive=$(gcc-specs-directive cc1) 684 directive=$(gcc-specs-directive cc1)
585 return $([[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]]) 685 [[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]]
586} 686}
587# Returns true if gcc builds with fno-strict-overflow 687# Returns true if gcc builds with fno-strict-overflow
588gcc-specs-nostrict() { 688gcc-specs-nostrict() {
589 local directive 689 local directive
590 directive=$(gcc-specs-directive cc1) 690 directive=$(gcc-specs-directive cc1)
591 return $([[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]]) 691 [[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]]
692}
693# Returns true if gcc builds with fstack-check
694gcc-specs-stack-check() {
695 local directive
696 directive=$(gcc-specs-directive cc1)
697 [[ "${directive/\{!fno-stack-check:}" != "${directive}" ]]
592} 698}
593 699
594 700
595# @FUNCTION: gen_usr_ldscript 701# @FUNCTION: gen_usr_ldscript
596# @USAGE: [-a] <list of libs to create linker scripts for> 702# @USAGE: [-a] <list of libs to create linker scripts for>
629 dodir /${libdir} 735 dodir /${libdir}
630 fi 736 fi
631 737
632 # OUTPUT_FORMAT gives hints to the linker as to what binary format 738 # OUTPUT_FORMAT gives hints to the linker as to what binary format
633 # is referenced ... makes multilib saner 739 # is referenced ... makes multilib saner
740 local flags=( ${CFLAGS} ${LDFLAGS} -Wl,--verbose )
741 if $(tc-getLD) --version | grep -q 'GNU gold' ; then
742 # If they're using gold, manually invoke the old bfd. #487696
743 local d="${T}/bfd-linker"
744 mkdir -p "${d}"
745 ln -sf $(which ${CHOST}-ld.bfd) "${d}"/ld
746 flags+=( -B"${d}" )
747 fi
634 output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p') 748 output_format=$($(tc-getCC) "${flags[@]}" 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
635 [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )" 749 [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
636 750
637 for lib in "$@" ; do 751 for lib in "$@" ; do
638 local tlib 752 local tlib
639 if ${auto} ; then 753 if ${auto} ; then

Legend:
Removed from v.1.115  
changed lines
  Added in v.1.137

  ViewVC Help
Powered by ViewVC 1.1.20