dev-lang/perl: Update upgrade prose to encourage depclean
[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 subsequent steps are still recommended"
77                 ewarn "to ensure system consistency."
78                 ewarn
79                 ewarn "You should start with a depclean to remove any unused perl dependencies"
80                 ewarn "that may confuse portage in future. Regular depcleans are also encouraged"
81                 ewarn "as part of your regular update cycle, as that will keep perl upgrades working."
82                 ewarn "Recommended: emerge --depclean -va"
83                 ewarn
84                 ewarn "You should then call perl-cleaner to clean up any old files and trigger any"
85                 ewarn "remaining rebuilds portage may have missed."
86                 ewarn "Use: perl-cleaner --all"
87         elif has_version dev-lang/perl ; then
88                 if (   use ithreads && ! has_version dev-lang/perl[ithreads] ) || \
89                    ( ! use ithreads &&   has_version dev-lang/perl[ithreads] ) || \
90                    (   use debug    && ! has_version dev-lang/perl[debug]    ) || \
91                    ( ! use debug    &&   has_version dev-lang/perl[debug]    ) ; then
92                         echo ""
93                         ewarn "TOGGLED USE-FLAGS WARNING:"
94                         ewarn "You changed one of the use-flags ithreads or debug."
95                         ewarn "You must rebuild all perl-modules installed."
96                         ewarn "Use: perl-cleaner --modules ; perl-cleaner --force --libperl"
97                 fi
98         fi
99 }
100
101 pkg_setup() {
102         case ${CHOST} in
103                 *-freebsd*)   osname="freebsd" ;;
104                 *-dragonfly*) osname="dragonfly" ;;
105                 *-netbsd*)    osname="netbsd" ;;
106                 *-openbsd*)   osname="openbsd" ;;
107                 *-darwin*)    osname="darwin" ;;
108                 *-interix*)   osname="interix" ;;
109                 *-aix*)       osname="aix" ;;
110                 *-cygwin*)    osname="cygwin" ;;
111                 *)            osname="linux" ;;
112         esac
113
114         myarch="${CHOST%%-*}-${osname}"
115         if use debug ; then
116                 myarch+="-debug"
117         fi
118         if use ithreads ; then
119                 mythreading="-multi"
120                 myarch+="-thread"
121         fi
122
123         LIBPERL="libperl$(get_libname ${MY_PV} )"
124         PRIV_LIB="/usr/$(get_libdir)/perl5/${MY_PV}"
125         ARCH_LIB="/usr/$(get_libdir)/perl5/${MY_PV}/${myarch}${mythreading}"
126         SITE_LIB="/usr/local/$(get_libdir)/perl5/${MY_PV}"
127         SITE_ARCH="/usr/local/$(get_libdir)/perl5/${MY_PV}/${myarch}${mythreading}"
128         VENDOR_LIB="/usr/$(get_libdir)/perl5/vendor_perl/${MY_PV}"
129         VENDOR_ARCH="/usr/$(get_libdir)/perl5/vendor_perl/${MY_PV}/${myarch}${mythreading}"
130
131         dual_scripts
132 }
133
134 src_remove_dual_file() {
135         local i pkg ver
136         pkg="$1"
137         ver="$2"
138         shift 2
139         case "${EBUILD_PHASE:-none}" in
140                 postinst|postrm)
141                         for i in "$@" ; do
142                                 alternatives_auto_makesym "${i}" "${i}-[0-9]*"
143                         done
144                         ;;
145                 setup)
146                         for i in "$@" ; do
147                                 if [[ -f ${EROOT}${i} && ! -h ${EROOT}${i} ]] ; then
148                                         has_version ${pkg} && ewarn "You must reinstall ${pkg} !"
149                                         break
150                                 fi
151                         done
152                         ;;
153                 install)
154                         for i in "$@" ; do
155                                 if ! [[ -f "${ED}"${i} ]] ; then
156                                         ewarn "${i} does not exist!"
157                                         continue
158                                 fi
159                                 mv "${ED}"${i}{,-${ver}-${P}} || die
160                         done
161                         ;;
162         esac
163 }
164
165 src_remove_dual_man() {
166         local i pkg ver ff
167         pkg="$1"
168         ver="$2"
169         shift 2
170         case "${EBUILD_PHASE:-none}" in
171                 postinst|postrm)
172                         for i in "$@" ; do
173                                 ff=`echo "${EROOT}${i%.[0-9]}-${ver}-${P}${i#${i%.[0-9]}}"*`
174                                 ff=${ff##*${i#${i%.[0-9]}}}
175                                 alternatives_auto_makesym "${i}${ff}" "${i%.[0-9]}-[0-9]*"
176                         done
177                         ;;
178                 install)
179                         for i in "$@" ; do
180                                 if ! [[ -f "${ED}"${i} ]] ; then
181                                         ewarn "${i} does not exist!"
182                                         continue
183                                 fi
184                                 mv "${ED}"${i} "${ED}"${i%.[0-9]}-${ver}-${P}${i#${i%.[0-9]}} || die
185                         done
186                         ;;
187         esac
188 }
189
190 src_remove_dual() {
191         local i pkg ver
192         pkg="$1"
193         ver="$2"
194         shift 2
195         for i in "$@" ; do
196                 src_remove_dual_file  "${pkg}" "${ver}" "/usr/bin/${i}"
197                 src_remove_dual_man   "${pkg}" "${ver}" "/usr/share/man/man1/${i}.1"
198         done
199 }
200
201 src_prepare_update_patchlevel_h() {
202         # Copied and modified from debian:
203         # Copyright 2011 Niko Tyni
204         # This program is free software; you can redistribute it and/or modify
205         # it under the same terms as Perl itself.
206         local patchdir="${WORKDIR}/patches"
207         local prefix
208         local patchoutput="patchlevel-gentoo.h"
209
210         [[ -f ${patchdir}/series ]] || return 0
211
212 while read patch
213 do
214         patchname=$(echo $patch | sed 's/\.diff$//')
215         < $patchdir/$patch sed -e '/^Subject:/ { N; s/\n / / }' | sed -n -e '
216
217         # massage the patch headers
218         s|^Bug: .*https\?://rt\.perl\.org/.*id=\(.*\).*|[perl #\1]|; tprepend;
219         s|^Bug: .*https\?://rt\.cpan\.org/.*id=\(.*\).*|[rt.cpan.org #\1]|; tprepend;
220         s|^Bug-Gentoo: ||; tprepend;
221         s/^\(Subject\|Description\): //; tappend;
222         s|^Origin: .*http://perl5\.git\.perl\.org/perl\.git/commit\(diff\)\?/\(.......\).*|[\2]|; tprepend;
223
224         # post-process at the end of input
225         $ { x;
226                 # include the version number in the patchlevel.h description (if available)
227                 s/List packaged patches/&'" for ${PF}(#${PATCH_VER})"'/;
228
229                 # escape any backslashes and double quotes
230                 s|\\|\\\\|g; s|"|\\"|g;
231
232                 # add a prefix
233                 s|^|\t,"'"$prefix$patchname"' - |;
234                 # newlines away
235                 s/\n/ /g; s/  */ /g;
236                 # add a suffix
237                 s/ *$/"/; p
238         };
239         # stop all processing
240         d;
241         # label: append to the hold space
242         :append H; d;
243         # label: prepend to the hold space
244         :prepend x; H; d;
245         '
246 done < "${WORKDIR}"/patches/series > "${S}/${patchoutput}"
247 echo "${patchoutput}" >> "${S}/MANIFEST"
248 }
249
250 src_prepare() {
251         local patch
252         EPATCH_OPTS+=" -p1"
253         einfo "Applying patches from ${MY_P}-${PATCH_VER} ..."
254         while read patch ; do
255                 EPATCH_SINGLE_MSG="  ${patch} ..."
256                 epatch "${WORKDIR}"/patches/${patch}
257         done < "${WORKDIR}"/patches/series
258
259         src_prepare_update_patchlevel_h
260
261         if ! tc-is-static-only ; then
262                 ln -s ${LIBPERL} libperl$(get_libname ${SHORT_PV}) || die
263                 ln -s ${LIBPERL} libperl$(get_libname ) || die
264         fi
265
266         default
267 }
268
269 myconf() {
270         # the myconf array is declared in src_configure
271         myconf=( "${myconf[@]}" "$@" )
272 }
273
274 src_configure() {
275         declare -a myconf
276
277         export LC_ALL="C"
278         [[ ${COLUMNS:-1} -ge 1 ]] || unset COLUMNS # bug #394091
279
280         # some arches and -O do not mix :)
281         use ppc && replace-flags -O? -O1
282
283         # Perl has problems compiling with -Os in your flags with glibc
284         use elibc_uclibc || replace-flags "-Os" "-O2"
285
286         # This flag makes compiling crash in interesting ways
287         filter-flags "-malign-double"
288
289         # Fixes bug #97645
290         use ppc && filter-flags "-mpowerpc-gpopt"
291
292         # Fixes bug #143895 on gcc-4.1.1
293         filter-flags "-fsched2-use-superblocks"
294
295         use sparc && myconf -Ud_longdbl
296
297         export BUILD_BZIP2=0
298         export BZIP2_INCLUDE=${EPREFIX}/usr/include
299         export BZIP2_LIB=${EPREFIX}/usr/$(get_libdir)
300
301         export BUILD_ZLIB=False
302         export ZLIB_INCLUDE=${EPREFIX}/usr/include
303         export ZLIB_LIB=${EPREFIX}/usr/$(get_libdir)
304
305         # allow either gdbm to provide ndbm (in <gdbm/ndbm.h>) or db1
306         myndbm='U'
307         mygdbm='U'
308         mydb='U'
309         if use gdbm ; then
310                 mygdbm='D'
311                 myndbm='D'
312         fi
313         if use berkdb ; then
314                 mydb='D'
315                 has_version '=sys-libs/db-1*' && myndbm='D'
316         fi
317
318         myconf "-${myndbm}i_ndbm" "-${mygdbm}i_gdbm" "-${mydb}i_db"
319
320         if use alpha && [[ "$(tc-getCC)" = "ccc" ]] ; then
321                 ewarn "Perl will not be built with berkdb support, use gcc if you needed it..."
322                 myconf -Ui_db -Ui_ndbm
323         fi
324
325         use ithreads && myconf -Dusethreads
326
327         if use debug ; then
328                 append-cflags "-g"
329                 myconf -DDEBUGGING
330         elif [[ ${CFLAGS} == *-g* ]] ; then
331                 myconf -DDEBUGGING=-g
332         else
333                 myconf -DDEBUGGING=none
334         fi
335
336         if [[ -n ${PERL_OLDVERSEN} ]] ; then
337                 local inclist=$(for v in ${PERL_OLDVERSEN}; do echo -n "${v}/${myarch}${mythreading} ${v} "; done )
338                 myconf -Dinc_version_list="${inclist}"
339         fi
340
341         [[ ${ELIBC} == "FreeBSD" ]] && myconf "-Dlibc=/usr/$(get_libdir)/libc.a"
342
343         # Make sure we can do the final link #523730, need to set deployment
344         # target to override hardcoded 10.3 which breaks on modern OSX
345         [[ ${CHOST} == *-darwin* ]] && \
346                 myconf "-Dld=env MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} $(tc-getCC)"
347
348         # Prefix: the host system needs not to follow Gentoo multilib stuff, and in
349         # Prefix itself we don't do multilib either, so make sure perl can find
350         # something compatible.
351         if use prefix ; then
352                 # Set a hook to check for each detected library whether it actually works.
353                 export libscheck="
354                         ( echo 'main(){}' > '${T}'/conftest.c &&
355                           $(tc-getCC) -o '${T}'/conftest '${T}'/conftest.c -l\$thislib >/dev/null 2>/dev/null
356                         ) || xxx=/dev/null"
357
358                 # Use all host paths that might contain useful stuff, the hook above will filter out bad choices.
359                 local paths="/lib/*-linux-gnu /usr/lib/*-linux-gnu /lib64 /lib/64 /usr/lib64 /usr/lib/64 /lib32 /usr/lib32 /lib /usr/lib"
360                 myconf "-Dlibpth=${EPREFIX}/$(get_libdir) ${EPREFIX}/usr/$(get_libdir) ${paths}"
361         elif [[ $(get_libdir) != "lib" ]] ; then
362                 # We need to use " and not ', as the written config.sh use ' ...
363                 myconf "-Dlibpth=/usr/local/$(get_libdir) /$(get_libdir) /usr/$(get_libdir)"
364         fi
365
366         # don't try building ODBM, bug #354453
367         disabled_extensions="ODBM_File"
368
369         if ! use gdbm ; then
370                 # workaround for bug #157774: don't try building GDBM related stuff with USE="-gdbm"
371                 disabled_extensions="${disabled_extensions} GDBM_File NDBM_File"
372         fi
373
374         myconf -Dnoextensions="${disabled_extensions}"
375
376         sh Configure \
377                 -des \
378                 -Duseshrplib \
379                 -Darchname="${myarch}" \
380                 -Dcc="$(tc-getCC)" \
381                 -Doptimize="${CFLAGS}" \
382                 -Dldflags="${LDFLAGS}" \
383                 -Dprefix="${EPREFIX}"'/usr' \
384                 -Dinstallprefix="${EPREFIX}"'/usr' \
385                 -Dsiteprefix="${EPREFIX}"'/usr/local' \
386                 -Dvendorprefix="${EPREFIX}"'/usr' \
387                 -Dscriptdir="${EPREFIX}"'/usr/bin' \
388                 -Dprivlib="${EPREFIX}${PRIV_LIB}" \
389                 -Darchlib="${EPREFIX}${ARCH_LIB}" \
390                 -Dsitelib="${EPREFIX}${SITE_LIB}" \
391                 -Dsitearch="${EPREFIX}${SITE_ARCH}" \
392                 -Dvendorlib="${EPREFIX}${VENDOR_LIB}" \
393                 -Dvendorarch="${EPREFIX}${VENDOR_ARCH}" \
394                 -Dman1dir="${EPREFIX}"/usr/share/man/man1 \
395                 -Dman3dir="${EPREFIX}"/usr/share/man/man3 \
396                 -Dsiteman1dir="${EPREFIX}"/usr/local/man/man1 \
397                 -Dsiteman3dir="${EPREFIX}"/usr/local/man/man3 \
398                 -Dvendorman1dir="${EPREFIX}"/usr/share/man/man1 \
399                 -Dvendorman3dir="${EPREFIX}"/usr/share/man/man3 \
400                 -Dman1ext='1' \
401                 -Dman3ext='3pm' \
402                 -Dlibperl="${LIBPERL}" \
403                 -Dlocincpth="${EPREFIX}"'/usr/include ' \
404                 -Dglibpth="${EPREFIX}/$(get_libdir) ${EPREFIX}/usr/$(get_libdir)"' ' \
405                 -Duselargefiles \
406                 -Dd_semctl_semun \
407                 -Dcf_by='Gentoo' \
408                 -Dmyhostname='localhost' \
409                 -Dperladmin='root@localhost' \
410                 -Dinstallusrbinperl='n' \
411                 -Ud_csh \
412                 -Dsh="${EPREFIX}"/bin/sh \
413                 -Dtargetsh="${EPREFIX}"/bin/sh \
414                 -Uusenm \
415                 "${myconf[@]}" || die "Unable to configure"
416 }
417
418 src_test() {
419         export NO_GENTOO_NETWORK_TESTS=1;
420         if [[ ${EUID} == 0 ]] ; then
421                 ewarn "Test fails with a sandbox error (#328793) if run as root. Skipping tests..."
422                 return 0
423         fi
424         use elibc_uclibc && export MAKEOPTS+=" -j1"
425         TEST_JOBS="$(makeopts_jobs)" make test_harness || die "test failed"
426 }
427
428 src_install() {
429         local i
430         local coredir="${ARCH_LIB}/CORE"
431
432         emake DESTDIR="${D}" install
433
434         rm -f "${ED}/usr/bin/perl${MY_PV}"
435         ln -s perl "${ED}"/usr/bin/perl${MY_PV} || die
436
437         if ! tc-is-static-only ; then
438                 dolib.so "${ED}"${coredir}/${LIBPERL}
439                 rm -f "${ED}"${coredir}/${LIBPERL}
440                 ln -sf ${LIBPERL} "${ED}"/usr/$(get_libdir)/libperl$(get_libname ${SHORT_PV}) || die
441                 ln -sf ${LIBPERL} "${ED}"/usr/$(get_libdir)/libperl$(get_libname) || die
442                 ln -sf ../../../../../$(get_libdir)/${LIBPERL} "${ED}"${coredir}/${LIBPERL} || die
443                 ln -sf ../../../../../$(get_libdir)/${LIBPERL} "${ED}"${coredir}/libperl$(get_libname ${SHORT_PV}) || die
444                 ln -sf ../../../../../$(get_libdir)/${LIBPERL} "${ED}"${coredir}/libperl$(get_libname) || die
445         fi
446
447         rm -rf "${ED}"/usr/share/man/man3 || die "Unable to remove module man pages"
448
449         # This removes ${D} from Config.pm
450         for i in $(find "${D}" -iname "Config.pm" ) ; do
451                 einfo "Removing ${D} from ${i}..."
452                 sed -i -e "s:${D}::" "${i}" || die "Sed failed"
453         done
454
455         dodoc Changes* README AUTHORS
456
457         if use doc ; then
458                 # HTML Documentation
459                 # We expect errors, warnings, and such with the following.
460
461                 dodir /usr/share/doc/${PF}/html
462                 LD_LIBRARY_PATH=. ./perl installhtml \
463                         --podroot='.' \
464                         --podpath='lib:ext:pod:vms' \
465                         --recurse \
466                         --htmldir="${ED}/usr/share/doc/${PF}/html"
467         fi
468
469         [[ -d ${ED}/usr/local ]] && rm -r "${ED}"/usr/local
470
471         dual_scripts
472 }
473
474 pkg_postinst() {
475         dual_scripts
476
477         if [[ "${ROOT}" = "/" ]] ; then
478                 local INC DIR file
479                 INC=$(perl -e 'for $line (@INC) { next if $line eq "."; next if $line =~ m/'${SHORT_PV}'|etc|local|perl$/; print "$line\n" }')
480                 einfo "Removing old .ph files"
481                 for DIR in ${INC} ; do
482                         if [[ -d "${DIR}" ]] ; then
483                                 for file in $(find "${DIR}" -name "*.ph" -type f ) ; do
484                                         rm -f "${file}"
485                                         einfo "<< ${file}"
486                                 done
487                         fi
488                 done
489                 # Silently remove the now empty dirs
490                 for DIR in ${INC} ; do
491                         if [[ -d "${DIR}" ]] ; then
492                                 find "${DIR}" -depth -type d -print0 | xargs -0 -r rmdir &> /dev/null
493                         fi
494                 done
495
496         fi
497 }
498
499 pkg_postrm(){
500         dual_scripts
501 }