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

Contents of /eclass/toolchain-funcs.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.138 - (hide annotations) (download)
Thu May 28 07:51:10 2015 UTC (8 months, 2 weeks ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Changes since 1.137: +5 -1 lines
tc-getGO: new helper from Chromium OS for locating the Go compiler

1 vapier 1.134 # Copyright 1999-2015 Gentoo Foundation
2 vapier 1.1 # Distributed under the terms of the GNU General Public License v2
3 vapier 1.138 # $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.137 2015/04/13 05:38:17 vapier Exp $
4 vapier 1.74
5     # @ECLASS: toolchain-funcs.eclass
6     # @MAINTAINER:
7     # Toolchain Ninjas <toolchain@gentoo.org>
8     # @BLURB: functions to query common info about the toolchain
9     # @DESCRIPTION:
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.
15 vapier 1.1
16 ulm 1.127 if [[ -z ${_TOOLCHAIN_FUNCS_ECLASS} ]]; then
17     _TOOLCHAIN_FUNCS_ECLASS=1
18 vapier 1.109
19     inherit multilib
20 eradicator 1.34
21 vapier 1.105 # tc-getPROG <VAR [search vars]> <default> [tuple]
22     _tc-getPROG() {
23     local tuple=$1
24     local v var vars=$2
25     local prog=$3
26    
27     var=${vars%% *}
28     for v in ${vars} ; do
29     if [[ -n ${!v} ]] ; then
30 vapier 1.106 export ${var}="${!v}"
31 vapier 1.105 echo "${!v}"
32     return 0
33     fi
34     done
35 vapier 1.1
36 eradicator 1.35 local search=
37 vapier 1.105 [[ -n $4 ]] && search=$(type -p "$4-${prog}")
38     [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p "${!tuple}-${prog}")
39 eradicator 1.35 [[ -n ${search} ]] && prog=${search##*/}
40 vapier 1.1
41 vapier 1.17 export ${var}=${prog}
42 vapier 1.1 echo "${!var}"
43     }
44 vapier 1.107 tc-getBUILD_PROG() { _tc-getPROG CBUILD "BUILD_$1 $1_FOR_BUILD HOST$1" "${@:2}"; }
45 vapier 1.105 tc-getPROG() { _tc-getPROG CHOST "$@"; }
46 vapier 1.1
47 vapier 1.74 # @FUNCTION: tc-getAR
48     # @USAGE: [toolchain prefix]
49     # @RETURN: name of the archiver
50 vapier 1.33 tc-getAR() { tc-getPROG AR ar "$@"; }
51 vapier 1.74 # @FUNCTION: tc-getAS
52     # @USAGE: [toolchain prefix]
53     # @RETURN: name of the assembler
54 vapier 1.33 tc-getAS() { tc-getPROG AS as "$@"; }
55 vapier 1.74 # @FUNCTION: tc-getCC
56     # @USAGE: [toolchain prefix]
57     # @RETURN: name of the C compiler
58 vapier 1.33 tc-getCC() { tc-getPROG CC gcc "$@"; }
59 vapier 1.74 # @FUNCTION: tc-getCPP
60     # @USAGE: [toolchain prefix]
61     # @RETURN: name of the C preprocessor
62 robbat2 1.58 tc-getCPP() { tc-getPROG CPP cpp "$@"; }
63 vapier 1.74 # @FUNCTION: tc-getCXX
64     # @USAGE: [toolchain prefix]
65     # @RETURN: name of the C++ compiler
66 vapier 1.33 tc-getCXX() { tc-getPROG CXX g++ "$@"; }
67 vapier 1.74 # @FUNCTION: tc-getLD
68     # @USAGE: [toolchain prefix]
69     # @RETURN: name of the linker
70 vapier 1.33 tc-getLD() { tc-getPROG LD ld "$@"; }
71 vapier 1.74 # @FUNCTION: tc-getSTRIP
72     # @USAGE: [toolchain prefix]
73     # @RETURN: name of the strip program
74 kanaka 1.59 tc-getSTRIP() { tc-getPROG STRIP strip "$@"; }
75 vapier 1.74 # @FUNCTION: tc-getNM
76     # @USAGE: [toolchain prefix]
77     # @RETURN: name of the symbol/object thingy
78 vapier 1.33 tc-getNM() { tc-getPROG NM nm "$@"; }
79 vapier 1.74 # @FUNCTION: tc-getRANLIB
80     # @USAGE: [toolchain prefix]
81     # @RETURN: name of the archiver indexer
82 vapier 1.33 tc-getRANLIB() { tc-getPROG RANLIB ranlib "$@"; }
83 kumba 1.86 # @FUNCTION: tc-getOBJCOPY
84     # @USAGE: [toolchain prefix]
85     # @RETURN: name of the object copier
86     tc-getOBJCOPY() { tc-getPROG OBJCOPY objcopy "$@"; }
87 vapier 1.134 # @FUNCTION: tc-getOBJDUMP
88     # @USAGE: [toolchain prefix]
89     # @RETURN: name of the object dumper
90     tc-getOBJDUMP() { tc-getPROG OBJDUMP objdump "$@"; }
91 vapier 1.74 # @FUNCTION: tc-getF77
92     # @USAGE: [toolchain prefix]
93     # @RETURN: name of the Fortran 77 compiler
94 dberkholz 1.101 tc-getF77() { tc-getPROG F77 gfortran "$@"; }
95 dberkholz 1.78 # @FUNCTION: tc-getFC
96 vapier 1.74 # @USAGE: [toolchain prefix]
97     # @RETURN: name of the Fortran 90 compiler
98 dberkholz 1.78 tc-getFC() { tc-getPROG FC gfortran "$@"; }
99 vapier 1.74 # @FUNCTION: tc-getGCJ
100     # @USAGE: [toolchain prefix]
101     # @RETURN: name of the java compiler
102 vapier 1.33 tc-getGCJ() { tc-getPROG GCJ gcj "$@"; }
103 vapier 1.138 # @FUNCTION: tc-getGO
104     # @USAGE: [toolchain prefix]
105     # @RETURN: name of the Go compiler
106     tc-getGO() { tc-getPROG GO gccgo "$@"; }
107 vapier 1.96 # @FUNCTION: tc-getPKG_CONFIG
108     # @USAGE: [toolchain prefix]
109     # @RETURN: name of the pkg-config tool
110     tc-getPKG_CONFIG() { tc-getPROG PKG_CONFIG pkg-config "$@"; }
111 vapier 1.98 # @FUNCTION: tc-getRC
112     # @USAGE: [toolchain prefix]
113     # @RETURN: name of the Windows resource compiler
114     tc-getRC() { tc-getPROG RC windres "$@"; }
115     # @FUNCTION: tc-getDLLWRAP
116     # @USAGE: [toolchain prefix]
117     # @RETURN: name of the Windows dllwrap utility
118     tc-getDLLWRAP() { tc-getPROG DLLWRAP dllwrap "$@"; }
119 vapier 1.1
120 vapier 1.107 # @FUNCTION: tc-getBUILD_AR
121     # @USAGE: [toolchain prefix]
122     # @RETURN: name of the archiver for building binaries to run on the build machine
123     tc-getBUILD_AR() { tc-getBUILD_PROG AR ar "$@"; }
124     # @FUNCTION: tc-getBUILD_AS
125     # @USAGE: [toolchain prefix]
126     # @RETURN: name of the assembler for building binaries to run on the build machine
127     tc-getBUILD_AS() { tc-getBUILD_PROG AS as "$@"; }
128 vapier 1.74 # @FUNCTION: tc-getBUILD_CC
129     # @USAGE: [toolchain prefix]
130     # @RETURN: name of the C compiler for building binaries to run on the build machine
131 vapier 1.107 tc-getBUILD_CC() { tc-getBUILD_PROG CC gcc "$@"; }
132 vapier 1.105 # @FUNCTION: tc-getBUILD_CPP
133     # @USAGE: [toolchain prefix]
134     # @RETURN: name of the C preprocessor for building binaries to run on the build machine
135 vapier 1.107 tc-getBUILD_CPP() { tc-getBUILD_PROG CPP cpp "$@"; }
136 vapier 1.105 # @FUNCTION: tc-getBUILD_CXX
137     # @USAGE: [toolchain prefix]
138     # @RETURN: name of the C++ compiler for building binaries to run on the build machine
139 vapier 1.107 tc-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
143     tc-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
147     tc-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
151     tc-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
155     tc-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
159     tc-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
163     tc-getBUILD_PKG_CONFIG() { tc-getBUILD_PROG PKG_CONFIG pkg-config "$@"; }
164 vapier 1.1
165 vapier 1.74 # @FUNCTION: tc-export
166     # @USAGE: <list of toolchain variables>
167     # @DESCRIPTION:
168     # Quick way to export a bunch of compiler vars at once.
169 vapier 1.10 tc-export() {
170     local var
171     for var in "$@" ; do
172 vapier 1.79 [[ $(type -t tc-get${var}) != "function" ]] && die "tc-export: invalid export variable '${var}'"
173 vapier 1.36 eval tc-get${var} > /dev/null
174 vapier 1.10 done
175     }
176    
177 vapier 1.74 # @FUNCTION: tc-is-cross-compiler
178     # @RETURN: Shell true if we are using a cross-compiler, shell false otherwise
179 vapier 1.12 tc-is-cross-compiler() {
180 blueness 1.128 [[ ${CBUILD:-${CHOST}} != ${CHOST} ]]
181 vapier 1.12 }
182    
183 vapier 1.74 # @FUNCTION: tc-is-softfloat
184     # @DESCRIPTION:
185 vapier 1.65 # See if this toolchain is a softfloat based one.
186 vapier 1.74 # @CODE
187 vapier 1.65 # The possible return values:
188 vapier 1.111 # - 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 vapier 1.74 # @CODE
193 vapier 1.65 # 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.
196     tc-is-softfloat() {
197 vapier 1.110 local CTARGET=${CTARGET:-${CHOST}}
198 vapier 1.65 case ${CTARGET} in
199 vapier 1.66 bfin*|h8300*)
200 vapier 1.65 echo "only" ;;
201     *)
202 vapier 1.111 if [[ ${CTARGET//_/-} == *-softfloat-* ]] ; then
203     echo "yes"
204     elif [[ ${CTARGET//_/-} == *-softfp-* ]] ; then
205     echo "softfp"
206     else
207     echo "no"
208     fi
209 vapier 1.65 ;;
210     esac
211     }
212 vapier 1.1
213 grobian 1.91 # @FUNCTION: tc-is-static-only
214     # @DESCRIPTION:
215     # Return shell true if the target does not support shared libs, shell false
216     # otherwise.
217     tc-is-static-only() {
218     local host=${CTARGET:-${CHOST}}
219    
220     # *MiNT doesn't have shared libraries, only platform so far
221 blueness 1.128 [[ ${host} == *-mint* ]]
222 grobian 1.91 }
223    
224 vapier 1.112 # @FUNCTION: tc-export_build_env
225     # @USAGE: [compiler variables]
226     # @DESCRIPTION:
227     # Export common build related compiler settings.
228     tc-export_build_env() {
229     tc-export "$@"
230 vapier 1.136 # Some build envs will initialize vars like:
231     # : ${BUILD_LDFLAGS:-${LDFLAGS}}
232     # So make sure all variables are non-empty. #526734
233 vapier 1.112 : ${BUILD_CFLAGS:=-O1 -pipe}
234     : ${BUILD_CXXFLAGS:=-O1 -pipe}
235 vapier 1.136 : ${BUILD_CPPFLAGS:= }
236     : ${BUILD_LDFLAGS:= }
237 vapier 1.112 export BUILD_{C,CXX,CPP,LD}FLAGS
238 vapier 1.122
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 vapier 1.112 }
245    
246 vapier 1.108 # @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.
254     tc-env_build() {
255 vapier 1.112 tc-export_build_env
256     CFLAGS=${BUILD_CFLAGS} \
257     CXXFLAGS=${BUILD_CXXFLAGS} \
258 vapier 1.108 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
310     econf_build() {
311 vapier 1.133 local CBUILD=${CBUILD:-${CHOST}}
312     tc-env_build econf --build=${CBUILD} --host=${CBUILD} "$@"
313 vapier 1.108 }
314    
315 vapier 1.135 # @FUNCTION: tc-ld-is-gold
316     # @USAGE: [toolchain prefix]
317     # @DESCRIPTION:
318     # Return true if the current linker is set to gold.
319     tc-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
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!
342     return 1
343     }
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.
350     tc-ld-disable-gold() {
351     if ! tc-ld-is-gold "$@" ; then
352     # They aren't using gold, so nothing to do!
353     return
354     fi
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 vapier 1.137 # 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 vapier 1.135 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 vapier 1.100 # @FUNCTION: tc-has-openmp
386     # @USAGE: [toolchain prefix]
387     # @DESCRIPTION:
388     # See if the toolchain supports OpenMP.
389     tc-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 vapier 1.97 # @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).
415     tc-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 grobian 1.91
439 swegener 1.40 # Parse information from CBUILD/CHOST/CTARGET rather than
440 vapier 1.20 # use external variables from the profile.
441     tc-ninja_magic_to_arch() {
442 vapier 1.21 ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; }
443 vapier 1.19
444     local type=$1
445     local host=$2
446 eradicator 1.25 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
447 vapier 1.19
448 axs 1.118 local KV=${KV:-${KV_FULL}}
449 axs 1.119 [[ ${type} == "kern" ]] && [[ -z ${KV} ]] && \
450     ewarn "QA: Kernel version could not be determined, please inherit kernel-2 or linux-info"
451 axs 1.118
452 vapier 1.19 case ${host} in
453 vapier 1.125 aarch64*) echo arm64;;
454 vapier 1.19 alpha*) echo alpha;;
455     arm*) echo arm;;
456 vapier 1.72 avr*) ninj avr32 avr;;
457 vapier 1.53 bfin*) ninj blackfin bfin;;
458 vapier 1.132 c6x*) echo c6x;;
459 vapier 1.47 cris*) echo cris;;
460 vapier 1.132 frv*) echo frv;;
461     hexagon*) echo hexagon;;
462 vapier 1.19 hppa*) ninj parisc hppa;;
463 vapier 1.75 i?86*)
464     # Starting with linux-2.6.24, the 'x86_64' and 'i386'
465     # trees have been unified into 'x86'.
466 aballier 1.77 # FreeBSD still uses i386
467     if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -lt $(KV_to_int 2.6.24) || ${host} == *freebsd* ]] ; then
468 vapier 1.75 echo i386
469     else
470     echo x86
471     fi
472     ;;
473 vapier 1.19 ia64*) echo ia64;;
474 vapier 1.23 m68*) echo m68k;;
475 vapier 1.132 metag*) echo metag;;
476     microblaze*) echo microblaze;;
477 vapier 1.19 mips*) echo mips;;
478 vapier 1.52 nios2*) echo nios2;;
479     nios*) echo nios;;
480 vapier 1.132 or32*) echo openrisc;;
481 vapier 1.49 powerpc*)
482 vapier 1.103 # 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 vapier 1.131 riscv*) echo riscv;;
502 vapier 1.47 s390*) echo s390;;
503 vapier 1.132 score*) echo score;;
504 vapier 1.47 sh64*) ninj sh64 sh;;
505     sh*) echo sh;;
506 vapier 1.19 sparc64*) ninj sparc64 sparc;;
507 vapier 1.28 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \
508     && ninj sparc64 sparc \
509     || echo sparc
510     ;;
511 vapier 1.121 tile*) echo tile;;
512 vapier 1.47 vax*) echo vax;;
513 aballier 1.104 x86_64*freebsd*) echo amd64;;
514 vapier 1.75 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 vapier 1.121 xtensa*) echo xtensa;;
524 vapier 1.73
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 vapier 1.19 esac
530     }
531 vapier 1.74 # @FUNCTION: tc-arch-kernel
532     # @USAGE: [toolchain prefix]
533     # @RETURN: name of the kernel arch according to the compiler target
534 vapier 1.20 tc-arch-kernel() {
535 vapier 1.74 tc-ninja_magic_to_arch kern "$@"
536 vapier 1.19 }
537 vapier 1.74 # @FUNCTION: tc-arch
538     # @USAGE: [toolchain prefix]
539     # @RETURN: name of the portage arch according to the compiler target
540 vapier 1.20 tc-arch() {
541 vapier 1.74 tc-ninja_magic_to_arch portage "$@"
542 vapier 1.19 }
543 vapier 1.74
544 robbat2 1.71 tc-endian() {
545     local host=$1
546     [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
547     host=${host%%-*}
548    
549     case ${host} in
550 vapier 1.116 aarch64*be) echo big;;
551     aarch64) echo little;;
552 robbat2 1.71 alpha*) echo big;;
553     arm*b*) echo big;;
554     arm*) echo little;;
555     cris*) echo little;;
556     hppa*) echo big;;
557     i?86*) echo little;;
558     ia64*) echo little;;
559     m68*) echo big;;
560     mips*l*) echo little;;
561     mips*) echo big;;
562 vapier 1.126 powerpc*le) echo little;;
563 robbat2 1.71 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;;
569     *) echo wtf;;
570     esac
571     }
572 vapier 1.19
573 vapier 1.102 # Internal func. The first argument is the version info to expand.
574     # Query the preprocessor to improve compatibility across different
575     # compilers rather than maintaining a --version flag matrix. #335943
576     _gcc_fullversion() {
577     local ver="$1"; shift
578     set -- `$(tc-getCPP "$@") -E -P - <<<"__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__"`
579     eval echo "$ver"
580     }
581    
582 vapier 1.74 # @FUNCTION: gcc-fullversion
583     # @RETURN: compiler version (major.minor.micro: [3.4.6])
584 vapier 1.1 gcc-fullversion() {
585 vapier 1.102 _gcc_fullversion '$1.$2.$3' "$@"
586 vapier 1.1 }
587 vapier 1.74 # @FUNCTION: gcc-version
588     # @RETURN: compiler version (major.minor: [3.4].6)
589 vapier 1.1 gcc-version() {
590 vapier 1.102 _gcc_fullversion '$1.$2' "$@"
591 vapier 1.1 }
592 vapier 1.74 # @FUNCTION: gcc-major-version
593     # @RETURN: major compiler version (major: [3].4.6)
594 vapier 1.1 gcc-major-version() {
595 vapier 1.102 _gcc_fullversion '$1' "$@"
596 vapier 1.1 }
597 vapier 1.74 # @FUNCTION: gcc-minor-version
598     # @RETURN: minor compiler version (minor: 3.[4].6)
599 vapier 1.1 gcc-minor-version() {
600 vapier 1.102 _gcc_fullversion '$2' "$@"
601 vapier 1.1 }
602 vapier 1.74 # @FUNCTION: gcc-micro-version
603     # @RETURN: micro compiler version (micro: 3.4.[6])
604 vapier 1.1 gcc-micro-version() {
605 vapier 1.102 _gcc_fullversion '$3' "$@"
606 vapier 1.1 }
607 vapier 1.74
608 kevquinn 1.68 # Returns the installation directory - internal toolchain
609     # function for use by _gcc-specs-exists (for flag-o-matic).
610     _gcc-install-dir() {
611 vapier 1.76 echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null |\
612 kevquinn 1.68 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 kevquinn 1.41
620 kevquinn 1.68 # Returns requested gcc specs directive unprocessed - for used by
621     # gcc-specs-directive()
622 kevquinn 1.46 # 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 kevquinn 1.68 # 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 kevquinn 1.57 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 kevquinn 1.46 'BEGIN { pspec=""; spec=""; outside=1 }
635     $1=="*"directive":" { pspec=spec; spec=""; outside=0; next }
636 kevquinn 1.41 outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next }
637 kevquinn 1.46 spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next }
638     { spec=spec $0 }
639     END { print spec }'
640     return 0
641 kevquinn 1.41 }
642    
643 kevquinn 1.68 # 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.
648     gcc-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 kevquinn 1.41 # Returns true if gcc sets relro
662     gcc-specs-relro() {
663     local directive
664     directive=$(gcc-specs-directive link_command)
665 blueness 1.128 [[ "${directive/\{!norelro:}" != "${directive}" ]]
666 kevquinn 1.41 }
667     # Returns true if gcc sets now
668     gcc-specs-now() {
669     local directive
670     directive=$(gcc-specs-directive link_command)
671 blueness 1.128 [[ "${directive/\{!nonow:}" != "${directive}" ]]
672 kevquinn 1.41 }
673     # Returns true if gcc builds PIEs
674     gcc-specs-pie() {
675     local directive
676     directive=$(gcc-specs-directive cc1)
677 blueness 1.128 [[ "${directive/\{!nopie:}" != "${directive}" ]]
678 kevquinn 1.41 }
679     # Returns true if gcc builds with the stack protector
680     gcc-specs-ssp() {
681     local directive
682     directive=$(gcc-specs-directive cc1)
683 blueness 1.128 [[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]]
684 kevquinn 1.41 }
685 kevquinn 1.46 # Returns true if gcc upgrades fstack-protector to fstack-protector-all
686     gcc-specs-ssp-to-all() {
687     local directive
688     directive=$(gcc-specs-directive cc1)
689 blueness 1.128 [[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]]
690 kevquinn 1.46 }
691 gengor 1.80 # Returns true if gcc builds with fno-strict-overflow
692     gcc-specs-nostrict() {
693     local directive
694     directive=$(gcc-specs-directive cc1)
695 blueness 1.128 [[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]]
696 gengor 1.80 }
697 blueness 1.129 # Returns true if gcc builds with fstack-check
698     gcc-specs-stack-check() {
699     local directive
700     directive=$(gcc-specs-directive cc1)
701     [[ "${directive/\{!fno-stack-check:}" != "${directive}" ]]
702     }
703 vapier 1.60
704    
705 vapier 1.74 # @FUNCTION: gen_usr_ldscript
706 vapier 1.85 # @USAGE: [-a] <list of libs to create linker scripts for>
707 vapier 1.74 # @DESCRIPTION:
708 vapier 1.60 # 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 vapier 1.74 # library search path. This causes many builds to fail.
714 vapier 1.60 # See bug #4411 for more info.
715     #
716     # Note that you should in general use the unversioned name of
717 vapier 1.74 # the library (libfoo.so), as ldconfig should usually update it
718     # correctly to point to the latest version of the library present.
719 vapier 1.70 gen_usr_ldscript() {
720 vapier 1.85 local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname)
721 grobian 1.91 [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/
722    
723     tc-is-static-only && return
724    
725 vapier 1.113 # Eventually we'd like to get rid of this func completely #417451
726     case ${CTARGET:-${CHOST}} in
727     *-darwin*) ;;
728 vapier 1.115 *linux*|*-freebsd*|*-openbsd*|*-netbsd*)
729 vapier 1.114 use prefix && return 0 ;;
730 vapier 1.113 *) return 0 ;;
731     esac
732    
733 vapier 1.60 # Just make sure it exists
734     dodir /usr/${libdir}
735    
736 vapier 1.85 if [[ $1 == "-a" ]] ; then
737     auto=true
738     shift
739     dodir /${libdir}
740     fi
741    
742 vapier 1.60 # OUTPUT_FORMAT gives hints to the linker as to what binary format
743     # is referenced ... makes multilib saner
744 vapier 1.123 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 vapier 1.60 [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
754    
755     for lib in "$@" ; do
756 grobian 1.91 local tlib
757     if ${auto} ; then
758     lib="lib${lib}${suffix}"
759 grobian 1.90 else
760 grobian 1.91 # 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 vapier 1.85 if ${auto} ; then
770 grobian 1.91 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 grobian 1.92 # 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 grobian 1.91 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 grobian 1.94 if [[ ! -w "${ED}/${libdir}/${tlib}" ]] ; then
794 grobian 1.95 chmod u+w "${ED}${libdir}/${tlib}" # needed to write to it
795 grobian 1.94 local nowrite=yes
796     fi
797 grobian 1.91 install_name_tool \
798     -id "${EPREFIX}"/${libdir}/${tlib} \
799 grobian 1.94 "${ED}"/${libdir}/${tlib} || die "install_name_tool failed"
800 grobian 1.95 [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}"
801 grobian 1.91 # 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 vapier 1.114 *)
808 grobian 1.91 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 vapier 1.88 # some SONAMEs are funky: they encode a version before the .so
813     if [[ ${tlib} != ${lib}* ]] ; then
814 grobian 1.91 mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die
815 vapier 1.88 fi
816 grobian 1.91 rm -f "${ED}"/${libdir}/${lib}
817 vapier 1.85 else
818     tlib=${lib}
819     fi
820 grobian 1.91 cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
821 grobian 1.61 /* GNU ld script
822 vapier 1.87 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 grobian 1.61
828     See bug http://bugs.gentoo.org/4411 for more info.
829     */
830     ${output_format}
831 grobian 1.91 GROUP ( ${EPREFIX}/${libdir}/${tlib} )
832 grobian 1.61 END_LDSCRIPT
833 grobian 1.91 ;;
834     esac
835     fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}"
836 vapier 1.60 done
837     }
838 vapier 1.109
839     fi

  ViewVC Help
Powered by ViewVC 1.1.20