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
79 SRC_URI="${SRC_URI} ${@/%//${a}}"
81 add_src_uri binutils-${BVER}-patches-${PATCHVER}.tar ${PATCHVER}
82 add_src_uri binutils-${BVER}-uclibc-patches-${UCLIBC_PATCHVER}.tar ${UCLIBC_PATCHVER}
83 add_src_uri elf2flt-${ELF2FLT_VER}.tar ${ELF2FLT_VER}
85 if version_is_at_least 2.18 ; then
86 LICENSE="|| ( GPL-3 LGPL-3 )"
88 LICENSE="|| ( GPL-2 LGPL-2 )"
90 IUSE="cxx multitarget nls static-libs test vanilla"
91 if version_is_at_least 2.19 && ! version_is_at_least 2.26 ; then
96 RDEPEND=">=sys-devel/binutils-config-3"
97 if in_iuse zlib ; then
98 RDEPEND+=" zlib? ( sys-libs/zlib )"
99 elif version_is_at_least 2.26 ; then
100 RDEPEND+=" sys-libs/zlib"
103 test? ( dev-util/dejagnu )
104 nls? ( sys-devel/gettext )
108 # The build assumes the host has libiberty and such when cross-compiling
109 # its build tools. We should probably make binutils itself build a local
110 # copy to use, but until then, be lazy.
111 DEPEND+=" >=sys-libs/binutils-libs-${PV}"
114 S=${WORKDIR}/binutils
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
125 BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${BVER}
127 BINPATH=/usr/${CTARGET}/binutils-bin/${BVER}
130 tc-binutils_unpack() {
132 git) git-2_src_unpack ;;
135 mkdir -p "${MY_BUILDDIR}"
136 [[ -d ${WORKDIR}/patch ]] && mkdir "${WORKDIR}"/patch/skip
139 # In case the ebuild wants to add a few of their own.
142 tc-binutils_apply_patches() {
145 if ! use vanilla ; then
146 if [[ -n ${PATCHVER} ]] ; then
147 EPATCH_SOURCE=${WORKDIR}/patch
148 if [[ ${CTARGET} == mips* ]] ; then
149 # remove gnu-hash for mips (bug #233233)
150 EPATCH_EXCLUDE+=" 77_all_generate-gnu-hash.patch"
152 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
153 && EPATCH_SUFFIX="patch.bz2" \
154 || EPATCH_SUFFIX="patch"
157 if [[ -n ${UCLIBC_PATCHVER} ]] ; then
158 EPATCH_SOURCE=${WORKDIR}/uclibc-patches
159 [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
160 && EPATCH_SUFFIX="patch.bz2" \
161 || EPATCH_SUFFIX="patch"
162 EPATCH_MULTI_MSG="Applying uClibc fixes ..." \
164 elif [[ ${CTARGET} == *-uclibc* ]] ; then
165 # starting with binutils-2.17.50.0.17, we no longer need
166 # uClibc patchsets :D
167 if grep -qs 'linux-gnu' "${S}"/ltconfig ; then
168 die "sorry, but this binutils doesn't yet support uClibc :("
171 [[ ${#PATCHES[@]} -gt 0 ]] && epatch "${PATCHES[@]}"
173 # Make sure our explicit libdir paths don't get clobbered. #562460
175 -e 's:@bfdlibdir@:@libdir@:g' \
176 -e 's:@bfdincludedir@:@includedir@:g' \
177 {bfd,opcodes}/Makefile.in || die
182 # fix locale issues if possible #122216
183 if [[ -e ${FILESDIR}/binutils-configure-LANG.patch ]] ; then
184 einfo "Fixing misc issues in configure files"
185 for f in $(find "${S}" -name configure -exec grep -l 'autoconf version 2.13' {} +) ; do
186 ebegin " Updating ${f/${S}\/}"
187 patch "${f}" "${FILESDIR}"/binutils-configure-LANG.patch >& "${T}"/configure-patch.log \
188 || eerror "Please file a bug about this"
192 # fix conflicts with newer glibc #272594
193 if [[ -e libiberty/testsuite/test-demangle.c ]] ; then
194 sed -i 's:\<getline\>:get_line:g' libiberty/testsuite/test-demangle.c
197 # Fix po Makefile generators
199 -e '/^datadir = /s:$(prefix)/@DATADIRNAME@:@datadir@:' \
200 -e '/^gnulocaledir = /s:$(prefix)/share:$(datadir):' \
201 */po/Make-in || die "sed po's failed"
203 # Run misc portage update scripts
205 elibtoolize --portage --no-uclibc
208 toolchain-binutils_src_unpack() {
211 0|1) toolchain-binutils_src_prepare ;;
215 toolchain-binutils_src_prepare() {
216 tc-binutils_apply_patches
220 has "${EAPI:-0}" 0 1 2 && ED=${D} EPREFIX= EROOT=${ROOT}
223 # Intended for ebuilds to override to set their own versioning information.
224 toolchain-binutils_bugurl() {
225 printf "https://bugs.gentoo.org/"
227 toolchain-binutils_pkgversion() {
228 printf "Gentoo ${BVER}"
229 [[ -n ${PATCHVER} ]] && printf " p${PATCHVER}"
232 toolchain-binutils_src_configure() {
235 # make sure we filter $LINGUAS so that only ones that
236 # actually work make it through #42033
237 strip-linguas -u */po
244 for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
245 einfo "$(printf '%10s' ${x}:) ${!x}"
252 # enable gold if available (installed as ld.gold)
254 if grep -q 'enable-gold=default' "${S}"/configure ; then
255 myconf+=( --enable-gold )
256 # old ways - remove when 2.21 is stable
257 elif grep -q 'enable-gold=both/ld' "${S}"/configure ; then
258 myconf+=( --enable-gold=both/ld )
259 elif grep -q 'enable-gold=both/bfd' "${S}"/configure ; then
260 myconf+=( --enable-gold=both/bfd )
262 if grep -q -e '--enable-plugins' "${S}"/ld/configure ; then
263 myconf+=( --enable-plugins )
268 && myconf+=( --without-included-gettext ) \
269 || myconf+=( --disable-nls )
271 if in_iuse zlib ; then
272 # older versions did not have an explicit configure flag
273 export ac_cv_search_zlibVersion=$(usex zlib -lz no)
274 myconf+=( $(use_with zlib) )
275 elif version_is_at_least 2.26 ; then
276 myconf+=( --with-system-zlib )
279 # For bi-arch systems, enable a 64bit bfd. This matches
280 # the bi-arch logic in toolchain.eclass. #446946
281 # We used to do it for everyone, but it's slow on 32bit arches. #438522
283 ppc|sparc|x86) myconf+=( --enable-64-bit-bfd ) ;;
286 use multitarget && myconf+=( --enable-targets=all --enable-64-bit-bfd )
287 [[ -n ${CBUILD} ]] && myconf+=( --build=${CBUILD} )
288 is_cross && myconf+=(
289 --with-sysroot="${EPREFIX}"/usr/${CTARGET}
290 --enable-poison-system-directories
293 # glibc-2.3.6 lacks support for this ... so rather than force glibc-2.5+
294 # on everyone in alpha (for now), we'll just enable it when possible
295 has_version ">=${CATEGORY}/glibc-2.5" && myconf+=( --enable-secureplt )
296 has_version ">=sys-libs/glibc-2.5" && myconf+=( --enable-secureplt )
299 --prefix="${EPREFIX}"/usr
302 --datadir="${EPREFIX}"${DATAPATH}
303 --infodir="${EPREFIX}"${DATAPATH}/info
304 --mandir="${EPREFIX}"${DATAPATH}/man
305 --bindir="${EPREFIX}"${BINPATH}
306 --libdir="${EPREFIX}"${LIBPATH}
307 --libexecdir="${EPREFIX}"${LIBPATH}
308 --includedir="${EPREFIX}"${INCPATH}
312 # Newer versions (>=2.27) offer a configure flag now.
314 # Newer versions (>=2.24) make this an explicit option. #497268
315 --enable-install-libiberty
317 --with-bugurl="$(toolchain-binutils_bugurl)"
318 --with-pkgversion="$(toolchain-binutils_pkgversion)"
319 $(use_enable static-libs static)
321 # Disable modules that are in a combined binutils/gdb tree. #490566
322 --disable-{gdb,libdecnumber,readline,sim}
323 # Strip out broken static link flags.
324 # https://gcc.gnu.org/PR56750
325 --without-stage1-ldflags
327 echo ./configure "${myconf[@]}"
328 "${S}"/configure "${myconf[@]}" || die
330 # Prevent makeinfo from running in releases. It may not always be
331 # installed, and older binutils may fail with newer texinfo.
332 # Besides, we never patch the doc files anyways, so regenerating
333 # in the first place is useless. #193364
334 # For older versions, it means we don't get any info pages at all.
335 # Oh well, tough luck. #294617
336 if [[ -e ${S}/gas/doc/as.info ]] || ! version_is_at_least 2.24 ; then
338 -e '/^MAKEINFO/s:=.*:= true:' \
343 toolchain-binutils_src_compile() {
346 0|1) toolchain-binutils_src_configure ;;
350 emake all || die "emake failed"
352 # only build info pages if we user wants them, and if
353 # we have makeinfo (may not exist when we bootstrap)
354 if type -p makeinfo > /dev/null ; then
355 emake info || die "make info failed"
357 # we nuke the manpages when we're left with junk
358 # (like when we bootstrap, no perl -> no manpages)
359 find . -name '*.1' -a -size 0 -delete
361 # elf2flt only works on some arches / targets
362 if [[ -n ${ELF2FLT_VER} ]] && [[ ${CTARGET} == *linux* || ${CTARGET} == *-elf* ]] ; then
363 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
365 local x supported_arches=$(sed -n '/defined(TARGET_/{s:^.*TARGET_::;s:)::;p}' elf2flt.c | sort -u)
366 for x in ${supported_arches} UNSUPPORTED ; do
367 [[ ${CTARGET} == ${x}* ]] && break
370 if [[ ${x} != "UNSUPPORTED" ]] ; then
371 append-flags -I"${S}"/include
373 --with-bfd-include-dir=${MY_BUILDDIR}/bfd
374 --with-libbfd=${MY_BUILDDIR}/bfd/libbfd.a
375 --with-libiberty=${MY_BUILDDIR}/libiberty/libiberty.a
376 --with-binutils-ldscript-dir="${EPREFIX}"${LIBPATH}/ldscripts
378 echo ./configure "${myconf[@]}"
379 ./configure "${myconf[@]}" || die
380 emake || die "make elf2flt failed"
385 toolchain-binutils_src_test() {
387 emake -k check || die "check failed :("
390 toolchain-binutils_src_install() {
395 emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install || die
396 rm -rf "${ED}"/${LIBPATH}/bin
397 use static-libs || find "${ED}" -name '*.la' -delete
399 # Newer versions of binutils get fancy with ${LIBPATH} #171905
400 cd "${ED}"/${LIBPATH}
402 [[ ${d} == ../${BVER} ]] && continue
407 # Now we collect everything intp the proper SLOT-ed dirs
408 # When something is built to cross-compile, it installs into
409 # /usr/$CHOST/ by default ... we have to 'fix' that :)
411 cd "${ED}"/${BINPATH}
413 mv ${x} ${x/${CTARGET}-}
416 if [[ -d ${ED}/usr/${CHOST}/${CTARGET} ]] ; then
417 mv "${ED}"/usr/${CHOST}/${CTARGET}/include "${ED}"/${INCPATH}
418 mv "${ED}"/usr/${CHOST}/${CTARGET}/lib/* "${ED}"/${LIBPATH}/
419 rm -r "${ED}"/usr/${CHOST}/{include,lib}
423 local libiberty_headers=(
424 # Not all the libiberty headers. See libiberty/Makefile.in:install_to_libdir.
433 doins "${libiberty_headers[@]/#/${S}/include/}" || die
434 if [[ -d ${ED}/${LIBPATH}/lib ]] ; then
435 mv "${ED}"/${LIBPATH}/lib/* "${ED}"/${LIBPATH}/
436 rm -r "${ED}"/${LIBPATH}/lib
439 # Insert elf2flt where appropriate
440 if [[ -x ${WORKDIR}/elf2flt-${ELF2FLT_VER}/elf2flt ]] ; then
441 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
442 insinto ${LIBPATH}/ldscripts
443 doins elf2flt.ld || die "doins elf2flt.ld failed"
445 doexe elf2flt flthdr || die "doexe elf2flt flthdr failed"
446 mv "${ED}"/${BINPATH}/{ld,ld.real} || die
447 newexe ld-elf2flt ld || die "doexe ld-elf2flt failed"
448 newdoc README README.elf2flt
451 # Generate an env.d entry for this binutils
452 insinto /etc/env.d/binutils
453 cat <<-EOF > "${T}"/env.d
456 LIBPATH="${EPREFIX}${LIBPATH}"
458 newins "${T}"/env.d ${CTARGET}-${BVER}
460 # Handle documentation
465 dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
467 dodoc binutils/ChangeLog binutils/NEWS binutils/README
469 dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
471 dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
473 dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
475 dodoc libiberty/ChangeLog* libiberty/README
477 dodoc opcodes/ChangeLog*
479 # Remove shared info pages
480 rm -f "${ED}"/${DATAPATH}/info/{dir,configure.info,standards.info}
481 # Trim all empty dirs
482 find "${ED}" -depth -type d -exec rmdir {} + 2>/dev/null
485 toolchain-binutils_pkg_postinst() {
487 # Make sure this ${CTARGET} has a binutils version selected
488 [[ -e ${EROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
489 binutils-config ${CTARGET}-${BVER}
492 toolchain-binutils_pkg_postrm() {
494 local current_profile=$(binutils-config -c ${CTARGET})
496 # If no other versions exist, then uninstall for this
497 # target ... otherwise, switch to the newest version
498 # Note: only do this if this version is unmerged. We
499 # rerun binutils-config if this is a remerge, as
500 # we want the mtimes on the symlinks updated (if
501 # it is the same as the current selected profile)
502 if [[ ! -e ${EPREFIX}${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${BVER} ]] ; then
503 local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}')
504 choice=${choice//$'\n'/ }
506 if [[ -z ${choice} ]] ; then
507 env -i ROOT="${ROOT}" binutils-config -u ${CTARGET}
509 binutils-config ${choice}
511 elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${BVER} ]] ; then
512 binutils-config ${CTARGET}-${BVER}