1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # Maintainer: Toolchain Ninjas <toolchain@gentoo.org>
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`).
11 # binutils-9999 -> live git
12 # binutils-9999_preYYMMDD -> nightly snapshot date YYMMDD
13 # binutils-# -> normal release
15 if [[ -n ${BINUTILS_TYPE} ]] ; then
16 BTYPE=${BINUTILS_TYPE}
20 9999_pre*) BTYPE="snap";;
21 *.*.90) BTYPE="snap";;
22 *.*.*.*.*) BTYPE="hjlu";;
30 EGIT_REPO_URI="git://sourceware.org/git/binutils-gdb.git"
37 BVER=${BINUTILS_VER:-${PV}}
41 inherit eutils libtool flag-o-matic gnuconfig multilib versionator unpacker
44 EXPORT_FUNCTIONS src_unpack src_compile src_test src_install pkg_postinst pkg_postrm ;;
46 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_postinst pkg_postrm ;;
47 *) die "unsupported EAPI ${EAPI}" ;;
50 export CTARGET=${CTARGET:-${CHOST}}
51 if [[ ${CTARGET} == ${CHOST} ]] ; then
52 if [[ ${CATEGORY} == cross-* ]] ; then
53 export CTARGET=${CATEGORY#cross-}
56 is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
58 DESCRIPTION="Tools necessary to build programs"
59 HOMEPAGE="https://sourceware.org/binutils/"
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" ;;
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" ;;
74 if version_is_at_least 2.22.52.0.2 ; then
79 set -- mirror://gentoo https://dev.gentoo.org/~vapier/dist
80 SRC_URI="${SRC_URI} ${@/%//${a}}"
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}
86 if version_is_at_least 2.18 ; then
87 LICENSE="|| ( GPL-3 LGPL-3 )"
89 LICENSE="|| ( GPL-2 LGPL-2 )"
91 IUSE="cxx multislot multitarget nls static-libs test vanilla"
92 if version_is_at_least 2.19 ; then
95 if ! version_is_at_least 2.25 || [[ ${BTYPE} != "rel" ]] || is_cross || use multislot ; then
101 RDEPEND=">=sys-devel/binutils-config-3"
102 in_iuse zlib && RDEPEND+=" zlib? ( sys-libs/zlib )"
104 test? ( dev-util/dejagnu )
105 nls? ( sys-devel/gettext )
109 S=${WORKDIR}/binutils
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
120 BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${BVER}
122 BINPATH=/usr/${CTARGET}/binutils-bin/${BVER}
125 tc-binutils_unpack() {
127 git) git-2_src_unpack ;;
130 mkdir -p "${MY_BUILDDIR}"
131 [[ -d ${WORKDIR}/patch ]] && mkdir "${WORKDIR}"/patch/skip
134 # In case the ebuild wants to add a few of their own.
137 tc-binutils_apply_patches() {
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"
147 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
148 && EPATCH_SUFFIX="patch.bz2" \
149 || EPATCH_SUFFIX="patch"
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 ..." \
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 :("
166 [[ ${#PATCHES[@]} -gt 0 ]] && epatch "${PATCHES[@]}"
168 # Make sure our explicit libdir paths don't get clobbered. #562460
170 -e 's:@bfdlibdir@:@libdir@:g' \
171 -e 's:@bfdincludedir@:@includedir@:g' \
172 {bfd,opcodes}/Makefile.in || die
177 # fix locale issues if possible #122216
178 if [[ -e ${FILESDIR}/binutils-configure-LANG.patch ]] ; then
179 einfo "Fixing misc issues in configure files"
180 for f in $(find "${S}" -name configure -exec grep -l 'autoconf version 2.13' {} +) ; do
181 ebegin " Updating ${f/${S}\/}"
182 patch "${f}" "${FILESDIR}"/binutils-configure-LANG.patch >& "${T}"/configure-patch.log \
183 || eerror "Please file a bug about this"
187 # fix conflicts with newer glibc #272594
188 if [[ -e libiberty/testsuite/test-demangle.c ]] ; then
189 sed -i 's:\<getline\>:get_line:g' libiberty/testsuite/test-demangle.c
192 # Fix po Makefile generators
194 -e '/^datadir = /s:$(prefix)/@DATADIRNAME@:@datadir@:' \
195 -e '/^gnulocaledir = /s:$(prefix)/share:$(datadir):' \
196 */po/Make-in || die "sed po's failed"
198 # Run misc portage update scripts
200 elibtoolize --portage --no-uclibc
203 toolchain-binutils_src_unpack() {
206 0|1) toolchain-binutils_src_prepare ;;
210 toolchain-binutils_src_prepare() {
211 tc-binutils_apply_patches
215 has "${EAPI:-0}" 0 1 2 && ED=${D} EPREFIX= EROOT=${ROOT}
218 # Intended for ebuilds to override to set their own versioning information.
219 toolchain-binutils_bugurl() {
220 printf "https://bugs.gentoo.org/"
222 toolchain-binutils_pkgversion() {
223 printf "Gentoo ${BVER}"
224 [[ -n ${PATCHVER} ]] && printf " p${PATCHVER}"
227 toolchain-binutils_src_configure() {
230 # make sure we filter $LINGUAS so that only ones that
231 # actually work make it through #42033
232 strip-linguas -u */po
239 for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
240 einfo "$(printf '%10s' ${x}:) ${!x}"
247 # enable gold if available (installed as ld.gold)
249 if grep -q 'enable-gold=default' "${S}"/configure ; then
250 myconf+=( --enable-gold )
251 # old ways - remove when 2.21 is stable
252 elif grep -q 'enable-gold=both/ld' "${S}"/configure ; then
253 myconf+=( --enable-gold=both/ld )
254 elif grep -q 'enable-gold=both/bfd' "${S}"/configure ; then
255 myconf+=( --enable-gold=both/bfd )
257 if grep -q -e '--enable-plugins' "${S}"/ld/configure ; then
258 myconf+=( --enable-plugins )
263 && myconf+=( --without-included-gettext ) \
264 || myconf+=( --disable-nls )
266 if in_iuse zlib ; then
267 # older versions did not have an explicit configure flag
268 export ac_cv_search_zlibVersion=$(usex zlib -lz no)
269 myconf+=( $(use_with zlib) )
272 # For bi-arch systems, enable a 64bit bfd. This matches
273 # the bi-arch logic in toolchain.eclass. #446946
274 # We used to do it for everyone, but it's slow on 32bit arches. #438522
276 ppc|sparc|x86) myconf+=( --enable-64-bit-bfd ) ;;
279 use multitarget && myconf+=( --enable-targets=all --enable-64-bit-bfd )
280 [[ -n ${CBUILD} ]] && myconf+=( --build=${CBUILD} )
281 is_cross && myconf+=(
282 --with-sysroot="${EPREFIX}"/usr/${CTARGET}
283 --enable-poison-system-directories
286 # glibc-2.3.6 lacks support for this ... so rather than force glibc-2.5+
287 # on everyone in alpha (for now), we'll just enable it when possible
288 has_version ">=${CATEGORY}/glibc-2.5" && myconf+=( --enable-secureplt )
289 has_version ">=sys-libs/glibc-2.5" && myconf+=( --enable-secureplt )
292 --prefix="${EPREFIX}"/usr
295 --datadir="${EPREFIX}"${DATAPATH}
296 --infodir="${EPREFIX}"${DATAPATH}/info
297 --mandir="${EPREFIX}"${DATAPATH}/man
298 --bindir="${EPREFIX}"${BINPATH}
299 --libdir="${EPREFIX}"${LIBPATH}
300 --libexecdir="${EPREFIX}"${LIBPATH}
301 --includedir="${EPREFIX}"${INCPATH}
305 # Newer versions (>=2.24) make this an explicit option. #497268
306 --enable-install-libiberty
308 --with-bugurl="$(toolchain-binutils_bugurl)"
309 --with-pkgversion="$(toolchain-binutils_pkgversion)"
310 $(use_enable static-libs static)
312 # Disable modules that are in a combined binutils/gdb tree. #490566
313 --disable-{gdb,libdecnumber,readline,sim}
314 # Strip out broken static link flags.
315 # https://gcc.gnu.org/PR56750
316 --without-stage1-ldflags
318 echo ./configure "${myconf[@]}"
319 "${S}"/configure "${myconf[@]}" || die
321 # Prevent makeinfo from running in releases. It may not always be
322 # installed, and older binutils may fail with newer texinfo.
323 # Besides, we never patch the doc files anyways, so regenerating
324 # in the first place is useless. #193364
325 # For older versions, it means we don't get any info pages at all.
326 # Oh well, tough luck. #294617
327 if [[ -e ${S}/gas/doc/as.info ]] || ! version_is_at_least 2.24 ; then
329 -e '/^MAKEINFO/s:=.*:= true:' \
334 toolchain-binutils_src_compile() {
337 0|1) toolchain-binutils_src_configure ;;
341 emake all || die "emake failed"
343 # only build info pages if we user wants them, and if
344 # we have makeinfo (may not exist when we bootstrap)
345 if type -p makeinfo > /dev/null ; then
346 emake info || die "make info failed"
348 # we nuke the manpages when we're left with junk
349 # (like when we bootstrap, no perl -> no manpages)
350 find . -name '*.1' -a -size 0 -delete
352 # elf2flt only works on some arches / targets
353 if [[ -n ${ELF2FLT_VER} ]] && [[ ${CTARGET} == *linux* || ${CTARGET} == *-elf* ]] ; then
354 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
356 local x supported_arches=$(sed -n '/defined(TARGET_/{s:^.*TARGET_::;s:)::;p}' elf2flt.c | sort -u)
357 for x in ${supported_arches} UNSUPPORTED ; do
358 [[ ${CTARGET} == ${x}* ]] && break
361 if [[ ${x} != "UNSUPPORTED" ]] ; then
362 append-flags -I"${S}"/include
364 --with-bfd-include-dir=${MY_BUILDDIR}/bfd
365 --with-libbfd=${MY_BUILDDIR}/bfd/libbfd.a
366 --with-libiberty=${MY_BUILDDIR}/libiberty/libiberty.a
367 --with-binutils-ldscript-dir="${EPREFIX}"${LIBPATH}/ldscripts
369 echo ./configure "${myconf[@]}"
370 ./configure "${myconf[@]}" || die
371 emake || die "make elf2flt failed"
376 toolchain-binutils_src_test() {
378 emake -k check || die "check failed :("
381 toolchain-binutils_src_install() {
386 emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install || die
387 rm -rf "${ED}"/${LIBPATH}/bin
388 use static-libs || find "${ED}" -name '*.la' -delete
390 # Newer versions of binutils get fancy with ${LIBPATH} #171905
391 cd "${ED}"/${LIBPATH}
393 [[ ${d} == ../${BVER} ]] && continue
398 # Now we collect everything intp the proper SLOT-ed dirs
399 # When something is built to cross-compile, it installs into
400 # /usr/$CHOST/ by default ... we have to 'fix' that :)
402 cd "${ED}"/${BINPATH}
404 mv ${x} ${x/${CTARGET}-}
407 if [[ -d ${ED}/usr/${CHOST}/${CTARGET} ]] ; then
408 mv "${ED}"/usr/${CHOST}/${CTARGET}/include "${ED}"/${INCPATH}
409 mv "${ED}"/usr/${CHOST}/${CTARGET}/lib/* "${ED}"/${LIBPATH}/
410 rm -r "${ED}"/usr/${CHOST}/{include,lib}
414 local libiberty_headers=(
415 # Not all the libiberty headers. See libiberty/Makefile.in:install_to_libdir.
424 doins "${libiberty_headers[@]/#/${S}/include/}" || die
425 if [[ -d ${ED}/${LIBPATH}/lib ]] ; then
426 mv "${ED}"/${LIBPATH}/lib/* "${ED}"/${LIBPATH}/
427 rm -r "${ED}"/${LIBPATH}/lib
430 # Insert elf2flt where appropriate
431 if [[ -x ${WORKDIR}/elf2flt-${ELF2FLT_VER}/elf2flt ]] ; then
432 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
433 insinto ${LIBPATH}/ldscripts
434 doins elf2flt.ld || die "doins elf2flt.ld failed"
436 doexe elf2flt flthdr || die "doexe elf2flt flthdr failed"
437 mv "${ED}"/${BINPATH}/{ld,ld.real} || die
438 newexe ld-elf2flt ld || die "doexe ld-elf2flt failed"
439 newdoc README README.elf2flt
442 # Generate an env.d entry for this binutils
443 insinto /etc/env.d/binutils
444 cat <<-EOF > "${T}"/env.d
447 LIBPATH="${EPREFIX}${LIBPATH}"
449 newins "${T}"/env.d ${CTARGET}-${BVER}
451 # Handle documentation
456 dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
458 dodoc binutils/ChangeLog binutils/NEWS binutils/README
460 dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
462 dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
464 dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
466 dodoc libiberty/ChangeLog* libiberty/README
468 dodoc opcodes/ChangeLog*
470 # Remove shared info pages
471 rm -f "${ED}"/${DATAPATH}/info/{dir,configure.info,standards.info}
472 # Trim all empty dirs
473 find "${ED}" -depth -type d -exec rmdir {} + 2>/dev/null
476 toolchain-binutils_pkg_postinst() {
478 # Make sure this ${CTARGET} has a binutils version selected
479 [[ -e ${EROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
480 binutils-config ${CTARGET}-${BVER}
483 toolchain-binutils_pkg_postrm() {
485 local current_profile=$(binutils-config -c ${CTARGET})
487 # If no other versions exist, then uninstall for this
488 # target ... otherwise, switch to the newest version
489 # Note: only do this if this version is unmerged. We
490 # rerun binutils-config if this is a remerge, as
491 # we want the mtimes on the symlinks updated (if
492 # it is the same as the current selected profile)
493 if [[ ! -e ${EPREFIX}${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${BVER} ]] ; then
494 local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}')
495 choice=${choice//$'\n'/ }
497 if [[ -z ${choice} ]] ; then
498 env -i ROOT="${ROOT}" binutils-config -u ${CTARGET}
500 binutils-config ${choice}
502 elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${BVER} ]] ; then
503 binutils-config ${CTARGET}-${BVER}