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
36 # This variable controls whether a runtime and build time dependency on
37 # dev-lang/perl is automatically added by the eclass. It defaults to yes.
38 # Set to no to disable, set to noslotop to add a perl dependency without
39 # slot operator (EAPI=6). All packages installing into the vendor_perl
40 # path must use yes here.
44 [[ ${CATEGORY} == perl-core ]] && \
45 PERL_EXPF+=" pkg_postinst pkg_postrm"
47 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
49 case "${GENTOO_DEPEND_ON_PERL_SUBSLOT:-yes}" in
51 DEPEND="dev-lang/perl:=[-build(-)]"
54 DEPEND="dev-lang/perl[-build(-)]"
61 case "${PERL_EXPORT_PHASE_FUNCTIONS:-yes}" in
63 EXPORT_FUNCTIONS ${PERL_EXPF}
66 debug-print "PERL_EXPORT_PHASE_FUNCTIONS=no"
69 die "PERL_EXPORT_PHASE_FUNCTIONS=${PERL_EXPORT_PHASE_FUNCTIONS} is not supported by perl-module.eclass"
74 [[ ${CATEGORY} == perl-core ]] && \
75 PERL_EXPF+=" pkg_postinst pkg_postrm"
77 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
79 DEPEND="dev-lang/perl:="
80 RDEPEND="dev-lang/perl:="
83 DEPEND="dev-lang/perl"
84 RDEPEND="dev-lang/perl"
88 if [[ "${GENTOO_DEPEND_ON_PERL_SUBSLOT}" ]]; then
89 eerror "GENTOO_DEPEND_ON_PERL_SUBSLOT is banned in EAPI=6. If you don't want a slot operator"
90 die "set GENTOO_DEPEND_ON_PERL=noslotop instead."
93 if [[ "${PERL_EXPORT_PHASE_FUNCTIONS}" ]]; then
94 eerror "PERL_EXPORT_PHASE_FUNCTIONS is banned in EAPI=6. Use perl-module.eclass if you need"
95 die "phase functions, perl-functions.eclass if not."
98 EXPORT_FUNCTIONS ${PERL_EXPF}
101 die "EAPI=${EAPI:-0} is not supported by perl-module.eclass"
105 LICENSE="${LICENSE:-|| ( Artistic GPL-1+ )}"
107 # @ECLASS-VARIABLE: DIST_NAME
109 # (EAPI=6) This variable provides a way to override PN for the calculation of S,
110 # SRC_URI, and HOMEPAGE. Defaults to PN.
112 # @ECLASS-VARIABLE: DIST_VERSION
114 # (EAPI=6) This variable provides a way to override PV for the calculation of S and SRC_URI.
115 # Use it to provide the non-normalized, upstream version number. Defaults to PV.
116 # Named MODULE_VERSION in EAPI=5.
118 # @ECLASS-VARIABLE: DIST_A_EXT
120 # (EAPI=6) This variable provides a way to override the distfile extension for the calculation of
121 # SRC_URI. Defaults to tar.gz. Named MODULE_A_EXT in EAPI=5.
123 # @ECLASS-VARIABLE: DIST_A
125 # (EAPI=6) This variable provides a way to override the distfile name for the calculation of
126 # SRC_URI. Defaults to ${DIST_NAME}-${DIST_VERSION}.${DIST_A_EXT} Named MODULE_A in EAPI=5.
128 # @ECLASS-VARIABLE: DIST_AUTHOR
130 # (EAPI=6) This variable sets the module author name for the calculation of
131 # SRC_URI. Named MODULE_AUTHOR in EAPI=5.
133 # @ECLASS-VARIABLE: DIST_SECTION
135 # (EAPI=6) This variable sets the module section for the calculation of
136 # SRC_URI. Only required in rare cases for very special snowflakes.
137 # Named MODULE_SECTION in EAPI=5.
139 # @ECLASS-VARIABLE: DIST_EXAMPLES
141 # (EAPI=6) This Bash array allows passing a list of example files to be installed
142 # in /usr/share/doc/${PF}/examples. If set before inherit, automatically adds
143 # a use-flag examples, if not you'll have to add the useflag in your ebuild.
144 # Examples are installed only if the useflag examples exists and is activated.
147 if [[ ${EAPI:-0} == 5 ]]; then
148 if [[ -n ${MY_PN} || -n ${MY_PV} || -n ${MODULE_VERSION} ]] ; then
149 : ${MY_P:=${MY_PN:-${PN}}-${MY_PV:-${MODULE_VERSION:-${PV}}}}
150 S=${MY_S:-${WORKDIR}/${MY_P}}
152 MODULE_NAME=${MY_PN:-${PN}}
153 MODULE_P=${MY_P:-${P}}
155 [[ -z "${SRC_URI}" && -z "${MODULE_A}" ]] && \
156 MODULE_A="${MODULE_P}.${MODULE_A_EXT:-tar.gz}"
157 [[ -z "${SRC_URI}" && -n "${MODULE_AUTHOR}" ]] && \
158 SRC_URI="mirror://cpan/authors/id/${MODULE_AUTHOR:0:1}/${MODULE_AUTHOR:0:2}/${MODULE_AUTHOR}/${MODULE_SECTION:+${MODULE_SECTION}/}${MODULE_A}"
159 [[ -z "${HOMEPAGE}" ]] && \
160 HOMEPAGE="http://search.cpan.org/dist/${MODULE_NAME}/"
164 DIST_NAME=${DIST_NAME:-${PN}}
165 DIST_P=${DIST_NAME}-${DIST_VERSION:-${PV}}
166 S=${WORKDIR}/${DIST_P}
168 [[ -z "${SRC_URI}" && -z "${DIST_A}" ]] && \
169 DIST_A="${DIST_P}.${DIST_A_EXT:-tar.gz}"
170 [[ -z "${SRC_URI}" && -n "${DIST_AUTHOR}" ]] && \
171 SRC_URI="mirror://cpan/authors/id/${DIST_AUTHOR:0:1}/${DIST_AUTHOR:0:2}/${DIST_AUTHOR}/${DIST_SECTION:+${DIST_SECTION}/}${DIST_A}"
172 [[ -z "${HOMEPAGE}" ]] && \
173 HOMEPAGE="http://search.cpan.org/dist/${DIST_NAME}/"
175 [[ -z "${DIST_EXAMPLES}" ]] || IUSE+=" examples"
183 # @FUNCTION: perl-module_src_unpack
184 # @USAGE: perl-module_src_unpack
186 # Unpack the ebuild tarball(s).
187 # This function is to be called during the ebuild src_unpack() phase.
188 perl-module_src_unpack() {
189 debug-print-function $FUNCNAME "$@"
190 [[ ${EAPI:-0} == 5 ]] || die "perl-module_src_unpack is banned in EAPI=6 or later"
194 # @FUNCTION: perl-module_src_prepare
195 # @USAGE: perl-module_src_prepare
197 # Get the ebuild sources ready.
198 # This function is to be called during the ebuild src_prepare() phase.
199 perl-module_src_prepare() {
200 debug-print-function $FUNCNAME "$@"
202 if [[ ${EAPI:-0} == 5 ]] ; then
203 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
204 debug-print "$FUNCNAME: applying user patches"
210 if [[ ${PERL_RM_FILES[@]} ]]; then
211 debug-print "$FUNCNAME: stripping unneeded files"
212 perl_rm_files "${PERL_RM_FILES[@]}"
217 # @FUNCTION: perl-module_src_configure
218 # @USAGE: perl-module_src_configure
220 # Configure the ebuild sources.
221 # This function is to be called during the ebuild src_configure() phase.
222 perl-module_src_configure() {
223 debug-print-function $FUNCNAME "$@"
225 if [[ ${EAPI:-0} == 5 && ${SRC_PREP} == yes ]]; then
234 [[ -z ${pm_echovar} ]] && export PERL_MM_USE_DEFAULT=1
235 # Disable ExtUtils::AutoInstall from prompting
236 export PERL_EXTUTILS_AUTOINSTALL="--skipdeps"
238 if [[ $(declare -p myconf 2>&-) != "declare -a myconf="* ]]; then
239 local myconf_local=(${myconf})
241 local myconf_local=("${myconf[@]}")
244 if [[ ( ${PREFER_BUILDPL} == yes || ! -f Makefile.PL ) && -f Build.PL ]] ; then
245 if grep -q '\(use\|require\)\s*Module::Build::Tiny' Build.PL ; then
246 einfo "Using Module::Build::Tiny"
247 if [[ ${DEPEND} != *dev-perl/Module-Build-Tiny* && ${PN} != Module-Build-Tiny ]]; then
248 eerror "QA Notice: The ebuild uses Module::Build::Tiny but doesn't depend on it."
249 die " Add dev-perl/Module-Build-Tiny to DEPEND!"
252 einfo "Using Module::Build"
253 if [[ ${DEPEND} != *virtual/perl-Module-Build* && ${DEPEND} != *dev-perl/Module-Build* && ${PN} != Module-Build ]] ; then
254 eerror "QA Notice: The ebuild uses Module::Build but doesn't depend on it."
255 die " Add dev-perl/Module-Build to DEPEND!"
259 --installdirs=vendor \
262 --create_packlist=1 \
264 einfo "perl Build.PL" "$@"
265 perl Build.PL "$@" <<< "${pm_echovar}" \
266 || die "Unable to build!"
267 elif [[ -f Makefile.PL ]] ; then
268 einfo "Using ExtUtils::MakeMaker"
270 PREFIX=${EPREFIX}/usr \
272 INSTALLMAN3DIR='none' \
275 einfo "perl Makefile.PL" "$@"
276 perl Makefile.PL "$@" <<< "${pm_echovar}" \
277 || die "Unable to build!"
279 if [[ ! -f Build.PL && ! -f Makefile.PL ]] ; then
280 einfo "No Make or Build file detected..."
285 # @FUNCTION: perl-module_src_compile
286 # @USAGE: 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
329 # (EAPI=6) Variable that controls if tests are run in the test phase
330 # at all, and if yes under which conditions. It is intended for use in
331 # make.conf or the environment by ebuild authors during testing, and
332 # accepts the same values as DIST_TEST. If set, it overrides DIST_TEST
333 # completely. DO NOT USE THIS IN EBUILDS!
335 # @FUNCTION: perl-module_src-test
336 # @USAGE: 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
392 # @USAGE: perl-module_src_install
394 # Install a Perl ebuild.
395 # This function is to be called during the ebuild src_install() phase.
396 perl-module_src_install() {
397 debug-print-function $FUNCNAME "$@"
403 if [[ -f Build ]]; then
404 mytargets="${mytargets:-install}"
405 mbparams="${mbparams:---pure}"
406 einfo "./Build ${mytargets} ${mbparams}"
407 ./Build ${mytargets} ${mbparams} \
408 || die "./Build ${mytargets} ${mbparams} failed"
409 elif [[ -f Makefile ]]; then
410 case "${CATEGORY}" in
411 dev-perl|perl-core) mytargets="pure_install" ;;
412 *) mytargets="install" ;;
414 if [[ $(declare -p myinst 2>&-) != "declare -a myinst="* ]]; then
415 local myinst_local=(${myinst})
417 local myinst_local=("${myinst[@]}")
419 emake "${myinst_local[@]}" ${mytargets} \
420 || die "emake ${myinst_local[@]} ${mytargets} failed"
423 perl_delete_module_manpages
425 if [[ ${EAPI:-0} == 5 ]] ; then
429 perl_delete_emptybsdir
433 for f in Change* CHANGES README* TODO FAQ ${mydoc}; do
434 [[ -s ${f} ]] && dodoc ${f}
437 if [[ ${EAPI:-0} != 5 ]] ; then
438 if in_iuse examples && use examples ; then
439 [[ ${#DIST_EXAMPLES[@]} -eq 0 ]] || perl_doexamples "${DIST_EXAMPLES[@]}"
443 perl_link_duallife_scripts
446 # @FUNCTION: perl-module_pkg_postinst
447 # @USAGE: perl-module_pkg_postinst
449 # This function is to be called during the pkg_postinst() phase. It only does
450 # useful things for the perl-core category, where it handles the file renaming and symbolic
451 # links that prevent file collisions for dual-life packages installing scripts.
452 # In any other category it immediately exits.
453 perl-module_pkg_postinst() {
454 debug-print-function $FUNCNAME "$@"
455 if [[ ${CATEGORY} != perl-core ]] ; then
456 eerror "perl-module.eclass: You are calling perl-module_pkg_postinst outside the perl-core category."
457 die " This does not do anything; the call can be removed."
459 perl_link_duallife_scripts
462 # @FUNCTION: perl-module_pkg_postrm
463 # @USAGE: perl-module_pkg_postrm
465 # This function is to be called during the pkg_postrm() phase. It only does
466 # useful things for the perl-core category, where it handles the file renaming and symbolic
467 # links that prevent file collisions for dual-life packages installing scripts.
468 # In any other category it immediately exits.
469 perl-module_pkg_postrm() {
470 debug-print-function $FUNCNAME "$@"
471 if [[ ${CATEGORY} != perl-core ]] ; then
472 eerror "perl-module.eclass: You are calling perl-module_pkg_postrm outside the perl-core category."
473 die " This does not do anything; the call can be removed."
475 perl_link_duallife_scripts