1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit eutils libtool flag-o-matic gnuconfig multilib toolchain-funcs versionator
8 DESCRIPTION="Tools necessary to build programs"
9 HOMEPAGE="https://sourceware.org/binutils/"
11 # USE="+cxx" is a transitional flag until llvm migrates to new flags:
13 IUSE="+cxx default-gold doc +gold multitarget +nls +plugins static-libs test"
14 REQUIRED_USE="cxx? ( gold plugins ) default-gold? ( gold )"
16 # Variables that can be set here:
17 # PATCH_VER - the patchset version
18 # Default: empty, no patching
19 # PATCH_BINUTILS_VER - the binutils version in the patchset name
21 # PATCH_DEV - Use download URI https://dev.gentoo.org/~{PATCH_DEV}/distfiles/...
23 # Default: dilfridge :)
30 EGIT_REPO_URI="https://sourceware.org/git/binutils-gdb.git"
33 EGIT_CHECKOUT_DIR=${S}
37 EGIT_REPO_URI="https://sourceware.org/git/binutils-gdb.git"
40 EGIT_CHECKOUT_DIR=${S}
41 EGIT_BRANCH=$(get_version_component_range 1-2)
42 EGIT_BRANCH="binutils-${EGIT_BRANCH/./_}-branch"
43 SLOT=$(get_version_component_range 1-2)
46 SRC_URI="mirror://gnu/binutils/binutils-${PV}.tar.xz"
47 SLOT=$(get_version_component_range 1-2)
48 KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 m68k ~mips ppc ppc64 ~riscv s390 sparc x86"
55 PATCH_BINUTILS_VER=${PATCH_BINUTILS_VER:-${PV}}
56 PATCH_DEV=${PATCH_DEV:-slyfox}
58 [[ -z ${PATCH_VER} ]] || SRC_URI="${SRC_URI}
59 https://dev.gentoo.org/~${PATCH_DEV}/distfiles/binutils-${PATCH_BINUTILS_VER}-patches-${PATCH_VER}.tar.xz"
61 # Disable gold testsuite since it always fails.
62 PATCHES=( "${FILESDIR}/${PN}-2.29.1-nogoldtest.patch" )
65 # The cross-compile logic
67 export CTARGET=${CTARGET:-${CHOST}}
68 if [[ ${CTARGET} == ${CHOST} ]] ; then
69 if [[ ${CATEGORY} == cross-* ]] ; then
70 export CTARGET=${CATEGORY#cross-}
73 is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
79 >=sys-devel/binutils-config-3
83 doc? ( sys-apps/texinfo )
84 test? ( dev-util/dejagnu )
85 nls? ( sys-devel/gettext )
90 RESTRICT="!test? ( test )"
92 MY_BUILDDIR=${WORKDIR}/build
103 mkdir -p "${MY_BUILDDIR}"
107 if [[ ! -z ${PATCH_VER} ]] ; then
108 # Use upstream patch to enable development mode
109 rm -v "${WORKDIR}/patch"/0000-Gentoo-Git-is-development.patch || die
111 einfo "Applying binutils-${PATCH_BINUTILS_VER} patchset ${PATCH_VER}"
112 eapply "${WORKDIR}/patch"/*.patch
115 # This check should probably go somewhere else, like pkg_pretend.
116 if [[ ${CTARGET} == *-uclibc* ]] ; then
117 if grep -qs 'linux-gnu' "${S}"/ltconfig ; then
118 die "sorry, but this binutils doesn't yet support uClibc :("
122 # Make sure our explicit libdir paths don't get clobbered. #562460
124 -e 's:@bfdlibdir@:@libdir@:g' \
125 -e 's:@bfdincludedir@:@includedir@:g' \
126 {bfd,opcodes}/Makefile.in || die
128 # Fix locale issues if possible #122216
129 if [[ -e ${FILESDIR}/binutils-configure-LANG.patch ]] ; then
130 einfo "Fixing misc issues in configure files"
131 for f in $(find "${S}" -name configure -exec grep -l 'autoconf version 2.13' {} +) ; do
132 ebegin " Updating ${f/${S}\/}"
133 patch "${f}" "${FILESDIR}"/binutils-configure-LANG.patch >& "${T}"/configure-patch.log \
134 || eerror "Please file a bug about this"
139 # Fix conflicts with newer glibc #272594
140 if [[ -e libiberty/testsuite/test-demangle.c ]] ; then
141 sed -i 's:\<getline\>:get_line:g' libiberty/testsuite/test-demangle.c
144 # Apply things from PATCHES and user dirs
147 # Run misc portage update scripts
149 elibtoolize --portage --no-uclibc
152 toolchain-binutils_bugurl() {
153 printf "https://bugs.gentoo.org/"
155 toolchain-binutils_pkgversion() {
156 printf "Gentoo ${PV}"
157 [[ -n ${PATCH_VER} ]] && printf " p${PATCH_VER}"
162 LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${PV}
163 INCPATH=${LIBPATH}/include
164 DATAPATH=/usr/share/binutils-data/${CTARGET}/${PV}
166 TOOLPATH=/usr/${CHOST}/${CTARGET}
168 TOOLPATH=/usr/${CTARGET}
170 BINPATH=${TOOLPATH}/binutils-bin/${PV}
172 # Make sure we filter $LINGUAS so that only ones that
173 # actually work make it through #42033
174 strip-linguas -u */po
181 for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
182 einfo "$(printf '%10s' ${x}:) ${!x}"
189 if use plugins ; then
190 myconf+=( --enable-plugins )
192 # enable gold (installed as ld.gold) and ld's plugin architecture
194 myconf+=( --enable-gold )
195 if use default-gold; then
196 myconf+=( --enable-gold=default )
201 myconf+=( --without-included-gettext )
203 myconf+=( --disable-nls )
206 myconf+=( --with-system-zlib )
208 # For bi-arch systems, enable a 64bit bfd. This matches
209 # the bi-arch logic in toolchain.eclass. #446946
210 # We used to do it for everyone, but it's slow on 32bit arches. #438522
212 ppc|sparc|x86) myconf+=( --enable-64-bit-bfd ) ;;
215 use multitarget && myconf+=( --enable-targets=all --enable-64-bit-bfd )
217 [[ -n ${CBUILD} ]] && myconf+=( --build=${CBUILD} )
219 is_cross && myconf+=(
220 --with-sysroot="${EPREFIX}"/usr/${CTARGET}
221 --enable-poison-system-directories
224 # glibc-2.3.6 lacks support for this ... so rather than force glibc-2.5+
225 # on everyone in alpha (for now), we'll just enable it when possible
226 has_version ">=${CATEGORY}/glibc-2.5" && myconf+=( --enable-secureplt )
227 has_version ">=sys-libs/glibc-2.5" && myconf+=( --enable-secureplt )
229 # mips can't do hash-style=gnu ...
230 if [[ $(tc-arch) != mips ]] ; then
231 myconf+=( --enable-default-hash-style=gnu )
235 --prefix="${EPREFIX}"/usr
238 --datadir="${EPREFIX}"${DATAPATH}
239 --datarootdir="${EPREFIX}"${DATAPATH}
240 --infodir="${EPREFIX}"${DATAPATH}/info
241 --mandir="${EPREFIX}"${DATAPATH}/man
242 --bindir="${EPREFIX}"${BINPATH}
243 --libdir="${EPREFIX}"${LIBPATH}
244 --libexecdir="${EPREFIX}"${LIBPATH}
245 --includedir="${EPREFIX}"${INCPATH}
249 # Newer versions (>=2.27) offer a configure flag now.
251 # Newer versions (>=2.24) make this an explicit option. #497268
252 --enable-install-libiberty
254 --with-bugurl="$(toolchain-binutils_bugurl)"
255 --with-pkgversion="$(toolchain-binutils_pkgversion)"
256 $(use_enable static-libs static)
258 # Disable modules that are in a combined binutils/gdb tree. #490566
259 --disable-{gdb,libdecnumber,readline,sim}
260 # Strip out broken static link flags.
261 # https://gcc.gnu.org/PR56750
262 --without-stage1-ldflags
263 # Change SONAME to avoid conflict across
264 # {native,cross}/binutils, binutils-libs. #666100
265 --with-extra-soversion-suffix=gentoo-${CATEGORY}-${PN}-$(usex multitarget mt st)
267 echo ./configure "${myconf[@]}"
268 "${S}"/configure "${myconf[@]}" || die
270 # Prevent makeinfo from running if doc is unset.
273 -e '/^MAKEINFO/s:=.*:= true:' \
280 # see Note [tooldir hack for ldscripts]
281 emake tooldir="${EPREFIX}${TOOLPATH}" all
283 # only build info pages if the user wants them
288 # we nuke the manpages when we're left with junk
289 # (like when we bootstrap, no perl -> no manpages)
290 find . -name '*.1' -a -size 0 -delete
297 filter-flags -Wall -Wreturn-type
299 # enable verbose test run and result logging
300 emake -k check RUNTESTFLAGS='-a -v' VERBOSE=1
307 # see Note [tooldir hack for ldscripts]
308 emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install
309 rm -rf "${ED}"/${LIBPATH}/bin
310 use static-libs || find "${ED}" -name '*.la' -delete
312 # Newer versions of binutils get fancy with ${LIBPATH} #171905
313 cd "${ED}"/${LIBPATH}
315 [[ ${d} == ../${PV} ]] && continue
320 # Now we collect everything intp the proper SLOT-ed dirs
321 # When something is built to cross-compile, it installs into
322 # /usr/$CHOST/ by default ... we have to 'fix' that :)
324 cd "${ED}"/${BINPATH}
326 mv ${x} ${x/${CTARGET}-}
329 if [[ -d ${ED}/usr/${CHOST}/${CTARGET} ]] ; then
330 mv "${ED}"/usr/${CHOST}/${CTARGET}/include "${ED}"/${INCPATH}
331 mv "${ED}"/usr/${CHOST}/${CTARGET}/lib/* "${ED}"/${LIBPATH}/
332 rm -r "${ED}"/usr/${CHOST}/{include,lib}
336 local libiberty_headers=(
337 # Not all the libiberty headers. See libiberty/Makefile.in:install_to_libdir.
346 doins "${libiberty_headers[@]/#/${S}/include/}"
347 if [[ -d ${ED}/${LIBPATH}/lib ]] ; then
348 mv "${ED}"/${LIBPATH}/lib/* "${ED}"/${LIBPATH}/
349 rm -r "${ED}"/${LIBPATH}/lib
352 # Generate an env.d entry for this binutils
353 insinto /etc/env.d/binutils
354 cat <<-EOF > "${T}"/env.d
357 LIBPATH="${EPREFIX}${LIBPATH}"
359 newins "${T}"/env.d ${CTARGET}-${PV}
361 # Handle documentation
366 dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
368 dodoc binutils/ChangeLog binutils/NEWS binutils/README
370 dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
372 dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
374 dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
376 dodoc libiberty/ChangeLog* libiberty/README
378 dodoc opcodes/ChangeLog*
381 # Remove shared info pages
382 rm -f "${ED}"/${DATAPATH}/info/{dir,configure.info,standards.info}
384 # Trim all empty dirs
385 find "${ED}" -depth -type d -exec rmdir {} + 2>/dev/null
389 # Make sure this ${CTARGET} has a binutils version selected
390 [[ -e ${EROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
391 binutils-config ${CTARGET}-${PV}
395 local current_profile=$(binutils-config -c ${CTARGET})
397 # If no other versions exist, then uninstall for this
398 # target ... otherwise, switch to the newest version
399 # Note: only do this if this version is unmerged. We
400 # rerun binutils-config if this is a remerge, as
401 # we want the mtimes on the symlinks updated (if
402 # it is the same as the current selected profile)
403 if [[ ! -e ${EPREFIX}${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${PV} ]] ; then
404 local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}')
405 choice=${choice//$'\n'/ }
407 if [[ -z ${choice} ]] ; then
408 binutils-config -u ${CTARGET}
410 binutils-config ${choice}
412 elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${PV} ]] ; then
413 binutils-config ${CTARGET}-${PV}
417 # Note [slotting support]
418 # -----------------------
419 # Gentoo's layout for binutils files is non-standard as Gentoo
420 # supports slotted installation for binutils. Many tools
421 # still expect binutils to reside in known locations.
422 # binutils-config package restores symlinks into known locations,
424 # /usr/bin/${CTARGET}-<tool>
425 # /usr/bin/${CHOST}/${CTARGET}/lib/ldscrips
428 # Note [tooldir hack for ldscripts]
429 # ---------------------------------
430 # Build system does not allow ./configure to tweak every location
431 # we need for slotting binutils hence all the shuffling in
432 # src_install(). This note is about SCRIPTDIR define handling.
434 # SCRIPTDIR defines 'ldscripts/' directory location. SCRIPTDIR value
435 # is set at build-time in ld/Makefile.am as: 'scriptdir = $(tooldir)/lib'
436 # and hardcoded as -DSCRIPTDIR='"$(scriptdir)"' at compile time.
437 # Thus we can't just move files around after compilation finished.
439 # Our goal is the following:
440 # - at build-time set scriptdir to point to symlinked location:
441 # ${TOOLPATH}: /usr/${CHOST} (or /usr/${CHOST}/${CTARGET} for cross-case)
442 # - at install-time set scriptdir to point to slotted location:
443 # ${LIBPATH}: /usr/$(get_libdir)/binutils/${CTARGET}/${PV}