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

Contents of /eclass/toolchain-binutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.121 - (show annotations) (download)
Mon Nov 26 18:06:55 2012 UTC (2 years, 2 months ago) by vapier
Branch: MAIN
Changes since 1.120: +1 -2 lines
drop SYMLINK_LIB patch since upstream has added a similar change to mainline

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.120 2012/10/24 03:24:45 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 use multitarget && myconf+=( --enable-targets=all --enable-64-bit-bfd )
257 [[ -n ${CBUILD} ]] && myconf+=( --build=${CBUILD} )
258 is_cross && myconf+=( --with-sysroot=/usr/${CTARGET} )
259
260 # glibc-2.3.6 lacks support for this ... so rather than force glibc-2.5+
261 # on everyone in alpha (for now), we'll just enable it when possible
262 has_version ">=${CATEGORY}/glibc-2.5" && myconf+=( --enable-secureplt )
263 has_version ">=sys-libs/glibc-2.5" && myconf+=( --enable-secureplt )
264
265 myconf+=(
266 --prefix=/usr
267 --host=${CHOST}
268 --target=${CTARGET}
269 --datadir=${DATAPATH}
270 --infodir=${DATAPATH}/info
271 --mandir=${DATAPATH}/man
272 --bindir=${BINPATH}
273 --libdir=${LIBPATH}
274 --libexecdir=${LIBPATH}
275 --includedir=${INCPATH}
276 --enable-obsolete
277 --enable-shared
278 --enable-threads
279 --disable-werror
280 --with-bugurl=http://bugs.gentoo.org/
281 $(use_enable static-libs static)
282 ${EXTRA_ECONF}
283 )
284 echo ./configure "${myconf[@]}"
285 "${S}"/configure "${myconf[@]}" || die
286
287 emake all || die "emake failed"
288
289 # only build info pages if we user wants them, and if
290 # we have makeinfo (may not exist when we bootstrap)
291 if type -p makeinfo > /dev/null ; then
292 emake info || die "make info failed"
293 fi
294 # we nuke the manpages when we're left with junk
295 # (like when we bootstrap, no perl -> no manpages)
296 find . -name '*.1' -a -size 0 | xargs rm -f
297
298 # elf2flt only works on some arches / targets
299 if [[ -n ${ELF2FLT_VER} ]] && [[ ${CTARGET} == *linux* || ${CTARGET} == *-elf* ]] ; then
300 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
301
302 local x supported_arches=$(sed -n '/defined(TARGET_/{s:^.*TARGET_::;s:)::;p}' elf2flt.c | sort -u)
303 for x in ${supported_arches} UNSUPPORTED ; do
304 [[ ${CTARGET} == ${x}* ]] && break
305 done
306
307 if [[ ${x} != "UNSUPPORTED" ]] ; then
308 append-flags -I"${S}"/include
309 myconf+=(
310 --with-bfd-include-dir=${MY_BUILDDIR}/bfd
311 --with-libbfd=${MY_BUILDDIR}/bfd/libbfd.a
312 --with-libiberty=${MY_BUILDDIR}/libiberty/libiberty.a
313 --with-binutils-ldscript-dir=${LIBPATH}/ldscripts
314 )
315 echo ./configure "${myconf[@]}"
316 ./configure "${myconf[@]}" || die
317 emake || die "make elf2flt failed"
318 fi
319 fi
320 }
321
322 toolchain-binutils_src_test() {
323 cd "${MY_BUILDDIR}"
324 emake -k check || die "check failed :("
325 }
326
327 toolchain-binutils_src_install() {
328 local x d
329
330 cd "${MY_BUILDDIR}"
331 emake DESTDIR="${D}" tooldir="${LIBPATH}" install || die
332 rm -rf "${D}"/${LIBPATH}/bin
333 use static-libs || find "${D}" -name '*.la' -delete
334
335 # Newer versions of binutils get fancy with ${LIBPATH} #171905
336 cd "${D}"/${LIBPATH}
337 for d in ../* ; do
338 [[ ${d} == ../${BVER} ]] && continue
339 mv ${d}/* . || die
340 rmdir ${d} || die
341 done
342
343 # Now we collect everything intp the proper SLOT-ed dirs
344 # When something is built to cross-compile, it installs into
345 # /usr/$CHOST/ by default ... we have to 'fix' that :)
346 if is_cross ; then
347 cd "${D}"/${BINPATH}
348 for x in * ; do
349 mv ${x} ${x/${CTARGET}-}
350 done
351
352 if [[ -d ${D}/usr/${CHOST}/${CTARGET} ]] ; then
353 mv "${D}"/usr/${CHOST}/${CTARGET}/include "${D}"/${INCPATH}
354 mv "${D}"/usr/${CHOST}/${CTARGET}/lib/* "${D}"/${LIBPATH}/
355 rm -r "${D}"/usr/${CHOST}/{include,lib}
356 fi
357 fi
358 insinto ${INCPATH}
359 local libiberty_headers=(
360 # Not all the libiberty headers. See libiberty/Makefile.in:install_to_libdir.
361 demangle.h
362 dyn-string.h
363 fibheap.h
364 hashtab.h
365 libiberty.h
366 objalloc.h
367 splay-tree.h
368 )
369 doins "${libiberty_headers[@]/#/${S}/include/}" || die
370 if [[ -d ${D}/${LIBPATH}/lib ]] ; then
371 mv "${D}"/${LIBPATH}/lib/* "${D}"/${LIBPATH}/
372 rm -r "${D}"/${LIBPATH}/lib
373 fi
374
375 # Insert elf2flt where appropriate
376 if [[ -x ${WORKDIR}/elf2flt-${ELF2FLT_VER}/elf2flt ]] ; then
377 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
378 insinto ${LIBPATH}/ldscripts
379 doins elf2flt.ld || die "doins elf2flt.ld failed"
380 exeinto ${BINPATH}
381 doexe elf2flt flthdr || die "doexe elf2flt flthdr failed"
382 mv "${D}"/${BINPATH}/{ld,ld.real} || die
383 newexe ld-elf2flt ld || die "doexe ld-elf2flt failed"
384 newdoc README README.elf2flt
385 fi
386
387 # Now, some binutils are tricky and actually provide
388 # for multiple TARGETS. Really, we're talking just
389 # 32bit/64bit support (like mips/ppc/sparc). Here
390 # we want to tell binutils-config that it's cool if
391 # it generates multiple sets of binutil symlinks.
392 # e.g. sparc gets {sparc,sparc64}-unknown-linux-gnu
393 local targ=${CTARGET/-*} src="" dst=""
394 local FAKE_TARGETS=${CTARGET}
395 case ${targ} in
396 mips*) src="mips" dst="mips64";;
397 powerpc*) src="powerpc" dst="powerpc64";;
398 s390*) src="s390" dst="s390x";;
399 sparc*) src="sparc" dst="sparc64";;
400 esac
401 case ${targ} in
402 mips64*|powerpc64*|s390x*|sparc64*) targ=${src} src=${dst} dst=${targ};;
403 esac
404 [[ -n ${src}${dst} ]] && FAKE_TARGETS="${FAKE_TARGETS} ${CTARGET/${src}/${dst}}"
405
406 # Generate an env.d entry for this binutils
407 cd "${S}"
408 insinto /etc/env.d/binutils
409 cat <<-EOF > env.d
410 TARGET="${CTARGET}"
411 VER="${BVER}"
412 LIBPATH="${LIBPATH}"
413 FAKE_TARGETS="${FAKE_TARGETS}"
414 EOF
415 newins env.d ${CTARGET}-${BVER}
416
417 # Handle documentation
418 if ! is_cross ; then
419 cd "${S}"
420 dodoc README
421 docinto bfd
422 dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
423 docinto binutils
424 dodoc binutils/ChangeLog binutils/NEWS binutils/README
425 docinto gas
426 dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
427 docinto gprof
428 dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
429 docinto ld
430 dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
431 docinto libiberty
432 dodoc libiberty/ChangeLog* libiberty/README
433 docinto opcodes
434 dodoc opcodes/ChangeLog*
435 fi
436 # Remove shared info pages
437 rm -f "${D}"/${DATAPATH}/info/{dir,configure.info,standards.info}
438 # Trim all empty dirs
439 find "${D}" -type d | xargs rmdir >& /dev/null
440 }
441
442 toolchain-binutils_pkg_postinst() {
443 # Make sure this ${CTARGET} has a binutils version selected
444 [[ -e ${ROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
445 binutils-config ${CTARGET}-${BVER}
446 }
447
448 toolchain-binutils_pkg_postrm() {
449 local current_profile=$(binutils-config -c ${CTARGET})
450
451 # If no other versions exist, then uninstall for this
452 # target ... otherwise, switch to the newest version
453 # Note: only do this if this version is unmerged. We
454 # rerun binutils-config if this is a remerge, as
455 # we want the mtimes on the symlinks updated (if
456 # it is the same as the current selected profile)
457 if [[ ! -e ${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${BVER} ]] ; then
458 local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}')
459 choice=${choice//$'\n'/ }
460 choice=${choice/* }
461 if [[ -z ${choice} ]] ; then
462 env -i ROOT="${ROOT}" binutils-config -u ${CTARGET}
463 else
464 binutils-config ${choice}
465 fi
466 elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${BVER} ]] ; then
467 binutils-config ${CTARGET}-${BVER}
468 fi
469 }

  ViewVC Help
Powered by ViewVC 1.1.20