/[gentoo-x86]/eclass/toolchain-binutils.eclass
Gentoo

Contents of /eclass/toolchain-binutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.142 - (show annotations) (download)
Mon May 25 08:41:16 2015 UTC (3 years, 11 months ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Changes since 1.141: +3 -3 lines
use slightly more readable version of CATEGORY/cross-* checking

1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-binutils.eclass,v 1.141 2015/05/25 08:39:36 vapier Exp $
4 #
5 # Maintainer: Toolchain Ninjas <toolchain@gentoo.org>
6 #
7 # We install binutils into CTARGET-VERSION specific directories. This lets
8 # us easily merge multiple versions for multiple targets (if we wish) and
9 # then switch the versions on the fly (with `binutils-config`).
10 #
11 # binutils-9999 -> live git
12 # binutils-9999_preYYMMDD -> nightly snapshot date YYMMDD
13 # binutils-# -> normal release
14
15 if [[ -n ${BINUTILS_TYPE} ]] ; then
16 BTYPE=${BINUTILS_TYPE}
17 else
18 case ${PV} in
19 9999) BTYPE="git";;
20 9999_pre*) BTYPE="snap";;
21 *.*.90) BTYPE="snap";;
22 *.*.*.*.*) BTYPE="hjlu";;
23 *) BTYPE="rel";;
24 esac
25 fi
26
27 case ${BTYPE} in
28 git)
29 BVER="git"
30 EGIT_REPO_URI="git://sourceware.org/git/binutils-gdb.git"
31 inherit git-2
32 ;;
33 snap)
34 BVER=${PV/9999_pre}
35 ;;
36 *)
37 BVER=${BINUTILS_VER:-${PV}}
38 ;;
39 esac
40
41 inherit eutils libtool flag-o-matic gnuconfig multilib versionator unpacker
42 case ${EAPI:-0} in
43 0|1)
44 EXPORT_FUNCTIONS src_unpack src_compile src_test src_install pkg_postinst pkg_postrm ;;
45 2|3|4|5)
46 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_postinst pkg_postrm ;;
47 *) die "unsupported EAPI ${EAPI}" ;;
48 esac
49
50 export CTARGET=${CTARGET:-${CHOST}}
51 if [[ ${CTARGET} == ${CHOST} ]] ; then
52 if [[ ${CATEGORY} == cross-* ]] ; then
53 export CTARGET=${CATEGORY#cross-}
54 fi
55 fi
56 is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
57
58 DESCRIPTION="Tools necessary to build programs"
59 HOMEPAGE="http://sourceware.org/binutils/"
60
61 case ${BTYPE} in
62 git) SRC_URI="" ;;
63 snap)
64 SRC_URI="ftp://gcc.gnu.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2
65 ftp://sourceware.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2" ;;
66 hjlu)
67 SRC_URI="mirror://kernel/linux/devel/binutils/binutils-${BVER}.tar."
68 version_is_at_least 2.21.51.0.5 && SRC_URI+="xz" || SRC_URI+="bz2" ;;
69 rel) SRC_URI="mirror://gnu/binutils/binutils-${BVER}.tar.bz2" ;;
70 esac
71 add_src_uri() {
72 [[ -z $2 ]] && return
73 local a=$1
74 if version_is_at_least 2.22.52.0.2 ; then
75 a+=".xz"
76 else
77 a+=".bz2"
78 fi
79 set -- mirror://gentoo http://dev.gentoo.org/~vapier/dist
80 SRC_URI="${SRC_URI} ${@/%//${a}}"
81 }
82 add_src_uri binutils-${BVER}-patches-${PATCHVER}.tar ${PATCHVER}
83 add_src_uri binutils-${BVER}-uclibc-patches-${UCLIBC_PATCHVER}.tar ${UCLIBC_PATCHVER}
84 add_src_uri elf2flt-${ELF2FLT_VER}.tar ${ELF2FLT_VER}
85
86 if version_is_at_least 2.18 ; then
87 LICENSE="|| ( GPL-3 LGPL-3 )"
88 else
89 LICENSE="|| ( GPL-2 LGPL-2 )"
90 fi
91 IUSE="cxx multislot multitarget nls static-libs test vanilla"
92 if version_is_at_least 2.19 ; then
93 IUSE+=" zlib"
94 fi
95 if ! version_is_at_least 2.23.90 || [[ ${BTYPE} != "rel" ]] || is_cross || use multislot ; then
96 SLOT="${BVER}"
97 else
98 SLOT="0"
99 fi
100
101 RDEPEND=">=sys-devel/binutils-config-3"
102 in_iuse zlib && RDEPEND+=" zlib? ( sys-libs/zlib )"
103 DEPEND="${RDEPEND}
104 test? ( dev-util/dejagnu )
105 nls? ( sys-devel/gettext )
106 sys-devel/flex
107 virtual/yacc"
108
109 S=${WORKDIR}/binutils
110 case ${BVER} in
111 git) ;;
112 *) S=${S}-${BVER} ;;
113 esac
114
115 LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${BVER}
116 INCPATH=${LIBPATH}/include
117 DATAPATH=/usr/share/binutils-data/${CTARGET}/${BVER}
118 MY_BUILDDIR=${WORKDIR}/build
119 if is_cross ; then
120 BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${BVER}
121 else
122 BINPATH=/usr/${CTARGET}/binutils-bin/${BVER}
123 fi
124
125 tc-binutils_unpack() {
126 case ${BTYPE} in
127 git) git-2_src_unpack ;;
128 *) unpacker ${A} ;;
129 esac
130 mkdir -p "${MY_BUILDDIR}"
131 [[ -d ${WORKDIR}/patch ]] && mkdir "${WORKDIR}"/patch/skip
132 }
133
134 # In case the ebuild wants to add a few of their own.
135 PATCHES=()
136
137 tc-binutils_apply_patches() {
138 cd "${S}"
139
140 if ! use vanilla ; then
141 if [[ -n ${PATCHVER} ]] ; then
142 EPATCH_SOURCE=${WORKDIR}/patch
143 if [[ ${CTARGET} == mips* ]] ; then
144 # remove gnu-hash for mips (bug #233233)
145 EPATCH_EXCLUDE+=" 77_all_generate-gnu-hash.patch"
146 fi
147 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
148 && EPATCH_SUFFIX="patch.bz2" \
149 || EPATCH_SUFFIX="patch"
150 epatch
151 fi
152 if [[ -n ${UCLIBC_PATCHVER} ]] ; then
153 EPATCH_SOURCE=${WORKDIR}/uclibc-patches
154 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
155 && EPATCH_SUFFIX="patch.bz2" \
156 || EPATCH_SUFFIX="patch"
157 EPATCH_MULTI_MSG="Applying uClibc fixes ..." \
158 epatch
159 elif [[ ${CTARGET} == *-uclibc* ]] ; then
160 # starting with binutils-2.17.50.0.17, we no longer need
161 # uClibc patchsets :D
162 if grep -qs 'linux-gnu' "${S}"/ltconfig ; then
163 die "sorry, but this binutils doesn't yet support uClibc :("
164 fi
165 fi
166 [[ ${#PATCHES[@]} -gt 0 ]] && epatch "${PATCHES[@]}"
167 epatch_user
168 fi
169
170 # fix locale issues if possible #122216
171 if [[ -e ${FILESDIR}/binutils-configure-LANG.patch ]] ; then
172 einfo "Fixing misc issues in configure files"
173 for f in $(find "${S}" -name configure -exec grep -l 'autoconf version 2.13' {} +) ; do
174 ebegin " Updating ${f/${S}\/}"
175 patch "${f}" "${FILESDIR}"/binutils-configure-LANG.patch >& "${T}"/configure-patch.log \
176 || eerror "Please file a bug about this"
177 eend $?
178 done
179 fi
180 # fix conflicts with newer glibc #272594
181 if [[ -e libiberty/testsuite/test-demangle.c ]] ; then
182 sed -i 's:\<getline\>:get_line:g' libiberty/testsuite/test-demangle.c
183 fi
184
185 # Fix po Makefile generators
186 sed -i \
187 -e '/^datadir = /s:$(prefix)/@DATADIRNAME@:@datadir@:' \
188 -e '/^gnulocaledir = /s:$(prefix)/share:$(datadir):' \
189 */po/Make-in || die "sed po's failed"
190
191 # Run misc portage update scripts
192 gnuconfig_update
193 elibtoolize --portage --no-uclibc
194 }
195
196 toolchain-binutils_src_unpack() {
197 tc-binutils_unpack
198 case ${EAPI:-0} in
199 0|1) toolchain-binutils_src_prepare ;;
200 esac
201 }
202
203 toolchain-binutils_src_prepare() {
204 tc-binutils_apply_patches
205 }
206
207 _eprefix_init() {
208 has "${EAPI:-0}" 0 1 2 && ED=${D} EPREFIX= EROOT=${ROOT}
209 }
210
211 # Intended for ebuilds to override to set their own versioning information.
212 toolchain-binutils_bugurl() {
213 printf "http://bugs.gentoo.org/"
214 }
215 toolchain-binutils_pkgversion() {
216 printf "Gentoo ${BVER}"
217 [[ -n ${PATCHVER} ]] && printf " p${PATCHVER}"
218 }
219
220 toolchain-binutils_src_configure() {
221 _eprefix_init
222
223 # make sure we filter $LINGUAS so that only ones that
224 # actually work make it through #42033
225 strip-linguas -u */po
226
227 # keep things sane
228 strip-flags
229
230 local x
231 echo
232 for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
233 einfo "$(printf '%10s' ${x}:) ${!x}"
234 done
235 echo
236
237 cd "${MY_BUILDDIR}"
238 local myconf=()
239
240 # enable gold if available (installed as ld.gold)
241 if use cxx ; then
242 if grep -q 'enable-gold=default' "${S}"/configure ; then
243 myconf+=( --enable-gold )
244 # old ways - remove when 2.21 is stable
245 elif grep -q 'enable-gold=both/ld' "${S}"/configure ; then
246 myconf+=( --enable-gold=both/ld )
247 elif grep -q 'enable-gold=both/bfd' "${S}"/configure ; then
248 myconf+=( --enable-gold=both/bfd )
249 fi
250 if grep -q -e '--enable-plugins' "${S}"/ld/configure ; then
251 myconf+=( --enable-plugins )
252 fi
253 fi
254
255 use nls \
256 && myconf+=( --without-included-gettext ) \
257 || myconf+=( --disable-nls )
258
259 if in_iuse zlib ; then
260 # older versions did not have an explicit configure flag
261 export ac_cv_search_zlibVersion=$(usex zlib -lz no)
262 myconf+=( $(use_with zlib) )
263 fi
264
265 # For bi-arch systems, enable a 64bit bfd. This matches
266 # the bi-arch logic in toolchain.eclass. #446946
267 # We used to do it for everyone, but it's slow on 32bit arches. #438522
268 case $(tc-arch) in
269 ppc|sparc|x86) myconf+=( --enable-64-bit-bfd ) ;;
270 esac
271
272 use multitarget && myconf+=( --enable-targets=all --enable-64-bit-bfd )
273 [[ -n ${CBUILD} ]] && myconf+=( --build=${CBUILD} )
274 is_cross && myconf+=(
275 --with-sysroot="${EPREFIX}"/usr/${CTARGET}
276 --enable-poison-system-directories
277 )
278
279 # glibc-2.3.6 lacks support for this ... so rather than force glibc-2.5+
280 # on everyone in alpha (for now), we'll just enable it when possible
281 has_version ">=${CATEGORY}/glibc-2.5" && myconf+=( --enable-secureplt )
282 has_version ">=sys-libs/glibc-2.5" && myconf+=( --enable-secureplt )
283
284 myconf+=(
285 --prefix="${EPREFIX}"/usr
286 --host=${CHOST}
287 --target=${CTARGET}
288 --datadir="${EPREFIX}"${DATAPATH}
289 --infodir="${EPREFIX}"${DATAPATH}/info
290 --mandir="${EPREFIX}"${DATAPATH}/man
291 --bindir="${EPREFIX}"${BINPATH}
292 --libdir="${EPREFIX}"${LIBPATH}
293 --libexecdir="${EPREFIX}"${LIBPATH}
294 --includedir="${EPREFIX}"${INCPATH}
295 --enable-obsolete
296 --enable-shared
297 --enable-threads
298 # Newer versions (>=2.24) make this an explicit option. #497268
299 --enable-install-libiberty
300 --disable-werror
301 --with-bugurl="$(toolchain-binutils_bugurl)"
302 --with-pkgversion="$(toolchain-binutils_pkgversion)"
303 $(use_enable static-libs static)
304 ${EXTRA_ECONF}
305 # Disable modules that are in a combined binutils/gdb tree. #490566
306 --disable-{gdb,libdecnumber,readline,sim}
307 # Strip out broken static link flags.
308 # https://gcc.gnu.org/PR56750
309 --without-stage1-ldflags
310 )
311 echo ./configure "${myconf[@]}"
312 "${S}"/configure "${myconf[@]}" || die
313
314 # Prevent makeinfo from running in releases. It may not always be
315 # installed, and older binutils may fail with newer texinfo.
316 # Besides, we never patch the doc files anyways, so regenerating
317 # in the first place is useless. #193364
318 # For older versions, it means we don't get any info pages at all.
319 # Oh well, tough luck. #294617
320 if [[ -e ${S}/gas/doc/as.info ]] || ! version_is_at_least 2.24 ; then
321 sed -i \
322 -e '/^MAKEINFO/s:=.*:= true:' \
323 Makefile || die
324 fi
325 }
326
327 toolchain-binutils_src_compile() {
328 _eprefix_init
329 case ${EAPI:-0} in
330 0|1) toolchain-binutils_src_configure ;;
331 esac
332
333 cd "${MY_BUILDDIR}"
334 emake all || die "emake failed"
335
336 # only build info pages if we user wants them, and if
337 # we have makeinfo (may not exist when we bootstrap)
338 if type -p makeinfo > /dev/null ; then
339 emake info || die "make info failed"
340 fi
341 # we nuke the manpages when we're left with junk
342 # (like when we bootstrap, no perl -> no manpages)
343 find . -name '*.1' -a -size 0 -delete
344
345 # elf2flt only works on some arches / targets
346 if [[ -n ${ELF2FLT_VER} ]] && [[ ${CTARGET} == *linux* || ${CTARGET} == *-elf* ]] ; then
347 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
348
349 local x supported_arches=$(sed -n '/defined(TARGET_/{s:^.*TARGET_::;s:)::;p}' elf2flt.c | sort -u)
350 for x in ${supported_arches} UNSUPPORTED ; do
351 [[ ${CTARGET} == ${x}* ]] && break
352 done
353
354 if [[ ${x} != "UNSUPPORTED" ]] ; then
355 append-flags -I"${S}"/include
356 myconf+=(
357 --with-bfd-include-dir=${MY_BUILDDIR}/bfd
358 --with-libbfd=${MY_BUILDDIR}/bfd/libbfd.a
359 --with-libiberty=${MY_BUILDDIR}/libiberty/libiberty.a
360 --with-binutils-ldscript-dir="${EPREFIX}"${LIBPATH}/ldscripts
361 )
362 echo ./configure "${myconf[@]}"
363 ./configure "${myconf[@]}" || die
364 emake || die "make elf2flt failed"
365 fi
366 fi
367 }
368
369 toolchain-binutils_src_test() {
370 cd "${MY_BUILDDIR}"
371 emake -k check || die "check failed :("
372 }
373
374 toolchain-binutils_src_install() {
375 _eprefix_init
376 local x d
377
378 cd "${MY_BUILDDIR}"
379 emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install || die
380 rm -rf "${ED}"/${LIBPATH}/bin
381 use static-libs || find "${ED}" -name '*.la' -delete
382
383 # Newer versions of binutils get fancy with ${LIBPATH} #171905
384 cd "${ED}"/${LIBPATH}
385 for d in ../* ; do
386 [[ ${d} == ../${BVER} ]] && continue
387 mv ${d}/* . || die
388 rmdir ${d} || die
389 done
390
391 # Now we collect everything intp the proper SLOT-ed dirs
392 # When something is built to cross-compile, it installs into
393 # /usr/$CHOST/ by default ... we have to 'fix' that :)
394 if is_cross ; then
395 cd "${ED}"/${BINPATH}
396 for x in * ; do
397 mv ${x} ${x/${CTARGET}-}
398 done
399
400 if [[ -d ${ED}/usr/${CHOST}/${CTARGET} ]] ; then
401 mv "${ED}"/usr/${CHOST}/${CTARGET}/include "${ED}"/${INCPATH}
402 mv "${ED}"/usr/${CHOST}/${CTARGET}/lib/* "${ED}"/${LIBPATH}/
403 rm -r "${ED}"/usr/${CHOST}/{include,lib}
404 fi
405 fi
406 insinto ${INCPATH}
407 local libiberty_headers=(
408 # Not all the libiberty headers. See libiberty/Makefile.in:install_to_libdir.
409 demangle.h
410 dyn-string.h
411 fibheap.h
412 hashtab.h
413 libiberty.h
414 objalloc.h
415 splay-tree.h
416 )
417 doins "${libiberty_headers[@]/#/${S}/include/}" || die
418 if [[ -d ${ED}/${LIBPATH}/lib ]] ; then
419 mv "${ED}"/${LIBPATH}/lib/* "${ED}"/${LIBPATH}/
420 rm -r "${ED}"/${LIBPATH}/lib
421 fi
422
423 # Insert elf2flt where appropriate
424 if [[ -x ${WORKDIR}/elf2flt-${ELF2FLT_VER}/elf2flt ]] ; then
425 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
426 insinto ${LIBPATH}/ldscripts
427 doins elf2flt.ld || die "doins elf2flt.ld failed"
428 exeinto ${BINPATH}
429 doexe elf2flt flthdr || die "doexe elf2flt flthdr failed"
430 mv "${ED}"/${BINPATH}/{ld,ld.real} || die
431 newexe ld-elf2flt ld || die "doexe ld-elf2flt failed"
432 newdoc README README.elf2flt
433 fi
434
435 # Generate an env.d entry for this binutils
436 insinto /etc/env.d/binutils
437 cat <<-EOF > "${T}"/env.d
438 TARGET="${CTARGET}"
439 VER="${BVER}"
440 LIBPATH="${EPREFIX}${LIBPATH}"
441 EOF
442 newins "${T}"/env.d ${CTARGET}-${BVER}
443
444 # Handle documentation
445 if ! is_cross ; then
446 cd "${S}"
447 dodoc README
448 docinto bfd
449 dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
450 docinto binutils
451 dodoc binutils/ChangeLog binutils/NEWS binutils/README
452 docinto gas
453 dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
454 docinto gprof
455 dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
456 docinto ld
457 dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
458 docinto libiberty
459 dodoc libiberty/ChangeLog* libiberty/README
460 docinto opcodes
461 dodoc opcodes/ChangeLog*
462 fi
463 # Remove shared info pages
464 rm -f "${ED}"/${DATAPATH}/info/{dir,configure.info,standards.info}
465 # Trim all empty dirs
466 find "${ED}" -depth -type d -exec rmdir {} + 2>/dev/null
467 }
468
469 toolchain-binutils_pkg_postinst() {
470 _eprefix_init
471 # Make sure this ${CTARGET} has a binutils version selected
472 [[ -e ${EROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
473 binutils-config ${CTARGET}-${BVER}
474 }
475
476 toolchain-binutils_pkg_postrm() {
477 _eprefix_init
478 local current_profile=$(binutils-config -c ${CTARGET})
479
480 # If no other versions exist, then uninstall for this
481 # target ... otherwise, switch to the newest version
482 # Note: only do this if this version is unmerged. We
483 # rerun binutils-config if this is a remerge, as
484 # we want the mtimes on the symlinks updated (if
485 # it is the same as the current selected profile)
486 if [[ ! -e ${EPREFIX}${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${BVER} ]] ; then
487 local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}')
488 choice=${choice//$'\n'/ }
489 choice=${choice/* }
490 if [[ -z ${choice} ]] ; then
491 env -i ROOT="${ROOT}" binutils-config -u ${CTARGET}
492 else
493 binutils-config ${choice}
494 fi
495 elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${BVER} ]] ; then
496 binutils-config ${CTARGET}-${BVER}
497 fi
498 }

  ViewVC Help
Powered by ViewVC 1.1.20