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>
5 # @SUPPORTED_EAPIS: 0 1 2 3 4 5
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}
19 9999_pre*) BTYPE="snap";;
20 *.*.90) BTYPE="snap";;
21 *.*.*.*.*) BTYPE="hjlu";;
31 BVER=${BINUTILS_VER:-${PV}}
35 inherit eutils libtool flag-o-matic gnuconfig multilib versionator unpacker
38 EXPORT_FUNCTIONS src_unpack src_compile src_test src_install pkg_postinst pkg_postrm ;;
40 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_postinst pkg_postrm ;;
41 *) die "unsupported EAPI ${EAPI}" ;;
44 export CTARGET=${CTARGET:-${CHOST}}
45 if [[ ${CTARGET} == ${CHOST} ]] ; then
46 if [[ ${CATEGORY} == cross-* ]] ; then
47 export CTARGET=${CATEGORY#cross-}
50 is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
52 DESCRIPTION="Tools necessary to build programs"
53 HOMEPAGE="https://sourceware.org/binutils/"
57 SRC_URI="ftp://gcc.gnu.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2
58 ftp://sourceware.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2" ;;
60 SRC_URI="mirror://kernel/linux/devel/binutils/binutils-${BVER}.tar."
61 version_is_at_least 2.21.51.0.5 && SRC_URI+="xz" || SRC_URI+="bz2" ;;
62 rel) SRC_URI="mirror://gnu/binutils/binutils-${BVER}.tar.bz2" ;;
67 if version_is_at_least 2.22.52.0.2 ; then
72 set -- mirror://gentoo https://dev.gentoo.org/~vapier/dist https://dev.gentoo.org/~tamiko/distfiles https://dev.gentoo.org/~dilfridge/distfiles
73 SRC_URI="${SRC_URI} ${@/%//${a}}"
75 PATCH_BINUTILS_VER=${PATCH_BINUTILS_VER:-${BVER}}
76 add_src_uri binutils-${PATCH_BINUTILS_VER}-patches-${PATCHVER}.tar ${PATCHVER}
77 add_src_uri binutils-${PATCH_BINUTILS_VER}-uclibc-patches-${UCLIBC_PATCHVER}.tar ${UCLIBC_PATCHVER}
78 add_src_uri elf2flt-${ELF2FLT_VER}.tar ${ELF2FLT_VER}
80 if version_is_at_least 2.18 ; then
81 LICENSE="|| ( GPL-3 LGPL-3 )"
83 LICENSE="|| ( GPL-2 LGPL-2 )"
85 IUSE="cxx multitarget nls static-libs test vanilla"
86 if version_is_at_least 2.19 && ! version_is_at_least 2.26 ; then
91 RDEPEND=">=sys-devel/binutils-config-3"
92 if in_iuse zlib ; then
93 RDEPEND+=" zlib? ( sys-libs/zlib )"
94 elif version_is_at_least 2.26 ; then
95 RDEPEND+=" sys-libs/zlib"
98 test? ( dev-util/dejagnu )
99 nls? ( sys-devel/gettext )
103 # The build assumes the host has libiberty and such when cross-compiling
104 # its build tools. We should probably make binutils itself build a local
105 # copy to use, but until then, be lazy.
106 DEPEND+=" >=sys-libs/binutils-libs-${PV}"
109 S=${WORKDIR}/binutils-${BVER}
111 LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${BVER}
112 INCPATH=${LIBPATH}/include
113 DATAPATH=/usr/share/binutils-data/${CTARGET}/${BVER}
114 MY_BUILDDIR=${WORKDIR}/build
116 BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${BVER}
118 BINPATH=/usr/${CTARGET}/binutils-bin/${BVER}
121 tc-binutils_unpack() {
123 mkdir -p "${MY_BUILDDIR}"
124 [[ -d ${WORKDIR}/patch ]] && mkdir "${WORKDIR}"/patch/skip
127 # In case the ebuild wants to add a few of their own.
130 tc-binutils_apply_patches() {
133 if ! use vanilla ; then
134 if [[ -n ${PATCHVER} ]] ; then
135 EPATCH_SOURCE=${WORKDIR}/patch
136 if [[ ${CTARGET} == mips* ]] ; then
137 # remove gnu-hash for mips (bug #233233)
138 EPATCH_EXCLUDE+=" 77_all_generate-gnu-hash.patch"
140 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
141 && EPATCH_SUFFIX="patch.bz2" \
142 || EPATCH_SUFFIX="patch"
145 if [[ -n ${UCLIBC_PATCHVER} ]] ; then
146 EPATCH_SOURCE=${WORKDIR}/uclibc-patches
147 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
148 && EPATCH_SUFFIX="patch.bz2" \
149 || EPATCH_SUFFIX="patch"
150 EPATCH_MULTI_MSG="Applying uClibc fixes ..." \
152 elif [[ ${CTARGET} == *-uclibc* ]] ; then
153 # starting with binutils-2.17.50.0.17, we no longer need
154 # uClibc patchsets :D
155 if grep -qs 'linux-gnu' "${S}"/ltconfig ; then
156 die "sorry, but this binutils doesn't yet support uClibc :("
159 [[ ${#PATCHES[@]} -gt 0 ]] && epatch "${PATCHES[@]}"
161 # Make sure our explicit libdir paths don't get clobbered. #562460
163 -e 's:@bfdlibdir@:@libdir@:g' \
164 -e 's:@bfdincludedir@:@includedir@:g' \
165 {bfd,opcodes}/Makefile.in || die
170 # fix locale issues if possible #122216
171 if [[ -e ${FILESDIR}/binutils-configure-LANG.patch ]] ; then
172 einfo "Fixing misc issues in configure files"
173 for f in $(find "${S}" -name configure -exec grep -l 'autoconf version 2.13' {} +) ; do
174 ebegin " Updating ${f/${S}\/}"
175 patch "${f}" "${FILESDIR}"/binutils-configure-LANG.patch >& "${T}"/configure-patch.log \
176 || eerror "Please file a bug about this"
180 # fix conflicts with newer glibc #272594
181 if [[ -e libiberty/testsuite/test-demangle.c ]] ; then
182 sed -i 's:\<getline\>:get_line:g' libiberty/testsuite/test-demangle.c
185 # Fix po Makefile generators
187 -e '/^datadir = /s:$(prefix)/@DATADIRNAME@:@datadir@:' \
188 -e '/^gnulocaledir = /s:$(prefix)/share:$(datadir):' \
189 */po/Make-in || die "sed po's failed"
191 # Run misc portage update scripts
193 elibtoolize --portage --no-uclibc
196 toolchain-binutils_src_unpack() {
199 0|1) toolchain-binutils_src_prepare ;;
203 toolchain-binutils_src_prepare() {
204 tc-binutils_apply_patches
208 has "${EAPI:-0}" 0 1 2 && ED=${D} EPREFIX= EROOT=${ROOT}
211 # Intended for ebuilds to override to set their own versioning information.
212 toolchain-binutils_bugurl() {
213 printf "https://bugs.gentoo.org/"
215 toolchain-binutils_pkgversion() {
216 printf "Gentoo ${BVER}"
217 [[ -n ${PATCHVER} ]] && printf " p${PATCHVER}"
220 toolchain-binutils_src_configure() {
223 # make sure we filter $LINGUAS so that only ones that
224 # actually work make it through #42033
225 strip-linguas -u */po
232 for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
233 einfo "$(printf '%10s' ${x}:) ${!x}"
240 # enable gold if available (installed as ld.gold)
242 if grep -q 'enable-gold=default' "${S}"/configure ; then
243 myconf+=( --enable-gold )
244 # old ways - remove when 2.21 is stable
245 elif grep -q 'enable-gold=both/ld' "${S}"/configure ; then
246 myconf+=( --enable-gold=both/ld )
247 elif grep -q 'enable-gold=both/bfd' "${S}"/configure ; then
248 myconf+=( --enable-gold=both/bfd )
250 if grep -q -e '--enable-plugins' "${S}"/ld/configure ; then
251 myconf+=( --enable-plugins )
256 && myconf+=( --without-included-gettext ) \
257 || myconf+=( --disable-nls )
259 if in_iuse zlib ; then
260 # older versions did not have an explicit configure flag
261 export ac_cv_search_zlibVersion=$(usex zlib -lz no)
262 myconf+=( $(use_with zlib) )
263 elif version_is_at_least 2.26 ; then
264 myconf+=( --with-system-zlib )
267 # For bi-arch systems, enable a 64bit bfd. This matches
268 # the bi-arch logic in toolchain.eclass. #446946
269 # We used to do it for everyone, but it's slow on 32bit arches. #438522
271 ppc|sparc|x86) myconf+=( --enable-64-bit-bfd ) ;;
274 use multitarget && myconf+=( --enable-targets=all --enable-64-bit-bfd )
275 [[ -n ${CBUILD} ]] && myconf+=( --build=${CBUILD} )
276 is_cross && myconf+=(
277 --with-sysroot="${EPREFIX}"/usr/${CTARGET}
278 --enable-poison-system-directories
281 # glibc-2.3.6 lacks support for this ... so rather than force glibc-2.5+
282 # on everyone in alpha (for now), we'll just enable it when possible
283 has_version ">=${CATEGORY}/glibc-2.5" && myconf+=( --enable-secureplt )
284 has_version ">=sys-libs/glibc-2.5" && myconf+=( --enable-secureplt )
287 --prefix="${EPREFIX}"/usr
290 --datadir="${EPREFIX}"${DATAPATH}
291 --infodir="${EPREFIX}"${DATAPATH}/info
292 --mandir="${EPREFIX}"${DATAPATH}/man
293 --bindir="${EPREFIX}"${BINPATH}
294 --libdir="${EPREFIX}"${LIBPATH}
295 --libexecdir="${EPREFIX}"${LIBPATH}
296 --includedir="${EPREFIX}"${INCPATH}
300 # Newer versions (>=2.27) offer a configure flag now.
302 # Newer versions (>=2.24) make this an explicit option. #497268
303 --enable-install-libiberty
305 --with-bugurl="$(toolchain-binutils_bugurl)"
306 --with-pkgversion="$(toolchain-binutils_pkgversion)"
307 $(use_enable static-libs static)
309 # Disable modules that are in a combined binutils/gdb tree. #490566
310 --disable-{gdb,libdecnumber,readline,sim}
311 # Strip out broken static link flags.
312 # https://gcc.gnu.org/PR56750
313 --without-stage1-ldflags
315 echo ./configure "${myconf[@]}"
316 "${S}"/configure "${myconf[@]}" || die
318 # Prevent makeinfo from running in releases. It may not always be
319 # installed, and older binutils may fail with newer texinfo.
320 # Besides, we never patch the doc files anyways, so regenerating
321 # in the first place is useless. #193364
322 # For older versions, it means we don't get any info pages at all.
323 # Oh well, tough luck. #294617
324 if [[ -e ${S}/gas/doc/as.info ]] || ! version_is_at_least 2.24 ; then
326 -e '/^MAKEINFO/s:=.*:= true:' \
331 toolchain-binutils_src_compile() {
334 0|1) toolchain-binutils_src_configure ;;
338 emake all || die "emake failed"
340 # only build info pages if we user wants them, and if
341 # we have makeinfo (may not exist when we bootstrap)
342 if type -p makeinfo > /dev/null ; then
343 emake info || die "make info failed"
345 # we nuke the manpages when we're left with junk
346 # (like when we bootstrap, no perl -> no manpages)
347 find . -name '*.1' -a -size 0 -delete
349 # elf2flt only works on some arches / targets
350 if [[ -n ${ELF2FLT_VER} ]] && [[ ${CTARGET} == *linux* || ${CTARGET} == *-elf* ]] ; then
351 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
353 local x supported_arches=$(sed -n '/defined(TARGET_/{s:^.*TARGET_::;s:)::;p}' elf2flt.c | sort -u)
354 for x in ${supported_arches} UNSUPPORTED ; do
355 [[ ${CTARGET} == ${x}* ]] && break
358 if [[ ${x} != "UNSUPPORTED" ]] ; then
359 append-flags -I"${S}"/include
361 --with-bfd-include-dir=${MY_BUILDDIR}/bfd
362 --with-libbfd=${MY_BUILDDIR}/bfd/libbfd.a
363 --with-libiberty=${MY_BUILDDIR}/libiberty/libiberty.a
364 --with-binutils-ldscript-dir="${EPREFIX}"${LIBPATH}/ldscripts
366 echo ./configure "${myconf[@]}"
367 ./configure "${myconf[@]}" || die
368 emake || die "make elf2flt failed"
373 toolchain-binutils_src_test() {
375 emake -k check || die "check failed :("
378 toolchain-binutils_src_install() {
383 emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install || die
384 rm -rf "${ED}"/${LIBPATH}/bin
385 use static-libs || find "${ED}" -name '*.la' -delete
387 # Newer versions of binutils get fancy with ${LIBPATH} #171905
388 cd "${ED}"/${LIBPATH}
390 [[ ${d} == ../${BVER} ]] && continue
395 # Now we collect everything intp the proper SLOT-ed dirs
396 # When something is built to cross-compile, it installs into
397 # /usr/$CHOST/ by default ... we have to 'fix' that :)
399 cd "${ED}"/${BINPATH}
401 mv ${x} ${x/${CTARGET}-}
404 if [[ -d ${ED}/usr/${CHOST}/${CTARGET} ]] ; then
405 mv "${ED}"/usr/${CHOST}/${CTARGET}/include "${ED}"/${INCPATH}
406 mv "${ED}"/usr/${CHOST}/${CTARGET}/lib/* "${ED}"/${LIBPATH}/
407 rm -r "${ED}"/usr/${CHOST}/{include,lib}
411 local libiberty_headers=(
412 # Not all the libiberty headers. See libiberty/Makefile.in:install_to_libdir.
421 doins "${libiberty_headers[@]/#/${S}/include/}" || die
422 if [[ -d ${ED}/${LIBPATH}/lib ]] ; then
423 mv "${ED}"/${LIBPATH}/lib/* "${ED}"/${LIBPATH}/
424 rm -r "${ED}"/${LIBPATH}/lib
427 # Insert elf2flt where appropriate
428 if [[ -x ${WORKDIR}/elf2flt-${ELF2FLT_VER}/elf2flt ]] ; then
429 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
430 insinto ${LIBPATH}/ldscripts
431 doins elf2flt.ld || die "doins elf2flt.ld failed"
433 doexe elf2flt flthdr || die "doexe elf2flt flthdr failed"
434 mv "${ED}"/${BINPATH}/{ld,ld.real} || die
435 newexe ld-elf2flt ld || die "doexe ld-elf2flt failed"
436 newdoc README README.elf2flt
439 # Generate an env.d entry for this binutils
440 insinto /etc/env.d/binutils
441 cat <<-EOF > "${T}"/env.d
444 LIBPATH="${EPREFIX}${LIBPATH}"
446 newins "${T}"/env.d ${CTARGET}-${BVER}
448 # Handle documentation
453 dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
455 dodoc binutils/ChangeLog binutils/NEWS binutils/README
457 dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
459 dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
461 dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
463 dodoc libiberty/ChangeLog* libiberty/README
465 dodoc opcodes/ChangeLog*
467 # Remove shared info pages
468 rm -f "${ED}"/${DATAPATH}/info/{dir,configure.info,standards.info}
469 # Trim all empty dirs
470 find "${ED}" -depth -type d -exec rmdir {} + 2>/dev/null
473 toolchain-binutils_pkg_postinst() {
475 # Make sure this ${CTARGET} has a binutils version selected
476 [[ -e ${EROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
477 binutils-config ${CTARGET}-${BVER}
480 toolchain-binutils_pkg_postrm() {
482 local current_profile=$(binutils-config -c ${CTARGET})
484 # If no other versions exist, then uninstall for this
485 # target ... otherwise, switch to the newest version
486 # Note: only do this if this version is unmerged. We
487 # rerun binutils-config if this is a remerge, as
488 # we want the mtimes on the symlinks updated (if
489 # it is the same as the current selected profile)
490 if [[ ! -e ${EPREFIX}${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${BVER} ]] ; then
491 local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}')
492 choice=${choice//$'\n'/ }
494 if [[ -z ${choice} ]] ; then
495 binutils-config -u ${CTARGET}
497 binutils-config ${choice}
499 elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${BVER} ]] ; then
500 binutils-config ${CTARGET}-${BVER}