www-client/firefox: security cleanup
[gentoo.git] / sys-devel / binutils-hppa64 / binutils-hppa64-2.30-r4.ebuild
1 # Copyright 1999-2018 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 export CTARGET=hppa64-${CHOST#*-}
7
8 inherit eutils libtool flag-o-matic gnuconfig multilib versionator
9
10 DESCRIPTION="Tools necessary to build programs"
11 HOMEPAGE="https://sourceware.org/binutils/"
12 LICENSE="GPL-3+"
13 IUSE="+cxx doc multitarget +nls static-libs test"
14
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
19 #                    - Default: PV
20 # PATCH_DEV          - Use download URI https://dev.gentoo.org/~{PATCH_DEV}/distfiles/...
21 #                      for the patchsets
22 #                      Default: dilfridge :)
23
24 PATCH_VER=5
25
26 case ${PV} in
27         9999)
28                 BVER="git"
29                 EGIT_REPO_URI="https://sourceware.org/git/binutils-gdb.git"
30                 inherit git-r3
31                 S=${WORKDIR}/binutils
32                 EGIT_CHECKOUT_DIR=${S}
33                 ;;
34         *)
35                 BVER=${PV}
36                 SRC_URI="mirror://gnu/binutils/binutils-${BVER}.tar.xz https://sourceware.org/pub/binutils/releases/binutils-${BVER}.tar.xz"
37                 ;;
38 esac
39 SLOT="${BVER}"
40 KEYWORDS="-* ~hppa"
41
42 #
43 # The Gentoo patchset
44 #
45 PATCH_BINUTILS_VER=${PATCH_BINUTILS_VER:-${BVER}}
46 PATCH_DEV=${PATCH_DEV:-slyfox}
47
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"
50
51 #
52 # The cross-compile logic
53 #
54 export CTARGET=${CTARGET:-${CHOST}}
55 if [[ ${CTARGET} == ${CHOST} ]] ; then
56         if [[ ${CATEGORY} == cross-* ]] ; then
57                 export CTARGET=${CATEGORY#cross-}
58         fi
59 fi
60 is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
61
62 #
63 # The dependencies
64 #
65 RDEPEND="
66         >=sys-devel/binutils-config-3
67         sys-libs/zlib
68 "
69 DEPEND="${RDEPEND}
70         doc? ( sys-apps/texinfo )
71         test? ( dev-util/dejagnu )
72         nls? ( sys-devel/gettext )
73         sys-devel/flex
74         virtual/yacc
75 "
76 if is_cross ; then
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}"
81 fi
82
83 MY_BUILDDIR=${WORKDIR}/build
84 S=${WORKDIR}/${P/-hppa64/}
85
86 src_unpack() {
87         case ${PV} in
88                 9999)
89                         git-r3_src_unpack;
90                         ;;
91                 *)
92                         default
93                         ;;
94         esac
95         mkdir -p "${MY_BUILDDIR}"
96 }
97
98 src_prepare() {
99         if [[ ! -z ${PATCH_VER} ]] ; then
100                 einfo "Applying binutils-${PATCH_BINUTILS_VER} patchset ${PATCH_VER}"
101                 eapply "${WORKDIR}/patch"/*.patch
102         fi
103
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 :("
108                 fi
109         fi
110
111         # Make sure our explicit libdir paths don't get clobbered. #562460
112         sed -i \
113                 -e 's:@bfdlibdir@:@libdir@:g' \
114                 -e 's:@bfdincludedir@:@includedir@:g' \
115                 {bfd,opcodes}/Makefile.in || die
116
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"
124                         eend $?
125                 done
126         fi
127
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
131         fi
132
133         # Apply things from PATCHES and user dirs
134         default
135
136         # Run misc portage update scripts
137         gnuconfig_update
138         elibtoolize --portage --no-uclibc
139 }
140
141 toolchain-binutils_bugurl() {
142         printf "https://bugs.gentoo.org/"
143 }
144 toolchain-binutils_pkgversion() {
145         printf "Gentoo ${BVER}"
146         [[ -n ${PATCH_VER} ]] && printf " p${PATCH_VER}"
147 }
148
149 src_configure() {
150         # Setup some paths
151         LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${BVER}
152         INCPATH=${LIBPATH}/include
153         DATAPATH=/usr/share/binutils-data/${CTARGET}/${BVER}
154         if is_cross ; then
155                 BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${BVER}
156         else
157                 BINPATH=/usr/${CTARGET}/binutils-bin/${BVER}
158         fi
159
160         # Make sure we filter $LINGUAS so that only ones that
161         # actually work make it through #42033
162         strip-linguas -u */po
163
164         # Keep things sane
165         strip-flags
166
167         local x
168         echo
169         for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS ; do
170                 einfo "$(printf '%10s' ${x}:) ${!x}"
171         done
172         echo
173
174         cd "${MY_BUILDDIR}"
175         local myconf=()
176
177         # enable gold (installed as ld.gold) and ld's plugin architecture
178         if use cxx ; then
179                 myconf+=( --enable-gold )
180                 myconf+=( --enable-plugins )
181         fi
182
183         if use nls ; then
184                 myconf+=( --without-included-gettext )
185         else
186                 myconf+=( --disable-nls )
187         fi
188
189         myconf+=( --with-system-zlib )
190
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
194         case $(tc-arch) in
195                 ppc|sparc|x86) myconf+=( --enable-64-bit-bfd ) ;;
196         esac
197
198         use multitarget && myconf+=( --enable-targets=all --enable-64-bit-bfd )
199
200         [[ -n ${CBUILD} ]] && myconf+=( --build=${CBUILD} )
201
202         is_cross && myconf+=(
203                 --with-sysroot="${EPREFIX}"/usr/${CTARGET}
204                 --enable-poison-system-directories
205         )
206
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 )
211
212         # mips can't do hash-style=gnu ...
213         if [[ $(tc-arch) != mips ]] ; then
214                 myconf+=( --enable-default-hash-style=gnu )
215         fi
216
217         myconf+=(
218                 --prefix="${EPREFIX}"/usr
219                 --host=${CHOST}
220                 --target=${CTARGET}
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}
229                 --enable-obsolete
230                 --enable-shared
231                 --enable-threads
232                 # Newer versions (>=2.27) offer a configure flag now.
233                 --enable-relro
234                 # Newer versions (>=2.24) make this an explicit option. #497268
235                 --enable-install-libiberty
236                 --disable-werror
237                 --with-bugurl="$(toolchain-binutils_bugurl)"
238                 --with-pkgversion="$(toolchain-binutils_pkgversion)"
239                 $(use_enable static-libs static)
240                 ${EXTRA_ECONF}
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)
249         )
250         echo ./configure "${myconf[@]}"
251         "${S}"/configure "${myconf[@]}" || die
252
253         # Prevent makeinfo from running if doc is unset.
254         if ! use doc ; then
255                 sed -i \
256                         -e '/^MAKEINFO/s:=.*:= true:' \
257                         Makefile || die
258         fi
259 }
260
261 src_compile() {
262         cd "${MY_BUILDDIR}"
263         emake all
264
265         # only build info pages if the user wants them
266         if use doc ; then
267                 emake info
268         fi
269
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
273 }
274
275 src_test() {
276         cd "${MY_BUILDDIR}"
277         emake -k check
278 }
279
280 src_install() {
281         local x d
282
283         cd "${MY_BUILDDIR}"
284         emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install
285         rm -rf "${ED}"/${LIBPATH}/bin
286         use static-libs || find "${ED}" -name '*.la' -delete
287
288         # Newer versions of binutils get fancy with ${LIBPATH} #171905
289         cd "${ED}"/${LIBPATH}
290         for d in ../* ; do
291                 [[ ${d} == ../${BVER} ]] && continue
292                 mv ${d}/* . || die
293                 rmdir ${d} || die
294         done
295
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 :)
299         if is_cross ; then
300                 cd "${ED}"/${BINPATH}
301                 for x in * ; do
302                         mv ${x} ${x/${CTARGET}-}
303                 done
304
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}
309                 fi
310         fi
311         insinto ${INCPATH}
312         local libiberty_headers=(
313                 # Not all the libiberty headers.  See libiberty/Makefile.in:install_to_libdir.
314                 demangle.h
315                 dyn-string.h
316                 fibheap.h
317                 hashtab.h
318                 libiberty.h
319                 objalloc.h
320                 splay-tree.h
321         )
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
326         fi
327
328         # Generate an env.d entry for this binutils
329         insinto /etc/env.d/binutils
330         cat <<-EOF > "${T}"/env.d
331                 TARGET="${CTARGET}"
332                 VER="${BVER}"
333                 LIBPATH="${EPREFIX}${LIBPATH}"
334         EOF
335         newins "${T}"/env.d ${CTARGET}-${BVER}
336
337         # Handle documentation
338         if ! is_cross ; then
339                 cd "${S}"
340                 dodoc README
341                 docinto bfd
342                 dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO
343                 docinto binutils
344                 dodoc binutils/ChangeLog binutils/NEWS binutils/README
345                 docinto gas
346                 dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*
347                 docinto gprof
348                 dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl
349                 docinto ld
350                 dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO
351                 docinto libiberty
352                 dodoc libiberty/ChangeLog* libiberty/README
353                 docinto opcodes
354                 dodoc opcodes/ChangeLog*
355         fi
356
357         # Remove shared info pages
358         rm -f "${ED}"/${DATAPATH}/info/{dir,configure.info,standards.info}
359
360         # Trim all empty dirs
361         find "${ED}" -depth -type d -exec rmdir {} + 2>/dev/null
362
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
367 }
368
369 pkg_postinst() {
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}
373 }
374
375 pkg_postrm() {
376         local current_profile=$(binutils-config -c ${CTARGET})
377
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'/ }
387                 choice=${choice/* }
388                 if [[ -z ${choice} ]] ; then
389                         binutils-config -u ${CTARGET}
390                 else
391                         binutils-config ${choice}
392                 fi
393         elif [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${BVER} ]] ; then
394                 binutils-config ${CTARGET}-${BVER}
395         fi
396 }