x11-themes/gentoo10-backgrounds: Cleanup per bug #85210
[gentoo.git] / eclass / perl-module.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: perl-module.eclass
6 # @MAINTAINER:
7 # perl@gentoo.org
8 # @AUTHOR:
9 # Seemant Kulleen <seemant@gentoo.org>
10 # Andreas K. Hüttel <dilfridge@gentoo.org>
11 # @BLURB: eclass for installing Perl module distributions
12 # @DESCRIPTION:
13 # The perl-module eclass is designed to allow easier installation of Perl
14 # module distributions, and their incorporation into the Gentoo Linux system.
15 # All exported functions from perl-functions.eclass (inherited here)
16 # explicitly also belong to the interface of perl-module.eclass.
17 # If your package does not use any Perl-specific build system (as, e.g.,
18 # ExtUtils::MakeMaker or Module::Build), we recommend to use perl-functions.eclass
19 # instead.
20
21 case ${EAPI:-0} in
22         5)
23                 inherit eutils multiprocessing unpacker perl-functions
24                 PERL_EXPF="src_unpack src_prepare src_configure src_compile src_test src_install"
25                 ;;
26         6)
27                 inherit multiprocessing perl-functions
28                 PERL_EXPF="src_prepare src_configure src_compile src_test src_install"
29                 ;;
30         *)
31                 die "EAPI=${EAPI} is not supported by perl-module.eclass"
32                 ;;
33 esac
34
35 # @ECLASS-VARIABLE: GENTOO_DEPEND_ON_PERL
36 # @DESCRIPTION:
37 # This variable controls whether a runtime and build time dependency on
38 # dev-lang/perl is automatically added by the eclass. It defaults to yes.
39 # Set to no to disable, set to noslotop to add a perl dependency without
40 # slot operator (EAPI=6). All packages installing into the vendor_perl
41 # path must use yes here.
42
43 case ${EAPI:-0} in
44         5)
45                 [[ ${CATEGORY} == perl-core ]] && \
46                         PERL_EXPF+=" pkg_postinst pkg_postrm"
47
48                 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
49                 yes)
50                         case "${GENTOO_DEPEND_ON_PERL_SUBSLOT:-yes}" in
51                         yes)
52                                 DEPEND="dev-lang/perl:=[-build(-)]"
53                                 ;;
54                         *)
55                                 DEPEND="dev-lang/perl[-build(-)]"
56                                 ;;
57                         esac
58                         RDEPEND="${DEPEND}"
59                         ;;
60                 esac
61
62                 case "${PERL_EXPORT_PHASE_FUNCTIONS:-yes}" in
63                         yes)
64                                 EXPORT_FUNCTIONS ${PERL_EXPF}
65                                 ;;
66                         no)
67                                 debug-print "PERL_EXPORT_PHASE_FUNCTIONS=no"
68                                 ;;
69                         *)
70                                 die "PERL_EXPORT_PHASE_FUNCTIONS=${PERL_EXPORT_PHASE_FUNCTIONS} is not supported by perl-module.eclass"
71                                 ;;
72                 esac
73                 ;;
74         6)
75                 [[ ${CATEGORY} == perl-core ]] && \
76                         PERL_EXPF+=" pkg_postinst pkg_postrm"
77
78                 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
79                         yes)
80                                 DEPEND="dev-lang/perl:="
81                                 RDEPEND="dev-lang/perl:="
82                                 ;;
83                         noslotop)
84                                 DEPEND="dev-lang/perl"
85                                 RDEPEND="dev-lang/perl"
86                                 ;;
87                 esac
88
89                 if [[ "${GENTOO_DEPEND_ON_PERL_SUBSLOT}" ]]; then
90                         eerror "GENTOO_DEPEND_ON_PERL_SUBSLOT is banned in EAPI=6. If you don't want a slot operator"
91                         die    "set GENTOO_DEPEND_ON_PERL=noslotop instead."
92                 fi
93
94                 if [[ "${PERL_EXPORT_PHASE_FUNCTIONS}" ]]; then
95                         eerror "PERL_EXPORT_PHASE_FUNCTIONS is banned in EAPI=6. Use perl-module.eclass if you need"
96                         die    "phase functions, perl-functions.eclass if not."
97                 fi
98
99                 EXPORT_FUNCTIONS ${PERL_EXPF}
100                 ;;
101         *)
102                 die "EAPI=${EAPI:-0} is not supported by perl-module.eclass"
103                 ;;
104 esac
105
106 LICENSE="${LICENSE:-|| ( Artistic GPL-1+ )}"
107
108 # @ECLASS-VARIABLE: DIST_NAME
109 # @DESCRIPTION:
110 # (EAPI=6) This variable provides a way to override PN for the calculation of S,
111 # SRC_URI, and HOMEPAGE. Defaults to PN.
112
113 # @ECLASS-VARIABLE: DIST_VERSION
114 # @DESCRIPTION:
115 # (EAPI=6) This variable provides a way to override PV for the calculation of S and SRC_URI.
116 # Use it to provide the non-normalized, upstream version number. Defaults to PV.
117 # Named MODULE_VERSION in EAPI=5.
118
119 # @ECLASS-VARIABLE: DIST_A_EXT
120 # @DESCRIPTION:
121 # (EAPI=6) This variable provides a way to override the distfile extension for the calculation of
122 # SRC_URI. Defaults to tar.gz. Named MODULE_A_EXT in EAPI=5.
123
124 # @ECLASS-VARIABLE: DIST_A
125 # @DESCRIPTION:
126 # (EAPI=6) This variable provides a way to override the distfile name for the calculation of
127 # SRC_URI. Defaults to ${DIST_NAME}-${DIST_VERSION}.${DIST_A_EXT} Named MODULE_A in EAPI=5.
128
129 # @ECLASS-VARIABLE: DIST_AUTHOR
130 # @DESCRIPTION:
131 # (EAPI=6) This variable sets the module author name for the calculation of
132 # SRC_URI. Named MODULE_AUTHOR in EAPI=5.
133
134 # @ECLASS-VARIABLE: DIST_EXAMPLES
135 # @DESCRIPTION:
136 # (EAPI=6) This Bash array allows passing a list of example files to be installed
137 # in /usr/share/doc/${PF}/examples. If set before inherit, automatically adds
138 # a use-flag examples, if not you'll have to add the useflag in your ebuild.
139 # Examples are installed only if the useflag examples exists and is activated.
140
141
142 if [[ ${EAPI:-0} == 5 ]]; then
143         if [[ -n ${MY_PN} || -n ${MY_PV} || -n ${MODULE_VERSION} ]] ; then
144                 : ${MY_P:=${MY_PN:-${PN}}-${MY_PV:-${MODULE_VERSION:-${PV}}}}
145                 S=${MY_S:-${WORKDIR}/${MY_P}}
146         fi
147         MODULE_NAME=${MY_PN:-${PN}}
148         MODULE_P=${MY_P:-${P}}
149
150         [[ -z "${SRC_URI}" && -z "${MODULE_A}" ]] && \
151                 MODULE_A="${MODULE_P}.${MODULE_A_EXT:-tar.gz}"
152         [[ -z "${SRC_URI}" && -n "${MODULE_AUTHOR}" ]] && \
153                 SRC_URI="mirror://cpan/authors/id/${MODULE_AUTHOR:0:1}/${MODULE_AUTHOR:0:2}/${MODULE_AUTHOR}/${MODULE_SECTION:+${MODULE_SECTION}/}${MODULE_A}"
154         [[ -z "${HOMEPAGE}" ]] && \
155                 HOMEPAGE="http://search.cpan.org/dist/${MODULE_NAME}/"
156
157         SRC_TEST="skip"
158 else
159         DIST_NAME=${DIST_NAME:-${PN}}
160         DIST_P=${DIST_NAME}-${DIST_VERSION:-${PV}}
161         S=${WORKDIR}/${DIST_P}
162
163         [[ -z "${SRC_URI}" && -z "${DIST_A}" ]] && \
164                 DIST_A="${DIST_P}.${DIST_A_EXT:-tar.gz}"
165         [[ -z "${SRC_URI}" && -n "${DIST_AUTHOR}" ]] && \
166                 SRC_URI="mirror://cpan/authors/id/${DIST_AUTHOR:0:1}/${DIST_AUTHOR:0:2}/${DIST_AUTHOR}/${DIST_SECTION:+${DIST_SECTION}/}${DIST_A}"
167         [[ -z "${HOMEPAGE}" ]] && \
168                 HOMEPAGE="http://search.cpan.org/dist/${DIST_NAME}/"
169
170         [[ -z "${DIST_EXAMPLES}" ]] || IUSE+=" examples"
171 fi
172
173 SRC_PREP="no"
174 PREFER_BUILDPL="yes"
175
176 pm_echovar=""
177
178 # @FUNCTION: perl-module_src_unpack
179 # @USAGE: perl-module_src_unpack
180 # @DESCRIPTION:
181 # Unpack the ebuild tarball(s).
182 # This function is to be called during the ebuild src_unpack() phase.
183 perl-module_src_unpack() {
184         debug-print-function $FUNCNAME "$@"
185         [[ ${EAPI:-0} == 5 ]] || die "perl-module_src_unpack is banned in EAPI=6 or later"
186         unpacker_src_unpack
187 }
188
189 # @FUNCTION: perl-module_src_prepare
190 # @USAGE: perl-module_src_prepare
191 # @DESCRIPTION:
192 # Get the ebuild sources ready.
193 # This function is to be called during the ebuild src_prepare() phase.
194 perl-module_src_prepare() {
195         debug-print-function $FUNCNAME "$@"
196
197         if [[ ${EAPI:-0} == 5 ]] ; then
198                 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
199                 debug-print "$FUNCNAME: applying user patches"
200                 epatch_user
201         else
202                 default
203         fi
204
205         if [[ ${PERL_RM_FILES[@]} ]]; then
206                 debug-print "$FUNCNAME: stripping unneeded files"
207                 perl_rm_files "${PERL_RM_FILES[@]}"
208         fi
209         perl_fix_osx_extra
210 }
211
212 # @FUNCTION: perl-module_src_configure
213 # @USAGE: perl-module_src_configure
214 # @DESCRIPTION:
215 # Configure the ebuild sources.
216 # This function is to be called during the ebuild src_configure() phase.
217 perl-module_src_configure() {
218         debug-print-function $FUNCNAME "$@"
219
220         if [[ ${EAPI:-0} == 5 && ${SRC_PREP} == yes ]]; then
221                 return 0
222         fi
223         SRC_PREP="yes"
224
225         perl_check_env
226
227         perl_set_version
228
229         [[ -z ${pm_echovar} ]] && export PERL_MM_USE_DEFAULT=1
230         # Disable ExtUtils::AutoInstall from prompting
231         export PERL_EXTUTILS_AUTOINSTALL="--skipdeps"
232
233         if [[ $(declare -p myconf 2>&-) != "declare -a myconf="* ]]; then
234                 local myconf_local=(${myconf})
235         else
236                 local myconf_local=("${myconf[@]}")
237         fi
238
239         if [[ ( ${PREFER_BUILDPL} == yes || ! -f Makefile.PL ) && -f Build.PL ]] ; then
240                 if grep -q '\(use\|require\)\s*Module::Build::Tiny' Build.PL ; then
241                         einfo "Using Module::Build::Tiny"
242                         if [[ ${DEPEND} != *dev-perl/Module-Build-Tiny* && ${PN} != Module-Build-Tiny ]]; then
243                                 eerror "QA Notice: The ebuild uses Module::Build::Tiny but doesn't depend on it."
244                                 die    " Add dev-perl/Module-Build-Tiny to DEPEND!"
245                         fi
246                 else
247                         einfo "Using Module::Build"
248                         if [[ ${DEPEND} != *virtual/perl-Module-Build* && ${DEPEND} != *dev-perl/Module-Build* && ${PN} != Module-Build ]] ; then
249                                 eerror "QA Notice: The ebuild uses Module::Build but doesn't depend on it."
250                                 die    " Add dev-perl/Module-Build to DEPEND!"
251                         fi
252                 fi
253                 set -- \
254                         --installdirs=vendor \
255                         --libdoc= \
256                         --destdir="${D}" \
257                         --create_packlist=1 \
258                         "${myconf_local[@]}"
259                 einfo "perl Build.PL" "$@"
260                 perl Build.PL "$@" <<< "${pm_echovar}" \
261                                 || die "Unable to build!"
262         elif [[ -f Makefile.PL ]] ; then
263                 einfo "Using ExtUtils::MakeMaker"
264                 set -- \
265                         PREFIX=${EPREFIX}/usr \
266                         INSTALLDIRS=vendor \
267                         INSTALLMAN3DIR='none' \
268                         DESTDIR="${D}" \
269                         "${myconf_local[@]}"
270                 einfo "perl Makefile.PL" "$@"
271                 perl Makefile.PL "$@" <<< "${pm_echovar}" \
272                                 || die "Unable to build!"
273         fi
274         if [[ ! -f Build.PL && ! -f Makefile.PL ]] ; then
275                 einfo "No Make or Build file detected..."
276                 return
277         fi
278 }
279
280 # @FUNCTION: perl-module_src_compile
281 # @USAGE: perl-module_src_compile
282 # @DESCRIPTION:
283 # Compile the ebuild sources.
284 # This function is to be called during the ebuild src_compile() phase.
285 perl-module_src_compile() {
286         debug-print-function $FUNCNAME "$@"
287         perl_set_version
288
289         if [[ $(declare -p mymake 2>&-) != "declare -a mymake="* ]]; then
290                 local mymake_local=(${mymake})
291         else
292                 local mymake_local=("${mymake[@]}")
293         fi
294
295         if [[ -f Build ]] ; then
296                 ./Build build \
297                         || die "Compilation failed"
298         elif [[ -f Makefile ]] ; then
299                 set -- \
300                         OTHERLDFLAGS="${LDFLAGS}" \
301                         "${mymake_local[@]}"
302                 einfo "emake" "$@"
303                 emake "$@" \
304                         || die "Compilation failed"
305 #                       OPTIMIZE="${CFLAGS}" \
306         fi
307 }
308
309 # @ECLASS-VARIABLE: DIST_TEST
310 # @DESCRIPTION:
311 # (EAPI=6) Variable that controls if tests are run in the test phase
312 # at all, and if yes under which conditions. Defaults to "do parallel"
313 # If neither "do" nor "parallel" is recognized, tests are skipped.
314 # (In EAPI=5 the variable is called SRC_TEST, defaults to "skip", and
315 # recognizes fewer options.)
316 # The following space-separated keywords are recognized:
317 #   do       : run tests
318 #   parallel : run tests in parallel
319 #   verbose  : increase test verbosity
320 #   network  : do not try to disable network tests
321
322 # @ECLASS-VARIABLE: DIST_TEST_OVERRIDE
323 # @DESCRIPTION:
324 # (EAPI=6) Variable that controls if tests are run in the test phase
325 # at all, and if yes under which conditions. It is intended for use in
326 # make.conf or the environment by ebuild authors during testing, and
327 # accepts the same values as DIST_TEST. If set, it overrides DIST_TEST
328 # completely. DO NOT USE THIS IN EBUILDS!
329
330 # @FUNCTION: perl-module_src-test
331 # @USAGE: perl-module_src_test()
332 # @DESCRIPTION:
333 # This code attempts to work out your threadingness and runs tests
334 # according to the settings of DIST_TEST using Test::Harness.
335 perl-module_src_test() {
336         debug-print-function $FUNCNAME "$@"
337         local my_test_control
338         local my_test_verbose
339
340         if [[ ${EAPI:-0} == 5 ]] ; then
341                 my_test_control=${SRC_TEST}
342                 my_test_verbose=${TEST_VERBOSE:-0}
343                 if has 'do' ${my_test_control} || has 'parallel' ${my_test_control} ; then
344                         if has "${my_test_verbose}" 0 && has 'parallel' ${my_test_control} ; then
345                                 export HARNESS_OPTIONS=j$(makeopts_jobs)
346                                 einfo "Test::Harness Jobs=$(makeopts_jobs)"
347                         fi
348                 else
349                         einfo Skipping tests due to SRC_TEST=${SRC_TEST}
350                         return 0
351                 fi
352         else
353                 [[ -n "${DIST_TEST_OVERRIDE}" ]] && ewarn DIST_TEST_OVERRIDE is set to ${DIST_TEST_OVERRIDE}
354                 my_test_control=${DIST_TEST_OVERRIDE:-${DIST_TEST:-do parallel}}
355
356                 if ! has 'do' ${my_test_control} && ! has 'parallel' ${my_test_control} ; then
357                         einfo Skipping tests due to DIST_TEST=${my_test_control}
358                         return 0
359                 fi
360
361                 if has verbose ${my_test_control} ; then
362                         my_test_verbose=1
363                 else
364                         my_test_verbose=0
365                 fi
366
367                 if has parallel ${my_test_control} ; then
368                         export HARNESS_OPTIONS=j$(makeopts_jobs)
369                         einfo "Test::Harness Jobs=$(makeopts_jobs)"
370                 fi
371
372                 # this might sometimes work...
373                 if ! has network ${my_test_control} ; then
374                         export NO_NETWORK_TESTING=1
375                 fi
376         fi
377
378         perl_set_version
379         if [[ -f Build ]] ; then
380                 ./Build test verbose=${my_test_verbose} || die "test failed"
381         elif [[ -f Makefile ]] ; then
382                 emake test TEST_VERBOSE=${my_test_verbose} || die "test failed"
383         fi
384 }
385
386 # @FUNCTION: perl-module_src_install
387 # @USAGE: perl-module_src_install
388 # @DESCRIPTION:
389 # Install a Perl ebuild.
390 # This function is to be called during the ebuild src_install() phase.
391 perl-module_src_install() {
392         debug-print-function $FUNCNAME "$@"
393
394         perl_set_version
395
396         local f
397
398         if [[ -f Build ]]; then
399                 mytargets="${mytargets:-install}"
400                 mbparams="${mbparams:---pure}"
401                 einfo "./Build ${mytargets} ${mbparams}"
402                 ./Build ${mytargets} ${mbparams} \
403                         || die "./Build ${mytargets} ${mbparams} failed"
404         elif [[ -f Makefile ]]; then
405                 case "${CATEGORY}" in
406                         dev-perl|perl-core) mytargets="pure_install" ;;
407                         *)                  mytargets="install" ;;
408                 esac
409                 if [[ $(declare -p myinst 2>&-) != "declare -a myinst="* ]]; then
410                         local myinst_local=(${myinst})
411                 else
412                         local myinst_local=("${myinst[@]}")
413                 fi
414                 emake "${myinst_local[@]}" ${mytargets} \
415                         || die "emake ${myinst_local[@]} ${mytargets} failed"
416         fi
417
418         perl_delete_module_manpages
419         perl_delete_localpod
420         if [[ ${EAPI:-0} == 5 ]] ; then
421                 perl_delete_packlist
422         else
423                 perl_fix_packlist
424                 perl_delete_emptybsdir
425         fi
426         perl_remove_temppath
427
428         for f in Change* CHANGES README* TODO FAQ ${mydoc}; do
429                 [[ -s ${f} ]] && dodoc ${f}
430         done
431
432         if [[ ${EAPI:-0} != 5 ]] ; then
433                 if in_iuse examples && use examples ; then
434                         [[ ${#DIST_EXAMPLES[@]} -eq 0 ]] || perl_doexamples "${DIST_EXAMPLES[@]}"
435                 fi
436         fi
437
438         perl_link_duallife_scripts
439 }
440
441 # @FUNCTION: perl-module_pkg_postinst
442 # @USAGE: perl-module_pkg_postinst
443 # @DESCRIPTION:
444 # This function is to be called during the pkg_postinst() phase. It only does 
445 # useful things for the perl-core category, where it handles the file renaming and symbolic
446 # links that prevent file collisions for dual-life packages installing scripts. 
447 # In any other category it immediately exits.
448 perl-module_pkg_postinst() {
449         debug-print-function $FUNCNAME "$@"
450         if [[ ${CATEGORY} != perl-core ]] ; then
451                 eerror "perl-module.eclass: You are calling perl-module_pkg_postinst outside the perl-core category."
452                 die    "   This does not do anything; the call can be removed."
453         fi
454         perl_link_duallife_scripts
455 }
456
457 # @FUNCTION: perl-module_pkg_postrm
458 # @USAGE: perl-module_pkg_postrm
459 # @DESCRIPTION:
460 # This function is to be called during the pkg_postrm() phase. It only does 
461 # useful things for the perl-core category, where it handles the file renaming and symbolic
462 # links that prevent file collisions for dual-life packages installing scripts. 
463 # In any other category it immediately exits.
464 perl-module_pkg_postrm() {
465         debug-print-function $FUNCNAME "$@"
466         if [[ ${CATEGORY} != perl-core ]] ; then
467                 eerror "perl-module.eclass: You are calling perl-module_pkg_postrm outside the perl-core category."
468                 die    "   This does not do anything; the call can be removed."
469         fi
470         perl_link_duallife_scripts
471 }