/[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.69 Revision 1.138
1# Copyright 1999-2007 Gentoo Foundation 1# Copyright 1999-2015 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.69 2007/03/27 01:46:50 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.138 2015/05/28 07:51:10 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" 16if [[ -z ${_TOOLCHAIN_FUNCS_ECLASS} ]]; then
11[[ -z ${___ECLASS_RECUR_MULTILIB} ]] && inherit multilib 17_TOOLCHAIN_FUNCS_ECLASS=1
12 18
13DESCRIPTION="Based on the ${ECLASS} eclass" 19inherit multilib
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 "BUILD_$1 $1_FOR_BUILD HOST$1" "${@:2}"; }
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-getOBJDUMP
88# @USAGE: [toolchain prefix]
89# @RETURN: name of the object dumper
90tc-getOBJDUMP() { tc-getPROG OBJDUMP objdump "$@"; }
91# @FUNCTION: tc-getF77
92# @USAGE: [toolchain prefix]
93# @RETURN: name of the Fortran 77 compiler
94tc-getF77() { tc-getPROG F77 gfortran "$@"; }
95# @FUNCTION: tc-getFC
96# @USAGE: [toolchain prefix]
97# @RETURN: name of the Fortran 90 compiler
98tc-getFC() { tc-getPROG FC gfortran "$@"; }
99# @FUNCTION: tc-getGCJ
100# @USAGE: [toolchain prefix]
101# @RETURN: name of the java compiler
102tc-getGCJ() { tc-getPROG GCJ gcj "$@"; }
103# @FUNCTION: tc-getGO
104# @USAGE: [toolchain prefix]
105# @RETURN: name of the Go compiler
106tc-getGO() { tc-getPROG GO gccgo "$@"; }
107# @FUNCTION: tc-getPKG_CONFIG
108# @USAGE: [toolchain prefix]
109# @RETURN: name of the pkg-config tool
110tc-getPKG_CONFIG() { tc-getPROG PKG_CONFIG pkg-config "$@"; }
111# @FUNCTION: tc-getRC
112# @USAGE: [toolchain prefix]
113# @RETURN: name of the Windows resource compiler
114tc-getRC() { tc-getPROG RC windres "$@"; }
115# @FUNCTION: tc-getDLLWRAP
116# @USAGE: [toolchain prefix]
117# @RETURN: name of the Windows dllwrap utility
118tc-getDLLWRAP() { tc-getPROG DLLWRAP dllwrap "$@"; }
119
120# @FUNCTION: tc-getBUILD_AR
121# @USAGE: [toolchain prefix]
122# @RETURN: name of the archiver for building binaries to run on the build machine
123tc-getBUILD_AR() { tc-getBUILD_PROG AR ar "$@"; }
124# @FUNCTION: tc-getBUILD_AS
125# @USAGE: [toolchain prefix]
126# @RETURN: name of the assembler for building binaries to run on the build machine
127tc-getBUILD_AS() { tc-getBUILD_PROG AS as "$@"; }
128# @FUNCTION: tc-getBUILD_CC
129# @USAGE: [toolchain prefix]
130# @RETURN: name of the C compiler for building binaries to run on the build machine
131tc-getBUILD_CC() { tc-getBUILD_PROG CC gcc "$@"; }
132# @FUNCTION: tc-getBUILD_CPP
133# @USAGE: [toolchain prefix]
134# @RETURN: name of the C preprocessor for building binaries to run on the build machine
135tc-getBUILD_CPP() { tc-getBUILD_PROG CPP cpp "$@"; }
136# @FUNCTION: tc-getBUILD_CXX
137# @USAGE: [toolchain prefix]
138# @RETURN: name of the C++ compiler for building binaries to run on the build machine
139tc-getBUILD_CXX() { tc-getBUILD_PROG CXX g++ "$@"; }
140# @FUNCTION: tc-getBUILD_LD
141# @USAGE: [toolchain prefix]
142# @RETURN: name of the linker for building binaries to run on the build machine
143tc-getBUILD_LD() { tc-getBUILD_PROG LD ld "$@"; }
144# @FUNCTION: tc-getBUILD_STRIP
145# @USAGE: [toolchain prefix]
146# @RETURN: name of the strip program for building binaries to run on the build machine
147tc-getBUILD_STRIP() { tc-getBUILD_PROG STRIP strip "$@"; }
148# @FUNCTION: tc-getBUILD_NM
149# @USAGE: [toolchain prefix]
150# @RETURN: name of the symbol/object thingy for building binaries to run on the build machine
151tc-getBUILD_NM() { tc-getBUILD_PROG NM nm "$@"; }
152# @FUNCTION: tc-getBUILD_RANLIB
153# @USAGE: [toolchain prefix]
154# @RETURN: name of the archiver indexer for building binaries to run on the build machine
155tc-getBUILD_RANLIB() { tc-getBUILD_PROG RANLIB ranlib "$@"; }
156# @FUNCTION: tc-getBUILD_OBJCOPY
157# @USAGE: [toolchain prefix]
158# @RETURN: name of the object copier for building binaries to run on the build machine
159tc-getBUILD_OBJCOPY() { tc-getBUILD_PROG OBJCOPY objcopy "$@"; }
160# @FUNCTION: tc-getBUILD_PKG_CONFIG
161# @USAGE: [toolchain prefix]
162# @RETURN: name of the pkg-config tool for building binaries to run on the build machine
163tc-getBUILD_PKG_CONFIG() { tc-getBUILD_PROG PKG_CONFIG pkg-config "$@"; }
164
165# @FUNCTION: tc-export
166# @USAGE: <list of toolchain variables>
167# @DESCRIPTION:
82# Quick way to export a bunch of vars at once 168# Quick way to export a bunch of compiler vars at once.
83tc-export() { 169tc-export() {
84 local var 170 local var
85 for var in "$@" ; do 171 for var in "$@" ; do
172 [[ $(type -t tc-get${var}) != "function" ]] && die "tc-export: invalid export variable '${var}'"
86 eval tc-get${var} > /dev/null 173 eval tc-get${var} > /dev/null
87 done 174 done
88} 175}
89 176
90# A simple way to see if we're using a cross-compiler ... 177# @FUNCTION: tc-is-cross-compiler
178# @RETURN: Shell true if we are using a cross-compiler, shell false otherwise
91tc-is-cross-compiler() { 179tc-is-cross-compiler() {
92 return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]]) 180 [[ ${CBUILD:-${CHOST}} != ${CHOST} ]]
93} 181}
94 182
183# @FUNCTION: tc-is-softfloat
184# @DESCRIPTION:
95# See if this toolchain is a softfloat based one. 185# See if this toolchain is a softfloat based one.
186# @CODE
96# The possible return values: 187# The possible return values:
97# - only: the target is always softfloat (never had fpu) 188# - only: the target is always softfloat (never had fpu)
98# - yes: the target should support softfloat 189# - yes: the target should support softfloat
190# - softfp: (arm specific) the target should use hardfloat insns, but softfloat calling convention
99# - no: the target should support hardfloat 191# - no: the target doesn't support softfloat
192# @CODE
100# This allows us to react differently where packages accept 193# This allows us to react differently where packages accept
101# softfloat flags in the case where support is optional, but 194# softfloat flags in the case where support is optional, but
102# rejects softfloat flags where the target always lacks an fpu. 195# rejects softfloat flags where the target always lacks an fpu.
103tc-is-softfloat() { 196tc-is-softfloat() {
197 local CTARGET=${CTARGET:-${CHOST}}
104 case ${CTARGET} in 198 case ${CTARGET} in
105 bfin*|h8300*) 199 bfin*|h8300*)
106 echo "only" ;; 200 echo "only" ;;
107 *) 201 *)
108 [[ ${CTARGET//_/-} == *-softfloat-* ]] \ 202 if [[ ${CTARGET//_/-} == *-softfloat-* ]] ; then
109 && echo "yes" \ 203 echo "yes"
204 elif [[ ${CTARGET//_/-} == *-softfp-* ]] ; then
205 echo "softfp"
206 else
110 || echo "no" 207 echo "no"
208 fi
111 ;; 209 ;;
112 esac 210 esac
113} 211}
212
213# @FUNCTION: tc-is-static-only
214# @DESCRIPTION:
215# Return shell true if the target does not support shared libs, shell false
216# otherwise.
217tc-is-static-only() {
218 local host=${CTARGET:-${CHOST}}
219
220 # *MiNT doesn't have shared libraries, only platform so far
221 [[ ${host} == *-mint* ]]
222}
223
224# @FUNCTION: tc-export_build_env
225# @USAGE: [compiler variables]
226# @DESCRIPTION:
227# Export common build related compiler settings.
228tc-export_build_env() {
229 tc-export "$@"
230 # Some build envs will initialize vars like:
231 # : ${BUILD_LDFLAGS:-${LDFLAGS}}
232 # So make sure all variables are non-empty. #526734
233 : ${BUILD_CFLAGS:=-O1 -pipe}
234 : ${BUILD_CXXFLAGS:=-O1 -pipe}
235 : ${BUILD_CPPFLAGS:= }
236 : ${BUILD_LDFLAGS:= }
237 export BUILD_{C,CXX,CPP,LD}FLAGS
238
239 # Some packages use XXX_FOR_BUILD.
240 local v
241 for v in BUILD_{C,CXX,CPP,LD}FLAGS ; do
242 export ${v#BUILD_}_FOR_BUILD="${!v}"
243 done
244}
245
246# @FUNCTION: tc-env_build
247# @USAGE: <command> [command args]
248# @INTERNAL
249# @DESCRIPTION:
250# Setup the compile environment to the build tools and then execute the
251# specified command. We use tc-getBUILD_XX here so that we work with
252# all of the semi-[non-]standard env vars like $BUILD_CC which often
253# the target build system does not check.
254tc-env_build() {
255 tc-export_build_env
256 CFLAGS=${BUILD_CFLAGS} \
257 CXXFLAGS=${BUILD_CXXFLAGS} \
258 CPPFLAGS=${BUILD_CPPFLAGS} \
259 LDFLAGS=${BUILD_LDFLAGS} \
260 AR=$(tc-getBUILD_AR) \
261 AS=$(tc-getBUILD_AS) \
262 CC=$(tc-getBUILD_CC) \
263 CPP=$(tc-getBUILD_CPP) \
264 CXX=$(tc-getBUILD_CXX) \
265 LD=$(tc-getBUILD_LD) \
266 NM=$(tc-getBUILD_NM) \
267 PKG_CONFIG=$(tc-getBUILD_PKG_CONFIG) \
268 RANLIB=$(tc-getBUILD_RANLIB) \
269 "$@"
270}
271
272# @FUNCTION: econf_build
273# @USAGE: [econf flags]
274# @DESCRIPTION:
275# Sometimes we need to locally build up some tools to run on CBUILD because
276# the package has helper utils which are compiled+executed when compiling.
277# This won't work when cross-compiling as the CHOST is set to a target which
278# we cannot natively execute.
279#
280# For example, the python package will build up a local python binary using
281# a portable build system (configure+make), but then use that binary to run
282# local python scripts to build up other components of the overall python.
283# We cannot rely on the python binary in $PATH as that often times will be
284# a different version, or not even installed in the first place. Instead,
285# we compile the code in a different directory to run on CBUILD, and then
286# use that binary when compiling the main package to run on CHOST.
287#
288# For example, with newer EAPIs, you'd do something like:
289# @CODE
290# src_configure() {
291# ECONF_SOURCE=${S}
292# if tc-is-cross-compiler ; then
293# mkdir "${WORKDIR}"/${CBUILD}
294# pushd "${WORKDIR}"/${CBUILD} >/dev/null
295# econf_build --disable-some-unused-stuff
296# popd >/dev/null
297# fi
298# ... normal build paths ...
299# }
300# src_compile() {
301# if tc-is-cross-compiler ; then
302# pushd "${WORKDIR}"/${CBUILD} >/dev/null
303# emake one-or-two-build-tools
304# ln/mv build-tools to normal build paths in ${S}/
305# popd >/dev/null
306# fi
307# ... normal build paths ...
308# }
309# @CODE
310econf_build() {
311 local CBUILD=${CBUILD:-${CHOST}}
312 tc-env_build econf --build=${CBUILD} --host=${CBUILD} "$@"
313}
314
315# @FUNCTION: tc-ld-is-gold
316# @USAGE: [toolchain prefix]
317# @DESCRIPTION:
318# Return true if the current linker is set to gold.
319tc-ld-is-gold() {
320 local out
321
322 # First check the linker directly.
323 out=$($(tc-getLD "$@") --version 2>&1)
324 if [[ ${out} == *"GNU gold"* ]] ; then
325 return 0
326 fi
327
328 # Then see if they're selecting gold via compiler flags.
329 # Note: We're assuming they're using LDFLAGS to hold the
330 # options and not CFLAGS/CXXFLAGS.
331 local base="${T}/test-tc-gold"
332 cat <<-EOF > "${base}.c"
333 int main() { return 0; }
334 EOF
335 out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version "${base}.c" -o "${base}" 2>&1)
336 rm -f "${base}"*
337 if [[ ${out} == *"GNU gold"* ]] ; then
338 return 0
339 fi
340
341 # No gold here!
342 return 1
343}
344
345# @FUNCTION: tc-ld-disable-gold
346# @USAGE: [toolchain prefix]
347# @DESCRIPTION:
348# If the gold linker is currently selected, configure the compilation
349# settings so that we use the older bfd linker instead.
350tc-ld-disable-gold() {
351 if ! tc-ld-is-gold "$@" ; then
352 # They aren't using gold, so nothing to do!
353 return
354 fi
355
356 ewarn "Forcing usage of the BFD linker instead of GOLD"
357
358 # Set up LD to point directly to bfd if it's available.
359 # We need to extract the first word in case there are flags appended
360 # to its value (like multilib). #545218
361 local ld=$(tc-getLD "$@")
362 local bfd_ld="${ld%% *}.bfd"
363 local path_ld=$(which "${bfd_ld}" 2>/dev/null)
364 [[ -e ${path_ld} ]] && export LD=${bfd_ld}
365
366 # Set up LDFLAGS to select gold based on the gcc version.
367 local major=$(gcc-major-version "$@")
368 local minor=$(gcc-minor-version "$@")
369 if [[ ${major} -lt 4 ]] || [[ ${major} -eq 4 && ${minor} -lt 8 ]] ; then
370 # <=gcc-4.7 requires some coercion. Only works if bfd exists.
371 if [[ -e ${path_ld} ]] ; then
372 local d="${T}/bfd-linker"
373 mkdir -p "${d}"
374 ln -sf "${path_ld}" "${d}"/ld
375 export LDFLAGS="${LDFLAGS} -B${d}"
376 else
377 die "unable to locate a BFD linker to bypass gold"
378 fi
379 else
380 # gcc-4.8+ supports -fuse-ld directly.
381 export LDFLAGS="${LDFLAGS} -fuse-ld=bfd"
382 fi
383}
384
385# @FUNCTION: tc-has-openmp
386# @USAGE: [toolchain prefix]
387# @DESCRIPTION:
388# See if the toolchain supports OpenMP.
389tc-has-openmp() {
390 local base="${T}/test-tc-openmp"
391 cat <<-EOF > "${base}.c"
392 #include <omp.h>
393 int main() {
394 int nthreads, tid, ret = 0;
395 #pragma omp parallel private(nthreads, tid)
396 {
397 tid = omp_get_thread_num();
398 nthreads = omp_get_num_threads(); ret += tid + nthreads;
399 }
400 return ret;
401 }
402 EOF
403 $(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" >&/dev/null
404 local ret=$?
405 rm -f "${base}"*
406 return ${ret}
407}
408
409# @FUNCTION: tc-has-tls
410# @USAGE: [-s|-c|-l] [toolchain prefix]
411# @DESCRIPTION:
412# See if the toolchain supports thread local storage (TLS). Use -s to test the
413# compiler, -c to also test the assembler, and -l to also test the C library
414# (the default).
415tc-has-tls() {
416 local base="${T}/test-tc-tls"
417 cat <<-EOF > "${base}.c"
418 int foo(int *i) {
419 static __thread int j = 0;
420 return *i ? j : *i;
421 }
422 EOF
423 local flags
424 case $1 in
425 -s) flags="-S";;
426 -c) flags="-c";;
427 -l) ;;
428 -*) die "Usage: tc-has-tls [-c|-l] [toolchain prefix]";;
429 esac
430 : ${flags:=-fPIC -shared -Wl,-z,defs}
431 [[ $1 == -* ]] && shift
432 $(tc-getCC "$@") ${flags} "${base}.c" -o "${base}" >&/dev/null
433 local ret=$?
434 rm -f "${base}"*
435 return ${ret}
436}
437
114 438
115# Parse information from CBUILD/CHOST/CTARGET rather than 439# Parse information from CBUILD/CHOST/CTARGET rather than
116# use external variables from the profile. 440# use external variables from the profile.
117tc-ninja_magic_to_arch() { 441tc-ninja_magic_to_arch() {
118ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; } 442ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; }
119 443
120 local type=$1 444 local type=$1
121 local host=$2 445 local host=$2
122 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}} 446 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
123 447
448 local KV=${KV:-${KV_FULL}}
449 [[ ${type} == "kern" ]] && [[ -z ${KV} ]] && \
450 ewarn "QA: Kernel version could not be determined, please inherit kernel-2 or linux-info"
451
124 case ${host} in 452 case ${host} in
453 aarch64*) echo arm64;;
125 alpha*) echo alpha;; 454 alpha*) echo alpha;;
126 arm*) echo arm;; 455 arm*) echo arm;;
456 avr*) ninj avr32 avr;;
127 bfin*) ninj blackfin bfin;; 457 bfin*) ninj blackfin bfin;;
458 c6x*) echo c6x;;
128 cris*) echo cris;; 459 cris*) echo cris;;
460 frv*) echo frv;;
461 hexagon*) echo hexagon;;
129 hppa*) ninj parisc hppa;; 462 hppa*) ninj parisc hppa;;
130 i?86*) ninj i386 x86;; 463 i?86*)
464 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
465 # trees have been unified into 'x86'.
466 # FreeBSD still uses i386
467 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -lt $(KV_to_int 2.6.24) || ${host} == *freebsd* ]] ; then
468 echo i386
469 else
470 echo x86
471 fi
472 ;;
131 ia64*) echo ia64;; 473 ia64*) echo ia64;;
132 m68*) echo m68k;; 474 m68*) echo m68k;;
475 metag*) echo metag;;
476 microblaze*) echo microblaze;;
133 mips*) echo mips;; 477 mips*) echo mips;;
134 nios2*) echo nios2;; 478 nios2*) echo nios2;;
135 nios*) echo nios;; 479 nios*) echo nios;;
480 or32*) echo openrisc;;
136 powerpc*) 481 powerpc*)
137 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees 482 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees
138 # have been unified into simply 'powerpc', but until 2.6.16, 483 # have been unified into simply 'powerpc', but until 2.6.16,
139 # ppc32 is still using ARCH="ppc" as default 484 # ppc32 is still using ARCH="ppc" as default
140 if [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]] && [[ ${type} == "kern" ]] ; then 485 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]] ; then
141 echo powerpc 486 echo powerpc
142 elif [[ $(KV_to_int ${KV}) -eq $(KV_to_int 2.6.15) ]] && [[ ${type} == "kern" ]] ; then 487 elif [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -eq $(KV_to_int 2.6.15) ]] ; then
143 if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]] ; then 488 if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]] ; then
144 echo powerpc 489 echo powerpc
145 else 490 else
146 echo ppc 491 echo ppc
147 fi 492 fi
148 elif [[ ${host} == powerpc64* ]] ; then 493 elif [[ ${host} == powerpc64* ]] ; then
149 echo ppc64 494 echo ppc64
150 elif [[ ${PROFILE_ARCH} == "ppc64" ]] ; then 495 elif [[ ${PROFILE_ARCH} == "ppc64" ]] ; then
151 ninj ppc64 ppc 496 ninj ppc64 ppc
152 else 497 else
153 echo ppc 498 echo ppc
154 fi 499 fi
155 ;; 500 ;;
501 riscv*) echo riscv;;
156 s390*) echo s390;; 502 s390*) echo s390;;
503 score*) echo score;;
157 sh64*) ninj sh64 sh;; 504 sh64*) ninj sh64 sh;;
158 sh*) echo sh;; 505 sh*) echo sh;;
159 sparc64*) ninj sparc64 sparc;; 506 sparc64*) ninj sparc64 sparc;;
160 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \ 507 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \
161 && ninj sparc64 sparc \ 508 && ninj sparc64 sparc \
162 || echo sparc 509 || echo sparc
163 ;; 510 ;;
511 tile*) echo tile;;
164 vax*) echo vax;; 512 vax*) echo vax;;
165 x86_64*) ninj x86_64 amd64;; 513 x86_64*freebsd*) echo amd64;;
166 *) echo ${ARCH};; 514 x86_64*)
515 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
516 # trees have been unified into 'x86'.
517 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.24) ]] ; then
518 echo x86
519 else
520 ninj x86_64 amd64
521 fi
522 ;;
523 xtensa*) echo xtensa;;
524
525 # since our usage of tc-arch is largely concerned with
526 # normalizing inputs for testing ${CTARGET}, let's filter
527 # other cross targets (mingw and such) into the unknown.
528 *) echo unknown;;
167 esac 529 esac
168} 530}
531# @FUNCTION: tc-arch-kernel
532# @USAGE: [toolchain prefix]
533# @RETURN: name of the kernel arch according to the compiler target
169tc-arch-kernel() { 534tc-arch-kernel() {
170 tc-ninja_magic_to_arch kern $@ 535 tc-ninja_magic_to_arch kern "$@"
171} 536}
537# @FUNCTION: tc-arch
538# @USAGE: [toolchain prefix]
539# @RETURN: name of the portage arch according to the compiler target
172tc-arch() { 540tc-arch() {
173 tc-ninja_magic_to_arch portage $@ 541 tc-ninja_magic_to_arch portage "$@"
174} 542}
175 543
176# Returns the version as by `$CC -dumpversion` 544tc-endian() {
545 local host=$1
546 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
547 host=${host%%-*}
548
549 case ${host} in
550 aarch64*be) echo big;;
551 aarch64) echo little;;
552 alpha*) echo big;;
553 arm*b*) echo big;;
554 arm*) echo little;;
555 cris*) echo little;;
556 hppa*) echo big;;
557 i?86*) echo little;;
558 ia64*) echo little;;
559 m68*) echo big;;
560 mips*l*) echo little;;
561 mips*) echo big;;
562 powerpc*le) echo little;;
563 powerpc*) echo big;;
564 s390*) echo big;;
565 sh*b*) echo big;;
566 sh*) echo little;;
567 sparc*) echo big;;
568 x86_64*) echo little;;
569 *) echo wtf;;
570 esac
571}
572
573# Internal func. The first argument is the version info to expand.
574# Query the preprocessor to improve compatibility across different
575# compilers rather than maintaining a --version flag matrix. #335943
576_gcc_fullversion() {
577 local ver="$1"; shift
578 set -- `$(tc-getCPP "$@") -E -P - <<<"__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__"`
579 eval echo "$ver"
580}
581
582# @FUNCTION: gcc-fullversion
583# @RETURN: compiler version (major.minor.micro: [3.4.6])
177gcc-fullversion() { 584gcc-fullversion() {
178 $(tc-getCC "$@") -dumpversion 585 _gcc_fullversion '$1.$2.$3' "$@"
179} 586}
180# Returns the version, but only the <major>.<minor> 587# @FUNCTION: gcc-version
588# @RETURN: compiler version (major.minor: [3.4].6)
181gcc-version() { 589gcc-version() {
182 gcc-fullversion "$@" | cut -f1,2 -d. 590 _gcc_fullversion '$1.$2' "$@"
183} 591}
184# Returns the Major version 592# @FUNCTION: gcc-major-version
593# @RETURN: major compiler version (major: [3].4.6)
185gcc-major-version() { 594gcc-major-version() {
186 gcc-version "$@" | cut -f1 -d. 595 _gcc_fullversion '$1' "$@"
187} 596}
188# Returns the Minor version 597# @FUNCTION: gcc-minor-version
598# @RETURN: minor compiler version (minor: 3.[4].6)
189gcc-minor-version() { 599gcc-minor-version() {
190 gcc-version "$@" | cut -f2 -d. 600 _gcc_fullversion '$2' "$@"
191} 601}
192# Returns the Micro version 602# @FUNCTION: gcc-micro-version
603# @RETURN: micro compiler version (micro: 3.4.[6])
193gcc-micro-version() { 604gcc-micro-version() {
194 gcc-fullversion "$@" | cut -f3 -d. | cut -f1 -d- 605 _gcc_fullversion '$3' "$@"
195} 606}
607
196# Returns the installation directory - internal toolchain 608# Returns the installation directory - internal toolchain
197# function for use by _gcc-specs-exists (for flag-o-matic). 609# function for use by _gcc-specs-exists (for flag-o-matic).
198_gcc-install-dir() { 610_gcc-install-dir() {
199 echo "$($(tc-getCC) -print-search-dirs 2> /dev/null |\ 611 echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null |\
200 awk '$1=="install:" {print $2}')" 612 awk '$1=="install:" {print $2}')"
201} 613}
202# Returns true if the indicated specs file exists - internal toolchain 614# Returns true if the indicated specs file exists - internal toolchain
203# function for use by flag-o-matic. 615# function for use by flag-o-matic.
204_gcc-specs-exists() { 616_gcc-specs-exists() {
248 660
249# Returns true if gcc sets relro 661# Returns true if gcc sets relro
250gcc-specs-relro() { 662gcc-specs-relro() {
251 local directive 663 local directive
252 directive=$(gcc-specs-directive link_command) 664 directive=$(gcc-specs-directive link_command)
253 return $([[ ${directive/\{!norelro:} != ${directive} ]]) 665 [[ "${directive/\{!norelro:}" != "${directive}" ]]
254} 666}
255# Returns true if gcc sets now 667# Returns true if gcc sets now
256gcc-specs-now() { 668gcc-specs-now() {
257 local directive 669 local directive
258 directive=$(gcc-specs-directive link_command) 670 directive=$(gcc-specs-directive link_command)
259 return $([[ ${directive/\{!nonow:} != ${directive} ]]) 671 [[ "${directive/\{!nonow:}" != "${directive}" ]]
260} 672}
261# Returns true if gcc builds PIEs 673# Returns true if gcc builds PIEs
262gcc-specs-pie() { 674gcc-specs-pie() {
263 local directive 675 local directive
264 directive=$(gcc-specs-directive cc1) 676 directive=$(gcc-specs-directive cc1)
265 return $([[ ${directive/\{!nopie:} != ${directive} ]]) 677 [[ "${directive/\{!nopie:}" != "${directive}" ]]
266} 678}
267# Returns true if gcc builds with the stack protector 679# Returns true if gcc builds with the stack protector
268gcc-specs-ssp() { 680gcc-specs-ssp() {
269 local directive 681 local directive
270 directive=$(gcc-specs-directive cc1) 682 directive=$(gcc-specs-directive cc1)
271 return $([[ ${directive/\{!fno-stack-protector:} != ${directive} ]]) 683 [[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]]
272} 684}
273# Returns true if gcc upgrades fstack-protector to fstack-protector-all 685# Returns true if gcc upgrades fstack-protector to fstack-protector-all
274gcc-specs-ssp-to-all() { 686gcc-specs-ssp-to-all() {
275 local directive 687 local directive
276 directive=$(gcc-specs-directive cc1) 688 directive=$(gcc-specs-directive cc1)
277 return $([[ ${directive/\{!fno-stack-protector-all:} != ${directive} ]]) 689 [[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]]
278} 690}
691# Returns true if gcc builds with fno-strict-overflow
692gcc-specs-nostrict() {
693 local directive
694 directive=$(gcc-specs-directive cc1)
695 [[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]]
696}
697# Returns true if gcc builds with fstack-check
698gcc-specs-stack-check() {
699 local directive
700 directive=$(gcc-specs-directive cc1)
701 [[ "${directive/\{!fno-stack-check:}" != "${directive}" ]]
702}
279 703
280 704
705# @FUNCTION: gen_usr_ldscript
706# @USAGE: [-a] <list of libs to create linker scripts for>
707# @DESCRIPTION:
281# This function generate linker scripts in /usr/lib for dynamic 708# This function generate linker scripts in /usr/lib for dynamic
282# libs in /lib. This is to fix linking problems when you have 709# libs in /lib. This is to fix linking problems when you have
283# the .so in /lib, and the .a in /usr/lib. What happens is that 710# the .so in /lib, and the .a in /usr/lib. What happens is that
284# in some cases when linking dynamic, the .a in /usr/lib is used 711# in some cases when linking dynamic, the .a in /usr/lib is used
285# instead of the .so in /lib due to gcc/libtool tweaking ld's 712# instead of the .so in /lib due to gcc/libtool tweaking ld's
286# library search path. This cause many builds to fail. 713# library search path. This causes many builds to fail.
287# See bug #4411 for more info. 714# See bug #4411 for more info.
288# 715#
289# To use, simply call:
290#
291# gen_usr_ldscript libfoo.so
292#
293# Note that you should in general use the unversioned name of 716# Note that you should in general use the unversioned name of
294# the library, as ldconfig should usually update it correctly 717# the library (libfoo.so), as ldconfig should usually update it
295# to point to the latest version of the library present. 718# correctly to point to the latest version of the library present.
296_tc_gen_usr_ldscript() { 719gen_usr_ldscript() {
297 local lib libdir=$(get_libdir) output_format="" 720 local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname)
721 [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/
722
723 tc-is-static-only && return
724
725 # Eventually we'd like to get rid of this func completely #417451
726 case ${CTARGET:-${CHOST}} in
727 *-darwin*) ;;
728 *linux*|*-freebsd*|*-openbsd*|*-netbsd*)
729 use prefix && return 0 ;;
730 *) return 0 ;;
731 esac
732
298 # Just make sure it exists 733 # Just make sure it exists
299 dodir /usr/${libdir} 734 dodir /usr/${libdir}
300 735
736 if [[ $1 == "-a" ]] ; then
737 auto=true
738 shift
739 dodir /${libdir}
740 fi
741
301 # OUTPUT_FORMAT gives hints to the linker as to what binary format 742 # OUTPUT_FORMAT gives hints to the linker as to what binary format
302 # is referenced ... makes multilib saner 743 # is referenced ... makes multilib saner
744 local flags=( ${CFLAGS} ${LDFLAGS} -Wl,--verbose )
745 if $(tc-getLD) --version | grep -q 'GNU gold' ; then
746 # If they're using gold, manually invoke the old bfd. #487696
747 local d="${T}/bfd-linker"
748 mkdir -p "${d}"
749 ln -sf $(which ${CHOST}-ld.bfd) "${d}"/ld
750 flags+=( -B"${d}" )
751 fi
303 output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p') 752 output_format=$($(tc-getCC) "${flags[@]}" 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
304 [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )" 753 [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
305 754
306 for lib in "$@" ; do 755 for lib in "$@" ; do
307 if [[ ${USERLAND} == "Darwin" ]] ; then 756 local tlib
308 ewarn "Not creating fake dynamic library for $lib on Darwin;" 757 if ${auto} ; then
309 ewarn "making a symlink instead." 758 lib="lib${lib}${suffix}"
310 dosym "/${libdir}/${lib}" "/usr/${libdir}/${lib}"
311 else 759 else
760 # Ensure /lib/${lib} exists to avoid dangling scripts/symlinks.
761 # This especially is for AIX where $(get_libname) can return ".a",
762 # so /lib/${lib} might be moved to /usr/lib/${lib} (by accident).
763 [[ -r ${ED}/${libdir}/${lib} ]] || continue
764 #TODO: better die here?
765 fi
766
767 case ${CTARGET:-${CHOST}} in
768 *-darwin*)
769 if ${auto} ; then
770 tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib})
771 else
772 tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib})
773 fi
774 [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}"
775 tlib=${tlib##*/}
776
777 if ${auto} ; then
778 mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die
779 # some install_names are funky: they encode a version
780 if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]] ; then
781 mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die
782 fi
783 rm -f "${ED}"/${libdir}/${lib}
784 fi
785
786 # Mach-O files have an id, which is like a soname, it tells how
787 # another object linking against this lib should reference it.
788 # Since we moved the lib from usr/lib into lib this reference is
789 # wrong. Hence, we update it here. We don't configure with
790 # libdir=/lib because that messes up libtool files.
791 # Make sure we don't lose the specific version, so just modify the
792 # existing install_name
793 if [[ ! -w "${ED}/${libdir}/${tlib}" ]] ; then
794 chmod u+w "${ED}${libdir}/${tlib}" # needed to write to it
795 local nowrite=yes
796 fi
797 install_name_tool \
798 -id "${EPREFIX}"/${libdir}/${tlib} \
799 "${ED}"/${libdir}/${tlib} || die "install_name_tool failed"
800 [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}"
801 # Now as we don't use GNU binutils and our linker doesn't
802 # understand linker scripts, just create a symlink.
803 pushd "${ED}/usr/${libdir}" > /dev/null
804 ln -snf "../../${libdir}/${tlib}" "${lib}"
805 popd > /dev/null
806 ;;
807 *)
808 if ${auto} ; then
809 tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib})
810 [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}"
811 mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die
812 # some SONAMEs are funky: they encode a version before the .so
813 if [[ ${tlib} != ${lib}* ]] ; then
814 mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die
815 fi
816 rm -f "${ED}"/${libdir}/${lib}
817 else
818 tlib=${lib}
819 fi
312 cat > "${D}/usr/${libdir}/${lib}" <<-END_LDSCRIPT 820 cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
313 /* GNU ld script 821 /* GNU ld script
314 Since Gentoo has critical dynamic libraries 822 Since Gentoo has critical dynamic libraries in /lib, and the static versions
315 in /lib, and the static versions in /usr/lib, 823 in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
316 we need to have a "fake" dynamic lib in /usr/lib, 824 run into linking problems. This "fake" dynamic lib is a linker script that
317 otherwise we run into linking problems. 825 redirects the linker to the real lib. And yes, this works in the cross-
826 compiling scenario as the sysroot-ed linker will prepend the real path.
318 827
319 See bug http://bugs.gentoo.org/4411 for more info. 828 See bug http://bugs.gentoo.org/4411 for more info.
320 */ 829 */
321 ${output_format} 830 ${output_format}
322 GROUP ( /${libdir}/${lib} ) 831 GROUP ( ${EPREFIX}/${libdir}/${tlib} )
323 END_LDSCRIPT 832 END_LDSCRIPT
324 fi 833 ;;
834 esac
325 fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}" 835 fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}"
326 done 836 done
327} 837}
328gen_usr_ldscript() { _tc_gen_usr_ldscript "$@" ; } 838
839fi

Legend:
Removed from v.1.69  
changed lines
  Added in v.1.138

  ViewVC Help
Powered by ViewVC 1.1.20