1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: perl-module.eclass
9 # Seemant Kulleen <seemant@gentoo.org>
10 # Andreas K. Hüttel <dilfridge@gentoo.org>
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
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}" ]]; 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."
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
131 # (EAPI=6) This variable sets the module author name for the calculation of
132 # SRC_URI. Named MODULE_AUTHOR in EAPI=5.
134 # @ECLASS-VARIABLE: DIST_EXAMPLES
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.
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}}
147 MODULE_NAME=${MY_PN:-${PN}}
148 MODULE_P=${MY_P:-${P}}
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}/"
159 DIST_NAME=${DIST_NAME:-${PN}}
160 DIST_P=${DIST_NAME}-${DIST_VERSION:-${PV}}
161 S=${WORKDIR}/${DIST_P}
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}/"
170 [[ -z "${DIST_EXAMPLES}" ]] || IUSE+=" examples"
178 # @FUNCTION: perl-module_src_unpack
179 # @USAGE: perl-module_src_unpack
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"
189 # @FUNCTION: perl-module_src_prepare
190 # @USAGE: perl-module_src_prepare
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 "$@"
197 if [[ ${EAPI:-0} == 5 ]] ; then
198 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
199 debug-print "$FUNCNAME: applying user patches"
205 if [[ ${PERL_RM_FILES[@]} ]]; then
206 debug-print "$FUNCNAME: stripping unneeded files"
207 perl_rm_files "${PERL_RM_FILES[@]}"
212 # @FUNCTION: perl-module_src_configure
213 # @USAGE: perl-module_src_configure
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 "$@"
220 if [[ ${EAPI:-0} == 5 && ${SRC_PREP} == yes ]]; then
229 [[ -z ${pm_echovar} ]] && export PERL_MM_USE_DEFAULT=1
230 # Disable ExtUtils::AutoInstall from prompting
231 export PERL_EXTUTILS_AUTOINSTALL="--skipdeps"
233 if [[ $(declare -p myconf 2>&-) != "declare -a myconf="* ]]; then
234 local myconf_local=(${myconf})
236 local myconf_local=("${myconf[@]}")
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!"
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!"
254 --installdirs=vendor \
257 --create_packlist=1 \
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"
265 PREFIX=${EPREFIX}/usr \
267 INSTALLMAN3DIR='none' \
270 einfo "perl Makefile.PL" "$@"
271 perl Makefile.PL "$@" <<< "${pm_echovar}" \
272 || die "Unable to build!"
274 if [[ ! -f Build.PL && ! -f Makefile.PL ]] ; then
275 einfo "No Make or Build file detected..."
280 # @FUNCTION: perl-module_src_compile
281 # @USAGE: perl-module_src_compile
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 "$@"
289 if [[ $(declare -p mymake 2>&-) != "declare -a mymake="* ]]; then
290 local mymake_local=(${mymake})
292 local mymake_local=("${mymake[@]}")
295 if [[ -f Build ]] ; then
297 || die "Compilation failed"
298 elif [[ -f Makefile ]] ; then
300 OTHERLDFLAGS="${LDFLAGS}" \
304 || die "Compilation failed"
305 # OPTIMIZE="${CFLAGS}" \
309 # @ECLASS-VARIABLE: DIST_TEST
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:
318 # parallel : run tests in parallel
319 # verbose : increase test verbosity
320 # network : do not try to disable network tests
322 # @ECLASS-VARIABLE: DIST_TEST_OVERRIDE
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!
330 # @FUNCTION: perl-module_src-test
331 # @USAGE: perl-module_src_test()
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
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)"
349 einfo Skipping tests due to SRC_TEST=${SRC_TEST}
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}}
356 if ! has 'do' ${my_test_control} && ! has 'parallel' ${my_test_control} ; then
357 einfo Skipping tests due to DIST_TEST=${my_test_control}
361 if has verbose ${my_test_control} ; then
367 if has parallel ${my_test_control} ; then
368 export HARNESS_OPTIONS=j$(makeopts_jobs)
369 einfo "Test::Harness Jobs=$(makeopts_jobs)"
372 # this might sometimes work...
373 if ! has network ${my_test_control} ; then
374 export NO_NETWORK_TESTING=1
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"
386 # @FUNCTION: perl-module_src_install
387 # @USAGE: perl-module_src_install
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 "$@"
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" ;;
409 if [[ $(declare -p myinst 2>&-) != "declare -a myinst="* ]]; then
410 local myinst_local=(${myinst})
412 local myinst_local=("${myinst[@]}")
414 emake "${myinst_local[@]}" ${mytargets} \
415 || die "emake ${myinst_local[@]} ${mytargets} failed"
418 perl_delete_module_manpages
420 if [[ ${EAPI:-0} == 5 ]] ; then
424 perl_delete_emptybsdir
428 for f in Change* CHANGES README* TODO FAQ ${mydoc}; do
429 [[ -s ${f} ]] && dodoc ${f}
432 if [[ ${EAPI:-0} != 5 ]] ; then
433 if in_iuse examples && use examples ; then
434 [[ ${#DIST_EXAMPLES[@]} -eq 0 ]] || perl_doexamples "${DIST_EXAMPLES[@]}"
438 perl_link_duallife_scripts
441 # @FUNCTION: perl-module_pkg_postinst
442 # @USAGE: perl-module_pkg_postinst
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."
454 perl_link_duallife_scripts
457 # @FUNCTION: perl-module_pkg_postrm
458 # @USAGE: perl-module_pkg_postrm
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."
470 perl_link_duallife_scripts