| 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.84 2009/01/08 11:06:10 gengor 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 |
5 | # @ECLASS: toolchain-funcs.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # Toolchain Ninjas <toolchain@gentoo.org> |
7 | # Toolchain Ninjas <toolchain@gentoo.org> |
| 8 | # @BLURB: functions to query common info about the toolchain |
8 | # @BLURB: functions to query common info about the toolchain |
| … | |
… | |
| 16 | ___ECLASS_RECUR_TOOLCHAIN_FUNCS="yes" |
16 | ___ECLASS_RECUR_TOOLCHAIN_FUNCS="yes" |
| 17 | [[ -z ${___ECLASS_RECUR_MULTILIB} ]] && inherit multilib |
17 | [[ -z ${___ECLASS_RECUR_MULTILIB} ]] && inherit multilib |
| 18 | |
18 | |
| 19 | DESCRIPTION="Based on the ${ECLASS} eclass" |
19 | DESCRIPTION="Based on the ${ECLASS} eclass" |
| 20 | |
20 | |
|
|
21 | # tc-getPROG <VAR [search vars]> <default> [tuple] |
| 21 | tc-getPROG() { |
22 | _tc-getPROG() { |
| 22 | local var=$1 |
23 | local tuple=$1 |
|
|
24 | local v var vars=$2 |
| 23 | local prog=$2 |
25 | local prog=$3 |
| 24 | |
26 | |
| 25 | if [[ -n ${!var} ]] ; then |
27 | var=${vars%% *} |
| 26 | echo "${!var}" |
28 | for v in ${vars} ; do |
| 27 | return 0 |
|
|
| 28 | fi |
|
|
| 29 | |
|
|
| 30 | local search= |
|
|
| 31 | [[ -n $3 ]] && search=$(type -p "$3-${prog}") |
|
|
| 32 | [[ -z ${search} && -n ${CHOST} ]] && search=$(type -p "${CHOST}-${prog}") |
|
|
| 33 | [[ -n ${search} ]] && prog=${search##*/} |
|
|
| 34 | |
|
|
| 35 | export ${var}=${prog} |
|
|
| 36 | echo "${!var}" |
|
|
| 37 | } |
|
|
| 38 | |
|
|
| 39 | # @FUNCTION: tc-getAR |
|
|
| 40 | # @USAGE: [toolchain prefix] |
|
|
| 41 | # @RETURN: name of the archiver |
|
|
| 42 | tc-getAR() { tc-getPROG AR ar "$@"; } |
|
|
| 43 | # @FUNCTION: tc-getAS |
|
|
| 44 | # @USAGE: [toolchain prefix] |
|
|
| 45 | # @RETURN: name of the assembler |
|
|
| 46 | tc-getAS() { tc-getPROG AS as "$@"; } |
|
|
| 47 | # @FUNCTION: tc-getCC |
|
|
| 48 | # @USAGE: [toolchain prefix] |
|
|
| 49 | # @RETURN: name of the C compiler |
|
|
| 50 | tc-getCC() { tc-getPROG CC gcc "$@"; } |
|
|
| 51 | # @FUNCTION: tc-getCPP |
|
|
| 52 | # @USAGE: [toolchain prefix] |
|
|
| 53 | # @RETURN: name of the C preprocessor |
|
|
| 54 | tc-getCPP() { tc-getPROG CPP cpp "$@"; } |
|
|
| 55 | # @FUNCTION: tc-getCXX |
|
|
| 56 | # @USAGE: [toolchain prefix] |
|
|
| 57 | # @RETURN: name of the C++ compiler |
|
|
| 58 | tc-getCXX() { tc-getPROG CXX g++ "$@"; } |
|
|
| 59 | # @FUNCTION: tc-getLD |
|
|
| 60 | # @USAGE: [toolchain prefix] |
|
|
| 61 | # @RETURN: name of the linker |
|
|
| 62 | tc-getLD() { tc-getPROG LD ld "$@"; } |
|
|
| 63 | # @FUNCTION: tc-getSTRIP |
|
|
| 64 | # @USAGE: [toolchain prefix] |
|
|
| 65 | # @RETURN: name of the strip program |
|
|
| 66 | tc-getSTRIP() { tc-getPROG STRIP strip "$@"; } |
|
|
| 67 | # @FUNCTION: tc-getNM |
|
|
| 68 | # @USAGE: [toolchain prefix] |
|
|
| 69 | # @RETURN: name of the symbol/object thingy |
|
|
| 70 | tc-getNM() { tc-getPROG NM nm "$@"; } |
|
|
| 71 | # @FUNCTION: tc-getRANLIB |
|
|
| 72 | # @USAGE: [toolchain prefix] |
|
|
| 73 | # @RETURN: name of the archiver indexer |
|
|
| 74 | tc-getRANLIB() { tc-getPROG RANLIB ranlib "$@"; } |
|
|
| 75 | # @FUNCTION: tc-getF77 |
|
|
| 76 | # @USAGE: [toolchain prefix] |
|
|
| 77 | # @RETURN: name of the Fortran 77 compiler |
|
|
| 78 | tc-getF77() { tc-getPROG F77 f77 "$@"; } |
|
|
| 79 | # @FUNCTION: tc-getFC |
|
|
| 80 | # @USAGE: [toolchain prefix] |
|
|
| 81 | # @RETURN: name of the Fortran 90 compiler |
|
|
| 82 | tc-getFC() { tc-getPROG FC gfortran "$@"; } |
|
|
| 83 | # @FUNCTION: tc-getGCJ |
|
|
| 84 | # @USAGE: [toolchain prefix] |
|
|
| 85 | # @RETURN: name of the java compiler |
|
|
| 86 | tc-getGCJ() { tc-getPROG GCJ gcj "$@"; } |
|
|
| 87 | |
|
|
| 88 | # @FUNCTION: tc-getBUILD_CC |
|
|
| 89 | # @USAGE: [toolchain prefix] |
|
|
| 90 | # @RETURN: name of the C compiler for building binaries to run on the build machine |
|
|
| 91 | tc-getBUILD_CC() { |
|
|
| 92 | local v |
|
|
| 93 | for v in CC_FOR_BUILD BUILD_CC HOSTCC ; do |
|
|
| 94 | if [[ -n ${!v} ]] ; then |
29 | if [[ -n ${!v} ]] ; then |
| 95 | export BUILD_CC=${!v} |
30 | export ${var}=${!v} |
| 96 | echo "${!v}" |
31 | echo "${!v}" |
| 97 | return 0 |
32 | return 0 |
| 98 | fi |
33 | fi |
| 99 | done |
34 | done |
| 100 | |
35 | |
| 101 | local search= |
36 | local search= |
| 102 | if [[ -n ${CBUILD} ]] ; then |
37 | [[ -n $4 ]] && search=$(type -p "$4-${prog}") |
| 103 | search=$(type -p ${CBUILD}-gcc) |
38 | [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p "${!tuple}-${prog}") |
| 104 | search=${search##*/} |
39 | [[ -n ${search} ]] && prog=${search##*/} |
| 105 | fi |
|
|
| 106 | search=${search:-gcc} |
|
|
| 107 | |
40 | |
| 108 | export BUILD_CC=${search} |
41 | export ${var}=${prog} |
| 109 | echo "${search}" |
42 | echo "${!var}" |
| 110 | } |
43 | } |
|
|
44 | tc-getBUILD_PROG() { _tc-getPROG CBUILD "$@"; } |
|
|
45 | tc-getPROG() { _tc-getPROG CHOST "$@"; } |
|
|
46 | |
|
|
47 | # @FUNCTION: tc-getAR |
|
|
48 | # @USAGE: [toolchain prefix] |
|
|
49 | # @RETURN: name of the archiver |
|
|
50 | tc-getAR() { tc-getPROG AR ar "$@"; } |
|
|
51 | # @FUNCTION: tc-getAS |
|
|
52 | # @USAGE: [toolchain prefix] |
|
|
53 | # @RETURN: name of the assembler |
|
|
54 | tc-getAS() { tc-getPROG AS as "$@"; } |
|
|
55 | # @FUNCTION: tc-getCC |
|
|
56 | # @USAGE: [toolchain prefix] |
|
|
57 | # @RETURN: name of the C compiler |
|
|
58 | tc-getCC() { tc-getPROG CC gcc "$@"; } |
|
|
59 | # @FUNCTION: tc-getCPP |
|
|
60 | # @USAGE: [toolchain prefix] |
|
|
61 | # @RETURN: name of the C preprocessor |
|
|
62 | tc-getCPP() { tc-getPROG CPP cpp "$@"; } |
|
|
63 | # @FUNCTION: tc-getCXX |
|
|
64 | # @USAGE: [toolchain prefix] |
|
|
65 | # @RETURN: name of the C++ compiler |
|
|
66 | tc-getCXX() { tc-getPROG CXX g++ "$@"; } |
|
|
67 | # @FUNCTION: tc-getLD |
|
|
68 | # @USAGE: [toolchain prefix] |
|
|
69 | # @RETURN: name of the linker |
|
|
70 | tc-getLD() { tc-getPROG LD ld "$@"; } |
|
|
71 | # @FUNCTION: tc-getSTRIP |
|
|
72 | # @USAGE: [toolchain prefix] |
|
|
73 | # @RETURN: name of the strip program |
|
|
74 | tc-getSTRIP() { tc-getPROG STRIP strip "$@"; } |
|
|
75 | # @FUNCTION: tc-getNM |
|
|
76 | # @USAGE: [toolchain prefix] |
|
|
77 | # @RETURN: name of the symbol/object thingy |
|
|
78 | tc-getNM() { tc-getPROG NM nm "$@"; } |
|
|
79 | # @FUNCTION: tc-getRANLIB |
|
|
80 | # @USAGE: [toolchain prefix] |
|
|
81 | # @RETURN: name of the archiver indexer |
|
|
82 | tc-getRANLIB() { tc-getPROG RANLIB ranlib "$@"; } |
|
|
83 | # @FUNCTION: tc-getOBJCOPY |
|
|
84 | # @USAGE: [toolchain prefix] |
|
|
85 | # @RETURN: name of the object copier |
|
|
86 | tc-getOBJCOPY() { tc-getPROG OBJCOPY objcopy "$@"; } |
|
|
87 | # @FUNCTION: tc-getF77 |
|
|
88 | # @USAGE: [toolchain prefix] |
|
|
89 | # @RETURN: name of the Fortran 77 compiler |
|
|
90 | tc-getF77() { tc-getPROG F77 gfortran "$@"; } |
|
|
91 | # @FUNCTION: tc-getFC |
|
|
92 | # @USAGE: [toolchain prefix] |
|
|
93 | # @RETURN: name of the Fortran 90 compiler |
|
|
94 | tc-getFC() { tc-getPROG FC gfortran "$@"; } |
|
|
95 | # @FUNCTION: tc-getGCJ |
|
|
96 | # @USAGE: [toolchain prefix] |
|
|
97 | # @RETURN: name of the java compiler |
|
|
98 | tc-getGCJ() { tc-getPROG GCJ gcj "$@"; } |
|
|
99 | # @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 | # @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 | |
|
|
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 |
|
|
115 | 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++ "$@"; } |
| 111 | |
124 | |
| 112 | # @FUNCTION: tc-export |
125 | # @FUNCTION: tc-export |
| 113 | # @USAGE: <list of toolchain variables> |
126 | # @USAGE: <list of toolchain variables> |
| 114 | # @DESCRIPTION: |
127 | # @DESCRIPTION: |
| 115 | # Quick way to export a bunch of compiler vars at once. |
128 | # Quick way to export a bunch of compiler vars at once. |
| … | |
… | |
| 132 | # See if this toolchain is a softfloat based one. |
145 | # See if this toolchain is a softfloat based one. |
| 133 | # @CODE |
146 | # @CODE |
| 134 | # The possible return values: |
147 | # The possible return values: |
| 135 | # - only: the target is always softfloat (never had fpu) |
148 | # - only: the target is always softfloat (never had fpu) |
| 136 | # - yes: the target should support softfloat |
149 | # - yes: the target should support softfloat |
| 137 | # - no: the target should support hardfloat |
150 | # - no: the target doesn't support softfloat |
| 138 | # @CODE |
151 | # @CODE |
| 139 | # This allows us to react differently where packages accept |
152 | # This allows us to react differently where packages accept |
| 140 | # softfloat flags in the case where support is optional, but |
153 | # softfloat flags in the case where support is optional, but |
| 141 | # rejects softfloat flags where the target always lacks an fpu. |
154 | # rejects softfloat flags where the target always lacks an fpu. |
| 142 | tc-is-softfloat() { |
155 | tc-is-softfloat() { |
| … | |
… | |
| 148 | && echo "yes" \ |
161 | && echo "yes" \ |
| 149 | || echo "no" |
162 | || echo "no" |
| 150 | ;; |
163 | ;; |
| 151 | esac |
164 | esac |
| 152 | } |
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 |
|
|
174 | tc-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. |
|
|
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 | # @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 | # @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 | |
| 153 | |
244 | |
| 154 | # Parse information from CBUILD/CHOST/CTARGET rather than |
245 | # Parse information from CBUILD/CHOST/CTARGET rather than |
| 155 | # use external variables from the profile. |
246 | # use external variables from the profile. |
| 156 | tc-ninja_magic_to_arch() { |
247 | tc-ninja_magic_to_arch() { |
| 157 | ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; } |
248 | ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; } |
| … | |
… | |
| 181 | m68*) echo m68k;; |
272 | m68*) echo m68k;; |
| 182 | mips*) echo mips;; |
273 | mips*) echo mips;; |
| 183 | nios2*) echo nios2;; |
274 | nios2*) echo nios2;; |
| 184 | nios*) echo nios;; |
275 | nios*) echo nios;; |
| 185 | powerpc*) |
276 | powerpc*) |
| 186 | # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees |
277 | # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees |
| 187 | # have been unified into simply 'powerpc', but until 2.6.16, |
278 | # have been unified into simply 'powerpc', but until 2.6.16, |
| 188 | # ppc32 is still using ARCH="ppc" as default |
279 | # ppc32 is still using ARCH="ppc" as default |
| 189 | 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 |
| 190 | echo powerpc |
281 | echo powerpc |
| 191 | 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 |
| 192 | if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]] ; then |
283 | if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]] ; then |
| 193 | echo powerpc |
284 | echo powerpc |
| 194 | else |
285 | else |
| 195 | echo ppc |
286 | echo ppc |
| 196 | fi |
287 | fi |
| 197 | elif [[ ${host} == powerpc64* ]] ; then |
288 | elif [[ ${host} == powerpc64* ]] ; then |
| 198 | echo ppc64 |
289 | echo ppc64 |
| 199 | elif [[ ${PROFILE_ARCH} == "ppc64" ]] ; then |
290 | elif [[ ${PROFILE_ARCH} == "ppc64" ]] ; then |
| 200 | ninj ppc64 ppc |
291 | ninj ppc64 ppc |
| 201 | else |
292 | else |
| 202 | echo ppc |
293 | echo ppc |
| 203 | fi |
294 | fi |
| 204 | ;; |
295 | ;; |
| 205 | s390*) echo s390;; |
296 | s390*) echo s390;; |
| 206 | sh64*) ninj sh64 sh;; |
297 | sh64*) ninj sh64 sh;; |
| 207 | sh*) echo sh;; |
298 | sh*) echo sh;; |
| 208 | sparc64*) ninj sparc64 sparc;; |
299 | sparc64*) ninj sparc64 sparc;; |
| 209 | sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \ |
300 | sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \ |
| 210 | && ninj sparc64 sparc \ |
301 | && ninj sparc64 sparc \ |
| 211 | || echo sparc |
302 | || echo sparc |
| 212 | ;; |
303 | ;; |
| 213 | vax*) echo vax;; |
304 | vax*) echo vax;; |
|
|
305 | x86_64*freebsd*) echo amd64;; |
| 214 | x86_64*) |
306 | x86_64*) |
| 215 | # Starting with linux-2.6.24, the 'x86_64' and 'i386' |
307 | # Starting with linux-2.6.24, the 'x86_64' and 'i386' |
| 216 | # trees have been unified into 'x86'. |
308 | # trees have been unified into 'x86'. |
| 217 | if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.24) ]] ; then |
309 | if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.24) ]] ; then |
| 218 | echo x86 |
310 | echo x86 |
| … | |
… | |
| 264 | x86_64*) echo little;; |
356 | x86_64*) echo little;; |
| 265 | *) echo wtf;; |
357 | *) echo wtf;; |
| 266 | esac |
358 | esac |
| 267 | } |
359 | } |
| 268 | |
360 | |
|
|
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 | |
| 269 | # @FUNCTION: gcc-fullversion |
370 | # @FUNCTION: gcc-fullversion |
| 270 | # @RETURN: compiler version (major.minor.micro: [3.4.6]) |
371 | # @RETURN: compiler version (major.minor.micro: [3.4.6]) |
| 271 | gcc-fullversion() { |
372 | gcc-fullversion() { |
| 272 | $(tc-getCC "$@") -dumpversion |
373 | _gcc_fullversion '$1.$2.$3' "$@" |
| 273 | } |
374 | } |
| 274 | # @FUNCTION: gcc-version |
375 | # @FUNCTION: gcc-version |
| 275 | # @RETURN: compiler version (major.minor: [3.4].6) |
376 | # @RETURN: compiler version (major.minor: [3.4].6) |
| 276 | gcc-version() { |
377 | gcc-version() { |
| 277 | gcc-fullversion "$@" | cut -f1,2 -d. |
378 | _gcc_fullversion '$1.$2' "$@" |
| 278 | } |
379 | } |
| 279 | # @FUNCTION: gcc-major-version |
380 | # @FUNCTION: gcc-major-version |
| 280 | # @RETURN: major compiler version (major: [3].4.6) |
381 | # @RETURN: major compiler version (major: [3].4.6) |
| 281 | gcc-major-version() { |
382 | gcc-major-version() { |
| 282 | gcc-version "$@" | cut -f1 -d. |
383 | _gcc_fullversion '$1' "$@" |
| 283 | } |
384 | } |
| 284 | # @FUNCTION: gcc-minor-version |
385 | # @FUNCTION: gcc-minor-version |
| 285 | # @RETURN: minor compiler version (minor: 3.[4].6) |
386 | # @RETURN: minor compiler version (minor: 3.[4].6) |
| 286 | gcc-minor-version() { |
387 | gcc-minor-version() { |
| 287 | gcc-version "$@" | cut -f2 -d. |
388 | _gcc_fullversion '$2' "$@" |
| 288 | } |
389 | } |
| 289 | # @FUNCTION: gcc-micro-version |
390 | # @FUNCTION: gcc-micro-version |
| 290 | # @RETURN: micro compiler version (micro: 3.4.[6]) |
391 | # @RETURN: micro compiler version (micro: 3.4.[6]) |
| 291 | gcc-micro-version() { |
392 | gcc-micro-version() { |
| 292 | gcc-fullversion "$@" | cut -f3 -d. | cut -f1 -d- |
393 | _gcc_fullversion '$3' "$@" |
| 293 | } |
394 | } |
| 294 | |
395 | |
| 295 | # Returns the installation directory - internal toolchain |
396 | # Returns the installation directory - internal toolchain |
| 296 | # function for use by _gcc-specs-exists (for flag-o-matic). |
397 | # function for use by _gcc-specs-exists (for flag-o-matic). |
| 297 | _gcc-install-dir() { |
398 | _gcc-install-dir() { |
| … | |
… | |
| 382 | return $([[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]]) |
483 | return $([[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]]) |
| 383 | } |
484 | } |
| 384 | |
485 | |
| 385 | |
486 | |
| 386 | # @FUNCTION: gen_usr_ldscript |
487 | # @FUNCTION: gen_usr_ldscript |
| 387 | # @USAGE: <list of libs to create linker scripts for> |
488 | # @USAGE: [-a] <list of libs to create linker scripts for> |
| 388 | # @DESCRIPTION: |
489 | # @DESCRIPTION: |
| 389 | # This function generate linker scripts in /usr/lib for dynamic |
490 | # This function generate linker scripts in /usr/lib for dynamic |
| 390 | # 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 |
| 391 | # 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 |
| 392 | # 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 |
| … | |
… | |
| 396 | # |
497 | # |
| 397 | # Note that you should in general use the unversioned name of |
498 | # Note that you should in general use the unversioned name of |
| 398 | # the library (libfoo.so), as ldconfig should usually update it |
499 | # the library (libfoo.so), as ldconfig should usually update it |
| 399 | # correctly to point to the latest version of the library present. |
500 | # correctly to point to the latest version of the library present. |
| 400 | gen_usr_ldscript() { |
501 | gen_usr_ldscript() { |
| 401 | 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 | |
| 402 | # Just make sure it exists |
507 | # Just make sure it exists |
| 403 | dodir /usr/${libdir} |
508 | dodir /usr/${libdir} |
|
|
509 | |
|
|
510 | if [[ $1 == "-a" ]] ; then |
|
|
511 | auto=true |
|
|
512 | shift |
|
|
513 | dodir /${libdir} |
|
|
514 | fi |
| 404 | |
515 | |
| 405 | # 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 |
| 406 | # is referenced ... makes multilib saner |
517 | # is referenced ... makes multilib saner |
| 407 | 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') |
| 408 | [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )" |
519 | [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )" |
| 409 | |
520 | |
| 410 | for lib in "$@" ; do |
521 | for lib in "$@" ; do |
| 411 | if [[ ${USERLAND} == "Darwin" ]] ; then |
522 | local tlib |
| 412 | ewarn "Not creating fake dynamic library for $lib on Darwin;" |
523 | if ${auto} ; then |
| 413 | ewarn "making a symlink instead." |
524 | lib="lib${lib}${suffix}" |
| 414 | dosym "/${libdir}/${lib}" "/usr/${libdir}/${lib}" |
|
|
| 415 | 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 |
| 416 | cat > "${D}/usr/${libdir}/${lib}" <<-END_LDSCRIPT |
645 | cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT |
| 417 | /* GNU ld script |
646 | /* GNU ld script |
| 418 | Since Gentoo has critical dynamic libraries |
647 | Since Gentoo has critical dynamic libraries in /lib, and the static versions |
| 419 | 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 |
| 420 | 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 |
| 421 | 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. |
| 422 | |
652 | |
| 423 | See bug http://bugs.gentoo.org/4411 for more info. |
653 | See bug http://bugs.gentoo.org/4411 for more info. |
| 424 | */ |
654 | */ |
| 425 | ${output_format} |
655 | ${output_format} |
| 426 | GROUP ( /${libdir}/${lib} ) |
656 | GROUP ( ${EPREFIX}/${libdir}/${tlib} ) |
| 427 | END_LDSCRIPT |
657 | END_LDSCRIPT |
| 428 | fi |
658 | ;; |
|
|
659 | esac |
| 429 | 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}" |
| 430 | done |
661 | done |
| 431 | } |
662 | } |