1 # Copyright 1999-2015 Gentoo Foundation
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 # @BLURB: eclass for installing Perl module distributions
12 # The perl-module eclass is designed to allow easier installation of Perl
13 # module distributions, and their incorporation into the Gentoo Linux system.
14 # All exported functions from perl-functions.eclass (inherited here)
15 # explicitly also belong to the interface of perl-module.eclass.
16 # If your package does not use any Perl-specific build system (as, e.g.,
17 # ExtUtils::MakeMaker or Module::Build), we recommend to use perl-functions.eclass
22 inherit eutils multiprocessing unpacker perl-functions
23 PERL_EXPF="src_unpack src_prepare src_configure src_compile src_test src_install"
26 inherit multiprocessing perl-functions
27 PERL_EXPF="src_prepare src_configure src_compile src_test src_install"
30 die "EAPI=${EAPI} is not supported by perl-module.eclass"
34 # @ECLASS-VARIABLE: GENTOO_DEPEND_ON_PERL
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.
45 [[ ${CATEGORY} == perl-core ]] && \
46 PERL_EXPF+=" pkg_postinst pkg_postrm"
48 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
50 case "${GENTOO_DEPEND_ON_PERL_SUBSLOT:-yes}" in
52 DEPEND="dev-lang/perl:=[-build(-)]"
55 DEPEND="dev-lang/perl[-build(-)]"
62 case "${PERL_EXPORT_PHASE_FUNCTIONS:-yes}" in
64 EXPORT_FUNCTIONS ${PERL_EXPF}
67 debug-print "PERL_EXPORT_PHASE_FUNCTIONS=no"
70 die "PERL_EXPORT_PHASE_FUNCTIONS=${PERL_EXPORT_PHASE_FUNCTIONS} is not supported by perl-module.eclass"
75 [[ ${CATEGORY} == perl-core ]] && \
76 PERL_EXPF+=" pkg_postinst pkg_postrm"
78 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
80 DEPEND="dev-lang/perl:="
81 RDEPEND="dev-lang/perl:="
84 DEPEND="dev-lang/perl"
85 RDEPEND="dev-lang/perl"
89 if [[ "${GENTOO_DEPEND_ON_PERL_SUBSLOT:-yes}" != "yes" ]]; then
90 eerror "GENTOO_DEPEND_ON_PERL_SUBSLOT=no is banned in EAPI=6. If you don't want a slot operator"
91 die "set GENTOO_DEPEND_ON_PERL=noslotop instead."
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."
99 EXPORT_FUNCTIONS ${PERL_EXPF}
102 die "EAPI=${EAPI:-0} is not supported by perl-module.eclass"
106 LICENSE="${LICENSE:-|| ( Artistic GPL-1+ )}"
108 # @ECLASS-VARIABLE: DIST_NAME
110 # (EAPI=6) This variable provides a way to override PN for the calculation of S,
111 # SRC_URI, and HOMEPAGE. Defaults to PN.
113 # @ECLASS-VARIABLE: DIST_VERSION
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.
119 # @ECLASS-VARIABLE: DIST_A_EXT
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.
124 # @ECLASS-VARIABLE: DIST_A
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.
129 # @ECLASS-VARIABLE: DIST_AUTHOR
132 # (EAPI=6) This variable sets the module author name for the calculation of
133 # SRC_URI. Named MODULE_AUTHOR in EAPI=5.
135 # @ECLASS-VARIABLE: DIST_SECTION
138 # (EAPI=6) This variable sets the module section for the calculation of
139 # SRC_URI. Only required in rare cases for very special snowflakes.
140 # Named MODULE_SECTION in EAPI=5.
142 # @ECLASS-VARIABLE: DIST_EXAMPLES
145 # (EAPI=6) This Bash array allows passing a list of example files to be installed
146 # in /usr/share/doc/${PF}/examples. If set before inherit, automatically adds
147 # a use-flag examples, if not you'll have to add the useflag in your ebuild.
148 # Examples are installed only if the useflag examples exists and is activated.
151 if [[ ${EAPI:-0} == 5 ]]; then
152 if [[ -n ${MY_PN} || -n ${MY_PV} || -n ${MODULE_VERSION} ]] ; then
153 : ${MY_P:=${MY_PN:-${PN}}-${MY_PV:-${MODULE_VERSION:-${PV}}}}
154 S=${MY_S:-${WORKDIR}/${MY_P}}
156 MODULE_NAME=${MY_PN:-${PN}}
157 MODULE_P=${MY_P:-${P}}
159 [[ -z "${SRC_URI}" && -z "${MODULE_A}" ]] && \
160 MODULE_A="${MODULE_P}.${MODULE_A_EXT:-tar.gz}"
161 [[ -z "${SRC_URI}" && -n "${MODULE_AUTHOR}" ]] && \
162 SRC_URI="mirror://cpan/authors/id/${MODULE_AUTHOR:0:1}/${MODULE_AUTHOR:0:2}/${MODULE_AUTHOR}/${MODULE_SECTION:+${MODULE_SECTION}/}${MODULE_A}"
163 [[ -z "${HOMEPAGE}" ]] && \
164 HOMEPAGE="http://search.cpan.org/dist/${MODULE_NAME}/"
168 DIST_NAME=${DIST_NAME:-${PN}}
169 DIST_P=${DIST_NAME}-${DIST_VERSION:-${PV}}
170 S=${WORKDIR}/${DIST_P}
172 [[ -z "${SRC_URI}" && -z "${DIST_A}" ]] && \
173 DIST_A="${DIST_P}.${DIST_A_EXT:-tar.gz}"
174 [[ -z "${SRC_URI}" && -n "${DIST_AUTHOR}" ]] && \
175 SRC_URI="mirror://cpan/authors/id/${DIST_AUTHOR:0:1}/${DIST_AUTHOR:0:2}/${DIST_AUTHOR}/${DIST_SECTION:+${DIST_SECTION}/}${DIST_A}"
176 [[ -z "${HOMEPAGE}" ]] && \
177 HOMEPAGE="http://search.cpan.org/dist/${DIST_NAME}/"
179 [[ -z "${DIST_EXAMPLES}" ]] || IUSE+=" examples"
187 # @FUNCTION: perl-module_src_unpack
189 # Unpack the ebuild tarball(s).
190 # This function is to be called during the ebuild src_unpack() phase.
191 perl-module_src_unpack() {
192 debug-print-function $FUNCNAME "$@"
193 [[ ${EAPI:-0} == 5 ]] || die "perl-module_src_unpack is banned in EAPI=6 or later"
197 # @FUNCTION: perl-module_src_prepare
199 # Get the ebuild sources ready.
200 # This function is to be called during the ebuild src_prepare() phase.
201 perl-module_src_prepare() {
202 debug-print-function $FUNCNAME "$@"
204 if [[ ${EAPI:-0} == 5 ]] ; then
205 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
206 debug-print "$FUNCNAME: applying user patches"
212 if [[ ${PERL_RM_FILES[@]} ]]; then
213 debug-print "$FUNCNAME: stripping unneeded files"
214 perl_rm_files "${PERL_RM_FILES[@]}"
219 # @FUNCTION: perl-module_src_configure
221 # Configure the ebuild sources.
222 # This function is to be called during the ebuild src_configure() phase.
223 perl-module_src_configure() {
224 debug-print-function $FUNCNAME "$@"
226 if [[ ${EAPI:-0} == 5 && ${SRC_PREP} == yes ]]; then
235 [[ -z ${pm_echovar} ]] && export PERL_MM_USE_DEFAULT=1
236 # Disable ExtUtils::AutoInstall from prompting
237 export PERL_EXTUTILS_AUTOINSTALL="--skipdeps"
239 if [[ $(declare -p myconf 2>&-) != "declare -a myconf="* ]]; then
240 local myconf_local=(${myconf})
242 local myconf_local=("${myconf[@]}")
245 if [[ ( ${PREFER_BUILDPL} == yes || ! -f Makefile.PL ) && -f Build.PL ]] ; then
246 if grep -q '\(use\|require\)\s*Module::Build::Tiny' Build.PL ; then
247 einfo "Using Module::Build::Tiny"
248 if [[ ${DEPEND} != *dev-perl/Module-Build-Tiny* && ${PN} != Module-Build-Tiny ]]; then
249 eerror "QA Notice: The ebuild uses Module::Build::Tiny but doesn't depend on it."
250 die " Add dev-perl/Module-Build-Tiny to DEPEND!"
253 einfo "Using Module::Build"
254 if [[ ${DEPEND} != *virtual/perl-Module-Build* && ${DEPEND} != *dev-perl/Module-Build* && ${PN} != Module-Build ]] ; then
255 eerror "QA Notice: The ebuild uses Module::Build but doesn't depend on it."
256 die " Add dev-perl/Module-Build to DEPEND!"
260 --installdirs=vendor \
263 --create_packlist=1 \
265 einfo "perl Build.PL" "$@"
266 perl Build.PL "$@" <<< "${pm_echovar}" \
267 || die "Unable to build!"
268 elif [[ -f Makefile.PL ]] ; then
269 einfo "Using ExtUtils::MakeMaker"
271 PREFIX=${EPREFIX}/usr \
273 INSTALLMAN3DIR='none' \
276 einfo "perl Makefile.PL" "$@"
277 perl Makefile.PL "$@" <<< "${pm_echovar}" \
278 || die "Unable to build!"
280 if [[ ! -f Build.PL && ! -f Makefile.PL ]] ; then
281 einfo "No Make or Build file detected..."
286 # @FUNCTION: perl-module_src_compile
288 # Compile the ebuild sources.
289 # This function is to be called during the ebuild src_compile() phase.
290 perl-module_src_compile() {
291 debug-print-function $FUNCNAME "$@"
294 if [[ $(declare -p mymake 2>&-) != "declare -a mymake="* ]]; then
295 local mymake_local=(${mymake})
297 local mymake_local=("${mymake[@]}")
300 if [[ -f Build ]] ; then
302 || die "Compilation failed"
303 elif [[ -f Makefile ]] ; then
305 OTHERLDFLAGS="${LDFLAGS}" \
309 || die "Compilation failed"
310 # OPTIMIZE="${CFLAGS}" \
314 # @ECLASS-VARIABLE: DIST_TEST
316 # (EAPI=6) Variable that controls if tests are run in the test phase
317 # at all, and if yes under which conditions. Defaults to "do parallel"
318 # If neither "do" nor "parallel" is recognized, tests are skipped.
319 # (In EAPI=5 the variable is called SRC_TEST, defaults to "skip", and
320 # recognizes fewer options.)
321 # The following space-separated keywords are recognized:
323 # parallel : run tests in parallel
324 # verbose : increase test verbosity
325 # network : do not try to disable network tests
327 # @ECLASS-VARIABLE: DIST_TEST_OVERRIDE
330 # (EAPI=6) Variable that controls if tests are run in the test phase
331 # at all, and if yes under which conditions. It is intended for use in
332 # make.conf or the environment by ebuild authors during testing, and
333 # accepts the same values as DIST_TEST. If set, it overrides DIST_TEST
334 # completely. DO NOT USE THIS IN EBUILDS!
336 # @FUNCTION: perl-module_src-test
338 # This code attempts to work out your threadingness and runs tests
339 # according to the settings of DIST_TEST using Test::Harness.
340 perl-module_src_test() {
341 debug-print-function $FUNCNAME "$@"
342 local my_test_control
343 local my_test_verbose
345 if [[ ${EAPI:-0} == 5 ]] ; then
346 my_test_control=${SRC_TEST}
347 my_test_verbose=${TEST_VERBOSE:-0}
348 if has 'do' ${my_test_control} || has 'parallel' ${my_test_control} ; then
349 if has "${my_test_verbose}" 0 && has 'parallel' ${my_test_control} ; then
350 export HARNESS_OPTIONS=j$(makeopts_jobs)
351 einfo "Test::Harness Jobs=$(makeopts_jobs)"
354 einfo Skipping tests due to SRC_TEST=${SRC_TEST}
358 [[ -n "${DIST_TEST_OVERRIDE}" ]] && ewarn DIST_TEST_OVERRIDE is set to ${DIST_TEST_OVERRIDE}
359 my_test_control=${DIST_TEST_OVERRIDE:-${DIST_TEST:-do parallel}}
361 if ! has 'do' ${my_test_control} && ! has 'parallel' ${my_test_control} ; then
362 einfo Skipping tests due to DIST_TEST=${my_test_control}
366 if has verbose ${my_test_control} ; then
372 if has parallel ${my_test_control} ; then
373 export HARNESS_OPTIONS=j$(makeopts_jobs)
374 einfo "Test::Harness Jobs=$(makeopts_jobs)"
377 # this might sometimes work...
378 if ! has network ${my_test_control} ; then
379 export NO_NETWORK_TESTING=1
384 if [[ -f Build ]] ; then
385 ./Build test verbose=${my_test_verbose} || die "test failed"
386 elif [[ -f Makefile ]] ; then
387 emake test TEST_VERBOSE=${my_test_verbose} || die "test failed"
391 # @FUNCTION: perl-module_src_install
393 # Install a Perl ebuild.
394 # This function is to be called during the ebuild src_install() phase.
395 perl-module_src_install() {
396 debug-print-function $FUNCNAME "$@"
402 if [[ -f Build ]]; then
403 mytargets="${mytargets:-install}"
404 mbparams="${mbparams:---pure}"
405 einfo "./Build ${mytargets} ${mbparams}"
406 ./Build ${mytargets} ${mbparams} \
407 || die "./Build ${mytargets} ${mbparams} failed"
408 elif [[ -f Makefile ]]; then
409 case "${CATEGORY}" in
410 dev-perl|perl-core) mytargets="pure_install" ;;
411 *) mytargets="install" ;;
413 if [[ $(declare -p myinst 2>&-) != "declare -a myinst="* ]]; then
414 local myinst_local=(${myinst})
416 local myinst_local=("${myinst[@]}")
418 emake "${myinst_local[@]}" ${mytargets} \
419 || die "emake ${myinst_local[@]} ${mytargets} failed"
422 perl_delete_module_manpages
424 if [[ ${EAPI:-0} == 5 ]] ; then
428 perl_delete_emptybsdir
432 for f in Change* CHANGES README* TODO FAQ ${mydoc}; do
433 [[ -s ${f} ]] && dodoc ${f}
436 if [[ ${EAPI:-0} != 5 ]] ; then
437 if in_iuse examples && use examples ; then
438 [[ ${#DIST_EXAMPLES[@]} -eq 0 ]] || perl_doexamples "${DIST_EXAMPLES[@]}"
442 perl_link_duallife_scripts
445 # @FUNCTION: perl-module_pkg_postinst
447 # This function is to be called during the pkg_postinst() phase. It only does
448 # useful things for the perl-core category, where it handles the file renaming and symbolic
449 # links that prevent file collisions for dual-life packages installing scripts.
450 # In any other category it immediately exits.
451 perl-module_pkg_postinst() {
452 debug-print-function $FUNCNAME "$@"
453 if [[ ${CATEGORY} != perl-core ]] ; then
454 eerror "perl-module.eclass: You are calling perl-module_pkg_postinst outside the perl-core category."
455 die " This does not do anything; the call can be removed."
457 perl_link_duallife_scripts
460 # @FUNCTION: perl-module_pkg_postrm
462 # This function is to be called during the pkg_postrm() phase. It only does
463 # useful things for the perl-core category, where it handles the file renaming and symbolic
464 # links that prevent file collisions for dual-life packages installing scripts.
465 # In any other category it immediately exits.
466 perl-module_pkg_postrm() {
467 debug-print-function $FUNCNAME "$@"
468 if [[ ${CATEGORY} != perl-core ]] ; then
469 eerror "perl-module.eclass: You are calling perl-module_pkg_postrm outside the perl-core category."
470 die " This does not do anything; the call can be removed."
472 perl_link_duallife_scripts