/[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.127 Revision 1.137
1# Copyright 1999-2014 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.127 2014/07/11 08:21:58 ulm 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
82tc-getRANLIB() { tc-getPROG RANLIB ranlib "$@"; } 82tc-getRANLIB() { tc-getPROG RANLIB ranlib "$@"; }
83# @FUNCTION: tc-getOBJCOPY 83# @FUNCTION: tc-getOBJCOPY
84# @USAGE: [toolchain prefix] 84# @USAGE: [toolchain prefix]
85# @RETURN: name of the object copier 85# @RETURN: name of the object copier
86tc-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 "$@"; }
87# @FUNCTION: tc-getF77 91# @FUNCTION: tc-getF77
88# @USAGE: [toolchain prefix] 92# @USAGE: [toolchain prefix]
89# @RETURN: name of the Fortran 77 compiler 93# @RETURN: name of the Fortran 77 compiler
90tc-getF77() { tc-getPROG F77 gfortran "$@"; } 94tc-getF77() { tc-getPROG F77 gfortran "$@"; }
91# @FUNCTION: tc-getFC 95# @FUNCTION: tc-getFC
167} 171}
168 172
169# @FUNCTION: tc-is-cross-compiler 173# @FUNCTION: tc-is-cross-compiler
170# @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
171tc-is-cross-compiler() { 175tc-is-cross-compiler() {
172 return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]]) 176 [[ ${CBUILD:-${CHOST}} != ${CHOST} ]]
173} 177}
174 178
175# @FUNCTION: tc-is-softfloat 179# @FUNCTION: tc-is-softfloat
176# @DESCRIPTION: 180# @DESCRIPTION:
177# See if this toolchain is a softfloat based one. 181# See if this toolchain is a softfloat based one.
208# otherwise. 212# otherwise.
209tc-is-static-only() { 213tc-is-static-only() {
210 local host=${CTARGET:-${CHOST}} 214 local host=${CTARGET:-${CHOST}}
211 215
212 # *MiNT doesn't have shared libraries, only platform so far 216 # *MiNT doesn't have shared libraries, only platform so far
213 return $([[ ${host} == *-mint* ]]) 217 [[ ${host} == *-mint* ]]
214} 218}
215 219
216# @FUNCTION: tc-export_build_env 220# @FUNCTION: tc-export_build_env
217# @USAGE: [compiler variables] 221# @USAGE: [compiler variables]
218# @DESCRIPTION: 222# @DESCRIPTION:
219# Export common build related compiler settings. 223# Export common build related compiler settings.
220tc-export_build_env() { 224tc-export_build_env() {
221 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
222 : ${BUILD_CFLAGS:=-O1 -pipe} 229 : ${BUILD_CFLAGS:=-O1 -pipe}
223 : ${BUILD_CXXFLAGS:=-O1 -pipe} 230 : ${BUILD_CXXFLAGS:=-O1 -pipe}
224 : ${BUILD_CPPFLAGS:=} 231 : ${BUILD_CPPFLAGS:= }
225 : ${BUILD_LDFLAGS:=} 232 : ${BUILD_LDFLAGS:= }
226 export BUILD_{C,CXX,CPP,LD}FLAGS 233 export BUILD_{C,CXX,CPP,LD}FLAGS
227 234
228 # Some packages use XXX_FOR_BUILD. 235 # Some packages use XXX_FOR_BUILD.
229 local v 236 local v
230 for v in BUILD_{C,CXX,CPP,LD}FLAGS ; do 237 for v in BUILD_{C,CXX,CPP,LD}FLAGS ; do
295# fi 302# fi
296# ... normal build paths ... 303# ... normal build paths ...
297# } 304# }
298# @CODE 305# @CODE
299econf_build() { 306econf_build() {
307 local CBUILD=${CBUILD:-${CHOST}}
300 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
301} 379}
302 380
303# @FUNCTION: tc-has-openmp 381# @FUNCTION: tc-has-openmp
304# @USAGE: [toolchain prefix] 382# @USAGE: [toolchain prefix]
305# @DESCRIPTION: 383# @DESCRIPTION:
371 aarch64*) echo arm64;; 449 aarch64*) echo arm64;;
372 alpha*) echo alpha;; 450 alpha*) echo alpha;;
373 arm*) echo arm;; 451 arm*) echo arm;;
374 avr*) ninj avr32 avr;; 452 avr*) ninj avr32 avr;;
375 bfin*) ninj blackfin bfin;; 453 bfin*) ninj blackfin bfin;;
376 c6x) echo c6x;; 454 c6x*) echo c6x;;
377 cris*) echo cris;; 455 cris*) echo cris;;
378 frv) echo frv;; 456 frv*) echo frv;;
379 hexagon) echo hexagon;; 457 hexagon*) echo hexagon;;
380 hppa*) ninj parisc hppa;; 458 hppa*) ninj parisc hppa;;
381 i?86*) 459 i?86*)
382 # Starting with linux-2.6.24, the 'x86_64' and 'i386' 460 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
383 # trees have been unified into 'x86'. 461 # trees have been unified into 'x86'.
384 # FreeBSD still uses i386 462 # FreeBSD still uses i386
388 echo x86 466 echo x86
389 fi 467 fi
390 ;; 468 ;;
391 ia64*) echo ia64;; 469 ia64*) echo ia64;;
392 m68*) echo m68k;; 470 m68*) echo m68k;;
393 metag) echo metag;; 471 metag*) echo metag;;
472 microblaze*) echo microblaze;;
394 mips*) echo mips;; 473 mips*) echo mips;;
395 nios2*) echo nios2;; 474 nios2*) echo nios2;;
396 nios*) echo nios;; 475 nios*) echo nios;;
397 or32) echo openrisc;; 476 or32*) echo openrisc;;
398 powerpc*) 477 powerpc*)
399 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees 478 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees
400 # have been unified into simply 'powerpc', but until 2.6.16, 479 # have been unified into simply 'powerpc', but until 2.6.16,
401 # ppc32 is still using ARCH="ppc" as default 480 # ppc32 is still using ARCH="ppc" as default
402 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
413 ninj ppc64 ppc 492 ninj ppc64 ppc
414 else 493 else
415 echo ppc 494 echo ppc
416 fi 495 fi
417 ;; 496 ;;
497 riscv*) echo riscv;;
418 s390*) echo s390;; 498 s390*) echo s390;;
419 score) echo score;; 499 score*) echo score;;
420 sh64*) ninj sh64 sh;; 500 sh64*) ninj sh64 sh;;
421 sh*) echo sh;; 501 sh*) echo sh;;
422 sparc64*) ninj sparc64 sparc;; 502 sparc64*) ninj sparc64 sparc;;
423 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \ 503 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \
424 && ninj sparc64 sparc \ 504 && ninj sparc64 sparc \
576 656
577# Returns true if gcc sets relro 657# Returns true if gcc sets relro
578gcc-specs-relro() { 658gcc-specs-relro() {
579 local directive 659 local directive
580 directive=$(gcc-specs-directive link_command) 660 directive=$(gcc-specs-directive link_command)
581 return $([[ "${directive/\{!norelro:}" != "${directive}" ]]) 661 [[ "${directive/\{!norelro:}" != "${directive}" ]]
582} 662}
583# Returns true if gcc sets now 663# Returns true if gcc sets now
584gcc-specs-now() { 664gcc-specs-now() {
585 local directive 665 local directive
586 directive=$(gcc-specs-directive link_command) 666 directive=$(gcc-specs-directive link_command)
587 return $([[ "${directive/\{!nonow:}" != "${directive}" ]]) 667 [[ "${directive/\{!nonow:}" != "${directive}" ]]
588} 668}
589# Returns true if gcc builds PIEs 669# Returns true if gcc builds PIEs
590gcc-specs-pie() { 670gcc-specs-pie() {
591 local directive 671 local directive
592 directive=$(gcc-specs-directive cc1) 672 directive=$(gcc-specs-directive cc1)
593 return $([[ "${directive/\{!nopie:}" != "${directive}" ]]) 673 [[ "${directive/\{!nopie:}" != "${directive}" ]]
594} 674}
595# Returns true if gcc builds with the stack protector 675# Returns true if gcc builds with the stack protector
596gcc-specs-ssp() { 676gcc-specs-ssp() {
597 local directive 677 local directive
598 directive=$(gcc-specs-directive cc1) 678 directive=$(gcc-specs-directive cc1)
599 return $([[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]]) 679 [[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]]
600} 680}
601# Returns true if gcc upgrades fstack-protector to fstack-protector-all 681# Returns true if gcc upgrades fstack-protector to fstack-protector-all
602gcc-specs-ssp-to-all() { 682gcc-specs-ssp-to-all() {
603 local directive 683 local directive
604 directive=$(gcc-specs-directive cc1) 684 directive=$(gcc-specs-directive cc1)
605 return $([[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]]) 685 [[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]]
606} 686}
607# Returns true if gcc builds with fno-strict-overflow 687# Returns true if gcc builds with fno-strict-overflow
608gcc-specs-nostrict() { 688gcc-specs-nostrict() {
609 local directive 689 local directive
610 directive=$(gcc-specs-directive cc1) 690 directive=$(gcc-specs-directive cc1)
611 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}" ]]
612} 698}
613 699
614 700
615# @FUNCTION: gen_usr_ldscript 701# @FUNCTION: gen_usr_ldscript
616# @USAGE: [-a] <list of libs to create linker scripts for> 702# @USAGE: [-a] <list of libs to create linker scripts for>

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

  ViewVC Help
Powered by ViewVC 1.1.20