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

Contents of /eclass/toolchain-binutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.133 - (show annotations) (download)
Sat Jun 7 05:08:19 2014 UTC (3 months, 1 week ago) by vapier
Branch: MAIN
Changes since 1.132: +4 -1 lines
start setting --with-pkgversion details in our builds so --version output looks good

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

  ViewVC Help
Powered by ViewVC 1.1.20