/[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.99 Revision 1.105
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.99 2010/04/22 18:28:11 armin76 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
19DESCRIPTION="Based on the ${ECLASS} eclass" 19DESCRIPTION="Based on the ${ECLASS} eclass"
20 20
21# tc-getPROG <VAR [search vars]> <default> [tuple]
21tc-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
42tc-getAR() { tc-getPROG AR ar "$@"; }
43# @FUNCTION: tc-getAS
44# @USAGE: [toolchain prefix]
45# @RETURN: name of the assembler
46tc-getAS() { tc-getPROG AS as "$@"; }
47# @FUNCTION: tc-getCC
48# @USAGE: [toolchain prefix]
49# @RETURN: name of the C compiler
50tc-getCC() { tc-getPROG CC gcc "$@"; }
51# @FUNCTION: tc-getCPP
52# @USAGE: [toolchain prefix]
53# @RETURN: name of the C preprocessor
54tc-getCPP() { tc-getPROG CPP cpp "$@"; }
55# @FUNCTION: tc-getCXX
56# @USAGE: [toolchain prefix]
57# @RETURN: name of the C++ compiler
58tc-getCXX() { tc-getPROG CXX g++ "$@"; }
59# @FUNCTION: tc-getLD
60# @USAGE: [toolchain prefix]
61# @RETURN: name of the linker
62tc-getLD() { tc-getPROG LD ld "$@"; }
63# @FUNCTION: tc-getSTRIP
64# @USAGE: [toolchain prefix]
65# @RETURN: name of the strip program
66tc-getSTRIP() { tc-getPROG STRIP strip "$@"; }
67# @FUNCTION: tc-getNM
68# @USAGE: [toolchain prefix]
69# @RETURN: name of the symbol/object thingy
70tc-getNM() { tc-getPROG NM nm "$@"; }
71# @FUNCTION: tc-getRANLIB
72# @USAGE: [toolchain prefix]
73# @RETURN: name of the archiver indexer
74tc-getRANLIB() { tc-getPROG RANLIB ranlib "$@"; }
75# @FUNCTION: tc-getOBJCOPY
76# @USAGE: [toolchain prefix]
77# @RETURN: name of the object copier
78tc-getOBJCOPY() { tc-getPROG OBJCOPY objcopy "$@"; }
79# @FUNCTION: tc-getF77
80# @USAGE: [toolchain prefix]
81# @RETURN: name of the Fortran 77 compiler
82tc-getF77() { tc-getPROG F77 f77 "$@"; }
83# @FUNCTION: tc-getFC
84# @USAGE: [toolchain prefix]
85# @RETURN: name of the Fortran 90 compiler
86tc-getFC() { tc-getPROG FC gfortran "$@"; }
87# @FUNCTION: tc-getGCJ
88# @USAGE: [toolchain prefix]
89# @RETURN: name of the java compiler
90tc-getGCJ() { tc-getPROG GCJ gcj "$@"; }
91# @FUNCTION: tc-getPKG_CONFIG
92# @USAGE: [toolchain prefix]
93# @RETURN: name of the pkg-config tool
94tc-getPKG_CONFIG() { tc-getPROG PKG_CONFIG pkg-config "$@"; }
95# @FUNCTION: tc-getRC
96# @USAGE: [toolchain prefix]
97# @RETURN: name of the Windows resource compiler
98tc-getRC() { tc-getPROG RC windres "$@"; }
99# @FUNCTION: tc-getDLLWRAP
100# @USAGE: [toolchain prefix]
101# @RETURN: name of the Windows dllwrap utility
102tc-getDLLWRAP() { tc-getPROG DLLWRAP dllwrap "$@"; }
103
104# @FUNCTION: tc-getBUILD_CC
105# @USAGE: [toolchain prefix]
106# @RETURN: name of the C compiler for building binaries to run on the build machine
107tc-getBUILD_CC() {
108 local v
109 for v in CC_FOR_BUILD BUILD_CC HOSTCC ; do
110 if [[ -n ${!v} ]] ; then 29 if [[ -n ${!v} ]] ; then
111 export BUILD_CC=${!v} 30 export ${var}=${!v}
112 echo "${!v}" 31 echo "${!v}"
113 return 0 32 return 0
114 fi 33 fi
115 done 34 done
116 35
117 local search= 36 local search=
118 if [[ -n ${CBUILD} ]] ; then 37 [[ -n $4 ]] && search=$(type -p "$4-${prog}")
119 search=$(type -p ${CBUILD}-gcc) 38 [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p "${!tuple}-${prog}")
120 search=${search##*/} 39 [[ -n ${search} ]] && prog=${search##*/}
121 fi
122 search=${search:-gcc}
123 40
124 export BUILD_CC=${search} 41 export ${var}=${prog}
125 echo "${search}" 42 echo "${!var}"
126} 43}
44tc-getBUILD_PROG() { _tc-getPROG CBUILD "$@"; }
45tc-getPROG() { _tc-getPROG CHOST "$@"; }
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++ "$@"; }
127 124
128# @FUNCTION: tc-export 125# @FUNCTION: tc-export
129# @USAGE: <list of toolchain variables> 126# @USAGE: <list of toolchain variables>
130# @DESCRIPTION: 127# @DESCRIPTION:
131# Quick way to export a bunch of compiler vars at once. 128# Quick way to export a bunch of compiler vars at once.
187tc-is-static-only() { 184tc-is-static-only() {
188 local host=${CTARGET:-${CHOST}} 185 local host=${CTARGET:-${CHOST}}
189 186
190 # *MiNT doesn't have shared libraries, only platform so far 187 # *MiNT doesn't have shared libraries, only platform so far
191 return $([[ ${host} == *-mint* ]]) 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}
192} 213}
193 214
194# @FUNCTION: tc-has-tls 215# @FUNCTION: tc-has-tls
195# @USAGE: [-s|-c|-l] [toolchain prefix] 216# @USAGE: [-s|-c|-l] [toolchain prefix]
196# @DESCRIPTION: 217# @DESCRIPTION:
251 m68*) echo m68k;; 272 m68*) echo m68k;;
252 mips*) echo mips;; 273 mips*) echo mips;;
253 nios2*) echo nios2;; 274 nios2*) echo nios2;;
254 nios*) echo nios;; 275 nios*) echo nios;;
255 powerpc*) 276 powerpc*)
256 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees 277 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees
257 # have been unified into simply 'powerpc', but until 2.6.16, 278 # have been unified into simply 'powerpc', but until 2.6.16,
258 # ppc32 is still using ARCH="ppc" as default 279 # ppc32 is still using ARCH="ppc" as default
259 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
260 echo powerpc 281 echo powerpc
261 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
262 if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]] ; then 283 if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]] ; then
263 echo powerpc 284 echo powerpc
264 else 285 else
265 echo ppc 286 echo ppc
266 fi 287 fi
267 elif [[ ${host} == powerpc64* ]] ; then 288 elif [[ ${host} == powerpc64* ]] ; then
268 echo ppc64 289 echo ppc64
269 elif [[ ${PROFILE_ARCH} == "ppc64" ]] ; then 290 elif [[ ${PROFILE_ARCH} == "ppc64" ]] ; then
270 ninj ppc64 ppc 291 ninj ppc64 ppc
271 else 292 else
272 echo ppc 293 echo ppc
273 fi 294 fi
274 ;; 295 ;;
275 s390*) echo s390;; 296 s390*) echo s390;;
276 sh64*) ninj sh64 sh;; 297 sh64*) ninj sh64 sh;;
277 sh*) echo sh;; 298 sh*) echo sh;;
278 sparc64*) ninj sparc64 sparc;; 299 sparc64*) ninj sparc64 sparc;;
279 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \ 300 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \
280 && ninj sparc64 sparc \ 301 && ninj sparc64 sparc \
281 || echo sparc 302 || echo sparc
282 ;; 303 ;;
283 vax*) echo vax;; 304 vax*) echo vax;;
305 x86_64*freebsd*) echo amd64;;
284 x86_64*) 306 x86_64*)
285 # Starting with linux-2.6.24, the 'x86_64' and 'i386' 307 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
286 # trees have been unified into 'x86'. 308 # trees have been unified into 'x86'.
287 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
288 echo x86 310 echo x86
334 x86_64*) echo little;; 356 x86_64*) echo little;;
335 *) echo wtf;; 357 *) echo wtf;;
336 esac 358 esac
337} 359}
338 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
339# @FUNCTION: gcc-fullversion 370# @FUNCTION: gcc-fullversion
340# @RETURN: compiler version (major.minor.micro: [3.4.6]) 371# @RETURN: compiler version (major.minor.micro: [3.4.6])
341gcc-fullversion() { 372gcc-fullversion() {
342 $(tc-getCC "$@") -dumpversion 373 _gcc_fullversion '$1.$2.$3' "$@"
343} 374}
344# @FUNCTION: gcc-version 375# @FUNCTION: gcc-version
345# @RETURN: compiler version (major.minor: [3.4].6) 376# @RETURN: compiler version (major.minor: [3.4].6)
346gcc-version() { 377gcc-version() {
347 gcc-fullversion "$@" | cut -f1,2 -d. 378 _gcc_fullversion '$1.$2' "$@"
348} 379}
349# @FUNCTION: gcc-major-version 380# @FUNCTION: gcc-major-version
350# @RETURN: major compiler version (major: [3].4.6) 381# @RETURN: major compiler version (major: [3].4.6)
351gcc-major-version() { 382gcc-major-version() {
352 gcc-version "$@" | cut -f1 -d. 383 _gcc_fullversion '$1' "$@"
353} 384}
354# @FUNCTION: gcc-minor-version 385# @FUNCTION: gcc-minor-version
355# @RETURN: minor compiler version (minor: 3.[4].6) 386# @RETURN: minor compiler version (minor: 3.[4].6)
356gcc-minor-version() { 387gcc-minor-version() {
357 gcc-version "$@" | cut -f2 -d. 388 _gcc_fullversion '$2' "$@"
358} 389}
359# @FUNCTION: gcc-micro-version 390# @FUNCTION: gcc-micro-version
360# @RETURN: micro compiler version (micro: 3.4.[6]) 391# @RETURN: micro compiler version (micro: 3.4.[6])
361gcc-micro-version() { 392gcc-micro-version() {
362 gcc-fullversion "$@" | cut -f3 -d. | cut -f1 -d- 393 _gcc_fullversion '$3' "$@"
363} 394}
364 395
365# Returns the installation directory - internal toolchain 396# Returns the installation directory - internal toolchain
366# function for use by _gcc-specs-exists (for flag-o-matic). 397# function for use by _gcc-specs-exists (for flag-o-matic).
367_gcc-install-dir() { 398_gcc-install-dir() {

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

  ViewVC Help
Powered by ViewVC 1.1.20