/[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.20 Revision 1.138
1# Copyright 1999-2004 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.20 2005/01/11 01:07:49 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.138 2015/05/28 07:51:10 vapier Exp $
4# 4
5# @ECLASS: toolchain-funcs.eclass
6# @MAINTAINER:
5# Author: Toolchain Ninjas <ninjas@gentoo.org> 7# Toolchain Ninjas <toolchain@gentoo.org>
6# 8# @BLURB: functions to query common info about the toolchain
7# This eclass contains (or should) functions to get common info 9# @DESCRIPTION:
8# about the toolchain (libc/compiler/binutils/etc...) 10# The toolchain-funcs aims to provide a complete suite of functions
11# for gleaning useful information about the toolchain and to simplify
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
14# something sane.
9 15
16if [[ -z ${_TOOLCHAIN_FUNCS_ECLASS} ]]; then
17_TOOLCHAIN_FUNCS_ECLASS=1
18
10inherit eutils 19inherit multilib
11 20
12ECLASS=toolchain-funcs 21# tc-getPROG <VAR [search vars]> <default> [tuple]
13INHERITED="$INHERITED $ECLASS"
14
15DESCRIPTION="Based on the ${ECLASS} eclass"
16
17tc-getPROG() { 22_tc-getPROG() {
18 local var=$1 23 local tuple=$1
24 local v var vars=$2
19 local prog=$2 25 local prog=$3
20 26
27 var=${vars%% *}
28 for v in ${vars} ; do
21 if [[ -n ${!var} ]] ; then 29 if [[ -n ${!v} ]] ; then
30 export ${var}="${!v}"
22 echo "${!var}" 31 echo "${!v}"
23 return 0 32 return 0
24 fi 33 fi
34 done
25 35
26 if [[ -n ${CHOST} ]] ; then 36 local search=
27 local search=$(type -p "${CHOST}-${prog}") 37 [[ -n $4 ]] && search=$(type -p "$4-${prog}")
38 [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p "${!tuple}-${prog}")
28 [[ -n ${search} ]] && prog=${search##*/} 39 [[ -n ${search} ]] && prog=${search##*/}
29 fi
30 40
31 export ${var}=${prog} 41 export ${var}=${prog}
32 echo "${!var}" 42 echo "${!var}"
33} 43}
44tc-getBUILD_PROG() { _tc-getPROG CBUILD "BUILD_$1 $1_FOR_BUILD HOST$1" "${@:2}"; }
45tc-getPROG() { _tc-getPROG CHOST "$@"; }
34 46
35# Returns the name of the archiver 47# @FUNCTION: tc-getAR
48# @USAGE: [toolchain prefix]
49# @RETURN: name of the archiver
36tc-getAR() { tc-getPROG AR ar; } 50tc-getAR() { tc-getPROG AR ar "$@"; }
37# Returns the name of the assembler 51# @FUNCTION: tc-getAS
52# @USAGE: [toolchain prefix]
53# @RETURN: name of the assembler
38tc-getAS() { tc-getPROG AS as; } 54tc-getAS() { tc-getPROG AS as "$@"; }
55# @FUNCTION: tc-getCC
56# @USAGE: [toolchain prefix]
39# Returns the name of the C compiler 57# @RETURN: name of the C compiler
40tc-getCC() { tc-getPROG CC gcc; } 58tc-getCC() { tc-getPROG CC gcc "$@"; }
59# @FUNCTION: tc-getCPP
60# @USAGE: [toolchain prefix]
61# @RETURN: name of the C preprocessor
62tc-getCPP() { tc-getPROG CPP cpp "$@"; }
63# @FUNCTION: tc-getCXX
64# @USAGE: [toolchain prefix]
41# Returns the name of the C++ compiler 65# @RETURN: name of the C++ compiler
42tc-getCXX() { tc-getPROG CXX g++; } 66tc-getCXX() { tc-getPROG CXX g++ "$@"; }
43# Returns the name of the linker 67# @FUNCTION: tc-getLD
68# @USAGE: [toolchain prefix]
69# @RETURN: name of the linker
44tc-getLD() { tc-getPROG LD ld; } 70tc-getLD() { tc-getPROG LD ld "$@"; }
71# @FUNCTION: tc-getSTRIP
72# @USAGE: [toolchain prefix]
73# @RETURN: name of the strip program
74tc-getSTRIP() { tc-getPROG STRIP strip "$@"; }
75# @FUNCTION: tc-getNM
76# @USAGE: [toolchain prefix]
45# Returns the name of the symbol/object thingy 77# @RETURN: name of the symbol/object thingy
46tc-getNM() { tc-getPROG NM nm; } 78tc-getNM() { tc-getPROG NM nm "$@"; }
79# @FUNCTION: tc-getRANLIB
80# @USAGE: [toolchain prefix]
47# Returns the name of the archiver indexer 81# @RETURN: name of the archiver indexer
48tc-getRANLIB() { tc-getPROG RANLIB ranlib; } 82tc-getRANLIB() { tc-getPROG RANLIB ranlib "$@"; }
49# Returns the name of the fortran compiler 83# @FUNCTION: tc-getOBJCOPY
84# @USAGE: [toolchain prefix]
85# @RETURN: name of the object copier
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 "$@"; }
91# @FUNCTION: tc-getF77
92# @USAGE: [toolchain prefix]
93# @RETURN: name of the Fortran 77 compiler
50tc-getF77() { tc-getPROG F77 f77; } 94tc-getF77() { tc-getPROG F77 gfortran "$@"; }
95# @FUNCTION: tc-getFC
96# @USAGE: [toolchain prefix]
97# @RETURN: name of the Fortran 90 compiler
98tc-getFC() { tc-getPROG FC gfortran "$@"; }
99# @FUNCTION: tc-getGCJ
100# @USAGE: [toolchain prefix]
51# Returns the name of the java compiler 101# @RETURN: name of the java compiler
52tc-getGCJ() { tc-getPROG GCJ gcj; } 102tc-getGCJ() { tc-getPROG GCJ gcj "$@"; }
103# @FUNCTION: tc-getGO
104# @USAGE: [toolchain prefix]
105# @RETURN: name of the Go compiler
106tc-getGO() { tc-getPROG GO gccgo "$@"; }
107# @FUNCTION: tc-getPKG_CONFIG
108# @USAGE: [toolchain prefix]
109# @RETURN: name of the pkg-config tool
110tc-getPKG_CONFIG() { tc-getPROG PKG_CONFIG pkg-config "$@"; }
111# @FUNCTION: tc-getRC
112# @USAGE: [toolchain prefix]
113# @RETURN: name of the Windows resource compiler
114tc-getRC() { tc-getPROG RC windres "$@"; }
115# @FUNCTION: tc-getDLLWRAP
116# @USAGE: [toolchain prefix]
117# @RETURN: name of the Windows dllwrap utility
118tc-getDLLWRAP() { tc-getPROG DLLWRAP dllwrap "$@"; }
53 119
54# Returns the name of the C compiler for build 120# @FUNCTION: tc-getBUILD_AR
55tc-getBUILD_CC() { 121# @USAGE: [toolchain prefix]
56 if [[ -n ${CC_FOR_BUILD} ]] ; then 122# @RETURN: name of the archiver for building binaries to run on the build machine
57 export BUILD_CC=${CC_FOR_BUILD} 123tc-getBUILD_AR() { tc-getBUILD_PROG AR ar "$@"; }
58 echo "${CC_FOR_BUILD}" 124# @FUNCTION: tc-getBUILD_AS
59 return 0 125# @USAGE: [toolchain prefix]
60 fi 126# @RETURN: name of the assembler for building binaries to run on the build machine
127tc-getBUILD_AS() { tc-getBUILD_PROG AS as "$@"; }
128# @FUNCTION: tc-getBUILD_CC
129# @USAGE: [toolchain prefix]
130# @RETURN: name of the C compiler for building binaries to run on the build machine
131tc-getBUILD_CC() { tc-getBUILD_PROG CC gcc "$@"; }
132# @FUNCTION: tc-getBUILD_CPP
133# @USAGE: [toolchain prefix]
134# @RETURN: name of the C preprocessor for building binaries to run on the build machine
135tc-getBUILD_CPP() { tc-getBUILD_PROG CPP cpp "$@"; }
136# @FUNCTION: tc-getBUILD_CXX
137# @USAGE: [toolchain prefix]
138# @RETURN: name of the C++ compiler for building binaries to run on the build machine
139tc-getBUILD_CXX() { tc-getBUILD_PROG CXX g++ "$@"; }
140# @FUNCTION: tc-getBUILD_LD
141# @USAGE: [toolchain prefix]
142# @RETURN: name of the linker for building binaries to run on the build machine
143tc-getBUILD_LD() { tc-getBUILD_PROG LD ld "$@"; }
144# @FUNCTION: tc-getBUILD_STRIP
145# @USAGE: [toolchain prefix]
146# @RETURN: name of the strip program for building binaries to run on the build machine
147tc-getBUILD_STRIP() { tc-getBUILD_PROG STRIP strip "$@"; }
148# @FUNCTION: tc-getBUILD_NM
149# @USAGE: [toolchain prefix]
150# @RETURN: name of the symbol/object thingy for building binaries to run on the build machine
151tc-getBUILD_NM() { tc-getBUILD_PROG NM nm "$@"; }
152# @FUNCTION: tc-getBUILD_RANLIB
153# @USAGE: [toolchain prefix]
154# @RETURN: name of the archiver indexer for building binaries to run on the build machine
155tc-getBUILD_RANLIB() { tc-getBUILD_PROG RANLIB ranlib "$@"; }
156# @FUNCTION: tc-getBUILD_OBJCOPY
157# @USAGE: [toolchain prefix]
158# @RETURN: name of the object copier for building binaries to run on the build machine
159tc-getBUILD_OBJCOPY() { tc-getBUILD_PROG OBJCOPY objcopy "$@"; }
160# @FUNCTION: tc-getBUILD_PKG_CONFIG
161# @USAGE: [toolchain prefix]
162# @RETURN: name of the pkg-config tool for building binaries to run on the build machine
163tc-getBUILD_PKG_CONFIG() { tc-getBUILD_PROG PKG_CONFIG pkg-config "$@"; }
61 164
62 local search= 165# @FUNCTION: tc-export
63 if [[ -n ${CBUILD} ]] ; then 166# @USAGE: <list of toolchain variables>
64 search=$(type -p "${CBUILD}-gcc") 167# @DESCRIPTION:
65 search=${search##*/}
66 else
67 search=gcc
68 fi
69
70 export BUILD_CC=${search}
71 echo "${search}"
72}
73
74# Quick way to export a bunch of vars at once 168# Quick way to export a bunch of compiler vars at once.
75tc-export() { 169tc-export() {
76 local var 170 local var
77 for var in "$@" ; do 171 for var in "$@" ; do
172 [[ $(type -t tc-get${var}) != "function" ]] && die "tc-export: invalid export variable '${var}'"
78 eval tc-get${var} 173 eval tc-get${var} > /dev/null
79 done 174 done
80} 175}
81 176
82# A simple way to see if we're using a cross-compiler ... 177# @FUNCTION: tc-is-cross-compiler
178# @RETURN: Shell true if we are using a cross-compiler, shell false otherwise
83tc-is-cross-compiler() { 179tc-is-cross-compiler() {
84 if [[ -n ${CBUILD} ]] ; then 180 [[ ${CBUILD:-${CHOST}} != ${CHOST} ]]
85 return $([[ ${CBUILD} != ${CHOST} ]]) 181}
182
183# @FUNCTION: tc-is-softfloat
184# @DESCRIPTION:
185# See if this toolchain is a softfloat based one.
186# @CODE
187# The possible return values:
188# - only: the target is always softfloat (never had fpu)
189# - yes: the target should support softfloat
190# - softfp: (arm specific) the target should use hardfloat insns, but softfloat calling convention
191# - no: the target doesn't support softfloat
192# @CODE
193# This allows us to react differently where packages accept
194# softfloat flags in the case where support is optional, but
195# rejects softfloat flags where the target always lacks an fpu.
196tc-is-softfloat() {
197 local CTARGET=${CTARGET:-${CHOST}}
198 case ${CTARGET} in
199 bfin*|h8300*)
200 echo "only" ;;
201 *)
202 if [[ ${CTARGET//_/-} == *-softfloat-* ]] ; then
203 echo "yes"
204 elif [[ ${CTARGET//_/-} == *-softfp-* ]] ; then
205 echo "softfp"
206 else
207 echo "no"
208 fi
209 ;;
210 esac
211}
212
213# @FUNCTION: tc-is-static-only
214# @DESCRIPTION:
215# Return shell true if the target does not support shared libs, shell false
216# otherwise.
217tc-is-static-only() {
218 local host=${CTARGET:-${CHOST}}
219
220 # *MiNT doesn't have shared libraries, only platform so far
221 [[ ${host} == *-mint* ]]
222}
223
224# @FUNCTION: tc-export_build_env
225# @USAGE: [compiler variables]
226# @DESCRIPTION:
227# Export common build related compiler settings.
228tc-export_build_env() {
229 tc-export "$@"
230 # Some build envs will initialize vars like:
231 # : ${BUILD_LDFLAGS:-${LDFLAGS}}
232 # So make sure all variables are non-empty. #526734
233 : ${BUILD_CFLAGS:=-O1 -pipe}
234 : ${BUILD_CXXFLAGS:=-O1 -pipe}
235 : ${BUILD_CPPFLAGS:= }
236 : ${BUILD_LDFLAGS:= }
237 export BUILD_{C,CXX,CPP,LD}FLAGS
238
239 # Some packages use XXX_FOR_BUILD.
240 local v
241 for v in BUILD_{C,CXX,CPP,LD}FLAGS ; do
242 export ${v#BUILD_}_FOR_BUILD="${!v}"
243 done
244}
245
246# @FUNCTION: tc-env_build
247# @USAGE: <command> [command args]
248# @INTERNAL
249# @DESCRIPTION:
250# Setup the compile environment to the build tools and then execute the
251# specified command. We use tc-getBUILD_XX here so that we work with
252# all of the semi-[non-]standard env vars like $BUILD_CC which often
253# the target build system does not check.
254tc-env_build() {
255 tc-export_build_env
256 CFLAGS=${BUILD_CFLAGS} \
257 CXXFLAGS=${BUILD_CXXFLAGS} \
258 CPPFLAGS=${BUILD_CPPFLAGS} \
259 LDFLAGS=${BUILD_LDFLAGS} \
260 AR=$(tc-getBUILD_AR) \
261 AS=$(tc-getBUILD_AS) \
262 CC=$(tc-getBUILD_CC) \
263 CPP=$(tc-getBUILD_CPP) \
264 CXX=$(tc-getBUILD_CXX) \
265 LD=$(tc-getBUILD_LD) \
266 NM=$(tc-getBUILD_NM) \
267 PKG_CONFIG=$(tc-getBUILD_PKG_CONFIG) \
268 RANLIB=$(tc-getBUILD_RANLIB) \
269 "$@"
270}
271
272# @FUNCTION: econf_build
273# @USAGE: [econf flags]
274# @DESCRIPTION:
275# Sometimes we need to locally build up some tools to run on CBUILD because
276# the package has helper utils which are compiled+executed when compiling.
277# This won't work when cross-compiling as the CHOST is set to a target which
278# we cannot natively execute.
279#
280# For example, the python package will build up a local python binary using
281# a portable build system (configure+make), but then use that binary to run
282# local python scripts to build up other components of the overall python.
283# We cannot rely on the python binary in $PATH as that often times will be
284# a different version, or not even installed in the first place. Instead,
285# we compile the code in a different directory to run on CBUILD, and then
286# use that binary when compiling the main package to run on CHOST.
287#
288# For example, with newer EAPIs, you'd do something like:
289# @CODE
290# src_configure() {
291# ECONF_SOURCE=${S}
292# if tc-is-cross-compiler ; then
293# mkdir "${WORKDIR}"/${CBUILD}
294# pushd "${WORKDIR}"/${CBUILD} >/dev/null
295# econf_build --disable-some-unused-stuff
296# popd >/dev/null
297# fi
298# ... normal build paths ...
299# }
300# src_compile() {
301# if tc-is-cross-compiler ; then
302# pushd "${WORKDIR}"/${CBUILD} >/dev/null
303# emake one-or-two-build-tools
304# ln/mv build-tools to normal build paths in ${S}/
305# popd >/dev/null
306# fi
307# ... normal build paths ...
308# }
309# @CODE
310econf_build() {
311 local CBUILD=${CBUILD:-${CHOST}}
312 tc-env_build econf --build=${CBUILD} --host=${CBUILD} "$@"
313}
314
315# @FUNCTION: tc-ld-is-gold
316# @USAGE: [toolchain prefix]
317# @DESCRIPTION:
318# Return true if the current linker is set to gold.
319tc-ld-is-gold() {
320 local out
321
322 # First check the linker directly.
323 out=$($(tc-getLD "$@") --version 2>&1)
324 if [[ ${out} == *"GNU gold"* ]] ; then
325 return 0
86 fi 326 fi
327
328 # Then see if they're selecting gold via compiler flags.
329 # Note: We're assuming they're using LDFLAGS to hold the
330 # options and not CFLAGS/CXXFLAGS.
331 local base="${T}/test-tc-gold"
332 cat <<-EOF > "${base}.c"
333 int main() { return 0; }
334 EOF
335 out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version "${base}.c" -o "${base}" 2>&1)
336 rm -f "${base}"*
337 if [[ ${out} == *"GNU gold"* ]] ; then
338 return 0
339 fi
340
341 # No gold here!
87 return 1 342 return 1
88} 343}
89 344
345# @FUNCTION: tc-ld-disable-gold
346# @USAGE: [toolchain prefix]
347# @DESCRIPTION:
348# If the gold linker is currently selected, configure the compilation
349# settings so that we use the older bfd linker instead.
350tc-ld-disable-gold() {
351 if ! tc-ld-is-gold "$@" ; then
352 # They aren't using gold, so nothing to do!
353 return
354 fi
90 355
356 ewarn "Forcing usage of the BFD linker instead of GOLD"
357
358 # Set up LD to point directly to bfd if it's available.
359 # We need to extract the first word in case there are flags appended
360 # to its value (like multilib). #545218
361 local ld=$(tc-getLD "$@")
362 local bfd_ld="${ld%% *}.bfd"
363 local path_ld=$(which "${bfd_ld}" 2>/dev/null)
364 [[ -e ${path_ld} ]] && export LD=${bfd_ld}
365
366 # Set up LDFLAGS to select gold based on the gcc version.
367 local major=$(gcc-major-version "$@")
368 local minor=$(gcc-minor-version "$@")
369 if [[ ${major} -lt 4 ]] || [[ ${major} -eq 4 && ${minor} -lt 8 ]] ; then
370 # <=gcc-4.7 requires some coercion. Only works if bfd exists.
371 if [[ -e ${path_ld} ]] ; then
372 local d="${T}/bfd-linker"
373 mkdir -p "${d}"
374 ln -sf "${path_ld}" "${d}"/ld
375 export LDFLAGS="${LDFLAGS} -B${d}"
376 else
377 die "unable to locate a BFD linker to bypass gold"
378 fi
379 else
380 # gcc-4.8+ supports -fuse-ld directly.
381 export LDFLAGS="${LDFLAGS} -fuse-ld=bfd"
382 fi
383}
384
385# @FUNCTION: tc-has-openmp
386# @USAGE: [toolchain prefix]
387# @DESCRIPTION:
388# See if the toolchain supports OpenMP.
389tc-has-openmp() {
390 local base="${T}/test-tc-openmp"
391 cat <<-EOF > "${base}.c"
392 #include <omp.h>
393 int main() {
394 int nthreads, tid, ret = 0;
395 #pragma omp parallel private(nthreads, tid)
396 {
397 tid = omp_get_thread_num();
398 nthreads = omp_get_num_threads(); ret += tid + nthreads;
399 }
400 return ret;
401 }
402 EOF
403 $(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" >&/dev/null
404 local ret=$?
405 rm -f "${base}"*
406 return ${ret}
407}
408
409# @FUNCTION: tc-has-tls
410# @USAGE: [-s|-c|-l] [toolchain prefix]
411# @DESCRIPTION:
412# See if the toolchain supports thread local storage (TLS). Use -s to test the
413# compiler, -c to also test the assembler, and -l to also test the C library
414# (the default).
415tc-has-tls() {
416 local base="${T}/test-tc-tls"
417 cat <<-EOF > "${base}.c"
418 int foo(int *i) {
419 static __thread int j = 0;
420 return *i ? j : *i;
421 }
422 EOF
423 local flags
424 case $1 in
425 -s) flags="-S";;
426 -c) flags="-c";;
427 -l) ;;
428 -*) die "Usage: tc-has-tls [-c|-l] [toolchain prefix]";;
429 esac
430 : ${flags:=-fPIC -shared -Wl,-z,defs}
431 [[ $1 == -* ]] && shift
432 $(tc-getCC "$@") ${flags} "${base}.c" -o "${base}" >&/dev/null
433 local ret=$?
434 rm -f "${base}"*
435 return ${ret}
436}
437
438
91# Parse information from CBUILD/CHOST/CTARGET rather than 439# Parse information from CBUILD/CHOST/CTARGET rather than
92# use external variables from the profile. 440# use external variables from the profile.
93tc-ninja_magic_to_arch() { 441tc-ninja_magic_to_arch() {
94ninj() { [[ ${type} = "kern" ]] && echo $1 || echo $2 ; } 442ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; }
95 443
96 local type=$1 444 local type=$1
97 local host=$2 445 local host=$2
98 [[ -z ${host} ]] && arg=${CHOST} 446 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
447
448 local KV=${KV:-${KV_FULL}}
449 [[ ${type} == "kern" ]] && [[ -z ${KV} ]] && \
450 ewarn "QA: Kernel version could not be determined, please inherit kernel-2 or linux-info"
99 451
100 case ${host} in 452 case ${host} in
453 aarch64*) echo arm64;;
101 alpha*) echo alpha;; 454 alpha*) echo alpha;;
102 x86_64*) ninj x86_64 amd64;;
103 arm*) echo arm;; 455 arm*) echo arm;;
456 avr*) ninj avr32 avr;;
457 bfin*) ninj blackfin bfin;;
458 c6x*) echo c6x;;
459 cris*) echo cris;;
460 frv*) echo frv;;
461 hexagon*) echo hexagon;;
104 hppa*) ninj parisc hppa;; 462 hppa*) ninj parisc hppa;;
463 i?86*)
464 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
465 # trees have been unified into 'x86'.
466 # FreeBSD still uses i386
467 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -lt $(KV_to_int 2.6.24) || ${host} == *freebsd* ]] ; then
468 echo i386
469 else
470 echo x86
471 fi
472 ;;
105 ia64*) echo ia64;; 473 ia64*) echo ia64;;
474 m68*) echo m68k;;
475 metag*) echo metag;;
476 microblaze*) echo microblaze;;
106 mips*) echo mips;; 477 mips*) echo mips;;
107 powerpc64*) echo ppc64;; 478 nios2*) echo nios2;;
108 powerpc*) echo ppc;; 479 nios*) echo nios;;
109 sparc64*) ninj sparc64 sparc;; 480 or32*) echo openrisc;;
110 sparc*) echo sparc;; 481 powerpc*)
482 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees
483 # have been unified into simply 'powerpc', but until 2.6.16,
484 # ppc32 is still using ARCH="ppc" as default
485 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]] ; then
486 echo powerpc
487 elif [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -eq $(KV_to_int 2.6.15) ]] ; then
488 if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]] ; then
489 echo powerpc
490 else
491 echo ppc
492 fi
493 elif [[ ${host} == powerpc64* ]] ; then
494 echo ppc64
495 elif [[ ${PROFILE_ARCH} == "ppc64" ]] ; then
496 ninj ppc64 ppc
497 else
498 echo ppc
499 fi
500 ;;
501 riscv*) echo riscv;;
111 s390*) echo s390;; 502 s390*) echo s390;;
503 score*) echo score;;
112 sh64*) ninj sh64 sh;; 504 sh64*) ninj sh64 sh;;
113 sh*) echo sh;; 505 sh*) echo sh;;
506 sparc64*) ninj sparc64 sparc;;
507 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \
508 && ninj sparc64 sparc \
509 || echo sparc
510 ;;
511 tile*) echo tile;;
512 vax*) echo vax;;
513 x86_64*freebsd*) echo amd64;;
514 x86_64*)
515 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
516 # trees have been unified into 'x86'.
517 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.24) ]] ; then
518 echo x86
519 else
520 ninj x86_64 amd64
521 fi
522 ;;
523 xtensa*) echo xtensa;;
524
525 # since our usage of tc-arch is largely concerned with
526 # normalizing inputs for testing ${CTARGET}, let's filter
527 # other cross targets (mingw and such) into the unknown.
528 *) echo unknown;;
529 esac
530}
531# @FUNCTION: tc-arch-kernel
532# @USAGE: [toolchain prefix]
533# @RETURN: name of the kernel arch according to the compiler target
534tc-arch-kernel() {
535 tc-ninja_magic_to_arch kern "$@"
536}
537# @FUNCTION: tc-arch
538# @USAGE: [toolchain prefix]
539# @RETURN: name of the portage arch according to the compiler target
540tc-arch() {
541 tc-ninja_magic_to_arch portage "$@"
542}
543
544tc-endian() {
545 local host=$1
546 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
547 host=${host%%-*}
548
549 case ${host} in
550 aarch64*be) echo big;;
551 aarch64) echo little;;
552 alpha*) echo big;;
553 arm*b*) echo big;;
554 arm*) echo little;;
555 cris*) echo little;;
556 hppa*) echo big;;
114 i?86*) echo x86;; 557 i?86*) echo little;;
558 ia64*) echo little;;
559 m68*) echo big;;
560 mips*l*) echo little;;
561 mips*) echo big;;
562 powerpc*le) echo little;;
563 powerpc*) echo big;;
564 s390*) echo big;;
565 sh*b*) echo big;;
566 sh*) echo little;;
567 sparc*) echo big;;
568 x86_64*) echo little;;
115 *) echo wtf;; 569 *) echo wtf;;
116 esac 570 esac
117} 571}
118tc-arch-kernel() {
119 tc-ninja_magic_to_arch kern $@
120}
121tc-arch() {
122 tc-ninja_magic_to_arch portage $@
123}
124tc-endian() {
125 local host=$1
126 [[ -z ${host} ]] && host=${CHOST}
127 572
128 case ${host} in 573# Internal func. The first argument is the version info to expand.
129 alpha*) echo big;; 574# Query the preprocessor to improve compatibility across different
130 x86_64*) echo little;; 575# compilers rather than maintaining a --version flag matrix. #335943
131 arm*eb-*) echo big;; 576_gcc_fullversion() {
132 arm*) echo little;; 577 local ver="$1"; shift
133 hppa*) echo big;; 578 set -- `$(tc-getCPP "$@") -E -P - <<<"__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__"`
134 ia64*) echo little;; 579 eval echo "$ver"
135 m68k*) echo big;; 580}
136 mips*el-*) echo little;; 581
137 mips*) echo big;; 582# @FUNCTION: gcc-fullversion
138 powerpc*) echo big;; 583# @RETURN: compiler version (major.minor.micro: [3.4.6])
139 sparc*) echo big;; 584gcc-fullversion() {
140 s390*) echo big;; 585 _gcc_fullversion '$1.$2.$3' "$@"
141 sh*el-) echo little;; 586}
142 sh*) echo big;; 587# @FUNCTION: gcc-version
143 i?86*) echo little;; 588# @RETURN: compiler version (major.minor: [3.4].6)
144 *) echo wtf;; 589gcc-version() {
590 _gcc_fullversion '$1.$2' "$@"
591}
592# @FUNCTION: gcc-major-version
593# @RETURN: major compiler version (major: [3].4.6)
594gcc-major-version() {
595 _gcc_fullversion '$1' "$@"
596}
597# @FUNCTION: gcc-minor-version
598# @RETURN: minor compiler version (minor: 3.[4].6)
599gcc-minor-version() {
600 _gcc_fullversion '$2' "$@"
601}
602# @FUNCTION: gcc-micro-version
603# @RETURN: micro compiler version (micro: 3.4.[6])
604gcc-micro-version() {
605 _gcc_fullversion '$3' "$@"
606}
607
608# Returns the installation directory - internal toolchain
609# function for use by _gcc-specs-exists (for flag-o-matic).
610_gcc-install-dir() {
611 echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null |\
612 awk '$1=="install:" {print $2}')"
613}
614# Returns true if the indicated specs file exists - internal toolchain
615# function for use by flag-o-matic.
616_gcc-specs-exists() {
617 [[ -f $(_gcc-install-dir)/$1 ]]
618}
619
620# Returns requested gcc specs directive unprocessed - for used by
621# gcc-specs-directive()
622# Note; later specs normally overwrite earlier ones; however if a later
623# spec starts with '+' then it appends.
624# gcc -dumpspecs is parsed first, followed by files listed by "gcc -v"
625# as "Reading <file>", in order. Strictly speaking, if there's a
626# $(gcc_install_dir)/specs, the built-in specs aren't read, however by
627# the same token anything from 'gcc -dumpspecs' is overridden by
628# the contents of $(gcc_install_dir)/specs so the result is the
629# same either way.
630_gcc-specs-directive_raw() {
631 local cc=$(tc-getCC)
632 local specfiles=$(LC_ALL=C ${cc} -v 2>&1 | awk '$1=="Reading" {print $NF}')
633 ${cc} -dumpspecs 2> /dev/null | cat - ${specfiles} | awk -v directive=$1 \
634'BEGIN { pspec=""; spec=""; outside=1 }
635$1=="*"directive":" { pspec=spec; spec=""; outside=0; next }
636 outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next }
637 spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next }
638 { spec=spec $0 }
639END { print spec }'
640 return 0
641}
642
643# Return the requested gcc specs directive, with all included
644# specs expanded.
645# Note, it does not check for inclusion loops, which cause it
646# to never finish - but such loops are invalid for gcc and we're
647# assuming gcc is operational.
648gcc-specs-directive() {
649 local directive subdname subdirective
650 directive="$(_gcc-specs-directive_raw $1)"
651 while [[ ${directive} == *%\(*\)* ]]; do
652 subdname=${directive/*%\(}
653 subdname=${subdname/\)*}
654 subdirective="$(_gcc-specs-directive_raw ${subdname})"
655 directive="${directive//\%(${subdname})/${subdirective}}"
656 done
657 echo "${directive}"
658 return 0
659}
660
661# Returns true if gcc sets relro
662gcc-specs-relro() {
663 local directive
664 directive=$(gcc-specs-directive link_command)
665 [[ "${directive/\{!norelro:}" != "${directive}" ]]
666}
667# Returns true if gcc sets now
668gcc-specs-now() {
669 local directive
670 directive=$(gcc-specs-directive link_command)
671 [[ "${directive/\{!nonow:}" != "${directive}" ]]
672}
673# Returns true if gcc builds PIEs
674gcc-specs-pie() {
675 local directive
676 directive=$(gcc-specs-directive cc1)
677 [[ "${directive/\{!nopie:}" != "${directive}" ]]
678}
679# Returns true if gcc builds with the stack protector
680gcc-specs-ssp() {
681 local directive
682 directive=$(gcc-specs-directive cc1)
683 [[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]]
684}
685# Returns true if gcc upgrades fstack-protector to fstack-protector-all
686gcc-specs-ssp-to-all() {
687 local directive
688 directive=$(gcc-specs-directive cc1)
689 [[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]]
690}
691# Returns true if gcc builds with fno-strict-overflow
692gcc-specs-nostrict() {
693 local directive
694 directive=$(gcc-specs-directive cc1)
695 [[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]]
696}
697# Returns true if gcc builds with fstack-check
698gcc-specs-stack-check() {
699 local directive
700 directive=$(gcc-specs-directive cc1)
701 [[ "${directive/\{!fno-stack-check:}" != "${directive}" ]]
702}
703
704
705# @FUNCTION: gen_usr_ldscript
706# @USAGE: [-a] <list of libs to create linker scripts for>
707# @DESCRIPTION:
708# This function generate linker scripts in /usr/lib for dynamic
709# libs in /lib. This is to fix linking problems when you have
710# the .so in /lib, and the .a in /usr/lib. What happens is that
711# in some cases when linking dynamic, the .a in /usr/lib is used
712# instead of the .so in /lib due to gcc/libtool tweaking ld's
713# library search path. This causes many builds to fail.
714# See bug #4411 for more info.
715#
716# Note that you should in general use the unversioned name of
717# the library (libfoo.so), as ldconfig should usually update it
718# correctly to point to the latest version of the library present.
719gen_usr_ldscript() {
720 local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname)
721 [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/
722
723 tc-is-static-only && return
724
725 # Eventually we'd like to get rid of this func completely #417451
726 case ${CTARGET:-${CHOST}} in
727 *-darwin*) ;;
728 *linux*|*-freebsd*|*-openbsd*|*-netbsd*)
729 use prefix && return 0 ;;
730 *) return 0 ;;
145 esac 731 esac
146}
147 732
148# Returns the version as by `$CC -dumpversion` 733 # Just make sure it exists
149gcc-fullversion() { 734 dodir /usr/${libdir}
150 echo "$($(tc-getCC) -dumpversion)" 735
736 if [[ $1 == "-a" ]] ; then
737 auto=true
738 shift
739 dodir /${libdir}
740 fi
741
742 # OUTPUT_FORMAT gives hints to the linker as to what binary format
743 # is referenced ... makes multilib saner
744 local flags=( ${CFLAGS} ${LDFLAGS} -Wl,--verbose )
745 if $(tc-getLD) --version | grep -q 'GNU gold' ; then
746 # If they're using gold, manually invoke the old bfd. #487696
747 local d="${T}/bfd-linker"
748 mkdir -p "${d}"
749 ln -sf $(which ${CHOST}-ld.bfd) "${d}"/ld
750 flags+=( -B"${d}" )
751 fi
752 output_format=$($(tc-getCC) "${flags[@]}" 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
753 [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
754
755 for lib in "$@" ; do
756 local tlib
757 if ${auto} ; then
758 lib="lib${lib}${suffix}"
759 else
760 # Ensure /lib/${lib} exists to avoid dangling scripts/symlinks.
761 # This especially is for AIX where $(get_libname) can return ".a",
762 # so /lib/${lib} might be moved to /usr/lib/${lib} (by accident).
763 [[ -r ${ED}/${libdir}/${lib} ]] || continue
764 #TODO: better die here?
765 fi
766
767 case ${CTARGET:-${CHOST}} in
768 *-darwin*)
769 if ${auto} ; then
770 tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib})
771 else
772 tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib})
773 fi
774 [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}"
775 tlib=${tlib##*/}
776
777 if ${auto} ; then
778 mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die
779 # some install_names are funky: they encode a version
780 if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]] ; then
781 mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die
782 fi
783 rm -f "${ED}"/${libdir}/${lib}
784 fi
785
786 # Mach-O files have an id, which is like a soname, it tells how
787 # another object linking against this lib should reference it.
788 # Since we moved the lib from usr/lib into lib this reference is
789 # wrong. Hence, we update it here. We don't configure with
790 # libdir=/lib because that messes up libtool files.
791 # Make sure we don't lose the specific version, so just modify the
792 # existing install_name
793 if [[ ! -w "${ED}/${libdir}/${tlib}" ]] ; then
794 chmod u+w "${ED}${libdir}/${tlib}" # needed to write to it
795 local nowrite=yes
796 fi
797 install_name_tool \
798 -id "${EPREFIX}"/${libdir}/${tlib} \
799 "${ED}"/${libdir}/${tlib} || die "install_name_tool failed"
800 [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}"
801 # Now as we don't use GNU binutils and our linker doesn't
802 # understand linker scripts, just create a symlink.
803 pushd "${ED}/usr/${libdir}" > /dev/null
804 ln -snf "../../${libdir}/${tlib}" "${lib}"
805 popd > /dev/null
806 ;;
807 *)
808 if ${auto} ; then
809 tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib})
810 [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}"
811 mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die
812 # some SONAMEs are funky: they encode a version before the .so
813 if [[ ${tlib} != ${lib}* ]] ; then
814 mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die
815 fi
816 rm -f "${ED}"/${libdir}/${lib}
817 else
818 tlib=${lib}
819 fi
820 cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
821 /* GNU ld script
822 Since Gentoo has critical dynamic libraries in /lib, and the static versions
823 in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
824 run into linking problems. This "fake" dynamic lib is a linker script that
825 redirects the linker to the real lib. And yes, this works in the cross-
826 compiling scenario as the sysroot-ed linker will prepend the real path.
827
828 See bug http://bugs.gentoo.org/4411 for more info.
829 */
830 ${output_format}
831 GROUP ( ${EPREFIX}/${libdir}/${tlib} )
832 END_LDSCRIPT
833 ;;
834 esac
835 fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}"
836 done
151} 837}
152# Returns the version, but only the <major>.<minor> 838
153gcc-version() { 839fi
154 echo "$(gcc-fullversion | cut -f1,2 -d.)"
155}
156# Returns the Major version
157gcc-major-version() {
158 echo "$(gcc-version | cut -f1 -d.)"
159}
160# Returns the Minor version
161gcc-minor-version() {
162 echo "$(gcc-version | cut -f2 -d.)"
163}
164# Returns the Micro version
165gcc-micro-version() {
166 echo "$(gcc-fullversion | cut -f3 -d.)"
167}

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.138

  ViewVC Help
Powered by ViewVC 1.1.20