media-plugins/gst-plugins-taglib-1.14.4: ppc stable, bug 674854
[gentoo.git] / eclass / toolchain-binutils.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 #
4 # Maintainer: Toolchain Ninjas <toolchain@gentoo.org>
5 # @SUPPORTED_EAPIS: 0 1 2 3 4 5
6 #
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`).
10 #
11 # binutils-9999           -> live git
12 # binutils-9999_preYYMMDD -> nightly snapshot date YYMMDD
13 # binutils-#              -> normal release
14
15 if [[ -n ${BINUTILS_TYPE} ]] ; then
16         BTYPE=${BINUTILS_TYPE}
17 else
18         case ${PV} in
19         9999_pre*) BTYPE="snap";;
20         *.*.90)    BTYPE="snap";;
21         *.*.*.*.*) BTYPE="hjlu";;
22         *)         BTYPE="rel";;
23         esac
24 fi
25
26 case ${BTYPE} in
27 snap)
28         BVER=${PV/9999_pre}
29         ;;
30 *)
31         BVER=${BINUTILS_VER:-${PV}}
32         ;;
33 esac
34
35 inherit eutils libtool flag-o-matic gnuconfig multilib versionator unpacker
36 case ${EAPI:-0} in
37 0|1)
38         EXPORT_FUNCTIONS src_unpack src_compile src_test src_install pkg_postinst pkg_postrm ;;
39 2|3|4|5)
40         EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_postinst pkg_postrm ;;
41 *) die "unsupported EAPI ${EAPI}" ;;
42 esac
43
44 export CTARGET=${CTARGET:-${CHOST}}
45 if [[ ${CTARGET} == ${CHOST} ]] ; then
46         if [[ ${CATEGORY} == cross-* ]] ; then
47                 export CTARGET=${CATEGORY#cross-}
48         fi
49 fi
50 is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
51
52 DESCRIPTION="Tools necessary to build programs"
53 HOMEPAGE="https://sourceware.org/binutils/"
54
55 case ${BTYPE} in
56         snap)
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" ;;
59         hjlu)
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" ;;
63 esac
64 add_src_uri() {
65         [[ -z $2 ]] && return
66         local a=$1
67         if version_is_at_least 2.22.52.0.2 ; then
68                 a+=".xz"
69         else
70                 a+=".bz2"
71         fi
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}}"
74 }
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}
79
80 if version_is_at_least 2.18 ; then
81         LICENSE="|| ( GPL-3 LGPL-3 )"
82 else
83         LICENSE="|| ( GPL-2 LGPL-2 )"
84 fi
85 IUSE="cxx multitarget nls static-libs test vanilla"
86 if version_is_at_least 2.19 && ! version_is_at_least 2.26 ; then
87         IUSE+=" zlib"
88 fi
89 SLOT="${BVER}"
90
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"
96 fi
97 DEPEND="${RDEPEND}
98         test? ( dev-util/dejagnu )
99         nls? ( sys-devel/gettext )
100         sys-devel/flex
101         virtual/yacc"
102 if is_cross ; then
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}"
107 fi
108
109 S=${WORKDIR}/binutils-${BVER}
110
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
115 if is_cross ; then
116         BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${BVER}
117 else
118         BINPATH=/usr/${CTARGET}/binutils-bin/${BVER}
119 fi
120
121 tc-binutils_unpack() {
122         unpacker ${A}
123         mkdir -p "${MY_BUILDDIR}"
124         [[ -d ${WORKDIR}/patch ]] && mkdir "${WORKDIR}"/patch/skip
125 }
126
127 # In case the ebuild wants to add a few of their own.
128 PATCHES=()
129
130 tc-binutils_apply_patches() {
131         cd "${S}"
132
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"
139                         fi
140                         [[ -n $(ls "${EPATCH_SOURCE}"/*.bz2 2>/dev/null) ]] \
141                                 && EPATCH_SUFFIX="patch.bz2" \
142                                 || EPATCH_SUFFIX="patch"
143                         epatch
144                 fi
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 ..." \
151                         epatch
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 :("
157                         fi
158                 fi
159                 [[ ${#PATCHES[@]} -gt 0 ]] && epatch "${PATCHES[@]}"
160
161                 # Make sure our explicit libdir paths don't get clobbered. #562460
162                 sed -i \
163                         -e 's:@bfdlibdir@:@libdir@:g' \
164                         -e 's:@bfdincludedir@:@includedir@:g' \
165                         {bfd,opcodes}/Makefile.in || die
166
167                 epatch_user
168         fi
169
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"
177                         eend $?
178                 done
179         fi
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
183         fi
184
185         # Fix po Makefile generators
186         sed -i \
187                 -e '/^datadir = /s:$(prefix)/@DATADIRNAME@:@datadir@:' \
188                 -e '/^gnulocaledir = /s:$(prefix)/share:$(datadir):' \
189                 */po/Make-in || die "sed po's failed"
190
191         # Run misc portage update scripts
192         gnuconfig_update
193         elibtoolize --portage --no-uclibc
194 }
195
196 toolchain-binutils_src_unpack() {
197         tc-binutils_unpack
198         case ${EAPI:-0} in
199         0|1) toolchain-binutils_src_prepare ;;
200         esac
201 }
202
203 toolchain-binutils_src_prepare() {
204         tc-binutils_apply_patches
205 }
206
207 _eprefix_init() {
208         has "${EAPI:-0}" 0 1 2 && ED=${D} EPREFIX= EROOT=${ROOT}
209 }
210
211 # Intended for ebuilds to override to set their own versioning information.
212 toolchain-binutils_bugurl() {
213         printf "https://bugs.gentoo.org/"
214 }
215 toolchain-binutils_pkgversion() {
216         printf "Gentoo ${BVER}"
217         [[ -n ${PATCHVER} ]] && printf " p${PATCHVER}"
218 }
219
220 toolchain-binutils_src_configure() {
221         _eprefix_init
222
223         # make sure we filter $LINGUAS so that only ones that
224         # actually work make it through #42033
225         strip-linguas -u */po
226
227         # keep things sane
228         strip-flags
229
230         local x
231         echo
232         for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
233                 einfo "$(printf '%10s' ${x}:) ${!x}"
234         done
235         echo
236
237         cd "${MY_BUILDDIR}"
238         local myconf=()
239
240         # enable gold if available (installed as ld.gold)
241         if use cxx ; then
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 )
249                 fi
250                 if grep -q -e '--enable-plugins' "${S}"/ld/configure ; then
251                         myconf+=( --enable-plugins )
252                 fi
253         fi
254
255         use nls \
256                 && myconf+=( --without-included-gettext ) \
257                 || myconf+=( --disable-nls )
258
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 )
265         fi
266
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
270         case $(tc-arch) in
271         ppc|sparc|x86) myconf+=( --enable-64-bit-bfd ) ;;
272         esac
273
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
279         )
280
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 )
285
286         myconf+=(
287                 --prefix="${EPREFIX}"/usr
288                 --host=${CHOST}
289                 --target=${CTARGET}
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}
297                 --enable-obsolete
298                 --enable-shared
299                 --enable-threads
300                 # Newer versions (>=2.27) offer a configure flag now.
301                 --enable-relro
302                 # Newer versions (>=2.24) make this an explicit option. #497268
303                 --enable-install-libiberty
304                 --disable-werror
305                 --with-bugurl="$(toolchain-binutils_bugurl)"
306                 --with-pkgversion="$(toolchain-binutils_pkgversion)"
307                 $(use_enable static-libs static)
308                 ${EXTRA_ECONF}
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
314         )
315         echo ./configure "${myconf[@]}"
316         "${S}"/configure "${myconf[@]}" || die
317
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
325                 sed -i \
326                         -e '/^MAKEINFO/s:=.*:= true:' \
327                         Makefile || die
328         fi
329 }
330
331 toolchain-binutils_src_compile() {
332         _eprefix_init
333         case ${EAPI:-0} in
334         0|1) toolchain-binutils_src_configure ;;
335         esac
336
337         cd "${MY_BUILDDIR}"
338         emake all || die "emake failed"
339
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"
344         fi
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
348
349         # elf2flt only works on some arches / targets
350         if [[ -n ${ELF2FLT_VER} ]] && [[ ${CTARGET} == *linux* || ${CTARGET} == *-elf* ]] ; then
351                 cd "${WORKDIR}"/elf2flt-${ELF2FLT_VER}
352
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
356                 done
357
358                 if [[ ${x} != "UNSUPPORTED" ]] ; then
359                         append-flags -I"${S}"/include
360                         myconf+=(
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
365                         )
366                         echo ./configure "${myconf[@]}"
367                         ./configure "${myconf[@]}" || die
368                         emake || die "make elf2flt failed"
369                 fi
370         fi
371 }
372
373 toolchain-binutils_src_test() {
374         cd "${MY_BUILDDIR}"
375         emake -k check || die "check failed :("
376 }
377
378 toolchain-binutils_src_install() {
379         _eprefix_init
380         local x d
381
382         cd "${MY_BUILDDIR}"
383         emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install || die
384         rm -rf "${ED}"/${LIBPATH}/bin
385         use static-libs || find "${ED}" -name '*.la' -delete
386
387         # Newer versions of binutils get fancy with ${LIBPATH} #171905
388         cd "${ED}"/${LIBPATH}
389         for d in ../* ; do
390                 [[ ${d} == ../${BVER} ]] && continue
391                 mv ${d}/* . || die
392                 rmdir ${d} || die
393         done
394
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 :)
398         if is_cross ; then
399                 cd "${ED}"/${BINPATH}
400                 for x in * ; do
401                         mv ${x} ${x/${CTARGET}-}
402                 done
403
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}
408                 fi
409         fi
410         insinto ${INCPATH}
411         local libiberty_headers=(
412                 # Not all the libiberty headers.  See libiberty/Makefile.in:install_to_libdir.
413                 demangle.h
414                 dyn-string.h
415                 fibheap.h
416                 hashtab.h
417                 libiberty.h
418                 objalloc.h
419                 splay-tree.h
420         )
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
425         fi
426
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"
432                 exeinto ${BINPATH}
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
437         fi
438
439         # Generate an env.d entry for this binutils
440         insinto /etc/env.d/binutils
441         cat <<-EOF > "${T}"/env.d
442                 TARGET="${CTARGET}"
443                 VER="${BVER}"
444                 LIBPATH="${EPREFIX}${LIBPATH}"
445         EOF
446         newins "${T}"/env.d ${CTARGET}-${BVER}
447
448         # Handle documentation
449         if ! is_cross ; then
450                 cd "${S}"
451                 dodoc README
452                 docinto bfd
453                 dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
454                 docinto binutils
455                 dodoc binutils/ChangeLog binutils/NEWS binutils/README
456                 docinto gas
457                 dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
458                 docinto gprof
459                 dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
460                 docinto ld
461                 dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
462                 docinto libiberty
463                 dodoc libiberty/ChangeLog* libiberty/README
464                 docinto opcodes
465                 dodoc opcodes/ChangeLog*
466         fi
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
471 }
472
473 toolchain-binutils_pkg_postinst() {
474         _eprefix_init
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}
478 }
479
480 toolchain-binutils_pkg_postrm() {
481         _eprefix_init
482         local current_profile=$(binutils-config -c ${CTARGET})
483
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'/ }
493                 choice=${choice/* }
494                 if [[ -z ${choice} ]] ; then
495                         binutils-config -u ${CTARGET}
496                 else
497                         binutils-config ${choice}
498                 fi
499         elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${BVER} ]] ; then
500                 binutils-config ${CTARGET}-${BVER}
501         fi
502 }