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

Contents of /eclass/toolchain-funcs.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.105 - (hide annotations) (download)
Tue Sep 6 22:54:45 2011 UTC (2 years, 10 months ago) by vapier
Branch: MAIN
Changes since 1.104: +28 -31 lines
unify tc-getPROG and tc-getBUILD_CC implementations, and add new tc-getBUILD_{CPP,CXX} helpers on top of that

1 vapier 1.67 # Copyright 1999-2007 Gentoo Foundation
2 vapier 1.1 # Distributed under the terms of the GNU General Public License v2
3 vapier 1.105 # $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.104 2011/07/12 14:29:41 aballier 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 vapier 1.69 ___ECLASS_RECUR_TOOLCHAIN_FUNCS="yes"
17     [[ -z ${___ECLASS_RECUR_MULTILIB} ]] && inherit multilib
18 eradicator 1.34
19 vapier 1.1 DESCRIPTION="Based on the ${ECLASS} eclass"
20    
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     export ${var}=${!v}
31     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.105 tc-getBUILD_PROG() { _tc-getPROG CBUILD "$@"; }
45     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.74 # @FUNCTION: tc-getF77
88     # @USAGE: [toolchain prefix]
89     # @RETURN: name of the Fortran 77 compiler
90 dberkholz 1.101 tc-getF77() { tc-getPROG F77 gfortran "$@"; }
91 dberkholz 1.78 # @FUNCTION: tc-getFC
92 vapier 1.74 # @USAGE: [toolchain prefix]
93     # @RETURN: name of the Fortran 90 compiler
94 dberkholz 1.78 tc-getFC() { tc-getPROG FC gfortran "$@"; }
95 vapier 1.74 # @FUNCTION: tc-getGCJ
96     # @USAGE: [toolchain prefix]
97     # @RETURN: name of the java compiler
98 vapier 1.33 tc-getGCJ() { tc-getPROG GCJ gcj "$@"; }
99 vapier 1.96 # @FUNCTION: tc-getPKG_CONFIG
100     # @USAGE: [toolchain prefix]
101     # @RETURN: name of the pkg-config tool
102     tc-getPKG_CONFIG() { tc-getPROG PKG_CONFIG pkg-config "$@"; }
103 vapier 1.98 # @FUNCTION: tc-getRC
104     # @USAGE: [toolchain prefix]
105     # @RETURN: name of the Windows resource compiler
106     tc-getRC() { tc-getPROG RC windres "$@"; }
107     # @FUNCTION: tc-getDLLWRAP
108     # @USAGE: [toolchain prefix]
109     # @RETURN: name of the Windows dllwrap utility
110     tc-getDLLWRAP() { tc-getPROG DLLWRAP dllwrap "$@"; }
111 vapier 1.1
112 vapier 1.74 # @FUNCTION: tc-getBUILD_CC
113     # @USAGE: [toolchain prefix]
114     # @RETURN: name of the C compiler for building binaries to run on the build machine
115 vapier 1.105 tc-getBUILD_CC() { tc-getBUILD_PROG "BUILD_CC CC_FOR_BUILD HOSTCC" gcc "$@"; }
116     # @FUNCTION: tc-getBUILD_CPP
117     # @USAGE: [toolchain prefix]
118     # @RETURN: name of the C preprocessor for building binaries to run on the build machine
119     tc-getBUILD_CPP() { tc-getBUILD_PROG "BUILD_CPP CPP_FOR_BUILD HOSTCPP" cpp "$@"; }
120     # @FUNCTION: tc-getBUILD_CXX
121     # @USAGE: [toolchain prefix]
122     # @RETURN: name of the C++ compiler for building binaries to run on the build machine
123     tc-getBUILD_CXX() { tc-getBUILD_PROG "BUILD_CXX CXX_FOR_BUILD HOSTCXX" g++ "$@"; }
124 vapier 1.1
125 vapier 1.74 # @FUNCTION: tc-export
126     # @USAGE: <list of toolchain variables>
127     # @DESCRIPTION:
128     # Quick way to export a bunch of compiler vars at once.
129 vapier 1.10 tc-export() {
130     local var
131     for var in "$@" ; do
132 vapier 1.79 [[ $(type -t tc-get${var}) != "function" ]] && die "tc-export: invalid export variable '${var}'"
133 vapier 1.36 eval tc-get${var} > /dev/null
134 vapier 1.10 done
135     }
136    
137 vapier 1.74 # @FUNCTION: tc-is-cross-compiler
138     # @RETURN: Shell true if we are using a cross-compiler, shell false otherwise
139 vapier 1.12 tc-is-cross-compiler() {
140 vapier 1.43 return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]])
141 vapier 1.12 }
142    
143 vapier 1.74 # @FUNCTION: tc-is-softfloat
144     # @DESCRIPTION:
145 vapier 1.65 # See if this toolchain is a softfloat based one.
146 vapier 1.74 # @CODE
147 vapier 1.65 # The possible return values:
148     # - only: the target is always softfloat (never had fpu)
149     # - yes: the target should support softfloat
150 armin76 1.99 # - no: the target doesn't support softfloat
151 vapier 1.74 # @CODE
152 vapier 1.65 # This allows us to react differently where packages accept
153     # softfloat flags in the case where support is optional, but
154     # rejects softfloat flags where the target always lacks an fpu.
155     tc-is-softfloat() {
156     case ${CTARGET} in
157 vapier 1.66 bfin*|h8300*)
158 vapier 1.65 echo "only" ;;
159     *)
160     [[ ${CTARGET//_/-} == *-softfloat-* ]] \
161     && echo "yes" \
162     || echo "no"
163     ;;
164     esac
165     }
166 vapier 1.1
167 armin76 1.99 # @FUNCTION: tc-is-hardfloat
168     # @DESCRIPTION:
169     # See if this toolchain is a hardfloat based one.
170     # @CODE
171     # The possible return values:
172     # - yes: the target should support hardfloat
173     # - no: the target doesn't support hardfloat
174     tc-is-hardfloat() {
175     [[ ${CTARGET//_/-} == *-hardfloat-* ]] \
176     && echo "yes" \
177     || echo "no"
178     }
179    
180 grobian 1.91 # @FUNCTION: tc-is-static-only
181     # @DESCRIPTION:
182     # Return shell true if the target does not support shared libs, shell false
183     # otherwise.
184     tc-is-static-only() {
185     local host=${CTARGET:-${CHOST}}
186    
187     # *MiNT doesn't have shared libraries, only platform so far
188     return $([[ ${host} == *-mint* ]])
189     }
190    
191 vapier 1.100 # @FUNCTION: tc-has-openmp
192     # @USAGE: [toolchain prefix]
193     # @DESCRIPTION:
194     # See if the toolchain supports OpenMP.
195     tc-has-openmp() {
196     local base="${T}/test-tc-openmp"
197     cat <<-EOF > "${base}.c"
198     #include <omp.h>
199     int main() {
200     int nthreads, tid, ret = 0;
201     #pragma omp parallel private(nthreads, tid)
202     {
203     tid = omp_get_thread_num();
204     nthreads = omp_get_num_threads(); ret += tid + nthreads;
205     }
206     return ret;
207     }
208     EOF
209     $(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" >&/dev/null
210     local ret=$?
211     rm -f "${base}"*
212     return ${ret}
213     }
214    
215 vapier 1.97 # @FUNCTION: tc-has-tls
216     # @USAGE: [-s|-c|-l] [toolchain prefix]
217     # @DESCRIPTION:
218     # See if the toolchain supports thread local storage (TLS). Use -s to test the
219     # compiler, -c to also test the assembler, and -l to also test the C library
220     # (the default).
221     tc-has-tls() {
222     local base="${T}/test-tc-tls"
223     cat <<-EOF > "${base}.c"
224     int foo(int *i) {
225     static __thread int j = 0;
226     return *i ? j : *i;
227     }
228     EOF
229     local flags
230     case $1 in
231     -s) flags="-S";;
232     -c) flags="-c";;
233     -l) ;;
234     -*) die "Usage: tc-has-tls [-c|-l] [toolchain prefix]";;
235     esac
236     : ${flags:=-fPIC -shared -Wl,-z,defs}
237     [[ $1 == -* ]] && shift
238     $(tc-getCC "$@") ${flags} "${base}.c" -o "${base}" >&/dev/null
239     local ret=$?
240     rm -f "${base}"*
241     return ${ret}
242     }
243    
244 grobian 1.91
245 swegener 1.40 # Parse information from CBUILD/CHOST/CTARGET rather than
246 vapier 1.20 # use external variables from the profile.
247     tc-ninja_magic_to_arch() {
248 vapier 1.21 ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; }
249 vapier 1.19
250     local type=$1
251     local host=$2
252 eradicator 1.25 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
253 vapier 1.19
254     case ${host} in
255     alpha*) echo alpha;;
256     arm*) echo arm;;
257 vapier 1.72 avr*) ninj avr32 avr;;
258 vapier 1.53 bfin*) ninj blackfin bfin;;
259 vapier 1.47 cris*) echo cris;;
260 vapier 1.19 hppa*) ninj parisc hppa;;
261 vapier 1.75 i?86*)
262     # Starting with linux-2.6.24, the 'x86_64' and 'i386'
263     # trees have been unified into 'x86'.
264 aballier 1.77 # FreeBSD still uses i386
265     if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -lt $(KV_to_int 2.6.24) || ${host} == *freebsd* ]] ; then
266 vapier 1.75 echo i386
267     else
268     echo x86
269     fi
270     ;;
271 vapier 1.19 ia64*) echo ia64;;
272 vapier 1.23 m68*) echo m68k;;
273 vapier 1.19 mips*) echo mips;;
274 vapier 1.52 nios2*) echo nios2;;
275     nios*) echo nios;;
276 vapier 1.49 powerpc*)
277 vapier 1.103 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees
278     # have been unified into simply 'powerpc', but until 2.6.16,
279     # ppc32 is still using ARCH="ppc" as default
280     if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]] ; then
281     echo powerpc
282     elif [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -eq $(KV_to_int 2.6.15) ]] ; then
283     if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]] ; then
284     echo powerpc
285     else
286     echo ppc
287     fi
288     elif [[ ${host} == powerpc64* ]] ; then
289     echo ppc64
290     elif [[ ${PROFILE_ARCH} == "ppc64" ]] ; then
291     ninj ppc64 ppc
292     else
293     echo ppc
294     fi
295     ;;
296 vapier 1.47 s390*) echo s390;;
297     sh64*) ninj sh64 sh;;
298     sh*) echo sh;;
299 vapier 1.19 sparc64*) ninj sparc64 sparc;;
300 vapier 1.28 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \
301     && ninj sparc64 sparc \
302     || echo sparc
303     ;;
304 vapier 1.47 vax*) echo vax;;
305 aballier 1.104 x86_64*freebsd*) echo amd64;;
306 vapier 1.75 x86_64*)
307     # Starting with linux-2.6.24, the 'x86_64' and 'i386'
308     # trees have been unified into 'x86'.
309     if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.24) ]] ; then
310     echo x86
311     else
312     ninj x86_64 amd64
313     fi
314     ;;
315 vapier 1.73
316     # since our usage of tc-arch is largely concerned with
317     # normalizing inputs for testing ${CTARGET}, let's filter
318     # other cross targets (mingw and such) into the unknown.
319     *) echo unknown;;
320 vapier 1.19 esac
321     }
322 vapier 1.74 # @FUNCTION: tc-arch-kernel
323     # @USAGE: [toolchain prefix]
324     # @RETURN: name of the kernel arch according to the compiler target
325 vapier 1.20 tc-arch-kernel() {
326 vapier 1.74 tc-ninja_magic_to_arch kern "$@"
327 vapier 1.19 }
328 vapier 1.74 # @FUNCTION: tc-arch
329     # @USAGE: [toolchain prefix]
330     # @RETURN: name of the portage arch according to the compiler target
331 vapier 1.20 tc-arch() {
332 vapier 1.74 tc-ninja_magic_to_arch portage "$@"
333 vapier 1.19 }
334 vapier 1.74
335 robbat2 1.71 tc-endian() {
336     local host=$1
337     [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
338     host=${host%%-*}
339    
340     case ${host} in
341     alpha*) echo big;;
342     arm*b*) echo big;;
343     arm*) echo little;;
344     cris*) echo little;;
345     hppa*) echo big;;
346     i?86*) echo little;;
347     ia64*) echo little;;
348     m68*) echo big;;
349     mips*l*) echo little;;
350     mips*) echo big;;
351     powerpc*) echo big;;
352     s390*) echo big;;
353     sh*b*) echo big;;
354     sh*) echo little;;
355     sparc*) echo big;;
356     x86_64*) echo little;;
357     *) echo wtf;;
358     esac
359     }
360 vapier 1.19
361 vapier 1.102 # Internal func. The first argument is the version info to expand.
362     # Query the preprocessor to improve compatibility across different
363     # compilers rather than maintaining a --version flag matrix. #335943
364     _gcc_fullversion() {
365     local ver="$1"; shift
366     set -- `$(tc-getCPP "$@") -E -P - <<<"__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__"`
367     eval echo "$ver"
368     }
369    
370 vapier 1.74 # @FUNCTION: gcc-fullversion
371     # @RETURN: compiler version (major.minor.micro: [3.4.6])
372 vapier 1.1 gcc-fullversion() {
373 vapier 1.102 _gcc_fullversion '$1.$2.$3' "$@"
374 vapier 1.1 }
375 vapier 1.74 # @FUNCTION: gcc-version
376     # @RETURN: compiler version (major.minor: [3.4].6)
377 vapier 1.1 gcc-version() {
378 vapier 1.102 _gcc_fullversion '$1.$2' "$@"
379 vapier 1.1 }
380 vapier 1.74 # @FUNCTION: gcc-major-version
381     # @RETURN: major compiler version (major: [3].4.6)
382 vapier 1.1 gcc-major-version() {
383 vapier 1.102 _gcc_fullversion '$1' "$@"
384 vapier 1.1 }
385 vapier 1.74 # @FUNCTION: gcc-minor-version
386     # @RETURN: minor compiler version (minor: 3.[4].6)
387 vapier 1.1 gcc-minor-version() {
388 vapier 1.102 _gcc_fullversion '$2' "$@"
389 vapier 1.1 }
390 vapier 1.74 # @FUNCTION: gcc-micro-version
391     # @RETURN: micro compiler version (micro: 3.4.[6])
392 vapier 1.1 gcc-micro-version() {
393 vapier 1.102 _gcc_fullversion '$3' "$@"
394 vapier 1.1 }
395 vapier 1.74
396 kevquinn 1.68 # Returns the installation directory - internal toolchain
397     # function for use by _gcc-specs-exists (for flag-o-matic).
398     _gcc-install-dir() {
399 vapier 1.76 echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null |\
400 kevquinn 1.68 awk '$1=="install:" {print $2}')"
401     }
402     # Returns true if the indicated specs file exists - internal toolchain
403     # function for use by flag-o-matic.
404     _gcc-specs-exists() {
405     [[ -f $(_gcc-install-dir)/$1 ]]
406     }
407 kevquinn 1.41
408 kevquinn 1.68 # Returns requested gcc specs directive unprocessed - for used by
409     # gcc-specs-directive()
410 kevquinn 1.46 # Note; later specs normally overwrite earlier ones; however if a later
411     # spec starts with '+' then it appends.
412     # gcc -dumpspecs is parsed first, followed by files listed by "gcc -v"
413 kevquinn 1.68 # as "Reading <file>", in order. Strictly speaking, if there's a
414     # $(gcc_install_dir)/specs, the built-in specs aren't read, however by
415     # the same token anything from 'gcc -dumpspecs' is overridden by
416     # the contents of $(gcc_install_dir)/specs so the result is the
417     # same either way.
418     _gcc-specs-directive_raw() {
419 kevquinn 1.57 local cc=$(tc-getCC)
420     local specfiles=$(LC_ALL=C ${cc} -v 2>&1 | awk '$1=="Reading" {print $NF}')
421     ${cc} -dumpspecs 2> /dev/null | cat - ${specfiles} | awk -v directive=$1 \
422 kevquinn 1.46 'BEGIN { pspec=""; spec=""; outside=1 }
423     $1=="*"directive":" { pspec=spec; spec=""; outside=0; next }
424 kevquinn 1.41 outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next }
425 kevquinn 1.46 spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next }
426     { spec=spec $0 }
427     END { print spec }'
428     return 0
429 kevquinn 1.41 }
430    
431 kevquinn 1.68 # Return the requested gcc specs directive, with all included
432     # specs expanded.
433     # Note, it does not check for inclusion loops, which cause it
434     # to never finish - but such loops are invalid for gcc and we're
435     # assuming gcc is operational.
436     gcc-specs-directive() {
437     local directive subdname subdirective
438     directive="$(_gcc-specs-directive_raw $1)"
439     while [[ ${directive} == *%\(*\)* ]]; do
440     subdname=${directive/*%\(}
441     subdname=${subdname/\)*}
442     subdirective="$(_gcc-specs-directive_raw ${subdname})"
443     directive="${directive//\%(${subdname})/${subdirective}}"
444     done
445     echo "${directive}"
446     return 0
447     }
448    
449 kevquinn 1.41 # Returns true if gcc sets relro
450     gcc-specs-relro() {
451     local directive
452     directive=$(gcc-specs-directive link_command)
453 gengor 1.84 return $([[ "${directive/\{!norelro:}" != "${directive}" ]])
454 kevquinn 1.41 }
455     # Returns true if gcc sets now
456     gcc-specs-now() {
457     local directive
458     directive=$(gcc-specs-directive link_command)
459 gengor 1.84 return $([[ "${directive/\{!nonow:}" != "${directive}" ]])
460 kevquinn 1.41 }
461     # Returns true if gcc builds PIEs
462     gcc-specs-pie() {
463     local directive
464     directive=$(gcc-specs-directive cc1)
465 gengor 1.84 return $([[ "${directive/\{!nopie:}" != "${directive}" ]])
466 kevquinn 1.41 }
467     # Returns true if gcc builds with the stack protector
468     gcc-specs-ssp() {
469     local directive
470     directive=$(gcc-specs-directive cc1)
471 gengor 1.84 return $([[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]])
472 kevquinn 1.41 }
473 kevquinn 1.46 # Returns true if gcc upgrades fstack-protector to fstack-protector-all
474     gcc-specs-ssp-to-all() {
475     local directive
476     directive=$(gcc-specs-directive cc1)
477 gengor 1.84 return $([[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]])
478 kevquinn 1.46 }
479 gengor 1.80 # Returns true if gcc builds with fno-strict-overflow
480     gcc-specs-nostrict() {
481     local directive
482     directive=$(gcc-specs-directive cc1)
483 gengor 1.84 return $([[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]])
484 gengor 1.80 }
485 vapier 1.60
486    
487 vapier 1.74 # @FUNCTION: gen_usr_ldscript
488 vapier 1.85 # @USAGE: [-a] <list of libs to create linker scripts for>
489 vapier 1.74 # @DESCRIPTION:
490 vapier 1.60 # This function generate linker scripts in /usr/lib for dynamic
491     # libs in /lib. This is to fix linking problems when you have
492     # the .so in /lib, and the .a in /usr/lib. What happens is that
493     # in some cases when linking dynamic, the .a in /usr/lib is used
494     # instead of the .so in /lib due to gcc/libtool tweaking ld's
495 vapier 1.74 # library search path. This causes many builds to fail.
496 vapier 1.60 # See bug #4411 for more info.
497     #
498     # Note that you should in general use the unversioned name of
499 vapier 1.74 # the library (libfoo.so), as ldconfig should usually update it
500     # correctly to point to the latest version of the library present.
501 vapier 1.70 gen_usr_ldscript() {
502 vapier 1.85 local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname)
503 grobian 1.91 [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/
504    
505     tc-is-static-only && return
506    
507 vapier 1.60 # Just make sure it exists
508     dodir /usr/${libdir}
509    
510 vapier 1.85 if [[ $1 == "-a" ]] ; then
511     auto=true
512     shift
513     dodir /${libdir}
514     fi
515    
516 vapier 1.60 # OUTPUT_FORMAT gives hints to the linker as to what binary format
517     # is referenced ... makes multilib saner
518     output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
519     [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
520    
521     for lib in "$@" ; do
522 grobian 1.91 local tlib
523     if ${auto} ; then
524     lib="lib${lib}${suffix}"
525 grobian 1.90 else
526 grobian 1.91 # Ensure /lib/${lib} exists to avoid dangling scripts/symlinks.
527     # This especially is for AIX where $(get_libname) can return ".a",
528     # so /lib/${lib} might be moved to /usr/lib/${lib} (by accident).
529     [[ -r ${ED}/${libdir}/${lib} ]] || continue
530     #TODO: better die here?
531     fi
532    
533     case ${CTARGET:-${CHOST}} in
534     *-darwin*)
535 vapier 1.85 if ${auto} ; then
536 grobian 1.91 tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib})
537     else
538     tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib})
539     fi
540     [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}"
541     tlib=${tlib##*/}
542    
543     if ${auto} ; then
544     mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die
545 grobian 1.92 # some install_names are funky: they encode a version
546     if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]] ; then
547     mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die
548     fi
549 grobian 1.91 rm -f "${ED}"/${libdir}/${lib}
550     fi
551    
552     # Mach-O files have an id, which is like a soname, it tells how
553     # another object linking against this lib should reference it.
554     # Since we moved the lib from usr/lib into lib this reference is
555     # wrong. Hence, we update it here. We don't configure with
556     # libdir=/lib because that messes up libtool files.
557     # Make sure we don't lose the specific version, so just modify the
558     # existing install_name
559 grobian 1.94 if [[ ! -w "${ED}/${libdir}/${tlib}" ]] ; then
560 grobian 1.95 chmod u+w "${ED}${libdir}/${tlib}" # needed to write to it
561 grobian 1.94 local nowrite=yes
562     fi
563 grobian 1.91 install_name_tool \
564     -id "${EPREFIX}"/${libdir}/${tlib} \
565 grobian 1.94 "${ED}"/${libdir}/${tlib} || die "install_name_tool failed"
566 grobian 1.95 [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}"
567 grobian 1.91 # Now as we don't use GNU binutils and our linker doesn't
568     # understand linker scripts, just create a symlink.
569     pushd "${ED}/usr/${libdir}" > /dev/null
570     ln -snf "../../${libdir}/${tlib}" "${lib}"
571     popd > /dev/null
572     ;;
573 grobian 1.93 *-aix*|*-irix*|*64*-hpux*|*-interix*|*-winnt*)
574 grobian 1.91 if ${auto} ; then
575     mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die
576     # no way to retrieve soname on these platforms (?)
577     tlib=$(readlink "${ED}"/${libdir}/${lib})
578     tlib=${tlib##*/}
579     if [[ -z ${tlib} ]] ; then
580     # ok, apparently was not a symlink, don't remove it and
581     # just link to it
582     tlib=${lib}
583     else
584     rm -f "${ED}"/${libdir}/${lib}
585     fi
586     else
587     tlib=${lib}
588     fi
589    
590     # we don't have GNU binutils on these platforms, so we symlink
591     # instead, which seems to work fine. Keep it relative, otherwise
592     # we break some QA checks in Portage
593     # on interix, the linker scripts would work fine in _most_
594     # situations. if a library links to such a linker script the
595     # absolute path to the correct library is inserted into the binary,
596     # which is wrong, since anybody linking _without_ libtool will miss
597     # some dependencies, since the stupid linker cannot find libraries
598     # hardcoded with absolute paths (as opposed to the loader, which
599     # seems to be able to do this).
600     # this has been seen while building shared-mime-info which needs
601     # libxml2, but links without libtool (and does not add libz to the
602     # command line by itself).
603     pushd "${ED}/usr/${libdir}" > /dev/null
604     ln -snf "../../${libdir}/${tlib}" "${lib}"
605     popd > /dev/null
606     ;;
607 grobian 1.93 hppa*-hpux*) # PA-RISC 32bit (SOM) only, others (ELF) match *64*-hpux* above.
608     if ${auto} ; then
609     tlib=$(chatr "${ED}"/usr/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}')
610     [[ -z ${tlib} ]] && tlib=${lib}
611     tlib=${tlib##*/} # 'internal name' can have a path component
612     mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die
613     # some SONAMEs are funky: they encode a version before the .so
614     if [[ ${tlib} != ${lib}* ]] ; then
615     mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die
616     fi
617     [[ ${tlib} != ${lib} ]] &&
618     rm -f "${ED}"/${libdir}/${lib}
619     else
620     tlib=$(chatr "${ED}"/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}')
621     [[ -z ${tlib} ]] && tlib=${lib}
622     tlib=${tlib##*/} # 'internal name' can have a path component
623     fi
624     pushd "${ED}"/usr/${libdir} >/dev/null
625     ln -snf "../../${libdir}/${tlib}" "${lib}"
626     # need the internal name in usr/lib too, to be available at runtime
627     # when linked with /path/to/lib.sl (hardcode_direct_absolute=yes)
628     [[ ${tlib} != ${lib} ]] &&
629     ln -snf "../../${libdir}/${tlib}" "${tlib}"
630     popd >/dev/null
631     ;;
632 grobian 1.91 *)
633     if ${auto} ; then
634     tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib})
635     [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}"
636     mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die
637 vapier 1.88 # some SONAMEs are funky: they encode a version before the .so
638     if [[ ${tlib} != ${lib}* ]] ; then
639 grobian 1.91 mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die
640 vapier 1.88 fi
641 grobian 1.91 rm -f "${ED}"/${libdir}/${lib}
642 vapier 1.85 else
643     tlib=${lib}
644     fi
645 grobian 1.91 cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
646 grobian 1.61 /* GNU ld script
647 vapier 1.87 Since Gentoo has critical dynamic libraries in /lib, and the static versions
648     in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
649     run into linking problems. This "fake" dynamic lib is a linker script that
650     redirects the linker to the real lib. And yes, this works in the cross-
651     compiling scenario as the sysroot-ed linker will prepend the real path.
652 grobian 1.61
653     See bug http://bugs.gentoo.org/4411 for more info.
654     */
655     ${output_format}
656 grobian 1.91 GROUP ( ${EPREFIX}/${libdir}/${tlib} )
657 grobian 1.61 END_LDSCRIPT
658 grobian 1.91 ;;
659     esac
660     fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}"
661 vapier 1.60 done
662     }

  ViewVC Help
Powered by ViewVC 1.1.20