/[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.71 Revision 1.106
1# Copyright 1999-2007 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.71 2007/07/11 04:06:29 robbat2 Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.106 2011/09/09 19:14:19 vapier Exp $
4# 4
5# @ECLASS: toolchain-funcs.eclass
6# @MAINTAINER:
5# Maintainer: Toolchain Ninjas <toolchain@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
10___ECLASS_RECUR_TOOLCHAIN_FUNCS="yes" 16___ECLASS_RECUR_TOOLCHAIN_FUNCS="yes"
11[[ -z ${___ECLASS_RECUR_MULTILIB} ]] && inherit multilib 17[[ -z ${___ECLASS_RECUR_MULTILIB} ]] && inherit multilib
12 18
13DESCRIPTION="Based on the ${ECLASS} eclass" 19DESCRIPTION="Based on the ${ECLASS} eclass"
14 20
21# tc-getPROG <VAR [search vars]> <default> [tuple]
15tc-getPROG() { 22_tc-getPROG() {
16 local var=$1 23 local tuple=$1
24 local v var vars=$2
17 local prog=$2 25 local prog=$3
18 26
19 if [[ -n ${!var} ]] ; then 27 var=${vars%% *}
20 echo "${!var}" 28 for v in ${vars} ; do
21 return 0
22 fi
23
24 local search=
25 [[ -n $3 ]] && search=$(type -p "$3-${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 preprocessor
40tc-getCPP() { tc-getPROG CPP cpp "$@"; }
41# Returns the name of the C++ compiler
42tc-getCXX() { tc-getPROG CXX g++ "$@"; }
43# Returns the name of the linker
44tc-getLD() { tc-getPROG LD ld "$@"; }
45# Returns the name of the strip prog
46tc-getSTRIP() { tc-getPROG STRIP strip "$@"; }
47# Returns the name of the symbol/object thingy
48tc-getNM() { tc-getPROG NM nm "$@"; }
49# Returns the name of the archiver indexer
50tc-getRANLIB() { tc-getPROG RANLIB ranlib "$@"; }
51# Returns the name of the fortran 77 compiler
52tc-getF77() { tc-getPROG F77 f77 "$@"; }
53# Returns the name of the fortran 90 compiler
54tc-getF90() { tc-getPROG F90 gfortran "$@"; }
55# Returns the name of the fortran compiler
56tc-getFORTRAN() { tc-getPROG FORTRAN gfortran "$@"; }
57# Returns the name of the java compiler
58tc-getGCJ() { tc-getPROG GCJ gcj "$@"; }
59
60# Returns the name of the C compiler for build
61tc-getBUILD_CC() {
62 local v
63 for v in CC_FOR_BUILD BUILD_CC HOSTCC ; do
64 if [[ -n ${!v} ]] ; then 29 if [[ -n ${!v} ]] ; then
65 export BUILD_CC=${!v} 30 export ${var}="${!v}"
66 echo "${!v}" 31 echo "${!v}"
67 return 0 32 return 0
68 fi 33 fi
69 done 34 done
70 35
71 local search= 36 local search=
72 if [[ -n ${CBUILD} ]] ; then 37 [[ -n $4 ]] && search=$(type -p "$4-${prog}")
73 search=$(type -p ${CBUILD}-gcc) 38 [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p "${!tuple}-${prog}")
74 search=${search##*/} 39 [[ -n ${search} ]] && prog=${search##*/}
75 fi
76 search=${search:-gcc}
77 40
78 export BUILD_CC=${search} 41 export ${var}=${prog}
79 echo "${search}" 42 echo "${!var}"
80} 43}
44tc-getBUILD_PROG() { _tc-getPROG CBUILD "$@"; }
45tc-getPROG() { _tc-getPROG CHOST "$@"; }
81 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:
82# Quick way to export a bunch of vars at once 128# Quick way to export a bunch of compiler vars at once.
83tc-export() { 129tc-export() {
84 local var 130 local var
85 for var in "$@" ; do 131 for var in "$@" ; do
132 [[ $(type -t tc-get${var}) != "function" ]] && die "tc-export: invalid export variable '${var}'"
86 eval tc-get${var} > /dev/null 133 eval tc-get${var} > /dev/null
87 done 134 done
88} 135}
89 136
90# 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
91tc-is-cross-compiler() { 139tc-is-cross-compiler() {
92 return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]]) 140 return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]])
93} 141}
94 142
143# @FUNCTION: tc-is-softfloat
144# @DESCRIPTION:
95# See if this toolchain is a softfloat based one. 145# See if this toolchain is a softfloat based one.
146# @CODE
96# The possible return values: 147# The possible return values:
97# - only: the target is always softfloat (never had fpu) 148# - only: the target is always softfloat (never had fpu)
98# - yes: the target should support softfloat 149# - yes: the target should support softfloat
99# - no: the target should support hardfloat 150# - no: the target doesn't support softfloat
151# @CODE
100# This allows us to react differently where packages accept 152# This allows us to react differently where packages accept
101# softfloat flags in the case where support is optional, but 153# softfloat flags in the case where support is optional, but
102# rejects softfloat flags where the target always lacks an fpu. 154# rejects softfloat flags where the target always lacks an fpu.
103tc-is-softfloat() { 155tc-is-softfloat() {
104 case ${CTARGET} in 156 case ${CTARGET} in
110 || echo "no" 162 || echo "no"
111 ;; 163 ;;
112 esac 164 esac
113} 165}
114 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}
242}
243
244
115# Parse information from CBUILD/CHOST/CTARGET rather than 245# Parse information from CBUILD/CHOST/CTARGET rather than
116# use external variables from the profile. 246# use external variables from the profile.
117tc-ninja_magic_to_arch() { 247tc-ninja_magic_to_arch() {
118ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; } 248ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; }
119 249
122 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}} 252 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
123 253
124 case ${host} in 254 case ${host} in
125 alpha*) echo alpha;; 255 alpha*) echo alpha;;
126 arm*) echo arm;; 256 arm*) echo arm;;
257 avr*) ninj avr32 avr;;
127 bfin*) ninj blackfin bfin;; 258 bfin*) ninj blackfin bfin;;
128 cris*) echo cris;; 259 cris*) echo cris;;
129 hppa*) ninj parisc hppa;; 260 hppa*) ninj parisc hppa;;
130 i?86*) ninj i386 x86;; 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 ;;
131 ia64*) echo ia64;; 271 ia64*) echo ia64;;
132 m68*) echo m68k;; 272 m68*) echo m68k;;
133 mips*) echo mips;; 273 mips*) echo mips;;
134 nios2*) echo nios2;; 274 nios2*) echo nios2;;
135 nios*) echo nios;; 275 nios*) echo nios;;
136 powerpc*) 276 powerpc*)
137 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees 277 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees
138 # have been unified into simply 'powerpc', but until 2.6.16, 278 # have been unified into simply 'powerpc', but until 2.6.16,
139 # ppc32 is still using ARCH="ppc" as default 279 # ppc32 is still using ARCH="ppc" as default
140 if [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]] && [[ ${type} == "kern" ]] ; then 280 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]] ; then
141 echo powerpc 281 echo powerpc
142 elif [[ $(KV_to_int ${KV}) -eq $(KV_to_int 2.6.15) ]] && [[ ${type} == "kern" ]] ; then 282 elif [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -eq $(KV_to_int 2.6.15) ]] ; then
143 if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]] ; then 283 if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]] ; then
144 echo powerpc 284 echo powerpc
145 else 285 else
146 echo ppc 286 echo ppc
147 fi 287 fi
148 elif [[ ${host} == powerpc64* ]] ; then 288 elif [[ ${host} == powerpc64* ]] ; then
149 echo ppc64 289 echo ppc64
150 elif [[ ${PROFILE_ARCH} == "ppc64" ]] ; then 290 elif [[ ${PROFILE_ARCH} == "ppc64" ]] ; then
151 ninj ppc64 ppc 291 ninj ppc64 ppc
152 else 292 else
153 echo ppc 293 echo ppc
154 fi 294 fi
155 ;; 295 ;;
156 s390*) echo s390;; 296 s390*) echo s390;;
157 sh64*) ninj sh64 sh;; 297 sh64*) ninj sh64 sh;;
158 sh*) echo sh;; 298 sh*) echo sh;;
159 sparc64*) ninj sparc64 sparc;; 299 sparc64*) ninj sparc64 sparc;;
160 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \ 300 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \
161 && ninj sparc64 sparc \ 301 && ninj sparc64 sparc \
162 || echo sparc 302 || echo sparc
163 ;; 303 ;;
164 vax*) echo vax;; 304 vax*) echo vax;;
165 x86_64*) ninj x86_64 amd64;; 305 x86_64*freebsd*) echo amd64;;
166 *) echo ${ARCH};; 306 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
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;;
167 esac 320 esac
168} 321}
322# @FUNCTION: tc-arch-kernel
323# @USAGE: [toolchain prefix]
324# @RETURN: name of the kernel arch according to the compiler target
169tc-arch-kernel() { 325tc-arch-kernel() {
170 tc-ninja_magic_to_arch kern $@ 326 tc-ninja_magic_to_arch kern "$@"
171} 327}
328# @FUNCTION: tc-arch
329# @USAGE: [toolchain prefix]
330# @RETURN: name of the portage arch according to the compiler target
172tc-arch() { 331tc-arch() {
173 tc-ninja_magic_to_arch portage $@ 332 tc-ninja_magic_to_arch portage "$@"
174} 333}
334
175tc-endian() { 335tc-endian() {
176 local host=$1 336 local host=$1
177 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}} 337 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
178 host=${host%%-*} 338 host=${host%%-*}
179 339
196 x86_64*) echo little;; 356 x86_64*) echo little;;
197 *) echo wtf;; 357 *) echo wtf;;
198 esac 358 esac
199} 359}
200 360
201# 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])
202gcc-fullversion() { 372gcc-fullversion() {
203 $(tc-getCC "$@") -dumpversion 373 _gcc_fullversion '$1.$2.$3' "$@"
204} 374}
205# Returns the version, but only the <major>.<minor> 375# @FUNCTION: gcc-version
376# @RETURN: compiler version (major.minor: [3.4].6)
206gcc-version() { 377gcc-version() {
207 gcc-fullversion "$@" | cut -f1,2 -d. 378 _gcc_fullversion '$1.$2' "$@"
208} 379}
209# Returns the Major version 380# @FUNCTION: gcc-major-version
381# @RETURN: major compiler version (major: [3].4.6)
210gcc-major-version() { 382gcc-major-version() {
211 gcc-version "$@" | cut -f1 -d. 383 _gcc_fullversion '$1' "$@"
212} 384}
213# Returns the Minor version 385# @FUNCTION: gcc-minor-version
386# @RETURN: minor compiler version (minor: 3.[4].6)
214gcc-minor-version() { 387gcc-minor-version() {
215 gcc-version "$@" | cut -f2 -d. 388 _gcc_fullversion '$2' "$@"
216} 389}
217# Returns the Micro version 390# @FUNCTION: gcc-micro-version
391# @RETURN: micro compiler version (micro: 3.4.[6])
218gcc-micro-version() { 392gcc-micro-version() {
219 gcc-fullversion "$@" | cut -f3 -d. | cut -f1 -d- 393 _gcc_fullversion '$3' "$@"
220} 394}
395
221# Returns the installation directory - internal toolchain 396# Returns the installation directory - internal toolchain
222# function for use by _gcc-specs-exists (for flag-o-matic). 397# function for use by _gcc-specs-exists (for flag-o-matic).
223_gcc-install-dir() { 398_gcc-install-dir() {
224 echo "$($(tc-getCC) -print-search-dirs 2> /dev/null |\ 399 echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null |\
225 awk '$1=="install:" {print $2}')" 400 awk '$1=="install:" {print $2}')"
226} 401}
227# Returns true if the indicated specs file exists - internal toolchain 402# Returns true if the indicated specs file exists - internal toolchain
228# function for use by flag-o-matic. 403# function for use by flag-o-matic.
229_gcc-specs-exists() { 404_gcc-specs-exists() {
273 448
274# Returns true if gcc sets relro 449# Returns true if gcc sets relro
275gcc-specs-relro() { 450gcc-specs-relro() {
276 local directive 451 local directive
277 directive=$(gcc-specs-directive link_command) 452 directive=$(gcc-specs-directive link_command)
278 return $([[ ${directive/\{!norelro:} != ${directive} ]]) 453 return $([[ "${directive/\{!norelro:}" != "${directive}" ]])
279} 454}
280# Returns true if gcc sets now 455# Returns true if gcc sets now
281gcc-specs-now() { 456gcc-specs-now() {
282 local directive 457 local directive
283 directive=$(gcc-specs-directive link_command) 458 directive=$(gcc-specs-directive link_command)
284 return $([[ ${directive/\{!nonow:} != ${directive} ]]) 459 return $([[ "${directive/\{!nonow:}" != "${directive}" ]])
285} 460}
286# Returns true if gcc builds PIEs 461# Returns true if gcc builds PIEs
287gcc-specs-pie() { 462gcc-specs-pie() {
288 local directive 463 local directive
289 directive=$(gcc-specs-directive cc1) 464 directive=$(gcc-specs-directive cc1)
290 return $([[ ${directive/\{!nopie:} != ${directive} ]]) 465 return $([[ "${directive/\{!nopie:}" != "${directive}" ]])
291} 466}
292# Returns true if gcc builds with the stack protector 467# Returns true if gcc builds with the stack protector
293gcc-specs-ssp() { 468gcc-specs-ssp() {
294 local directive 469 local directive
295 directive=$(gcc-specs-directive cc1) 470 directive=$(gcc-specs-directive cc1)
296 return $([[ ${directive/\{!fno-stack-protector:} != ${directive} ]]) 471 return $([[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]])
297} 472}
298# Returns true if gcc upgrades fstack-protector to fstack-protector-all 473# Returns true if gcc upgrades fstack-protector to fstack-protector-all
299gcc-specs-ssp-to-all() { 474gcc-specs-ssp-to-all() {
300 local directive 475 local directive
301 directive=$(gcc-specs-directive cc1) 476 directive=$(gcc-specs-directive cc1)
302 return $([[ ${directive/\{!fno-stack-protector-all:} != ${directive} ]]) 477 return $([[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]])
303} 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}
304 485
305 486
487# @FUNCTION: gen_usr_ldscript
488# @USAGE: [-a] <list of libs to create linker scripts for>
489# @DESCRIPTION:
306# This function generate linker scripts in /usr/lib for dynamic 490# This function generate linker scripts in /usr/lib for dynamic
307# libs in /lib. This is to fix linking problems when you have 491# libs in /lib. This is to fix linking problems when you have
308# the .so in /lib, and the .a in /usr/lib. What happens is that 492# the .so in /lib, and the .a in /usr/lib. What happens is that
309# in some cases when linking dynamic, the .a in /usr/lib is used 493# in some cases when linking dynamic, the .a in /usr/lib is used
310# instead of the .so in /lib due to gcc/libtool tweaking ld's 494# instead of the .so in /lib due to gcc/libtool tweaking ld's
311# library search path. This cause many builds to fail. 495# library search path. This causes many builds to fail.
312# See bug #4411 for more info. 496# See bug #4411 for more info.
313# 497#
314# To use, simply call:
315#
316# gen_usr_ldscript libfoo.so
317#
318# Note that you should in general use the unversioned name of 498# Note that you should in general use the unversioned name of
319# the library, as ldconfig should usually update it correctly 499# the library (libfoo.so), as ldconfig should usually update it
320# to point to the latest version of the library present. 500# correctly to point to the latest version of the library present.
321gen_usr_ldscript() { 501gen_usr_ldscript() {
322 local lib libdir=$(get_libdir) output_format="" 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
323 # Just make sure it exists 507 # Just make sure it exists
324 dodir /usr/${libdir} 508 dodir /usr/${libdir}
509
510 if [[ $1 == "-a" ]] ; then
511 auto=true
512 shift
513 dodir /${libdir}
514 fi
325 515
326 # OUTPUT_FORMAT gives hints to the linker as to what binary format 516 # OUTPUT_FORMAT gives hints to the linker as to what binary format
327 # is referenced ... makes multilib saner 517 # is referenced ... makes multilib saner
328 output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p') 518 output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
329 [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )" 519 [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
330 520
331 for lib in "$@" ; do 521 for lib in "$@" ; do
332 if [[ ${USERLAND} == "Darwin" ]] ; then 522 local tlib
333 ewarn "Not creating fake dynamic library for $lib on Darwin;" 523 if ${auto} ; then
334 ewarn "making a symlink instead." 524 lib="lib${lib}${suffix}"
335 dosym "/${libdir}/${lib}" "/usr/${libdir}/${lib}"
336 else 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
337 cat > "${D}/usr/${libdir}/${lib}" <<-END_LDSCRIPT 645 cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
338 /* GNU ld script 646 /* GNU ld script
339 Since Gentoo has critical dynamic libraries 647 Since Gentoo has critical dynamic libraries in /lib, and the static versions
340 in /lib, and the static versions in /usr/lib, 648 in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
341 we need to have a "fake" dynamic lib in /usr/lib, 649 run into linking problems. This "fake" dynamic lib is a linker script that
342 otherwise we run into linking problems. 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.
343 652
344 See bug http://bugs.gentoo.org/4411 for more info. 653 See bug http://bugs.gentoo.org/4411 for more info.
345 */ 654 */
346 ${output_format} 655 ${output_format}
347 GROUP ( /${libdir}/${lib} ) 656 GROUP ( ${EPREFIX}/${libdir}/${tlib} )
348 END_LDSCRIPT 657 END_LDSCRIPT
349 fi 658 ;;
659 esac
350 fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}" 660 fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}"
351 done 661 done
352} 662}

Legend:
Removed from v.1.71  
changed lines
  Added in v.1.106

  ViewVC Help
Powered by ViewVC 1.1.20