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}
18 9999_pre*) BTYPE="snap";;
19 *.*.90) BTYPE="snap";;
20 *.*.*.*.*) BTYPE="hjlu";;
30 BVER=${BINUTILS_VER:-${PV}}
34 inherit eutils libtool flag-o-matic gnuconfig multilib versionator unpacker
37 EXPORT_FUNCTIONS src_unpack src_compile src_test src_install pkg_postinst pkg_postrm ;;
39 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_postinst pkg_postrm ;;
40 *) die "unsupported EAPI ${EAPI}" ;;
43 export CTARGET=${CTARGET:-${CHOST}}
44 if [[ ${CTARGET} == ${CHOST} ]] ; then
45 if [[ ${CATEGORY} == cross-* ]] ; then
46 export CTARGET=${CATEGORY#cross-}
49 is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
51 DESCRIPTION="Tools necessary to build programs"
52 HOMEPAGE="https://sourceware.org/binutils/"
56 SRC_URI="ftp://gcc.gnu.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2
57 ftp://sourceware.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2" ;;
59 SRC_URI="mirror://kernel/linux/devel/binutils/binutils-${BVER}.tar."
60 version_is_at_least 2.21.51.0.5 && SRC_URI+="xz" || SRC_URI+="bz2" ;;
61 rel) SRC_URI="mirror://gnu/binutils/binutils-${BVER}.tar.bz2" ;;
66 if version_is_at_least 2.22.52.0.2 ; then
71 set -- mirror://gentoo https://dev.gentoo.org/~vapier/dist https://dev.gentoo.org/~tamiko/distfiles https://dev.gentoo.org/~dilfridge/distfiles
72 SRC_URI="${SRC_URI} ${@/%//${a}}"
74 PATCH_BINUTILS_VER=${PATCH_BINUTILS_VER:-${BVER}}
75 add_src_uri binutils-${PATCH_BINUTILS_VER}-patches-${PATCHVER}.tar ${PATCHVER}
76 add_src_uri binutils-${PATCH_BINUTILS_VER}-uclibc-patches-${UCLIBC_PATCHVER}.tar ${UCLIBC_PATCHVER}
77 add_src_uri elf2flt-${ELF2FLT_VER}.tar ${ELF2FLT_VER}
79 if version_is_at_least 2.18 ; then
80 LICENSE="|| ( GPL-3 LGPL-3 )"
82 LICENSE="|| ( GPL-2 LGPL-2 )"
84 IUSE="cxx multitarget nls static-libs test vanilla"
85 if version_is_at_least 2.19 && ! version_is_at_least 2.26 ; then
90 RDEPEND=">=sys-devel/binutils-config-3"
91 if in_iuse zlib ; then
92 RDEPEND+=" zlib? ( sys-libs/zlib )"
93 elif version_is_at_least 2.26 ; then
94 RDEPEND+=" sys-libs/zlib"
97 test? ( dev-util/dejagnu )
98 nls? ( sys-devel/gettext )
102 # The build assumes the host has libiberty and such when cross-compiling
103 # its build tools. We should probably make binutils itself build a local
104 # copy to use, but until then, be lazy.
105 DEPEND+=" >=sys-libs/binutils-libs-${PV}"
108 S=${WORKDIR}/binutils-${BVER}
110 LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${BVER}
111 INCPATH=${LIBPATH}/include
112 DATAPATH=/usr/share/binutils-data/${CTARGET}/${BVER}
113 MY_BUILDDIR=${WORKDIR}/build
115 BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${BVER}
117 BINPATH=/usr/${CTARGET}/binutils-bin/${BVER}
120 tc-binutils_unpack() {
122 mkdir -p "${MY_BUILDDIR}"
123 [[ -d ${WORKDIR}/patch ]] && mkdir "${WORKDIR}"/patch/skip
126 # In case the ebuild wants to add a few of their own.
129 tc-binutils_apply_patches() {
132 if ! use vanilla ; then
133 if [[ -n ${PATCHVER} ]] ; then
134 EPATCH_SOURCE=${WORKDIR}/patch
135 if [[ ${CTARGET} == mips* ]] ; then
136 # remove gnu-hash for mips (bug #233233)
137 EPATCH_EXCLUDE+=" 77_all_generate-gnu-hash.patch"
139 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
140 && EPATCH_SUFFIX="patch.bz2" \
141 || EPATCH_SUFFIX="patch"
144 if [[ -n ${UCLIBC_PATCHVER} ]] ; then
145 EPATCH_SOURCE=${WORKDIR}/uclibc-patches
146 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
147 && EPATCH_SUFFIX="patch.bz2" \
148 || EPATCH_SUFFIX="patch"
149 EPATCH_MULTI_MSG="Applying uClibc fixes ..." \
151 elif [[ ${CTARGET} == *-uclibc* ]] ; then
152 # starting with binutils-2.17.50.0.17, we no longer need
153 # uClibc patchsets :D
154 if grep -qs 'linux-gnu' "${S}"/ltconfig ; then
155 die "sorry, but this binutils doesn't yet support uClibc :("
158 [[ ${#PATCHES[@]} -gt 0 ]] && epatch "${PATCHES[@]}"
160 # Make sure our explicit libdir paths don't get clobbered. #562460
162 -e 's:@bfdlibdir@:@libdir@:g' \
163 -e 's:@bfdincludedir@:@includedir@:g' \
164 {bfd,opcodes}/Makefile.in || die
169 # fix locale issues if possible #122216
170 if [[ -e ${FILESDIR}/binutils-configure-LANG.patch ]] ; then
171 einfo "Fixing misc issues in configure files"
172 for f in $(find "${S}" -name configure -exec grep -l 'autoconf version 2.13' {} +) ; do
173 ebegin " Updating ${f/${S}\/}"
174 patch "${f}" "${FILESDIR}"/binutils-configure-LANG.patch >& "${T}"/configure-patch.log \
175 || eerror "Please file a bug about this"
179 # fix conflicts with newer glibc #272594
180 if [[ -e libiberty/testsuite/test-demangle.c ]] ; then
181 sed -i 's:\<getline\>:get_line:g' libiberty/testsuite/test-demangle.c
184 # Fix po Makefile generators
186 -e '/^datadir = /s:$(prefix)/@DATADIRNAME@:@datadir@:' \
187 -e '/^gnulocaledir = /s:$(prefix)/share:$(datadir):' \
188 */po/Make-in || die "sed po's failed"
190 # Run misc portage update scripts
192 elibtoolize --portage --no-uclibc
195 toolchain-binutils_src_unpack() {
198 0|1) toolchain-binutils_src_prepare ;;
202 toolchain-binutils_src_prepare() {
203 tc-binutils_apply_patches
207 has "${EAPI:-0}" 0 1 2 && ED=${D} EPREFIX= EROOT=${ROOT}
210 # Intended for ebuilds to override to set their own versioning information.
211 toolchain-binutils_bugurl() {
212 printf "https://bugs.gentoo.org/"
214 toolchain-binutils_pkgversion() {
215 printf "Gentoo ${BVER}"
216 [[ -n ${PATCHVER} ]] && printf " p${PATCHVER}"
219 toolchain-binutils_src_configure() {
222 # make sure we filter $LINGUAS so that only ones that
223 # actually work make it through #42033
224 strip-linguas -u */po
231 for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
232 einfo "$(printf '%10s' ${x}:) ${!x}"
239 # enable gold if available (installed as ld.gold)
241 if grep -q 'enable-gold=default' "${S}"/configure ; then
242 myconf+=( --enable-gold )
243 # old ways - remove when 2.21 is stable
244 elif grep -q 'enable-gold=both/ld' "${S}"/configure ; then
245 myconf+=( --enable-gold=both/ld )
246 elif grep -q 'enable-gold=both/bfd' "${S}"/configure ; then
247 myconf+=( --enable-gold=both/bfd )
249 if grep -q -e '--enable-plugins' "${S}"/ld/configure ; then
250 myconf+=( --enable-plugins )
255 && myconf+=( --without-included-gettext ) \
256 || myconf+=( --disable-nls )
258 if in_iuse zlib ; then
259 # older versions did not have an explicit configure flag
260 export ac_cv_search_zlibVersion=$(usex zlib -lz no)
261 myconf+=( $(use_with zlib) )
262 elif version_is_at_least 2.26 ; then
263 myconf+=( --with-system-zlib )
266 # For bi-arch systems, enable a 64bit bfd. This matches
267 # the bi-arch logic in toolchain.eclass. #446946
268 # We used to do it for everyone, but it's slow on 32bit arches. #438522
270 ppc|sparc|x86) myconf+=( --enable-64-bit-bfd ) ;;
273 use multitarget && myconf+=( --enable-targets=all --enable-64-bit-bfd )
274 [[ -n ${CBUILD} ]] && myconf+=( --build=${CBUILD} )
275 is_cross && myconf+=(
276 --with-sysroot="${EPREFIX}"/usr/${CTARGET}
277 --enable-poison-system-directories
280 # glibc-2.3.6 lacks support for this ... so rather than force glibc-2.5+
281 # on everyone in alpha (for now), we'll just enable it when possible
282 has_version ">=${CATEGORY}/glibc-2.5" && myconf+=( --enable-secureplt )
283 has_version ">=sys-libs/glibc-2.5" && myconf+=( --enable-secureplt )
286 --prefix="${EPREFIX}"/usr
289 --datadir="${EPREFIX}"${DATAPATH}
290 --infodir="${EPREFIX}"${DATAPATH}/info
291 --mandir="${EPREFIX}"${DATAPATH}/man
292 --bindir="${EPREFIX}"${BINPATH}
293 --libdir="${EPREFIX}"${LIBPATH}
294 --libexecdir="${EPREFIX}"${LIBPATH}
295 --includedir="${EPREFIX}"${INCPATH}
299 # Newer versions (>=2.27) offer a configure flag now.
301 # Newer versions (>=2.24) make this an explicit option. #497268
302 --enable-install-libiberty
304 --with-bugurl="$(toolchain-binutils_bugurl)"
305 --with-pkgversion="$(toolchain-binutils_pkgversion)"
306 $(use_enable static-libs static)
308 # Disable modules that are in a combined binutils/gdb tree. #490566
309 --disable-{gdb,libdecnumber,readline,sim}
310 # Strip out broken static link flags.
311 # https://gcc.gnu.org/PR56750
312 --without-stage1-ldflags
314 echo ./configure "${myconf[@]}"
315 "${S}"/configure "${myconf[@]}" || die
317 # Prevent makeinfo from running in releases. It may not always be
318 # installed, and older binutils may fail with newer texinfo.
319 # Besides, we never patch the doc files anyways, so regenerating
320 # in the first place is useless. #193364
321 # For older versions, it means we don't get any info pages at all.
322 # Oh well, tough luck. #294617
323 if [[ -e ${S}/gas/doc/as.info ]] || ! version_is_at_least 2.24 ; then
325 -e '/^MAKEINFO/s:=.*:= true:' \
330 toolchain-binutils_src_compile() {
333 0|1) toolchain-binutils_src_configure ;;
337 emake all || die "emake failed"
339 # only build info pages if we user wants them, and if
340 # we have makeinfo (may not exist when we bootstrap)
341 if type -p makeinfo > /dev/null ; then
342 emake info || die "make info failed"
344 # we nuke the manpages when we're left with junk
345 # (like when we bootstrap, no perl -> no manpages)
346 find . -name '*.1' -a -size 0 -delete
348 # elf2flt only works on some arches / targets
349 if [[ -n ${ELF2FLT_VER} ]] && [[ ${CTARGET} == *linux* || ${CTARGET} == *-elf* ]] ; then
350 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
352 local x supported_arches=$(sed -n '/defined(TARGET_/{s:^.*TARGET_::;s:)::;p}' elf2flt.c | sort -u)
353 for x in ${supported_arches} UNSUPPORTED ; do
354 [[ ${CTARGET} == ${x}* ]] && break
357 if [[ ${x} != "UNSUPPORTED" ]] ; then
358 append-flags -I"${S}"/include
360 --with-bfd-include-dir=${MY_BUILDDIR}/bfd
361 --with-libbfd=${MY_BUILDDIR}/bfd/libbfd.a
362 --with-libiberty=${MY_BUILDDIR}/libiberty/libiberty.a
363 --with-binutils-ldscript-dir="${EPREFIX}"${LIBPATH}/ldscripts
365 echo ./configure "${myconf[@]}"
366 ./configure "${myconf[@]}" || die
367 emake || die "make elf2flt failed"
372 toolchain-binutils_src_test() {
374 emake -k check || die "check failed :("
377 toolchain-binutils_src_install() {
382 emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install || die
383 rm -rf "${ED}"/${LIBPATH}/bin
384 use static-libs || find "${ED}" -name '*.la' -delete
386 # Newer versions of binutils get fancy with ${LIBPATH} #171905
387 cd "${ED}"/${LIBPATH}
389 [[ ${d} == ../${BVER} ]] && continue
394 # Now we collect everything intp the proper SLOT-ed dirs
395 # When something is built to cross-compile, it installs into
396 # /usr/$CHOST/ by default ... we have to 'fix' that :)
398 cd "${ED}"/${BINPATH}
400 mv ${x} ${x/${CTARGET}-}
403 if [[ -d ${ED}/usr/${CHOST}/${CTARGET} ]] ; then
404 mv "${ED}"/usr/${CHOST}/${CTARGET}/include "${ED}"/${INCPATH}
405 mv "${ED}"/usr/${CHOST}/${CTARGET}/lib/* "${ED}"/${LIBPATH}/
406 rm -r "${ED}"/usr/${CHOST}/{include,lib}
410 local libiberty_headers=(
411 # Not all the libiberty headers. See libiberty/Makefile.in:install_to_libdir.
420 doins "${libiberty_headers[@]/#/${S}/include/}" || die
421 if [[ -d ${ED}/${LIBPATH}/lib ]] ; then
422 mv "${ED}"/${LIBPATH}/lib/* "${ED}"/${LIBPATH}/
423 rm -r "${ED}"/${LIBPATH}/lib
426 # Insert elf2flt where appropriate
427 if [[ -x ${WORKDIR}/elf2flt-${ELF2FLT_VER}/elf2flt ]] ; then
428 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
429 insinto ${LIBPATH}/ldscripts
430 doins elf2flt.ld || die "doins elf2flt.ld failed"
432 doexe elf2flt flthdr || die "doexe elf2flt flthdr failed"
433 mv "${ED}"/${BINPATH}/{ld,ld.real} || die
434 newexe ld-elf2flt ld || die "doexe ld-elf2flt failed"
435 newdoc README README.elf2flt
438 # Generate an env.d entry for this binutils
439 insinto /etc/env.d/binutils
440 cat <<-EOF > "${T}"/env.d
443 LIBPATH="${EPREFIX}${LIBPATH}"
445 newins "${T}"/env.d ${CTARGET}-${BVER}
447 # Handle documentation
452 dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
454 dodoc binutils/ChangeLog binutils/NEWS binutils/README
456 dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
458 dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
460 dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
462 dodoc libiberty/ChangeLog* libiberty/README
464 dodoc opcodes/ChangeLog*
466 # Remove shared info pages
467 rm -f "${ED}"/${DATAPATH}/info/{dir,configure.info,standards.info}
468 # Trim all empty dirs
469 find "${ED}" -depth -type d -exec rmdir {} + 2>/dev/null
472 toolchain-binutils_pkg_postinst() {
474 # Make sure this ${CTARGET} has a binutils version selected
475 [[ -e ${EROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
476 binutils-config ${CTARGET}-${BVER}
479 toolchain-binutils_pkg_postrm() {
481 local current_profile=$(binutils-config -c ${CTARGET})
483 # If no other versions exist, then uninstall for this
484 # target ... otherwise, switch to the newest version
485 # Note: only do this if this version is unmerged. We
486 # rerun binutils-config if this is a remerge, as
487 # we want the mtimes on the symlinks updated (if
488 # it is the same as the current selected profile)
489 if [[ ! -e ${EPREFIX}${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${BVER} ]] ; then
490 local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}')
491 choice=${choice//$'\n'/ }
493 if [[ -z ${choice} ]] ; then
494 binutils-config -u ${CTARGET}
496 binutils-config ${choice}
498 elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${BVER} ]] ; then
499 binutils-config ${CTARGET}-${BVER}