1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # Maintainer: Toolchain Ninjas <toolchain@gentoo.org>
6 # We install binutils into CTARGET-VERSION specific directories. This lets
7 # us easily merge multiple versions for multiple targets (if we wish) and
8 # then switch the versions on the fly (with `binutils-config`).
10 # binutils-9999 -> live git
11 # binutils-9999_preYYMMDD -> nightly snapshot date YYMMDD
12 # binutils-# -> normal release
14 if [[ -n ${BINUTILS_TYPE} ]] ; then
15 BTYPE=${BINUTILS_TYPE}
19 9999_pre*) BTYPE="snap";;
20 *.*.90) BTYPE="snap";;
21 *.*.*.*.*) BTYPE="hjlu";;
29 EGIT_REPO_URI="git://sourceware.org/git/binutils-gdb.git"
36 BVER=${BINUTILS_VER:-${PV}}
40 inherit eutils libtool flag-o-matic gnuconfig multilib versionator unpacker
43 EXPORT_FUNCTIONS src_unpack src_compile src_test src_install pkg_postinst pkg_postrm ;;
45 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_postinst pkg_postrm ;;
46 *) die "unsupported EAPI ${EAPI}" ;;
49 export CTARGET=${CTARGET:-${CHOST}}
50 if [[ ${CTARGET} == ${CHOST} ]] ; then
51 if [[ ${CATEGORY} == cross-* ]] ; then
52 export CTARGET=${CATEGORY#cross-}
55 is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
57 DESCRIPTION="Tools necessary to build programs"
58 HOMEPAGE="https://sourceware.org/binutils/"
63 SRC_URI="ftp://gcc.gnu.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2
64 ftp://sourceware.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2" ;;
66 SRC_URI="mirror://kernel/linux/devel/binutils/binutils-${BVER}.tar."
67 version_is_at_least 2.21.51.0.5 && SRC_URI+="xz" || SRC_URI+="bz2" ;;
68 rel) SRC_URI="mirror://gnu/binutils/binutils-${BVER}.tar.bz2" ;;
73 if version_is_at_least 2.22.52.0.2 ; then
78 set -- mirror://gentoo https://dev.gentoo.org/~vapier/dist https://dev.gentoo.org/~tamiko/distfiles https://dev.gentoo.org/~dilfridge/distfiles
79 SRC_URI="${SRC_URI} ${@/%//${a}}"
81 PATCH_BINUTILS_VER=${PATCH_BINUTILS_VER:-${BVER}}
82 add_src_uri binutils-${PATCH_BINUTILS_VER}-patches-${PATCHVER}.tar ${PATCHVER}
83 add_src_uri binutils-${PATCH_BINUTILS_VER}-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 multitarget nls static-libs test vanilla"
92 if version_is_at_least 2.19 && ! version_is_at_least 2.26 ; then
97 RDEPEND=">=sys-devel/binutils-config-3"
98 if in_iuse zlib ; then
99 RDEPEND+=" zlib? ( sys-libs/zlib )"
100 elif version_is_at_least 2.26 ; then
101 RDEPEND+=" sys-libs/zlib"
104 test? ( dev-util/dejagnu )
105 nls? ( sys-devel/gettext )
109 # The build assumes the host has libiberty and such when cross-compiling
110 # its build tools. We should probably make binutils itself build a local
111 # copy to use, but until then, be lazy.
112 DEPEND+=" >=sys-libs/binutils-libs-${PV}"
115 S=${WORKDIR}/binutils
121 LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${BVER}
122 INCPATH=${LIBPATH}/include
123 DATAPATH=/usr/share/binutils-data/${CTARGET}/${BVER}
124 MY_BUILDDIR=${WORKDIR}/build
126 BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${BVER}
128 BINPATH=/usr/${CTARGET}/binutils-bin/${BVER}
131 tc-binutils_unpack() {
133 git) git-2_src_unpack ;;
136 mkdir -p "${MY_BUILDDIR}"
137 [[ -d ${WORKDIR}/patch ]] && mkdir "${WORKDIR}"/patch/skip
140 # In case the ebuild wants to add a few of their own.
143 tc-binutils_apply_patches() {
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"
153 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
154 && EPATCH_SUFFIX="patch.bz2" \
155 || EPATCH_SUFFIX="patch"
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 ..." \
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 :("
172 [[ ${#PATCHES[@]} -gt 0 ]] && epatch "${PATCHES[@]}"
174 # Make sure our explicit libdir paths don't get clobbered. #562460
176 -e 's:@bfdlibdir@:@libdir@:g' \
177 -e 's:@bfdincludedir@:@includedir@:g' \
178 {bfd,opcodes}/Makefile.in || die
183 # fix locale issues if possible #122216
184 if [[ -e ${FILESDIR}/binutils-configure-LANG.patch ]] ; then
185 einfo "Fixing misc issues in configure files"
186 for f in $(find "${S}" -name configure -exec grep -l 'autoconf version 2.13' {} +) ; do
187 ebegin " Updating ${f/${S}\/}"
188 patch "${f}" "${FILESDIR}"/binutils-configure-LANG.patch >& "${T}"/configure-patch.log \
189 || eerror "Please file a bug about this"
193 # fix conflicts with newer glibc #272594
194 if [[ -e libiberty/testsuite/test-demangle.c ]] ; then
195 sed -i 's:\<getline\>:get_line:g' libiberty/testsuite/test-demangle.c
198 # Fix po Makefile generators
200 -e '/^datadir = /s:$(prefix)/@DATADIRNAME@:@datadir@:' \
201 -e '/^gnulocaledir = /s:$(prefix)/share:$(datadir):' \
202 */po/Make-in || die "sed po's failed"
204 # Run misc portage update scripts
206 elibtoolize --portage --no-uclibc
209 toolchain-binutils_src_unpack() {
212 0|1) toolchain-binutils_src_prepare ;;
216 toolchain-binutils_src_prepare() {
217 tc-binutils_apply_patches
221 has "${EAPI:-0}" 0 1 2 && ED=${D} EPREFIX= EROOT=${ROOT}
224 # Intended for ebuilds to override to set their own versioning information.
225 toolchain-binutils_bugurl() {
226 printf "https://bugs.gentoo.org/"
228 toolchain-binutils_pkgversion() {
229 printf "Gentoo ${BVER}"
230 [[ -n ${PATCHVER} ]] && printf " p${PATCHVER}"
233 toolchain-binutils_src_configure() {
236 # make sure we filter $LINGUAS so that only ones that
237 # actually work make it through #42033
238 strip-linguas -u */po
245 for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
246 einfo "$(printf '%10s' ${x}:) ${!x}"
253 # enable gold if available (installed as ld.gold)
255 if grep -q 'enable-gold=default' "${S}"/configure ; then
256 myconf+=( --enable-gold )
257 # old ways - remove when 2.21 is stable
258 elif grep -q 'enable-gold=both/ld' "${S}"/configure ; then
259 myconf+=( --enable-gold=both/ld )
260 elif grep -q 'enable-gold=both/bfd' "${S}"/configure ; then
261 myconf+=( --enable-gold=both/bfd )
263 if grep -q -e '--enable-plugins' "${S}"/ld/configure ; then
264 myconf+=( --enable-plugins )
269 && myconf+=( --without-included-gettext ) \
270 || myconf+=( --disable-nls )
272 if in_iuse zlib ; then
273 # older versions did not have an explicit configure flag
274 export ac_cv_search_zlibVersion=$(usex zlib -lz no)
275 myconf+=( $(use_with zlib) )
276 elif version_is_at_least 2.26 ; then
277 myconf+=( --with-system-zlib )
280 # For bi-arch systems, enable a 64bit bfd. This matches
281 # the bi-arch logic in toolchain.eclass. #446946
282 # We used to do it for everyone, but it's slow on 32bit arches. #438522
284 ppc|sparc|x86) myconf+=( --enable-64-bit-bfd ) ;;
287 use multitarget && myconf+=( --enable-targets=all --enable-64-bit-bfd )
288 [[ -n ${CBUILD} ]] && myconf+=( --build=${CBUILD} )
289 is_cross && myconf+=(
290 --with-sysroot="${EPREFIX}"/usr/${CTARGET}
291 --enable-poison-system-directories
294 # glibc-2.3.6 lacks support for this ... so rather than force glibc-2.5+
295 # on everyone in alpha (for now), we'll just enable it when possible
296 has_version ">=${CATEGORY}/glibc-2.5" && myconf+=( --enable-secureplt )
297 has_version ">=sys-libs/glibc-2.5" && myconf+=( --enable-secureplt )
300 --prefix="${EPREFIX}"/usr
303 --datadir="${EPREFIX}"${DATAPATH}
304 --infodir="${EPREFIX}"${DATAPATH}/info
305 --mandir="${EPREFIX}"${DATAPATH}/man
306 --bindir="${EPREFIX}"${BINPATH}
307 --libdir="${EPREFIX}"${LIBPATH}
308 --libexecdir="${EPREFIX}"${LIBPATH}
309 --includedir="${EPREFIX}"${INCPATH}
313 # Newer versions (>=2.27) offer a configure flag now.
315 # Newer versions (>=2.24) make this an explicit option. #497268
316 --enable-install-libiberty
318 --with-bugurl="$(toolchain-binutils_bugurl)"
319 --with-pkgversion="$(toolchain-binutils_pkgversion)"
320 $(use_enable static-libs static)
322 # Disable modules that are in a combined binutils/gdb tree. #490566
323 --disable-{gdb,libdecnumber,readline,sim}
324 # Strip out broken static link flags.
325 # https://gcc.gnu.org/PR56750
326 --without-stage1-ldflags
328 echo ./configure "${myconf[@]}"
329 "${S}"/configure "${myconf[@]}" || die
331 # Prevent makeinfo from running in releases. It may not always be
332 # installed, and older binutils may fail with newer texinfo.
333 # Besides, we never patch the doc files anyways, so regenerating
334 # in the first place is useless. #193364
335 # For older versions, it means we don't get any info pages at all.
336 # Oh well, tough luck. #294617
337 if [[ -e ${S}/gas/doc/as.info ]] || ! version_is_at_least 2.24 ; then
339 -e '/^MAKEINFO/s:=.*:= true:' \
344 toolchain-binutils_src_compile() {
347 0|1) toolchain-binutils_src_configure ;;
351 emake all || die "emake failed"
353 # only build info pages if we user wants them, and if
354 # we have makeinfo (may not exist when we bootstrap)
355 if type -p makeinfo > /dev/null ; then
356 emake info || die "make info failed"
358 # we nuke the manpages when we're left with junk
359 # (like when we bootstrap, no perl -> no manpages)
360 find . -name '*.1' -a -size 0 -delete
362 # elf2flt only works on some arches / targets
363 if [[ -n ${ELF2FLT_VER} ]] && [[ ${CTARGET} == *linux* || ${CTARGET} == *-elf* ]] ; then
364 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
366 local x supported_arches=$(sed -n '/defined(TARGET_/{s:^.*TARGET_::;s:)::;p}' elf2flt.c | sort -u)
367 for x in ${supported_arches} UNSUPPORTED ; do
368 [[ ${CTARGET} == ${x}* ]] && break
371 if [[ ${x} != "UNSUPPORTED" ]] ; then
372 append-flags -I"${S}"/include
374 --with-bfd-include-dir=${MY_BUILDDIR}/bfd
375 --with-libbfd=${MY_BUILDDIR}/bfd/libbfd.a
376 --with-libiberty=${MY_BUILDDIR}/libiberty/libiberty.a
377 --with-binutils-ldscript-dir="${EPREFIX}"${LIBPATH}/ldscripts
379 echo ./configure "${myconf[@]}"
380 ./configure "${myconf[@]}" || die
381 emake || die "make elf2flt failed"
386 toolchain-binutils_src_test() {
388 emake -k check || die "check failed :("
391 toolchain-binutils_src_install() {
396 emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install || die
397 rm -rf "${ED}"/${LIBPATH}/bin
398 use static-libs || find "${ED}" -name '*.la' -delete
400 # Newer versions of binutils get fancy with ${LIBPATH} #171905
401 cd "${ED}"/${LIBPATH}
403 [[ ${d} == ../${BVER} ]] && continue
408 # Now we collect everything intp the proper SLOT-ed dirs
409 # When something is built to cross-compile, it installs into
410 # /usr/$CHOST/ by default ... we have to 'fix' that :)
412 cd "${ED}"/${BINPATH}
414 mv ${x} ${x/${CTARGET}-}
417 if [[ -d ${ED}/usr/${CHOST}/${CTARGET} ]] ; then
418 mv "${ED}"/usr/${CHOST}/${CTARGET}/include "${ED}"/${INCPATH}
419 mv "${ED}"/usr/${CHOST}/${CTARGET}/lib/* "${ED}"/${LIBPATH}/
420 rm -r "${ED}"/usr/${CHOST}/{include,lib}
424 local libiberty_headers=(
425 # Not all the libiberty headers. See libiberty/Makefile.in:install_to_libdir.
434 doins "${libiberty_headers[@]/#/${S}/include/}" || die
435 if [[ -d ${ED}/${LIBPATH}/lib ]] ; then
436 mv "${ED}"/${LIBPATH}/lib/* "${ED}"/${LIBPATH}/
437 rm -r "${ED}"/${LIBPATH}/lib
440 # Insert elf2flt where appropriate
441 if [[ -x ${WORKDIR}/elf2flt-${ELF2FLT_VER}/elf2flt ]] ; then
442 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
443 insinto ${LIBPATH}/ldscripts
444 doins elf2flt.ld || die "doins elf2flt.ld failed"
446 doexe elf2flt flthdr || die "doexe elf2flt flthdr failed"
447 mv "${ED}"/${BINPATH}/{ld,ld.real} || die
448 newexe ld-elf2flt ld || die "doexe ld-elf2flt failed"
449 newdoc README README.elf2flt
452 # Generate an env.d entry for this binutils
453 insinto /etc/env.d/binutils
454 cat <<-EOF > "${T}"/env.d
457 LIBPATH="${EPREFIX}${LIBPATH}"
459 newins "${T}"/env.d ${CTARGET}-${BVER}
461 # Handle documentation
466 dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
468 dodoc binutils/ChangeLog binutils/NEWS binutils/README
470 dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
472 dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
474 dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
476 dodoc libiberty/ChangeLog* libiberty/README
478 dodoc opcodes/ChangeLog*
480 # Remove shared info pages
481 rm -f "${ED}"/${DATAPATH}/info/{dir,configure.info,standards.info}
482 # Trim all empty dirs
483 find "${ED}" -depth -type d -exec rmdir {} + 2>/dev/null
486 toolchain-binutils_pkg_postinst() {
488 # Make sure this ${CTARGET} has a binutils version selected
489 [[ -e ${EROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
490 binutils-config ${CTARGET}-${BVER}
493 toolchain-binutils_pkg_postrm() {
495 local current_profile=$(binutils-config -c ${CTARGET})
497 # If no other versions exist, then uninstall for this
498 # target ... otherwise, switch to the newest version
499 # Note: only do this if this version is unmerged. We
500 # rerun binutils-config if this is a remerge, as
501 # we want the mtimes on the symlinks updated (if
502 # it is the same as the current selected profile)
503 if [[ ! -e ${EPREFIX}${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${BVER} ]] ; then
504 local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}')
505 choice=${choice//$'\n'/ }
507 if [[ -z ${choice} ]] ; then
508 binutils-config -u ${CTARGET}
510 binutils-config ${choice}
512 elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${BVER} ]] ; then
513 binutils-config ${CTARGET}-${BVER}