0bd67107bde56c38e0e67aaa9a516163bdb31339
[gentoo.git] / dev-lang / perl / perl-5.24.0-r1.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=6
6
7 inherit eutils alternatives flag-o-matic toolchain-funcs multilib multiprocessing
8
9 PATCH_VER=2
10
11 PERL_OLDVERSEN=""
12 MODULE_AUTHOR=RJBS
13
14 SHORT_PV="${PV%.*}"
15 MY_P="perl-${PV/_rc/-RC}"
16 MY_PV="${PV%_rc*}"
17
18 DESCRIPTION="Larry Wall's Practical Extraction and Report Language"
19
20 SRC_URI="
21         mirror://cpan/src/5.0/${MY_P}.tar.bz2
22         mirror://cpan/authors/id/${MODULE_AUTHOR:0:1}/${MODULE_AUTHOR:0:2}/${MODULE_AUTHOR}/${MY_P}.tar.bz2
23         mirror://gentoo/${MY_P}-patches-${PATCH_VER}.tar.xz
24         https://dev.gentoo.org/~dilfridge/distfiles/${MY_P}-patches-${PATCH_VER}.tar.xz
25 "
26 HOMEPAGE="http://www.perl.org/"
27
28 LICENSE="|| ( Artistic GPL-1+ )"
29 SLOT="0/${SHORT_PV}"
30 KEYWORDS="~alpha ~amd64 ~amd64-fbsd ~amd64-linux ~arm ~arm64 ~hppa ~hppa-hpux ~ia64 ~ia64-hpux ~ia64-linux ~m68k ~m68k-mint ~mips ~ppc ~ppc64 ~ppc-aix ~ppc-macos ~s390 ~sh ~sparc ~sparc64-solaris ~sparc-solaris ~x64-freebsd ~x64-macos ~x64-solaris ~x86 ~x86-fbsd ~x86-freebsd ~x86-interix ~x86-linux ~x86-macos ~x86-solaris"
31 IUSE="berkdb debug doc gdbm ithreads"
32
33 RDEPEND="
34         berkdb? ( sys-libs/db:* )
35         gdbm? ( >=sys-libs/gdbm-1.8.3 )
36         app-arch/bzip2
37         sys-libs/zlib
38 "
39 DEPEND="${RDEPEND}
40         !prefix? ( elibc_FreeBSD? ( sys-freebsd/freebsd-mk-defs ) )
41 "
42 PDEPEND="
43         >=app-admin/perl-cleaner-2.5
44         >=virtual/perl-File-Temp-0.230.400-r2
45         >=virtual/perl-Data-Dumper-2.154.0
46         virtual/perl-Test-Harness
47 "
48 # bug 390719, bug 523624
49 # virtual/perl-Test-Harness is here for the bundled ExtUtils::MakeMaker
50
51 S="${WORKDIR}/${MY_P}"
52
53 dual_scripts() {
54         src_remove_dual      perl-core/Archive-Tar        2.40.0        ptar ptardiff ptargrep
55         src_remove_dual      perl-core/Digest-SHA         5.950.0       shasum
56         src_remove_dual      perl-core/CPAN               2.110.0       cpan
57         src_remove_dual      perl-core/Encode             2.800.0       enc2xs piconv
58         src_remove_dual      perl-core/ExtUtils-MakeMaker 7.100.100_rc  instmodsh
59         src_remove_dual      perl-core/ExtUtils-ParseXS   3.310.0       xsubpp
60         src_remove_dual      perl-core/IO-Compress        2.69.0        zipdetails
61         src_remove_dual      perl-core/JSON-PP            2.273.0       json_pp
62         src_remove_dual      perl-core/Module-CoreList    5.201.605.60  corelist
63         src_remove_dual      perl-core/Pod-Parser         1.630.0       pod2usage podchecker podselect
64         src_remove_dual      perl-core/Pod-Perldoc        3.250.200_rc  perldoc
65         src_remove_dual      perl-core/Test-Harness       3.360.0       prove
66         src_remove_dual      perl-core/podlators          4.70.0        pod2man pod2text
67         src_remove_dual_man  perl-core/podlators          4.70.0        /usr/share/man/man1/perlpodstyle.1
68 }
69
70 check_rebuild() {
71         if has_version "<dev-lang/perl-${SHORT_PV}" ; then
72                 echo ""
73                 ewarn "UPDATE THE PERL MODULES:"
74                 ewarn "After updating dev-lang/perl the installed Perl modules"
75                 ewarn "have to be re-installed. In most cases, this is done automatically"
76                 ewarn "by the package manager, but you should still call perl-cleaner to"
77                 ewarn "make sure your system is consistent."
78                 ewarn "Use: perl-cleaner --all"
79         elif has_version dev-lang/perl ; then
80                 if (   use ithreads && ! has_version dev-lang/perl[ithreads] ) || \
81                    ( ! use ithreads &&   has_version dev-lang/perl[ithreads] ) || \
82                    (   use debug    && ! has_version dev-lang/perl[debug]    ) || \
83                    ( ! use debug    &&   has_version dev-lang/perl[debug]    ) ; then
84                         echo ""
85                         ewarn "TOGGLED USE-FLAGS WARNING:"
86                         ewarn "You changed one of the use-flags ithreads or debug."
87                         ewarn "You must rebuild all perl-modules installed."
88                         ewarn "Use: perl-cleaner --modules ; perl-cleaner --force --libperl"
89                 fi
90         fi
91 }
92
93 pkg_setup() {
94         case ${CHOST} in
95                 *-freebsd*)   osname="freebsd" ;;
96                 *-dragonfly*) osname="dragonfly" ;;
97                 *-netbsd*)    osname="netbsd" ;;
98                 *-openbsd*)   osname="openbsd" ;;
99                 *-darwin*)    osname="darwin" ;;
100                 *-interix*)   osname="interix" ;;
101                 *-aix*)       osname="aix" ;;
102                 *-cygwin*)    osname="cygwin" ;;
103                 *)            osname="linux" ;;
104         esac
105
106         myarch="${CHOST%%-*}-${osname}"
107         if use debug ; then
108                 myarch+="-debug"
109         fi
110         if use ithreads ; then
111                 mythreading="-multi"
112                 myarch+="-thread"
113         fi
114
115         LIBPERL="libperl$(get_libname ${MY_PV} )"
116         PRIV_LIB="/usr/$(get_libdir)/perl5/${MY_PV}"
117         ARCH_LIB="/usr/$(get_libdir)/perl5/${MY_PV}/${myarch}${mythreading}"
118         SITE_LIB="/usr/local/$(get_libdir)/perl5/${MY_PV}"
119         SITE_ARCH="/usr/local/$(get_libdir)/perl5/${MY_PV}/${myarch}${mythreading}"
120         VENDOR_LIB="/usr/$(get_libdir)/perl5/vendor_perl/${MY_PV}"
121         VENDOR_ARCH="/usr/$(get_libdir)/perl5/vendor_perl/${MY_PV}/${myarch}${mythreading}"
122
123         dual_scripts
124 }
125
126 src_remove_dual_file() {
127         local i pkg ver
128         pkg="$1"
129         ver="$2"
130         shift 2
131         case "${EBUILD_PHASE:-none}" in
132                 postinst|postrm)
133                         for i in "$@" ; do
134                                 alternatives_auto_makesym "${i}" "${i}-[0-9]*"
135                         done
136                         ;;
137                 setup)
138                         for i in "$@" ; do
139                                 if [[ -f ${EROOT}${i} && ! -h ${EROOT}${i} ]] ; then
140                                         has_version ${pkg} && ewarn "You must reinstall ${pkg} !"
141                                         break
142                                 fi
143                         done
144                         ;;
145                 install)
146                         for i in "$@" ; do
147                                 if ! [[ -f "${ED}"${i} ]] ; then
148                                         ewarn "${i} does not exist!"
149                                         continue
150                                 fi
151                                 mv "${ED}"${i}{,-${ver}-${P}} || die
152                         done
153                         ;;
154         esac
155 }
156
157 src_remove_dual_man() {
158         local i pkg ver ff
159         pkg="$1"
160         ver="$2"
161         shift 2
162         case "${EBUILD_PHASE:-none}" in
163                 postinst|postrm)
164                         for i in "$@" ; do
165                                 ff=`echo "${EROOT}${i%.[0-9]}-${ver}-${P}${i#${i%.[0-9]}}"*`
166                                 ff=${ff##*${i#${i%.[0-9]}}}
167                                 alternatives_auto_makesym "${i}${ff}" "${i%.[0-9]}-[0-9]*"
168                         done
169                         ;;
170                 install)
171                         for i in "$@" ; do
172                                 if ! [[ -f "${ED}"${i} ]] ; then
173                                         ewarn "${i} does not exist!"
174                                         continue
175                                 fi
176                                 mv "${ED}"${i} "${ED}"${i%.[0-9]}-${ver}-${P}${i#${i%.[0-9]}} || die
177                         done
178                         ;;
179         esac
180 }
181
182 src_remove_dual() {
183         local i pkg ver
184         pkg="$1"
185         ver="$2"
186         shift 2
187         for i in "$@" ; do
188                 src_remove_dual_file  "${pkg}" "${ver}" "/usr/bin/${i}"
189                 src_remove_dual_man   "${pkg}" "${ver}" "/usr/share/man/man1/${i}.1"
190         done
191 }
192
193 src_prepare_update_patchlevel_h() {
194         # Copied and modified from debian:
195         # Copyright 2011 Niko Tyni
196         # This program is free software; you can redistribute it and/or modify
197         # it under the same terms as Perl itself.
198         local patchdir="${WORKDIR}/patches"
199         local prefix
200         local patchoutput="patchlevel-gentoo.h"
201
202         [[ -f ${patchdir}/series ]] || return 0
203
204 while read patch
205 do
206         patchname=$(echo $patch | sed 's/\.diff$//')
207         < $patchdir/$patch sed -e '/^Subject:/ { N; s/\n / / }' | sed -n -e '
208
209         # massage the patch headers
210         s|^Bug: .*https\?://rt\.perl\.org/.*id=\(.*\).*|[perl #\1]|; tprepend;
211         s|^Bug: .*https\?://rt\.cpan\.org/.*id=\(.*\).*|[rt.cpan.org #\1]|; tprepend;
212         s|^Bug-Gentoo: ||; tprepend;
213         s/^\(Subject\|Description\): //; tappend;
214         s|^Origin: .*http://perl5\.git\.perl\.org/perl\.git/commit\(diff\)\?/\(.......\).*|[\2]|; tprepend;
215
216         # post-process at the end of input
217         $ { x;
218                 # include the version number in the patchlevel.h description (if available)
219                 s/List packaged patches/&'" for ${PF}(#${PATCH_VER})"'/;
220
221                 # escape any backslashes and double quotes
222                 s|\\|\\\\|g; s|"|\\"|g;
223
224                 # add a prefix
225                 s|^|\t,"'"$prefix$patchname"' - |;
226                 # newlines away
227                 s/\n/ /g; s/  */ /g;
228                 # add a suffix
229                 s/ *$/"/; p
230         };
231         # stop all processing
232         d;
233         # label: append to the hold space
234         :append H; d;
235         # label: prepend to the hold space
236         :prepend x; H; d;
237         '
238 done < "${WORKDIR}"/patches/series > "${S}/${patchoutput}"
239 echo "${patchoutput}" >> "${S}/MANIFEST"
240 }
241
242 src_prepare() {
243         local patch
244         EPATCH_OPTS+=" -p1"
245         einfo "Applying patches from ${MY_P}-${PATCH_VER} ..."
246         while read patch ; do
247                 EPATCH_SINGLE_MSG="  ${patch} ..."
248                 epatch "${WORKDIR}"/patches/${patch}
249         done < "${WORKDIR}"/patches/series
250
251         src_prepare_update_patchlevel_h
252
253         if ! tc-is-static-only ; then
254                 ln -s ${LIBPERL} libperl$(get_libname ${SHORT_PV}) || die
255                 ln -s ${LIBPERL} libperl$(get_libname ) || die
256         fi
257
258         default
259 }
260
261 myconf() {
262         # the myconf array is declared in src_configure
263         myconf=( "${myconf[@]}" "$@" )
264 }
265
266 src_configure() {
267         declare -a myconf
268
269         export LC_ALL="C"
270         [[ ${COLUMNS:-1} -ge 1 ]] || unset COLUMNS # bug #394091
271
272         # some arches and -O do not mix :)
273         use ppc && replace-flags -O? -O1
274
275         # Perl has problems compiling with -Os in your flags with glibc
276         use elibc_uclibc || replace-flags "-Os" "-O2"
277
278         # This flag makes compiling crash in interesting ways
279         filter-flags "-malign-double"
280
281         # Fixes bug #97645
282         use ppc && filter-flags "-mpowerpc-gpopt"
283
284         # Fixes bug #143895 on gcc-4.1.1
285         filter-flags "-fsched2-use-superblocks"
286
287         use sparc && myconf -Ud_longdbl
288
289         export BUILD_BZIP2=0
290         export BZIP2_INCLUDE=${EPREFIX}/usr/include
291         export BZIP2_LIB=${EPREFIX}/usr/$(get_libdir)
292
293         export BUILD_ZLIB=False
294         export ZLIB_INCLUDE=${EPREFIX}/usr/include
295         export ZLIB_LIB=${EPREFIX}/usr/$(get_libdir)
296
297         # allow either gdbm to provide ndbm (in <gdbm/ndbm.h>) or db1
298         myndbm='U'
299         mygdbm='U'
300         mydb='U'
301         if use gdbm ; then
302                 mygdbm='D'
303                 myndbm='D'
304         fi
305         if use berkdb ; then
306                 mydb='D'
307                 has_version '=sys-libs/db-1*' && myndbm='D'
308         fi
309
310         myconf "-${myndbm}i_ndbm" "-${mygdbm}i_gdbm" "-${mydb}i_db"
311
312         if use alpha && [[ "$(tc-getCC)" = "ccc" ]] ; then
313                 ewarn "Perl will not be built with berkdb support, use gcc if you needed it..."
314                 myconf -Ui_db -Ui_ndbm
315         fi
316
317         use ithreads && myconf -Dusethreads
318
319         if use debug ; then
320                 append-cflags "-g"
321                 myconf -DDEBUGGING
322         elif [[ ${CFLAGS} == *-g* ]] ; then
323                 myconf -DDEBUGGING=-g
324         else
325                 myconf -DDEBUGGING=none
326         fi
327
328         if [[ -n ${PERL_OLDVERSEN} ]] ; then
329                 local inclist=$(for v in ${PERL_OLDVERSEN}; do echo -n "${v}/${myarch}${mythreading} ${v} "; done )
330                 myconf -Dinc_version_list="${inclist}"
331         fi
332
333         [[ ${ELIBC} == "FreeBSD" ]] && myconf "-Dlibc=/usr/$(get_libdir)/libc.a"
334
335         # Make sure we can do the final link #523730, need to set deployment
336         # target to override hardcoded 10.3 which breaks on modern OSX
337         [[ ${CHOST} == *-darwin* ]] && \
338                 myconf "-Dld=env MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} $(tc-getCC)"
339
340         # Prefix: the host system needs not to follow Gentoo multilib stuff, and in
341         # Prefix itself we don't do multilib either, so make sure perl can find
342         # something compatible.
343         if use prefix ; then
344                 # Set a hook to check for each detected library whether it actually works.
345                 export libscheck="
346                         ( echo 'main(){}' > '${T}'/conftest.c &&
347                           $(tc-getCC) -o '${T}'/conftest '${T}'/conftest.c -l\$thislib >/dev/null 2>/dev/null
348                         ) || xxx=/dev/null"
349
350                 # Use all host paths that might contain useful stuff, the hook above will filter out bad choices.
351                 local paths="/lib/*-linux-gnu /usr/lib/*-linux-gnu /lib64 /lib/64 /usr/lib64 /usr/lib/64 /lib32 /usr/lib32 /lib /usr/lib"
352                 myconf "-Dlibpth=${EPREFIX}/$(get_libdir) ${EPREFIX}/usr/$(get_libdir) ${paths}"
353         elif [[ $(get_libdir) != "lib" ]] ; then
354                 # We need to use " and not ', as the written config.sh use ' ...
355                 myconf "-Dlibpth=/usr/local/$(get_libdir) /$(get_libdir) /usr/$(get_libdir)"
356         fi
357
358         # don't try building ODBM, bug #354453
359         disabled_extensions="ODBM_File"
360
361         if ! use gdbm ; then
362                 # workaround for bug #157774: don't try building GDBM related stuff with USE="-gdbm"
363                 disabled_extensions="${disabled_extensions} GDBM_File NDBM_File"
364         fi
365
366         myconf -Dnoextensions="${disabled_extensions}"
367
368         sh Configure \
369                 -des \
370                 -Duseshrplib \
371                 -Darchname="${myarch}" \
372                 -Dcc="$(tc-getCC)" \
373                 -Doptimize="${CFLAGS}" \
374                 -Dldflags="${LDFLAGS}" \
375                 -Dprefix="${EPREFIX}"'/usr' \
376                 -Dinstallprefix="${EPREFIX}"'/usr' \
377                 -Dsiteprefix="${EPREFIX}"'/usr/local' \
378                 -Dvendorprefix="${EPREFIX}"'/usr' \
379                 -Dscriptdir="${EPREFIX}"'/usr/bin' \
380                 -Dprivlib="${EPREFIX}${PRIV_LIB}" \
381                 -Darchlib="${EPREFIX}${ARCH_LIB}" \
382                 -Dsitelib="${EPREFIX}${SITE_LIB}" \
383                 -Dsitearch="${EPREFIX}${SITE_ARCH}" \
384                 -Dvendorlib="${EPREFIX}${VENDOR_LIB}" \
385                 -Dvendorarch="${EPREFIX}${VENDOR_ARCH}" \
386                 -Dman1dir="${EPREFIX}"/usr/share/man/man1 \
387                 -Dman3dir="${EPREFIX}"/usr/share/man/man3 \
388                 -Dsiteman1dir="${EPREFIX}"/usr/local/man/man1 \
389                 -Dsiteman3dir="${EPREFIX}"/usr/local/man/man3 \
390                 -Dvendorman1dir="${EPREFIX}"/usr/share/man/man1 \
391                 -Dvendorman3dir="${EPREFIX}"/usr/share/man/man3 \
392                 -Dman1ext='1' \
393                 -Dman3ext='3pm' \
394                 -Dlibperl="${LIBPERL}" \
395                 -Dlocincpth="${EPREFIX}"'/usr/include ' \
396                 -Dglibpth="${EPREFIX}/$(get_libdir) ${EPREFIX}/usr/$(get_libdir)"' ' \
397                 -Duselargefiles \
398                 -Dd_semctl_semun \
399                 -Dcf_by='Gentoo' \
400                 -Dmyhostname='localhost' \
401                 -Dperladmin='root@localhost' \
402                 -Dinstallusrbinperl='n' \
403                 -Ud_csh \
404                 -Dsh="${EPREFIX}"/bin/sh \
405                 -Dtargetsh="${EPREFIX}"/bin/sh \
406                 -Uusenm \
407                 "${myconf[@]}" || die "Unable to configure"
408 }
409
410 src_test() {
411         export NO_GENTOO_NETWORK_TESTS=1;
412         if [[ ${EUID} == 0 ]] ; then
413                 ewarn "Test fails with a sandbox error (#328793) if run as root. Skipping tests..."
414                 return 0
415         fi
416         use elibc_uclibc && export MAKEOPTS+=" -j1"
417         TEST_JOBS="$(makeopts_jobs)" make test_harness || die "test failed"
418 }
419
420 src_install() {
421         local i
422         local coredir="${ARCH_LIB}/CORE"
423
424         emake DESTDIR="${D}" install
425
426         rm -f "${ED}/usr/bin/perl${MY_PV}"
427         ln -s perl "${ED}"/usr/bin/perl${MY_PV} || die
428
429         if ! tc-is-static-only ; then
430                 dolib.so "${ED}"${coredir}/${LIBPERL}
431                 rm -f "${ED}"${coredir}/${LIBPERL}
432                 ln -sf ${LIBPERL} "${ED}"/usr/$(get_libdir)/libperl$(get_libname ${SHORT_PV}) || die
433                 ln -sf ${LIBPERL} "${ED}"/usr/$(get_libdir)/libperl$(get_libname) || die
434                 ln -sf ../../../../../$(get_libdir)/${LIBPERL} "${ED}"${coredir}/${LIBPERL} || die
435                 ln -sf ../../../../../$(get_libdir)/${LIBPERL} "${ED}"${coredir}/libperl$(get_libname ${SHORT_PV}) || die
436                 ln -sf ../../../../../$(get_libdir)/${LIBPERL} "${ED}"${coredir}/libperl$(get_libname) || die
437         fi
438
439         rm -rf "${ED}"/usr/share/man/man3 || die "Unable to remove module man pages"
440
441         # This removes ${D} from Config.pm
442         for i in $(find "${D}" -iname "Config.pm" ) ; do
443                 einfo "Removing ${D} from ${i}..."
444                 sed -i -e "s:${D}::" "${i}" || die "Sed failed"
445         done
446
447         dodoc Changes* README AUTHORS
448
449         if use doc ; then
450                 # HTML Documentation
451                 # We expect errors, warnings, and such with the following.
452
453                 dodir /usr/share/doc/${PF}/html
454                 LD_LIBRARY_PATH=. ./perl installhtml \
455                         --podroot='.' \
456                         --podpath='lib:ext:pod:vms' \
457                         --recurse \
458                         --htmldir="${ED}/usr/share/doc/${PF}/html"
459         fi
460
461         [[ -d ${ED}/usr/local ]] && rm -r "${ED}"/usr/local
462
463         dual_scripts
464 }
465
466 pkg_postinst() {
467         dual_scripts
468
469         if [[ "${ROOT}" = "/" ]] ; then
470                 local INC DIR file
471                 INC=$(perl -e 'for $line (@INC) { next if $line eq "."; next if $line =~ m/'${SHORT_PV}'|etc|local|perl$/; print "$line\n" }')
472                 einfo "Removing old .ph files"
473                 for DIR in ${INC} ; do
474                         if [[ -d "${DIR}" ]] ; then
475                                 for file in $(find "${DIR}" -name "*.ph" -type f ) ; do
476                                         rm -f "${file}"
477                                         einfo "<< ${file}"
478                                 done
479                         fi
480                 done
481                 # Silently remove the now empty dirs
482                 for DIR in ${INC} ; do
483                         if [[ -d "${DIR}" ]] ; then
484                                 find "${DIR}" -depth -type d -print0 | xargs -0 -r rmdir &> /dev/null
485                         fi
486                 done
487
488         fi
489 }
490
491 pkg_postrm(){
492         dual_scripts
493 }