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

Contents of /eclass/toolchain-binutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.122 - (show annotations) (download)
Sun Dec 23 23:37:26 2012 UTC (20 months, 3 weeks ago) by vapier
Branch: MAIN
Changes since 1.121: +8 -1 lines
re-enable 64bit bfd for arches which want to do bi-arch #446946

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

  ViewVC Help
Powered by ViewVC 1.1.20