/[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.45 Revision 1.105
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2007 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.45 2005/10/06 01:52:51 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.105 2011/09/06 22:54:45 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
10inherit multilib 16___ECLASS_RECUR_TOOLCHAIN_FUNCS="yes"
17[[ -z ${___ECLASS_RECUR_MULTILIB} ]] && inherit multilib
11 18
12DESCRIPTION="Based on the ${ECLASS} eclass" 19DESCRIPTION="Based on the ${ECLASS} eclass"
13 20
21# tc-getPROG <VAR [search vars]> <default> [tuple]
14tc-getPROG() { 22_tc-getPROG() {
15 local var=$1 23 local tuple=$1
24 local v var vars=$2
16 local prog=$2 25 local prog=$3
17 26
18 if [[ -n ${!var} ]] ; then 27 var=${vars%% *}
19 echo "${!var}" 28 for v in ${vars} ; do
20 return 0
21 fi
22
23 local search=
24 [[ -n $3 ]] && search=$(type -p "$3-${prog}")
25 [[ -z ${search} && -n $(get_abi_CHOST) ]] && search=$(type -p "$(get_abi_CHOST)-${prog}")
26 [[ -z ${search} && -n ${CHOST} ]] && search=$(type -p "${CHOST}-${prog}")
27 [[ -n ${search} ]] && prog=${search##*/}
28
29 export ${var}=${prog}
30 echo "${!var}"
31}
32
33# Returns the name of the archiver
34tc-getAR() { tc-getPROG AR ar "$@"; }
35# Returns the name of the assembler
36tc-getAS() { tc-getPROG AS as "$@"; }
37# Returns the name of the C compiler
38tc-getCC() { tc-getPROG CC gcc "$@"; }
39# Returns the name of the C++ compiler
40tc-getCXX() { tc-getPROG CXX g++ "$@"; }
41# Returns the name of the linker
42tc-getLD() { tc-getPROG LD ld "$@"; }
43# Returns the name of the symbol/object thingy
44tc-getNM() { tc-getPROG NM nm "$@"; }
45# Returns the name of the archiver indexer
46tc-getRANLIB() { tc-getPROG RANLIB ranlib "$@"; }
47# Returns the name of the fortran compiler
48tc-getF77() { tc-getPROG F77 f77 "$@"; }
49# Returns the name of the java compiler
50tc-getGCJ() { tc-getPROG GCJ gcj "$@"; }
51
52# Returns the name of the C compiler for build
53tc-getBUILD_CC() {
54 local v
55 for v in CC_FOR_BUILD BUILD_CC HOSTCC ; do
56 if [[ -n ${!v} ]] ; then 29 if [[ -n ${!v} ]] ; then
57 export BUILD_CC=${!v} 30 export ${var}=${!v}
58 echo "${!v}" 31 echo "${!v}"
59 return 0 32 return 0
60 fi 33 fi
61 done 34 done
62 35
63 local search= 36 local search=
64 if [[ -n ${CBUILD} ]] ; then 37 [[ -n $4 ]] && search=$(type -p "$4-${prog}")
65 search=$(type -p ${CBUILD}-gcc) 38 [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p "${!tuple}-${prog}")
66 search=${search##*/} 39 [[ -n ${search} ]] && prog=${search##*/}
67 fi
68 search=${search:-gcc}
69 40
70 export BUILD_CC=${search} 41 export ${var}=${prog}
71 echo "${search}" 42 echo "${!var}"
72} 43}
44tc-getBUILD_PROG() { _tc-getPROG CBUILD "$@"; }
45tc-getPROG() { _tc-getPROG CHOST "$@"; }
73 46
47# @FUNCTION: tc-getAR
48# @USAGE: [toolchain prefix]
49# @RETURN: name of the archiver
50tc-getAR() { tc-getPROG AR ar "$@"; }
51# @FUNCTION: tc-getAS
52# @USAGE: [toolchain prefix]
53# @RETURN: name of the assembler
54tc-getAS() { tc-getPROG AS as "$@"; }
55# @FUNCTION: tc-getCC
56# @USAGE: [toolchain prefix]
57# @RETURN: name of the C compiler
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]
65# @RETURN: name of the C++ compiler
66tc-getCXX() { tc-getPROG CXX g++ "$@"; }
67# @FUNCTION: tc-getLD
68# @USAGE: [toolchain prefix]
69# @RETURN: name of the linker
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]
77# @RETURN: name of the symbol/object thingy
78tc-getNM() { tc-getPROG NM nm "$@"; }
79# @FUNCTION: tc-getRANLIB
80# @USAGE: [toolchain prefix]
81# @RETURN: name of the archiver indexer
82tc-getRANLIB() { tc-getPROG RANLIB ranlib "$@"; }
83# @FUNCTION: tc-getOBJCOPY
84# @USAGE: [toolchain prefix]
85# @RETURN: name of the object copier
86tc-getOBJCOPY() { tc-getPROG OBJCOPY objcopy "$@"; }
87# @FUNCTION: tc-getF77
88# @USAGE: [toolchain prefix]
89# @RETURN: name of the Fortran 77 compiler
90tc-getF77() { tc-getPROG F77 gfortran "$@"; }
91# @FUNCTION: tc-getFC
92# @USAGE: [toolchain prefix]
93# @RETURN: name of the Fortran 90 compiler
94tc-getFC() { tc-getPROG FC gfortran "$@"; }
95# @FUNCTION: tc-getGCJ
96# @USAGE: [toolchain prefix]
97# @RETURN: name of the java compiler
98tc-getGCJ() { tc-getPROG GCJ gcj "$@"; }
99# @FUNCTION: tc-getPKG_CONFIG
100# @USAGE: [toolchain prefix]
101# @RETURN: name of the pkg-config tool
102tc-getPKG_CONFIG() { tc-getPROG PKG_CONFIG pkg-config "$@"; }
103# @FUNCTION: tc-getRC
104# @USAGE: [toolchain prefix]
105# @RETURN: name of the Windows resource compiler
106tc-getRC() { tc-getPROG RC windres "$@"; }
107# @FUNCTION: tc-getDLLWRAP
108# @USAGE: [toolchain prefix]
109# @RETURN: name of the Windows dllwrap utility
110tc-getDLLWRAP() { tc-getPROG DLLWRAP dllwrap "$@"; }
111
112# @FUNCTION: tc-getBUILD_CC
113# @USAGE: [toolchain prefix]
114# @RETURN: name of the C compiler for building binaries to run on the build machine
115tc-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
119tc-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
123tc-getBUILD_CXX() { tc-getBUILD_PROG "BUILD_CXX CXX_FOR_BUILD HOSTCXX" g++ "$@"; }
124
125# @FUNCTION: tc-export
126# @USAGE: <list of toolchain variables>
127# @DESCRIPTION:
74# Quick way to export a bunch of vars at once 128# Quick way to export a bunch of compiler vars at once.
75tc-export() { 129tc-export() {
76 local var 130 local var
77 for var in "$@" ; do 131 for var in "$@" ; do
132 [[ $(type -t tc-get${var}) != "function" ]] && die "tc-export: invalid export variable '${var}'"
78 eval tc-get${var} > /dev/null 133 eval tc-get${var} > /dev/null
79 done 134 done
80} 135}
81 136
82# A simple way to see if we're using a cross-compiler ... 137# @FUNCTION: tc-is-cross-compiler
138# @RETURN: Shell true if we are using a cross-compiler, shell false otherwise
83tc-is-cross-compiler() { 139tc-is-cross-compiler() {
84 return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]]) 140 return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]])
141}
142
143# @FUNCTION: tc-is-softfloat
144# @DESCRIPTION:
145# See if this toolchain is a softfloat based one.
146# @CODE
147# The possible return values:
148# - only: the target is always softfloat (never had fpu)
149# - yes: the target should support softfloat
150# - no: the target doesn't support softfloat
151# @CODE
152# 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.
155tc-is-softfloat() {
156 case ${CTARGET} in
157 bfin*|h8300*)
158 echo "only" ;;
159 *)
160 [[ ${CTARGET//_/-} == *-softfloat-* ]] \
161 && echo "yes" \
162 || echo "no"
163 ;;
164 esac
165}
166
167# @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
174tc-is-hardfloat() {
175 [[ ${CTARGET//_/-} == *-hardfloat-* ]] \
176 && echo "yes" \
177 || echo "no"
178}
179
180# @FUNCTION: tc-is-static-only
181# @DESCRIPTION:
182# Return shell true if the target does not support shared libs, shell false
183# otherwise.
184tc-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# @FUNCTION: tc-has-openmp
192# @USAGE: [toolchain prefix]
193# @DESCRIPTION:
194# See if the toolchain supports OpenMP.
195tc-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# @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).
221tc-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}
85} 242}
86 243
87 244
88# Parse information from CBUILD/CHOST/CTARGET rather than 245# Parse information from CBUILD/CHOST/CTARGET rather than
89# use external variables from the profile. 246# use external variables from the profile.
94 local host=$2 251 local host=$2
95 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}} 252 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
96 253
97 case ${host} in 254 case ${host} in
98 alpha*) echo alpha;; 255 alpha*) echo alpha;;
99 x86_64*) ninj x86_64 amd64;;
100 arm*) echo arm;; 256 arm*) echo arm;;
101 thumb*) echo arm;; 257 avr*) ninj avr32 avr;;
258 bfin*) ninj blackfin bfin;;
259 cris*) echo cris;;
102 hppa*) ninj parisc hppa;; 260 hppa*) ninj parisc hppa;;
261 i?86*)
262 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
263 # trees have been unified into 'x86'.
264 # FreeBSD still uses i386
265 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -lt $(KV_to_int 2.6.24) || ${host} == *freebsd* ]] ; then
266 echo i386
267 else
268 echo x86
269 fi
270 ;;
103 ia64*) echo ia64;; 271 ia64*) echo ia64;;
104 m68*) echo m68k;; 272 m68*) echo m68k;;
105 mips*) echo mips;; 273 mips*) echo mips;;
106 powerpc64*) echo ppc64;; 274 nios2*) echo nios2;;
107 powerpc*) [[ ${PROFILE_ARCH} == "ppc64" ]] \ 275 nios*) echo nios;;
108 && ninj ppc64 ppc \ 276 powerpc*)
277 # 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
109 || echo ppc 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
110 ;; 295 ;;
296 s390*) echo s390;;
297 sh64*) ninj sh64 sh;;
298 sh*) echo sh;;
111 sparc64*) ninj sparc64 sparc;; 299 sparc64*) ninj sparc64 sparc;;
112 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \ 300 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \
113 && ninj sparc64 sparc \ 301 && ninj sparc64 sparc \
114 || echo sparc 302 || echo sparc
115 ;; 303 ;;
116 s390*) echo s390;; 304 vax*) echo vax;;
117 sh64*) ninj sh64 sh;; 305 x86_64*freebsd*) echo amd64;;
118 sh*) echo sh;; 306 x86_64*)
119 i?86*) ninj i386 x86;; 307 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
120 *) echo ${ARCH};; 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
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;;
121 esac 320 esac
122} 321}
322# @FUNCTION: tc-arch-kernel
323# @USAGE: [toolchain prefix]
324# @RETURN: name of the kernel arch according to the compiler target
123tc-arch-kernel() { 325tc-arch-kernel() {
124 tc-ninja_magic_to_arch kern $@ 326 tc-ninja_magic_to_arch kern "$@"
125} 327}
328# @FUNCTION: tc-arch
329# @USAGE: [toolchain prefix]
330# @RETURN: name of the portage arch according to the compiler target
126tc-arch() { 331tc-arch() {
127 tc-ninja_magic_to_arch portage $@ 332 tc-ninja_magic_to_arch portage "$@"
128} 333}
334
129tc-endian() { 335tc-endian() {
130 local host=$1 336 local host=$1
131 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}} 337 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
132 host=${host%%-*} 338 host=${host%%-*}
133 339
134 case ${host} in 340 case ${host} in
135 alpha*) echo big;; 341 alpha*) echo big;;
136 x86_64*) echo little;;
137 arm*b*) echo big;; 342 arm*b*) echo big;;
138 arm*) echo little;; 343 arm*) echo little;;
139 thumb*) echo little;; 344 cris*) echo little;;
140 hppa*) echo big;; 345 hppa*) echo big;;
346 i?86*) echo little;;
141 ia64*) echo little;; 347 ia64*) echo little;;
142 m68*) echo big;; 348 m68*) echo big;;
143 mips*l*) echo little;; 349 mips*l*) echo little;;
144 mips*) echo big;; 350 mips*) echo big;;
145 powerpc*) echo big;; 351 powerpc*) echo big;;
146 sparc*) echo big;;
147 s390*) echo big;; 352 s390*) echo big;;
148 sh*b*) echo big;; 353 sh*b*) echo big;;
149 sh*) echo little;; 354 sh*) echo little;;
355 sparc*) echo big;;
150 i?86*) echo little;; 356 x86_64*) echo little;;
151 *) echo wtf;; 357 *) echo wtf;;
152 esac 358 esac
153} 359}
154 360
155# Returns the version as by `$CC -dumpversion` 361# 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# @FUNCTION: gcc-fullversion
371# @RETURN: compiler version (major.minor.micro: [3.4.6])
156gcc-fullversion() { 372gcc-fullversion() {
157 echo "$($(tc-getCC) -dumpversion)" 373 _gcc_fullversion '$1.$2.$3' "$@"
158} 374}
159# Returns the version, but only the <major>.<minor> 375# @FUNCTION: gcc-version
376# @RETURN: compiler version (major.minor: [3.4].6)
160gcc-version() { 377gcc-version() {
161 echo "$(gcc-fullversion | cut -f1,2 -d.)" 378 _gcc_fullversion '$1.$2' "$@"
162} 379}
163# Returns the Major version 380# @FUNCTION: gcc-major-version
381# @RETURN: major compiler version (major: [3].4.6)
164gcc-major-version() { 382gcc-major-version() {
165 echo "$(gcc-version | cut -f1 -d.)" 383 _gcc_fullversion '$1' "$@"
166} 384}
167# Returns the Minor version 385# @FUNCTION: gcc-minor-version
386# @RETURN: minor compiler version (minor: 3.[4].6)
168gcc-minor-version() { 387gcc-minor-version() {
169 echo "$(gcc-version | cut -f2 -d.)" 388 _gcc_fullversion '$2' "$@"
170} 389}
171# Returns the Micro version 390# @FUNCTION: gcc-micro-version
391# @RETURN: micro compiler version (micro: 3.4.[6])
172gcc-micro-version() { 392gcc-micro-version() {
173 echo "$(gcc-fullversion | cut -f3 -d. | cut -f1 -d-)" 393 _gcc_fullversion '$3' "$@"
174} 394}
175 395
396# Returns the installation directory - internal toolchain
397# function for use by _gcc-specs-exists (for flag-o-matic).
398_gcc-install-dir() {
399 echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null |\
400 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
408# Returns requested gcc specs directive unprocessed - for used by
409# gcc-specs-directive()
410# 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# 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 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'BEGIN { pspec=""; spec=""; outside=1 }
423$1=="*"directive":" { pspec=spec; spec=""; outside=0; next }
424 outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next }
425 spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next }
426 { spec=spec $0 }
427END { print spec }'
428 return 0
429}
430
176# Returns requested gcc specs directive 431# Return the requested gcc specs directive, with all included
177# Note; if a spec exists more than once (e.g. in more than one specs file) 432# specs expanded.
178# the last one read is the active definition - i.e. they do not accumulate, 433# Note, it does not check for inclusion loops, which cause it
179# each new definition replaces any previous definition. 434# to never finish - but such loops are invalid for gcc and we're
435# assuming gcc is operational.
180gcc-specs-directive() { 436gcc-specs-directive() {
181 local specfiles=$($(tc-getCC) -v 2>&1 | grep "^Reading" | awk '{print $NF}') 437 local directive subdname subdirective
182 [[ -z ${specfiles} ]] && return 0 438 directive="$(_gcc-specs-directive_raw $1)"
183 awk -v spec=$1 \ 439 while [[ ${directive} == *%\(*\)* ]]; do
184'BEGIN { sstr=""; outside=1 } 440 subdname=${directive/*%\(}
185 $1=="*"spec":" { sstr=""; outside=0; next } 441 subdname=${subdname/\)*}
186 outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next } 442 subdirective="$(_gcc-specs-directive_raw ${subdname})"
187 { sstr=sstr $0 } 443 directive="${directive//\%(${subdname})/${subdirective}}"
188END { print sstr }' ${specfiles} 444 done
445 echo "${directive}"
446 return 0
189} 447}
190 448
191# Returns true if gcc sets relro 449# Returns true if gcc sets relro
192gcc-specs-relro() { 450gcc-specs-relro() {
193 local directive 451 local directive
194 directive=$(gcc-specs-directive link_command) 452 directive=$(gcc-specs-directive link_command)
195 return $([[ ${directive/\{!norelro:} != ${directive} ]]) 453 return $([[ "${directive/\{!norelro:}" != "${directive}" ]])
196} 454}
197# Returns true if gcc sets now 455# Returns true if gcc sets now
198gcc-specs-now() { 456gcc-specs-now() {
199 local directive 457 local directive
200 directive=$(gcc-specs-directive link_command) 458 directive=$(gcc-specs-directive link_command)
201 return $([[ ${directive/\{!nonow:} != ${directive} ]]) 459 return $([[ "${directive/\{!nonow:}" != "${directive}" ]])
202} 460}
203# Returns true if gcc builds PIEs 461# Returns true if gcc builds PIEs
204gcc-specs-pie() { 462gcc-specs-pie() {
205 local directive 463 local directive
206 directive=$(gcc-specs-directive cc1) 464 directive=$(gcc-specs-directive cc1)
207 return $([[ ${directive/\{!nopie:} != ${directive} ]]) 465 return $([[ "${directive/\{!nopie:}" != "${directive}" ]])
208} 466}
209# Returns true if gcc builds with the stack protector 467# Returns true if gcc builds with the stack protector
210gcc-specs-ssp() { 468gcc-specs-ssp() {
211 local directive 469 local directive
212 directive=$(gcc-specs-directive cc1) 470 directive=$(gcc-specs-directive cc1)
213 return $([[ ${directive/\{!fno-stack-protector:} != ${directive} ]]) 471 return $([[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]])
214} 472}
473# Returns true if gcc upgrades fstack-protector to fstack-protector-all
474gcc-specs-ssp-to-all() {
475 local directive
476 directive=$(gcc-specs-directive cc1)
477 return $([[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]])
478}
479# Returns true if gcc builds with fno-strict-overflow
480gcc-specs-nostrict() {
481 local directive
482 directive=$(gcc-specs-directive cc1)
483 return $([[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]])
484}
485
486
487# @FUNCTION: gen_usr_ldscript
488# @USAGE: [-a] <list of libs to create linker scripts for>
489# @DESCRIPTION:
490# 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# library search path. This causes many builds to fail.
496# See bug #4411 for more info.
497#
498# Note that you should in general use the unversioned name of
499# the library (libfoo.so), as ldconfig should usually update it
500# correctly to point to the latest version of the library present.
501gen_usr_ldscript() {
502 local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname)
503 [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/
504
505 tc-is-static-only && return
506
507 # Just make sure it exists
508 dodir /usr/${libdir}
509
510 if [[ $1 == "-a" ]] ; then
511 auto=true
512 shift
513 dodir /${libdir}
514 fi
515
516 # 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 local tlib
523 if ${auto} ; then
524 lib="lib${lib}${suffix}"
525 else
526 # 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 if ${auto} ; then
536 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 # 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 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 if [[ ! -w "${ED}/${libdir}/${tlib}" ]] ; then
560 chmod u+w "${ED}${libdir}/${tlib}" # needed to write to it
561 local nowrite=yes
562 fi
563 install_name_tool \
564 -id "${EPREFIX}"/${libdir}/${tlib} \
565 "${ED}"/${libdir}/${tlib} || die "install_name_tool failed"
566 [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}"
567 # 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 *-aix*|*-irix*|*64*-hpux*|*-interix*|*-winnt*)
574 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 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 *)
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 # some SONAMEs are funky: they encode a version before the .so
638 if [[ ${tlib} != ${lib}* ]] ; then
639 mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die
640 fi
641 rm -f "${ED}"/${libdir}/${lib}
642 else
643 tlib=${lib}
644 fi
645 cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
646 /* GNU ld script
647 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
653 See bug http://bugs.gentoo.org/4411 for more info.
654 */
655 ${output_format}
656 GROUP ( ${EPREFIX}/${libdir}/${tlib} )
657 END_LDSCRIPT
658 ;;
659 esac
660 fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}"
661 done
662}

Legend:
Removed from v.1.45  
changed lines
  Added in v.1.105

  ViewVC Help
Powered by ViewVC 1.1.20