1 # Copyright 1999-2018 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 export CTARGET=hppa64-${CHOST#*-}
8 inherit eutils libtool flag-o-matic gnuconfig multilib versionator
10 DESCRIPTION="Tools necessary to build programs"
11 HOMEPAGE="https://sourceware.org/binutils/"
13 IUSE="+cxx doc multitarget +nls static-libs test"
15 # Variables that can be set here:
16 # PATCH_VER - the patchset version
17 # Default: empty, no patching
18 # PATCH_BINUTILS_VER - the binutils version in the patchset name
20 # PATCH_DEV - Use download URI https://dev.gentoo.org/~{PATCH_DEV}/distfiles/...
22 # Default: dilfridge :)
29 EGIT_REPO_URI="https://sourceware.org/git/binutils-gdb.git"
32 EGIT_CHECKOUT_DIR=${S}
36 SRC_URI="mirror://gnu/binutils/binutils-${BVER}.tar.xz https://sourceware.org/pub/binutils/releases/binutils-${BVER}.tar.xz"
45 PATCH_BINUTILS_VER=${PATCH_BINUTILS_VER:-${BVER}}
46 PATCH_DEV=${PATCH_DEV:-slyfox}
48 [[ -z ${PATCH_VER} ]] || SRC_URI="${SRC_URI}
49 https://dev.gentoo.org/~${PATCH_DEV}/distfiles/binutils-${PATCH_BINUTILS_VER}-patches-${PATCH_VER}.tar.xz"
52 # The cross-compile logic
54 export CTARGET=${CTARGET:-${CHOST}}
55 if [[ ${CTARGET} == ${CHOST} ]] ; then
56 if [[ ${CATEGORY} == cross-* ]] ; then
57 export CTARGET=${CATEGORY#cross-}
60 is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
66 >=sys-devel/binutils-config-3
70 doc? ( sys-apps/texinfo )
71 test? ( dev-util/dejagnu )
72 nls? ( sys-devel/gettext )
77 # The build assumes the host has libiberty and such when cross-compiling
78 # its build tools. We should probably make binutils itself build a local
79 # copy to use, but until then, be lazy.
80 DEPEND+=" >=sys-libs/binutils-libs-${PV}"
83 MY_BUILDDIR=${WORKDIR}/build
84 S=${WORKDIR}/${P/-hppa64/}
95 mkdir -p "${MY_BUILDDIR}"
99 if [[ ! -z ${PATCH_VER} ]] ; then
100 einfo "Applying binutils-${PATCH_BINUTILS_VER} patchset ${PATCH_VER}"
101 eapply "${WORKDIR}/patch"/*.patch
104 # This check should probably go somewhere else, like pkg_pretend.
105 if [[ ${CTARGET} == *-uclibc* ]] ; then
106 if grep -qs 'linux-gnu' "${S}"/ltconfig ; then
107 die "sorry, but this binutils doesn't yet support uClibc :("
111 # Make sure our explicit libdir paths don't get clobbered. #562460
113 -e 's:@bfdlibdir@:@libdir@:g' \
114 -e 's:@bfdincludedir@:@includedir@:g' \
115 {bfd,opcodes}/Makefile.in || die
117 # Fix locale issues if possible #122216
118 if [[ -e ${FILESDIR}/binutils-configure-LANG.patch ]] ; then
119 einfo "Fixing misc issues in configure files"
120 for f in $(find "${S}" -name configure -exec grep -l 'autoconf version 2.13' {} +) ; do
121 ebegin " Updating ${f/${S}\/}"
122 patch "${f}" "${FILESDIR}"/binutils-configure-LANG.patch >& "${T}"/configure-patch.log \
123 || eerror "Please file a bug about this"
128 # Fix conflicts with newer glibc #272594
129 if [[ -e libiberty/testsuite/test-demangle.c ]] ; then
130 sed -i 's:\<getline\>:get_line:g' libiberty/testsuite/test-demangle.c
133 # Apply things from PATCHES and user dirs
136 # Run misc portage update scripts
138 elibtoolize --portage --no-uclibc
141 toolchain-binutils_bugurl() {
142 printf "https://bugs.gentoo.org/"
144 toolchain-binutils_pkgversion() {
145 printf "Gentoo ${BVER}"
146 [[ -n ${PATCH_VER} ]] && printf " p${PATCH_VER}"
151 LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${BVER}
152 INCPATH=${LIBPATH}/include
153 DATAPATH=/usr/share/binutils-data/${CTARGET}/${BVER}
155 BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${BVER}
157 BINPATH=/usr/${CTARGET}/binutils-bin/${BVER}
160 # Make sure we filter $LINGUAS so that only ones that
161 # actually work make it through #42033
162 strip-linguas -u */po
169 for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
170 einfo "$(printf '%10s' ${x}:) ${!x}"
177 # enable gold (installed as ld.gold) and ld's plugin architecture
179 myconf+=( --enable-gold )
180 myconf+=( --enable-plugins )
184 myconf+=( --without-included-gettext )
186 myconf+=( --disable-nls )
189 myconf+=( --with-system-zlib )
191 # For bi-arch systems, enable a 64bit bfd. This matches
192 # the bi-arch logic in toolchain.eclass. #446946
193 # We used to do it for everyone, but it's slow on 32bit arches. #438522
195 ppc|sparc|x86) myconf+=( --enable-64-bit-bfd ) ;;
198 use multitarget && myconf+=( --enable-targets=all --enable-64-bit-bfd )
200 [[ -n ${CBUILD} ]] && myconf+=( --build=${CBUILD} )
202 is_cross && myconf+=(
203 --with-sysroot="${EPREFIX}"/usr/${CTARGET}
204 --enable-poison-system-directories
207 # glibc-2.3.6 lacks support for this ... so rather than force glibc-2.5+
208 # on everyone in alpha (for now), we'll just enable it when possible
209 has_version ">=${CATEGORY}/glibc-2.5" && myconf+=( --enable-secureplt )
210 has_version ">=sys-libs/glibc-2.5" && myconf+=( --enable-secureplt )
212 # mips can't do hash-style=gnu ...
213 if [[ $(tc-arch) != mips ]] ; then
214 myconf+=( --enable-default-hash-style=gnu )
218 --prefix="${EPREFIX}"/usr
221 --datadir="${EPREFIX}"${DATAPATH}
222 --datarootdir="${EPREFIX}"${DATAPATH}
223 --infodir="${EPREFIX}"${DATAPATH}/info
224 --mandir="${EPREFIX}"${DATAPATH}/man
225 --bindir="${EPREFIX}"${BINPATH}
226 --libdir="${EPREFIX}"${LIBPATH}
227 --libexecdir="${EPREFIX}"${LIBPATH}
228 --includedir="${EPREFIX}"${INCPATH}
232 # Newer versions (>=2.27) offer a configure flag now.
234 # Newer versions (>=2.24) make this an explicit option. #497268
235 --enable-install-libiberty
237 --with-bugurl="$(toolchain-binutils_bugurl)"
238 --with-pkgversion="$(toolchain-binutils_pkgversion)"
239 $(use_enable static-libs static)
241 # Disable modules that are in a combined binutils/gdb tree. #490566
242 --disable-{gdb,libdecnumber,readline,sim}
243 # Strip out broken static link flags.
244 # https://gcc.gnu.org/PR56750
245 --without-stage1-ldflags
246 # Change SONAME to avoid conflict across
247 # {native,cross}/binutils, binutils-libs. #666100
248 --with-extra-soversion-suffix=gentoo-${CATEGORY}-${PN}-$(usex multitarget mt st)
250 echo ./configure "${myconf[@]}"
251 "${S}"/configure "${myconf[@]}" || die
253 # Prevent makeinfo from running if doc is unset.
256 -e '/^MAKEINFO/s:=.*:= true:' \
265 # only build info pages if the user wants them
270 # we nuke the manpages when we're left with junk
271 # (like when we bootstrap, no perl -> no manpages)
272 find . -name '*.1' -a -size 0 -delete
284 emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install
285 rm -rf "${ED}"/${LIBPATH}/bin
286 use static-libs || find "${ED}" -name '*.la' -delete
288 # Newer versions of binutils get fancy with ${LIBPATH} #171905
289 cd "${ED}"/${LIBPATH}
291 [[ ${d} == ../${BVER} ]] && continue
296 # Now we collect everything intp the proper SLOT-ed dirs
297 # When something is built to cross-compile, it installs into
298 # /usr/$CHOST/ by default ... we have to 'fix' that :)
300 cd "${ED}"/${BINPATH}
302 mv ${x} ${x/${CTARGET}-}
305 if [[ -d ${ED}/usr/${CHOST}/${CTARGET} ]] ; then
306 mv "${ED}"/usr/${CHOST}/${CTARGET}/include "${ED}"/${INCPATH}
307 mv "${ED}"/usr/${CHOST}/${CTARGET}/lib/* "${ED}"/${LIBPATH}/
308 rm -r "${ED}"/usr/${CHOST}/{include,lib}
312 local libiberty_headers=(
313 # Not all the libiberty headers. See libiberty/Makefile.in:install_to_libdir.
322 doins "${libiberty_headers[@]/#/${S}/include/}" || die
323 if [[ -d ${ED}/${LIBPATH}/lib ]] ; then
324 mv "${ED}"/${LIBPATH}/lib/* "${ED}"/${LIBPATH}/
325 rm -r "${ED}"/${LIBPATH}/lib
328 # Generate an env.d entry for this binutils
329 insinto /etc/env.d/binutils
330 cat <<-EOF > "${T}"/env.d
333 LIBPATH="${EPREFIX}${LIBPATH}"
335 newins "${T}"/env.d ${CTARGET}-${BVER}
337 # Handle documentation
342 dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
344 dodoc binutils/ChangeLog binutils/NEWS binutils/README
346 dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
348 dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
350 dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
352 dodoc libiberty/ChangeLog* libiberty/README
354 dodoc opcodes/ChangeLog*
357 # Remove shared info pages
358 rm -f "${ED}"/${DATAPATH}/info/{dir,configure.info,standards.info}
360 # Trim all empty dirs
361 find "${ED}" -depth -type d -exec rmdir {} + 2>/dev/null
363 # the hppa64 hack; this should go into 9999 as a PN-conditional
364 # tweak the default fake list a little bit
365 cd "${D}"/etc/env.d/binutils
366 sed -i '/FAKE_TARGETS=/s:"$: hppa64-linux":' ${CTARGET}-${BVER} || die
370 # Make sure this ${CTARGET} has a binutils version selected
371 [[ -e ${EROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
372 binutils-config ${CTARGET}-${BVER}
376 local current_profile=$(binutils-config -c ${CTARGET})
378 # If no other versions exist, then uninstall for this
379 # target ... otherwise, switch to the newest version
380 # Note: only do this if this version is unmerged. We
381 # rerun binutils-config if this is a remerge, as
382 # we want the mtimes on the symlinks updated (if
383 # it is the same as the current selected profile)
384 if [[ ! -e ${EPREFIX}${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${BVER} ]] ; then
385 local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}')
386 choice=${choice//$'\n'/ }
388 if [[ -z ${choice} ]] ; then
389 binutils-config -u ${CTARGET}
391 binutils-config ${choice}
393 elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${BVER} ]] ; then
394 binutils-config ${CTARGET}-${BVER}