1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: perl-module.eclass
8 # Seemant Kulleen <seemant@gentoo.org>
9 # Andreas K. Hüttel <dilfridge@gentoo.org>
10 # @SUPPORTED_EAPIS: 5 6 7
11 # @BLURB: eclass for installing Perl module distributions
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
23 inherit eutils multiprocessing unpacker perl-functions
24 PERL_EXPF="src_unpack src_prepare src_configure src_compile src_test src_install"
27 inherit multiprocessing perl-functions
28 PERL_EXPF="src_prepare src_configure src_compile src_test src_install"
31 die "EAPI=${EAPI} is not supported by perl-module.eclass"
35 # @ECLASS-VARIABLE: GENTOO_DEPEND_ON_PERL
38 # This variable controls whether a runtime and build time dependency on
39 # dev-lang/perl is automatically added by the eclass. It defaults to yes.
40 # Set to no to disable, set to noslotop to add a perl dependency without
41 # slot operator (EAPI=6). All packages installing into the vendor_perl
42 # path must use yes here.
46 [[ ${CATEGORY} == perl-core ]] && \
47 PERL_EXPF+=" pkg_postinst pkg_postrm"
49 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
51 case "${GENTOO_DEPEND_ON_PERL_SUBSLOT:-yes}" in
53 DEPEND="dev-lang/perl:=[-build(-)]"
56 DEPEND="dev-lang/perl[-build(-)]"
63 case "${PERL_EXPORT_PHASE_FUNCTIONS:-yes}" in
65 EXPORT_FUNCTIONS ${PERL_EXPF}
68 debug-print "PERL_EXPORT_PHASE_FUNCTIONS=no"
71 die "PERL_EXPORT_PHASE_FUNCTIONS=${PERL_EXPORT_PHASE_FUNCTIONS} is not supported by perl-module.eclass"
76 [[ ${CATEGORY} == perl-core ]] && \
77 PERL_EXPF+=" pkg_postinst pkg_postrm"
79 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
81 DEPEND="dev-lang/perl"
82 RDEPEND="dev-lang/perl:="
85 DEPEND="dev-lang/perl"
86 RDEPEND="dev-lang/perl"
90 if [[ "${GENTOO_DEPEND_ON_PERL_SUBSLOT:-yes}" != "yes" ]]; then
91 eerror "GENTOO_DEPEND_ON_PERL_SUBSLOT=no is banned in EAPI=6 and later. If you don't want a slot operator"
92 die "set GENTOO_DEPEND_ON_PERL=noslotop instead."
95 if [[ "${PERL_EXPORT_PHASE_FUNCTIONS}" ]]; then
96 eerror "PERL_EXPORT_PHASE_FUNCTIONS is banned in EAPI=6 and later. Use perl-module.eclass if you need"
97 die "phase functions, perl-functions.eclass if not."
100 EXPORT_FUNCTIONS ${PERL_EXPF}
103 [[ ${CATEGORY} == perl-core ]] && \
104 PERL_EXPF+=" pkg_postinst pkg_postrm"
106 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
108 DEPEND="dev-lang/perl"
109 BDEPEND="dev-lang/perl"
110 RDEPEND="dev-lang/perl:="
113 DEPEND="dev-lang/perl"
114 BDEPEND="dev-lang/perl"
115 RDEPEND="dev-lang/perl"
119 if [[ "${GENTOO_DEPEND_ON_PERL_SUBSLOT:-yes}" != "yes" ]]; then
120 die "GENTOO_DEPEND_ON_PERL_SUBSLOT=no is banned in EAPI=6 and later."
123 if [[ "${PERL_EXPORT_PHASE_FUNCTIONS}" ]]; then
124 die "PERL_EXPORT_PHASE_FUNCTIONS is banned in EAPI=6 and later."
127 EXPORT_FUNCTIONS ${PERL_EXPF}
130 die "EAPI=${EAPI:-0} is not supported by perl-module.eclass"
134 LICENSE="${LICENSE:-|| ( Artistic GPL-1+ )}"
136 # @ECLASS-VARIABLE: DIST_NAME
139 # (EAPI=6 and later) This variable provides a way to override PN for the calculation of S,
140 # SRC_URI, and HOMEPAGE. If unset, defaults to PN.
142 # @ECLASS-VARIABLE: DIST_VERSION
145 # (EAPI=6 and later) This variable provides a way to override PV for the calculation of S and SRC_URI.
146 # Use it to provide the non-normalized, upstream version number. If unset, defaults to PV.
147 # Named MODULE_VERSION in EAPI=5.
149 # @ECLASS-VARIABLE: DIST_A_EXT
152 # (EAPI=6 and later) This variable provides a way to override the distfile extension for the calculation of
153 # SRC_URI. If unset, defaults to tar.gz. Named MODULE_A_EXT in EAPI=5.
155 # @ECLASS-VARIABLE: DIST_A
158 # (EAPI=6 and later) This variable provides a way to override the distfile name for the calculation of
159 # SRC_URI. If unset, defaults to ${DIST_NAME}-${DIST_VERSION}.${DIST_A_EXT} Named MODULE_A in EAPI=5.
161 # @ECLASS-VARIABLE: DIST_AUTHOR
164 # (EAPI=6 and later) This variable sets the module author name for the calculation of
165 # SRC_URI. Named MODULE_AUTHOR in EAPI=5.
167 # @ECLASS-VARIABLE: DIST_SECTION
170 # (EAPI=6 and later) This variable sets the module section for the calculation of
171 # SRC_URI. Only required in rare cases for very special snowflakes.
172 # Named MODULE_SECTION in EAPI=5.
174 # @ECLASS-VARIABLE: DIST_EXAMPLES
177 # (EAPI=6 and later) This Bash array allows passing a list of example files to be installed
178 # in /usr/share/doc/${PF}/examples. If set before inherit, automatically adds
179 # a use-flag examples, if not you'll have to add the useflag in your ebuild.
180 # Examples are installed only if the useflag examples exists and is activated.
183 if [[ ${EAPI:-0} == 5 ]]; then
184 if [[ -n ${MY_PN} || -n ${MY_PV} || -n ${MODULE_VERSION} ]] ; then
185 : ${MY_P:=${MY_PN:-${PN}}-${MY_PV:-${MODULE_VERSION:-${PV}}}}
186 S=${MY_S:-${WORKDIR}/${MY_P}}
188 MODULE_NAME=${MY_PN:-${PN}}
189 MODULE_P=${MY_P:-${P}}
191 [[ -z "${SRC_URI}" && -z "${MODULE_A}" ]] && \
192 MODULE_A="${MODULE_P}.${MODULE_A_EXT:-tar.gz}"
193 [[ -z "${SRC_URI}" && -n "${MODULE_AUTHOR}" ]] && \
194 SRC_URI="mirror://cpan/authors/id/${MODULE_AUTHOR:0:1}/${MODULE_AUTHOR:0:2}/${MODULE_AUTHOR}/${MODULE_SECTION:+${MODULE_SECTION}/}${MODULE_A}"
195 [[ -z "${HOMEPAGE}" ]] && \
196 HOMEPAGE="https://metacpan.org/release/${MODULE_NAME}"
200 DIST_NAME=${DIST_NAME:-${PN}}
201 DIST_P=${DIST_NAME}-${DIST_VERSION:-${PV}}
202 S=${WORKDIR}/${DIST_P}
204 [[ -z "${SRC_URI}" && -z "${DIST_A}" ]] && \
205 DIST_A="${DIST_P}.${DIST_A_EXT:-tar.gz}"
206 [[ -z "${SRC_URI}" && -n "${DIST_AUTHOR}" ]] && \
207 SRC_URI="mirror://cpan/authors/id/${DIST_AUTHOR:0:1}/${DIST_AUTHOR:0:2}/${DIST_AUTHOR}/${DIST_SECTION:+${DIST_SECTION}/}${DIST_A}"
208 [[ -z "${HOMEPAGE}" ]] && \
209 HOMEPAGE="https://metacpan.org/release/${DIST_NAME}"
211 [[ -z "${DIST_EXAMPLES}" ]] || IUSE+=" examples"
219 # @FUNCTION: perl-module_src_unpack
221 # Unpack the ebuild tarball(s).
222 # This function is to be called during the ebuild src_unpack() phase.
223 perl-module_src_unpack() {
224 debug-print-function $FUNCNAME "$@"
225 [[ ${EAPI:-0} == 5 ]] || die "perl-module_src_unpack is banned in EAPI=6 or later"
229 # @FUNCTION: perl-module_src_prepare
231 # Get the ebuild sources ready.
232 # This function is to be called during the ebuild src_prepare() phase.
233 perl-module_src_prepare() {
234 debug-print-function $FUNCNAME "$@"
236 if [[ ${EAPI:-0} == 5 ]] ; then
237 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
238 debug-print "$FUNCNAME: applying user patches"
244 if [[ ${PERL_RM_FILES[@]} ]]; then
245 debug-print "$FUNCNAME: stripping unneeded files"
246 perl_rm_files "${PERL_RM_FILES[@]}"
251 # @FUNCTION: perl-module_src_configure
253 # Configure the ebuild sources.
254 # This function is to be called during the ebuild src_configure() phase.
255 perl-module_src_configure() {
256 debug-print-function $FUNCNAME "$@"
258 if [[ ${EAPI:-0} == 5 && ${SRC_PREP} == yes ]]; then
267 [[ -z ${pm_echovar} ]] && export PERL_MM_USE_DEFAULT=1
268 # Disable ExtUtils::AutoInstall from prompting
269 export PERL_EXTUTILS_AUTOINSTALL="--skipdeps"
271 if [[ $(declare -p myconf 2>&-) != "declare -a myconf="* ]]; then
272 local myconf_local=(${myconf})
274 local myconf_local=("${myconf[@]}")
277 if [[ ( ${PREFER_BUILDPL} == yes || ! -f Makefile.PL ) && -f Build.PL ]] ; then
278 if grep -q '\(use\|require\)\s*Module::Build::Tiny' Build.PL ; then
279 einfo "Using Module::Build::Tiny"
280 if [[ ${DEPEND} != *dev-perl/Module-Build-Tiny* && ${PN} != Module-Build-Tiny ]]; then
281 eerror "QA Notice: The ebuild uses Module::Build::Tiny but doesn't depend on it."
282 die " Add dev-perl/Module-Build-Tiny to DEPEND!"
285 einfo "Using Module::Build"
286 if [[ ${DEPEND} != *virtual/perl-Module-Build* && ${DEPEND} != *dev-perl/Module-Build* && ${PN} != Module-Build ]] ; then
287 eerror "QA Notice: The ebuild uses Module::Build but doesn't depend on it."
288 die " Add dev-perl/Module-Build to DEPEND!"
292 --installdirs=vendor \
295 --create_packlist=1 \
297 einfo "perl Build.PL" "$@"
298 perl Build.PL "$@" <<< "${pm_echovar}" \
299 || die "Unable to build!"
300 elif [[ -f Makefile.PL ]] ; then
301 einfo "Using ExtUtils::MakeMaker"
303 PREFIX=${EPREFIX}/usr \
305 INSTALLMAN3DIR='none' \
308 einfo "perl Makefile.PL" "$@"
309 perl Makefile.PL "$@" <<< "${pm_echovar}" \
310 || die "Unable to build!"
312 if [[ ! -f Build.PL && ! -f Makefile.PL ]] ; then
313 einfo "No Make or Build file detected..."
318 # @FUNCTION: perl-module_src_compile
320 # Compile the ebuild sources.
321 # This function is to be called during the ebuild src_compile() phase.
322 perl-module_src_compile() {
323 debug-print-function $FUNCNAME "$@"
326 if [[ $(declare -p mymake 2>&-) != "declare -a mymake="* ]]; then
327 local mymake_local=(${mymake})
329 local mymake_local=("${mymake[@]}")
332 if [[ -f Build ]] ; then
334 || die "Compilation failed"
335 elif [[ -f Makefile ]] ; then
337 OTHERLDFLAGS="${LDFLAGS}" \
341 || die "Compilation failed"
342 # OPTIMIZE="${CFLAGS}" \
346 # @ECLASS-VARIABLE: DIST_TEST
349 # (EAPI=6 and later) Variable that controls if tests are run in the test phase
350 # at all, and if yes under which conditions. If unset, defaults to "do parallel"
351 # If neither "do" nor "parallel" is recognized, tests are skipped.
352 # (In EAPI=5 the variable is called SRC_TEST, defaults to "skip", and
353 # recognizes fewer options.)
354 # The following space-separated keywords are recognized:
356 # parallel : run tests in parallel
357 # verbose : increase test verbosity
358 # network : do not try to disable network tests
360 # @ECLASS-VARIABLE: DIST_TEST_OVERRIDE
363 # (EAPI=6 and later) Variable that controls if tests are run in the test phase
364 # at all, and if yes under which conditions. It is intended for use in
365 # make.conf or the environment by ebuild authors during testing, and
366 # accepts the same values as DIST_TEST. If set, it overrides DIST_TEST
367 # completely. DO NOT USE THIS IN EBUILDS!
369 # @FUNCTION: perl-module_src-test
371 # This code attempts to work out your threadingness and runs tests
372 # according to the settings of DIST_TEST using Test::Harness.
373 perl-module_src_test() {
374 debug-print-function $FUNCNAME "$@"
375 local my_test_control
376 local my_test_verbose
378 if [[ ${EAPI:-0} == 5 ]] ; then
379 my_test_control=${SRC_TEST}
380 my_test_verbose=${TEST_VERBOSE:-0}
381 if has 'do' ${my_test_control} || has 'parallel' ${my_test_control} ; then
382 if has "${my_test_verbose}" 0 && has 'parallel' ${my_test_control} ; then
383 export HARNESS_OPTIONS=j$(makeopts_jobs)
384 einfo "Test::Harness Jobs=$(makeopts_jobs)"
387 einfo Skipping tests due to SRC_TEST=${SRC_TEST}
391 [[ -n "${DIST_TEST_OVERRIDE}" ]] && ewarn DIST_TEST_OVERRIDE is set to ${DIST_TEST_OVERRIDE}
392 my_test_control=${DIST_TEST_OVERRIDE:-${DIST_TEST:-do parallel}}
394 if ! has 'do' ${my_test_control} && ! has 'parallel' ${my_test_control} ; then
395 einfo Skipping tests due to DIST_TEST=${my_test_control}
399 if has verbose ${my_test_control} ; then
405 if has parallel ${my_test_control} ; then
406 export HARNESS_OPTIONS=j$(makeopts_jobs)
407 einfo "Test::Harness Jobs=$(makeopts_jobs)"
410 # this might sometimes work...
411 if ! has network ${my_test_control} ; then
412 export NO_NETWORK_TESTING=1
417 if [[ -f Build ]] ; then
418 ./Build test verbose=${my_test_verbose} || die "test failed"
419 elif [[ -f Makefile ]] ; then
420 emake test TEST_VERBOSE=${my_test_verbose} || die "test failed"
424 # @FUNCTION: perl-module_src_install
426 # Install a Perl ebuild.
427 # This function is to be called during the ebuild src_install() phase.
428 perl-module_src_install() {
429 debug-print-function $FUNCNAME "$@"
435 if [[ -f Build ]]; then
436 mytargets="${mytargets:-install}"
437 mbparams="${mbparams:---pure}"
438 einfo "./Build ${mytargets} ${mbparams}"
439 ./Build ${mytargets} ${mbparams} \
440 || die "./Build ${mytargets} ${mbparams} failed"
441 elif [[ -f Makefile ]]; then
442 case "${CATEGORY}" in
443 dev-perl|perl-core) mytargets="pure_install" ;;
444 *) mytargets="install" ;;
446 if [[ $(declare -p myinst 2>&-) != "declare -a myinst="* ]]; then
447 local myinst_local=(${myinst})
449 local myinst_local=("${myinst[@]}")
451 emake "${myinst_local[@]}" ${mytargets} \
452 || die "emake ${myinst_local[@]} ${mytargets} failed"
455 perl_delete_module_manpages
457 if [[ ${EAPI:-0} == 5 ]] ; then
461 perl_delete_emptybsdir
465 for f in Change* CHANGES README* TODO FAQ ${mydoc}; do
466 [[ -s ${f} ]] && dodoc ${f}
469 if [[ ${EAPI:-0} != 5 ]] ; then
470 if in_iuse examples && use examples ; then
471 [[ ${#DIST_EXAMPLES[@]} -eq 0 ]] || perl_doexamples "${DIST_EXAMPLES[@]}"
475 perl_link_duallife_scripts
478 # @FUNCTION: perl-module_pkg_postinst
480 # This function is to be called during the pkg_postinst() phase. It only does
481 # useful things for the perl-core category, where it handles the file renaming and symbolic
482 # links that prevent file collisions for dual-life packages installing scripts.
483 # In any other category it immediately exits.
484 perl-module_pkg_postinst() {
485 debug-print-function $FUNCNAME "$@"
486 if [[ ${CATEGORY} != perl-core ]] ; then
487 eerror "perl-module.eclass: You are calling perl-module_pkg_postinst outside the perl-core category."
488 die " This does not do anything; the call can be removed."
490 perl_link_duallife_scripts
493 # @FUNCTION: perl-module_pkg_postrm
495 # This function is to be called during the pkg_postrm() phase. It only does
496 # useful things for the perl-core category, where it handles the file renaming and symbolic
497 # links that prevent file collisions for dual-life packages installing scripts.
498 # In any other category it immediately exits.
499 perl-module_pkg_postrm() {
500 debug-print-function $FUNCNAME "$@"
501 if [[ ${CATEGORY} != perl-core ]] ; then
502 eerror "perl-module.eclass: You are calling perl-module_pkg_postrm outside the perl-core category."
503 die " This does not do anything; the call can be removed."
505 perl_link_duallife_scripts