/[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.107 Revision 1.127
1# Copyright 1999-2007 Gentoo Foundation 1# Copyright 1999-2014 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.107 2011/09/12 21:42:08 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.127 2014/07/11 08:21:58 ulm 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
11# for gleaning useful information about the toolchain and to simplify 11# for gleaning useful information about the toolchain and to simplify
12# ugly things like cross-compiling and multilib. All of this is done 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 13# in such a way that you can rely on the function always returning
14# something sane. 14# something sane.
15 15
16___ECLASS_RECUR_TOOLCHAIN_FUNCS="yes" 16if [[ -z ${_TOOLCHAIN_FUNCS_ECLASS} ]]; then
17[[ -z ${___ECLASS_RECUR_MULTILIB} ]] && inherit multilib 17_TOOLCHAIN_FUNCS_ECLASS=1
18 18
19DESCRIPTION="Based on the ${ECLASS} eclass" 19inherit multilib
20 20
21# tc-getPROG <VAR [search vars]> <default> [tuple] 21# tc-getPROG <VAR [search vars]> <default> [tuple]
22_tc-getPROG() { 22_tc-getPROG() {
23 local tuple=$1 23 local tuple=$1
24 local v var vars=$2 24 local v var vars=$2
175# @FUNCTION: tc-is-softfloat 175# @FUNCTION: tc-is-softfloat
176# @DESCRIPTION: 176# @DESCRIPTION:
177# See if this toolchain is a softfloat based one. 177# See if this toolchain is a softfloat based one.
178# @CODE 178# @CODE
179# The possible return values: 179# The possible return values:
180# - only: the target is always softfloat (never had fpu) 180# - only: the target is always softfloat (never had fpu)
181# - yes: the target should support softfloat 181# - yes: the target should support softfloat
182# - softfp: (arm specific) the target should use hardfloat insns, but softfloat calling convention
182# - no: the target doesn't support softfloat 183# - no: the target doesn't support softfloat
183# @CODE 184# @CODE
184# This allows us to react differently where packages accept 185# This allows us to react differently where packages accept
185# softfloat flags in the case where support is optional, but 186# softfloat flags in the case where support is optional, but
186# rejects softfloat flags where the target always lacks an fpu. 187# rejects softfloat flags where the target always lacks an fpu.
187tc-is-softfloat() { 188tc-is-softfloat() {
189 local CTARGET=${CTARGET:-${CHOST}}
188 case ${CTARGET} in 190 case ${CTARGET} in
189 bfin*|h8300*) 191 bfin*|h8300*)
190 echo "only" ;; 192 echo "only" ;;
191 *) 193 *)
192 [[ ${CTARGET//_/-} == *-softfloat-* ]] \ 194 if [[ ${CTARGET//_/-} == *-softfloat-* ]] ; then
193 && echo "yes" \ 195 echo "yes"
196 elif [[ ${CTARGET//_/-} == *-softfp-* ]] ; then
197 echo "softfp"
198 else
194 || echo "no" 199 echo "no"
200 fi
195 ;; 201 ;;
196 esac 202 esac
197}
198
199# @FUNCTION: tc-is-hardfloat
200# @DESCRIPTION:
201# See if this toolchain is a hardfloat based one.
202# @CODE
203# The possible return values:
204# - yes: the target should support hardfloat
205# - no: the target doesn't support hardfloat
206tc-is-hardfloat() {
207 [[ ${CTARGET//_/-} == *-hardfloat-* ]] \
208 && echo "yes" \
209 || echo "no"
210} 203}
211 204
212# @FUNCTION: tc-is-static-only 205# @FUNCTION: tc-is-static-only
213# @DESCRIPTION: 206# @DESCRIPTION:
214# Return shell true if the target does not support shared libs, shell false 207# Return shell true if the target does not support shared libs, shell false
216tc-is-static-only() { 209tc-is-static-only() {
217 local host=${CTARGET:-${CHOST}} 210 local host=${CTARGET:-${CHOST}}
218 211
219 # *MiNT doesn't have shared libraries, only platform so far 212 # *MiNT doesn't have shared libraries, only platform so far
220 return $([[ ${host} == *-mint* ]]) 213 return $([[ ${host} == *-mint* ]])
214}
215
216# @FUNCTION: tc-export_build_env
217# @USAGE: [compiler variables]
218# @DESCRIPTION:
219# Export common build related compiler settings.
220tc-export_build_env() {
221 tc-export "$@"
222 : ${BUILD_CFLAGS:=-O1 -pipe}
223 : ${BUILD_CXXFLAGS:=-O1 -pipe}
224 : ${BUILD_CPPFLAGS:=}
225 : ${BUILD_LDFLAGS:=}
226 export BUILD_{C,CXX,CPP,LD}FLAGS
227
228 # Some packages use XXX_FOR_BUILD.
229 local v
230 for v in BUILD_{C,CXX,CPP,LD}FLAGS ; do
231 export ${v#BUILD_}_FOR_BUILD="${!v}"
232 done
233}
234
235# @FUNCTION: tc-env_build
236# @USAGE: <command> [command args]
237# @INTERNAL
238# @DESCRIPTION:
239# Setup the compile environment to the build tools and then execute the
240# specified command. We use tc-getBUILD_XX here so that we work with
241# all of the semi-[non-]standard env vars like $BUILD_CC which often
242# the target build system does not check.
243tc-env_build() {
244 tc-export_build_env
245 CFLAGS=${BUILD_CFLAGS} \
246 CXXFLAGS=${BUILD_CXXFLAGS} \
247 CPPFLAGS=${BUILD_CPPFLAGS} \
248 LDFLAGS=${BUILD_LDFLAGS} \
249 AR=$(tc-getBUILD_AR) \
250 AS=$(tc-getBUILD_AS) \
251 CC=$(tc-getBUILD_CC) \
252 CPP=$(tc-getBUILD_CPP) \
253 CXX=$(tc-getBUILD_CXX) \
254 LD=$(tc-getBUILD_LD) \
255 NM=$(tc-getBUILD_NM) \
256 PKG_CONFIG=$(tc-getBUILD_PKG_CONFIG) \
257 RANLIB=$(tc-getBUILD_RANLIB) \
258 "$@"
259}
260
261# @FUNCTION: econf_build
262# @USAGE: [econf flags]
263# @DESCRIPTION:
264# Sometimes we need to locally build up some tools to run on CBUILD because
265# the package has helper utils which are compiled+executed when compiling.
266# This won't work when cross-compiling as the CHOST is set to a target which
267# we cannot natively execute.
268#
269# For example, the python package will build up a local python binary using
270# a portable build system (configure+make), but then use that binary to run
271# local python scripts to build up other components of the overall python.
272# We cannot rely on the python binary in $PATH as that often times will be
273# a different version, or not even installed in the first place. Instead,
274# we compile the code in a different directory to run on CBUILD, and then
275# use that binary when compiling the main package to run on CHOST.
276#
277# For example, with newer EAPIs, you'd do something like:
278# @CODE
279# src_configure() {
280# ECONF_SOURCE=${S}
281# if tc-is-cross-compiler ; then
282# mkdir "${WORKDIR}"/${CBUILD}
283# pushd "${WORKDIR}"/${CBUILD} >/dev/null
284# econf_build --disable-some-unused-stuff
285# popd >/dev/null
286# fi
287# ... normal build paths ...
288# }
289# src_compile() {
290# if tc-is-cross-compiler ; then
291# pushd "${WORKDIR}"/${CBUILD} >/dev/null
292# emake one-or-two-build-tools
293# ln/mv build-tools to normal build paths in ${S}/
294# popd >/dev/null
295# fi
296# ... normal build paths ...
297# }
298# @CODE
299econf_build() {
300 tc-env_build econf --build=${CBUILD:-${CHOST}} "$@"
221} 301}
222 302
223# @FUNCTION: tc-has-openmp 303# @FUNCTION: tc-has-openmp
224# @USAGE: [toolchain prefix] 304# @USAGE: [toolchain prefix]
225# @DESCRIPTION: 305# @DESCRIPTION:
281 361
282 local type=$1 362 local type=$1
283 local host=$2 363 local host=$2
284 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}} 364 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
285 365
366 local KV=${KV:-${KV_FULL}}
367 [[ ${type} == "kern" ]] && [[ -z ${KV} ]] && \
368 ewarn "QA: Kernel version could not be determined, please inherit kernel-2 or linux-info"
369
286 case ${host} in 370 case ${host} in
371 aarch64*) echo arm64;;
287 alpha*) echo alpha;; 372 alpha*) echo alpha;;
288 arm*) echo arm;; 373 arm*) echo arm;;
289 avr*) ninj avr32 avr;; 374 avr*) ninj avr32 avr;;
290 bfin*) ninj blackfin bfin;; 375 bfin*) ninj blackfin bfin;;
376 c6x) echo c6x;;
291 cris*) echo cris;; 377 cris*) echo cris;;
378 frv) echo frv;;
379 hexagon) echo hexagon;;
292 hppa*) ninj parisc hppa;; 380 hppa*) ninj parisc hppa;;
293 i?86*) 381 i?86*)
294 # Starting with linux-2.6.24, the 'x86_64' and 'i386' 382 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
295 # trees have been unified into 'x86'. 383 # trees have been unified into 'x86'.
296 # FreeBSD still uses i386 384 # FreeBSD still uses i386
300 echo x86 388 echo x86
301 fi 389 fi
302 ;; 390 ;;
303 ia64*) echo ia64;; 391 ia64*) echo ia64;;
304 m68*) echo m68k;; 392 m68*) echo m68k;;
393 metag) echo metag;;
305 mips*) echo mips;; 394 mips*) echo mips;;
306 nios2*) echo nios2;; 395 nios2*) echo nios2;;
307 nios*) echo nios;; 396 nios*) echo nios;;
397 or32) echo openrisc;;
308 powerpc*) 398 powerpc*)
309 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees 399 # Starting with linux-2.6.15, the 'ppc' and 'ppc64' trees
310 # have been unified into simply 'powerpc', but until 2.6.16, 400 # have been unified into simply 'powerpc', but until 2.6.16,
311 # ppc32 is still using ARCH="ppc" as default 401 # ppc32 is still using ARCH="ppc" as default
312 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]] ; then 402 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]] ; then
324 else 414 else
325 echo ppc 415 echo ppc
326 fi 416 fi
327 ;; 417 ;;
328 s390*) echo s390;; 418 s390*) echo s390;;
419 score) echo score;;
329 sh64*) ninj sh64 sh;; 420 sh64*) ninj sh64 sh;;
330 sh*) echo sh;; 421 sh*) echo sh;;
331 sparc64*) ninj sparc64 sparc;; 422 sparc64*) ninj sparc64 sparc;;
332 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \ 423 sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] \
333 && ninj sparc64 sparc \ 424 && ninj sparc64 sparc \
334 || echo sparc 425 || echo sparc
335 ;; 426 ;;
427 tile*) echo tile;;
336 vax*) echo vax;; 428 vax*) echo vax;;
337 x86_64*freebsd*) echo amd64;; 429 x86_64*freebsd*) echo amd64;;
338 x86_64*) 430 x86_64*)
339 # Starting with linux-2.6.24, the 'x86_64' and 'i386' 431 # Starting with linux-2.6.24, the 'x86_64' and 'i386'
340 # trees have been unified into 'x86'. 432 # trees have been unified into 'x86'.
342 echo x86 434 echo x86
343 else 435 else
344 ninj x86_64 amd64 436 ninj x86_64 amd64
345 fi 437 fi
346 ;; 438 ;;
439 xtensa*) echo xtensa;;
347 440
348 # since our usage of tc-arch is largely concerned with 441 # since our usage of tc-arch is largely concerned with
349 # normalizing inputs for testing ${CTARGET}, let's filter 442 # normalizing inputs for testing ${CTARGET}, let's filter
350 # other cross targets (mingw and such) into the unknown. 443 # other cross targets (mingw and such) into the unknown.
351 *) echo unknown;; 444 *) echo unknown;;
368 local host=$1 461 local host=$1
369 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}} 462 [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}
370 host=${host%%-*} 463 host=${host%%-*}
371 464
372 case ${host} in 465 case ${host} in
466 aarch64*be) echo big;;
467 aarch64) echo little;;
373 alpha*) echo big;; 468 alpha*) echo big;;
374 arm*b*) echo big;; 469 arm*b*) echo big;;
375 arm*) echo little;; 470 arm*) echo little;;
376 cris*) echo little;; 471 cris*) echo little;;
377 hppa*) echo big;; 472 hppa*) echo big;;
378 i?86*) echo little;; 473 i?86*) echo little;;
379 ia64*) echo little;; 474 ia64*) echo little;;
380 m68*) echo big;; 475 m68*) echo big;;
381 mips*l*) echo little;; 476 mips*l*) echo little;;
382 mips*) echo big;; 477 mips*) echo big;;
478 powerpc*le) echo little;;
383 powerpc*) echo big;; 479 powerpc*) echo big;;
384 s390*) echo big;; 480 s390*) echo big;;
385 sh*b*) echo big;; 481 sh*b*) echo big;;
386 sh*) echo little;; 482 sh*) echo little;;
387 sparc*) echo big;; 483 sparc*) echo big;;
534 local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname) 630 local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname)
535 [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/ 631 [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/
536 632
537 tc-is-static-only && return 633 tc-is-static-only && return
538 634
635 # Eventually we'd like to get rid of this func completely #417451
636 case ${CTARGET:-${CHOST}} in
637 *-darwin*) ;;
638 *linux*|*-freebsd*|*-openbsd*|*-netbsd*)
639 use prefix && return 0 ;;
640 *) return 0 ;;
641 esac
642
539 # Just make sure it exists 643 # Just make sure it exists
540 dodir /usr/${libdir} 644 dodir /usr/${libdir}
541 645
542 if [[ $1 == "-a" ]] ; then 646 if [[ $1 == "-a" ]] ; then
543 auto=true 647 auto=true
545 dodir /${libdir} 649 dodir /${libdir}
546 fi 650 fi
547 651
548 # OUTPUT_FORMAT gives hints to the linker as to what binary format 652 # OUTPUT_FORMAT gives hints to the linker as to what binary format
549 # is referenced ... makes multilib saner 653 # is referenced ... makes multilib saner
654 local flags=( ${CFLAGS} ${LDFLAGS} -Wl,--verbose )
655 if $(tc-getLD) --version | grep -q 'GNU gold' ; then
656 # If they're using gold, manually invoke the old bfd. #487696
657 local d="${T}/bfd-linker"
658 mkdir -p "${d}"
659 ln -sf $(which ${CHOST}-ld.bfd) "${d}"/ld
660 flags+=( -B"${d}" )
661 fi
550 output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p') 662 output_format=$($(tc-getCC) "${flags[@]}" 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
551 [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )" 663 [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
552 664
553 for lib in "$@" ; do 665 for lib in "$@" ; do
554 local tlib 666 local tlib
555 if ${auto} ; then 667 if ${auto} ; then
600 # understand linker scripts, just create a symlink. 712 # understand linker scripts, just create a symlink.
601 pushd "${ED}/usr/${libdir}" > /dev/null 713 pushd "${ED}/usr/${libdir}" > /dev/null
602 ln -snf "../../${libdir}/${tlib}" "${lib}" 714 ln -snf "../../${libdir}/${tlib}" "${lib}"
603 popd > /dev/null 715 popd > /dev/null
604 ;; 716 ;;
605 *-aix*|*-irix*|*64*-hpux*|*-interix*|*-winnt*)
606 if ${auto} ; then
607 mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die
608 # no way to retrieve soname on these platforms (?)
609 tlib=$(readlink "${ED}"/${libdir}/${lib})
610 tlib=${tlib##*/}
611 if [[ -z ${tlib} ]] ; then
612 # ok, apparently was not a symlink, don't remove it and
613 # just link to it
614 tlib=${lib}
615 else
616 rm -f "${ED}"/${libdir}/${lib}
617 fi
618 else
619 tlib=${lib}
620 fi
621
622 # we don't have GNU binutils on these platforms, so we symlink
623 # instead, which seems to work fine. Keep it relative, otherwise
624 # we break some QA checks in Portage
625 # on interix, the linker scripts would work fine in _most_
626 # situations. if a library links to such a linker script the
627 # absolute path to the correct library is inserted into the binary,
628 # which is wrong, since anybody linking _without_ libtool will miss
629 # some dependencies, since the stupid linker cannot find libraries
630 # hardcoded with absolute paths (as opposed to the loader, which
631 # seems to be able to do this).
632 # this has been seen while building shared-mime-info which needs
633 # libxml2, but links without libtool (and does not add libz to the
634 # command line by itself).
635 pushd "${ED}/usr/${libdir}" > /dev/null
636 ln -snf "../../${libdir}/${tlib}" "${lib}"
637 popd > /dev/null
638 ;;
639 hppa*-hpux*) # PA-RISC 32bit (SOM) only, others (ELF) match *64*-hpux* above.
640 if ${auto} ; then
641 tlib=$(chatr "${ED}"/usr/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}')
642 [[ -z ${tlib} ]] && tlib=${lib}
643 tlib=${tlib##*/} # 'internal name' can have a path component
644 mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die
645 # some SONAMEs are funky: they encode a version before the .so
646 if [[ ${tlib} != ${lib}* ]] ; then
647 mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die
648 fi
649 [[ ${tlib} != ${lib} ]] &&
650 rm -f "${ED}"/${libdir}/${lib}
651 else
652 tlib=$(chatr "${ED}"/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}')
653 [[ -z ${tlib} ]] && tlib=${lib}
654 tlib=${tlib##*/} # 'internal name' can have a path component
655 fi
656 pushd "${ED}"/usr/${libdir} >/dev/null
657 ln -snf "../../${libdir}/${tlib}" "${lib}"
658 # need the internal name in usr/lib too, to be available at runtime
659 # when linked with /path/to/lib.sl (hardcode_direct_absolute=yes)
660 [[ ${tlib} != ${lib} ]] &&
661 ln -snf "../../${libdir}/${tlib}" "${tlib}"
662 popd >/dev/null
663 ;;
664 *) 717 *)
665 if ${auto} ; then 718 if ${auto} ; then
666 tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib}) 719 tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib})
667 [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}" 720 [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}"
668 mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die 721 mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die
690 ;; 743 ;;
691 esac 744 esac
692 fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}" 745 fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}"
693 done 746 done
694} 747}
748
749fi

Legend:
Removed from v.1.107  
changed lines
  Added in v.1.127

  ViewVC Help
Powered by ViewVC 1.1.20