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 if [[ ${EAPI:-0} == 5 ]]; then
135 if [[ -n ${MY_PN} || -n ${MY_PV} || -n ${MODULE_VERSION} ]] ; then
136 : ${MY_P:=${MY_PN:-${PN}}-${MY_PV:-${MODULE_VERSION:-${PV}}}}
137 S=${MY_S:-${WORKDIR}/${MY_P}}
139 MODULE_NAME=${MY_PN:-${PN}}
140 MODULE_P=${MY_P:-${P}}
142 [[ -z "${SRC_URI}" && -z "${MODULE_A}" ]] && \
143 MODULE_A="${MODULE_P}.${MODULE_A_EXT:-tar.gz}"
144 [[ -z "${SRC_URI}" && -n "${MODULE_AUTHOR}" ]] && \
145 SRC_URI="mirror://cpan/authors/id/${MODULE_AUTHOR:0:1}/${MODULE_AUTHOR:0:2}/${MODULE_AUTHOR}/${MODULE_SECTION:+${MODULE_SECTION}/}${MODULE_A}"
146 [[ -z "${HOMEPAGE}" ]] && \
147 HOMEPAGE="http://search.cpan.org/dist/${MODULE_NAME}/"
151 DIST_NAME=${DIST_NAME:-${PN}}
152 DIST_P=${DIST_NAME}-${DIST_VERSION:-${PV}}
153 S=${WORKDIR}/${DIST_P}
155 [[ -z "${SRC_URI}" && -z "${DIST_A}" ]] && \
156 DIST_A="${DIST_P}.${DIST_A_EXT:-tar.gz}"
157 [[ -z "${SRC_URI}" && -n "${DIST_AUTHOR}" ]] && \
158 SRC_URI="mirror://cpan/authors/id/${DIST_AUTHOR:0:1}/${DIST_AUTHOR:0:2}/${DIST_AUTHOR}/${DIST_SECTION:+${DIST_SECTION}/}${DIST_A}"
159 [[ -z "${HOMEPAGE}" ]] && \
160 HOMEPAGE="http://search.cpan.org/dist/${DIST_NAME}/"
168 # @FUNCTION: perl-module_src_unpack
169 # @USAGE: perl-module_src_unpack
171 # Unpack the ebuild tarball(s).
172 # This function is to be called during the ebuild src_unpack() phase.
173 perl-module_src_unpack() {
174 debug-print-function $FUNCNAME "$@"
175 [[ ${EAPI:-0} == 5 ]] || die "perl-module_src_unpack is banned in EAPI=6 or later"
179 # @FUNCTION: perl-module_src_prepare
180 # @USAGE: perl-module_src_prepare
182 # Get the ebuild sources ready.
183 # This function is to be called during the ebuild src_prepare() phase.
184 perl-module_src_prepare() {
185 debug-print-function $FUNCNAME "$@"
187 if [[ ${EAPI:-0} == 5 ]] ; then
188 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
189 debug-print "$FUNCNAME: applying user patches"
195 if [[ ${PERL_RM_FILES[@]} ]]; then
196 debug-print "$FUNCNAME: stripping unneeded files"
197 perl_rm_files "${PERL_RM_FILES[@]}"
202 # @FUNCTION: perl-module_src_configure
203 # @USAGE: perl-module_src_configure
205 # Configure the ebuild sources.
206 # This function is to be called during the ebuild src_configure() phase.
207 perl-module_src_configure() {
208 debug-print-function $FUNCNAME "$@"
210 if [[ ${EAPI:-0} == 5 && ${SRC_PREP} == yes ]]; then
219 [[ -z ${pm_echovar} ]] && export PERL_MM_USE_DEFAULT=1
220 # Disable ExtUtils::AutoInstall from prompting
221 export PERL_EXTUTILS_AUTOINSTALL="--skipdeps"
223 if [[ $(declare -p myconf 2>&-) != "declare -a myconf="* ]]; then
224 local myconf_local=(${myconf})
226 local myconf_local=("${myconf[@]}")
229 if [[ ( ${PREFER_BUILDPL} == yes || ! -f Makefile.PL ) && -f Build.PL ]] ; then
230 if grep -q '\(use\|require\)\s*Module::Build::Tiny' Build.PL ; then
231 einfo "Using Module::Build::Tiny"
232 if [[ ${DEPEND} != *dev-perl/Module-Build-Tiny* && ${PN} != Module-Build-Tiny ]]; then
233 eerror "QA Notice: The ebuild uses Module::Build::Tiny but doesn't depend on it."
234 die " Add dev-perl/Module-Build-Tiny to DEPEND!"
237 einfo "Using Module::Build"
238 if [[ ${DEPEND} != *virtual/perl-Module-Build* && ${DEPEND} != *dev-perl/Module-Build* && ${PN} != Module-Build ]] ; then
239 eerror "QA Notice: The ebuild uses Module::Build but doesn't depend on it."
240 die " Add dev-perl/Module-Build to DEPEND!"
244 --installdirs=vendor \
247 --create_packlist=1 \
249 einfo "perl Build.PL" "$@"
250 perl Build.PL "$@" <<< "${pm_echovar}" \
251 || die "Unable to build!"
252 elif [[ -f Makefile.PL ]] ; then
253 einfo "Using ExtUtils::MakeMaker"
255 PREFIX=${EPREFIX}/usr \
257 INSTALLMAN3DIR='none' \
260 einfo "perl Makefile.PL" "$@"
261 perl Makefile.PL "$@" <<< "${pm_echovar}" \
262 || die "Unable to build!"
264 if [[ ! -f Build.PL && ! -f Makefile.PL ]] ; then
265 einfo "No Make or Build file detected..."
270 # @FUNCTION: perl-module_src_compile
271 # @USAGE: perl-module_src_compile
273 # Compile the ebuild sources.
274 # This function is to be called during the ebuild src_compile() phase.
275 perl-module_src_compile() {
276 debug-print-function $FUNCNAME "$@"
279 if [[ $(declare -p mymake 2>&-) != "declare -a mymake="* ]]; then
280 local mymake_local=(${mymake})
282 local mymake_local=("${mymake[@]}")
285 if [[ -f Build ]] ; then
287 || die "Compilation failed"
288 elif [[ -f Makefile ]] ; then
290 OTHERLDFLAGS="${LDFLAGS}" \
294 || die "Compilation failed"
295 # OPTIMIZE="${CFLAGS}" \
299 # @ECLASS-VARIABLE: DIST_TEST
301 # (EAPI=6) Variable that controls if tests are run in the test phase
302 # at all, and if yes under which conditions. Defaults to "do parallel"
303 # If neither "do" nor "parallel" is recognized, tests are skipped.
304 # (In EAPI=5 the variable is called SRC_TEST, defaults to "skip", and
305 # recognizes fewer options.)
306 # The following space-separated keywords are recognized:
308 # parallel : run tests in parallel
309 # verbose : increase test verbosity
310 # network : do not try to disable network tests
312 # @ECLASS-VARIABLE: DIST_TEST_OVERRIDE
314 # (EAPI=6) Variable that controls if tests are run in the test phase
315 # at all, and if yes under which conditions. It is intended for use in
316 # make.conf or the environment by ebuild authors during testing, and
317 # accepts the same values as DIST_TEST. If set, it overrides DIST_TEST
318 # completely. DO NOT USE THIS IN EBUILDS!
320 # @FUNCTION: perl-module_src-test
321 # @USAGE: perl-module_src_test()
323 # This code attempts to work out your threadingness and runs tests
324 # according to the settings of DIST_TEST using Test::Harness.
325 perl-module_src_test() {
326 debug-print-function $FUNCNAME "$@"
327 local my_test_control
328 local my_test_verbose
330 if [[ ${EAPI:-0} == 5 ]] ; then
331 my_test_control=${SRC_TEST}
332 my_test_verbose=${TEST_VERBOSE:-0}
333 if has 'do' ${my_test_control} || has 'parallel' ${my_test_control} ; then
334 if has "${my_test_verbose}" 0 && has 'parallel' ${my_test_control} ; then
335 export HARNESS_OPTIONS=j$(makeopts_jobs)
336 einfo "Test::Harness Jobs=$(makeopts_jobs)"
339 einfo Skipping tests due to SRC_TEST=${SRC_TEST}
343 [[ -n "${DIST_TEST_OVERRIDE}" ]] && ewarn DIST_TEST_OVERRIDE is set to ${DIST_TEST_OVERRIDE}
344 my_test_control=${DIST_TEST_OVERRIDE:-${DIST_TEST:-do parallel}}
346 if ! has 'do' ${my_test_control} && ! has 'parallel' ${my_test_control} ; then
347 einfo Skipping tests due to DIST_TEST=${my_test_control}
351 if has verbose ${my_test_control} ; then
357 if has parallel ${my_test_control} ; then
358 export HARNESS_OPTIONS=j$(makeopts_jobs)
359 einfo "Test::Harness Jobs=$(makeopts_jobs)"
362 # this might sometimes work...
363 if ! has network ${my_test_control} ; then
364 export NO_NETWORK_TESTING=1
369 if [[ -f Build ]] ; then
370 ./Build test verbose=${my_test_verbose} || die "test failed"
371 elif [[ -f Makefile ]] ; then
372 emake test TEST_VERBOSE=${my_test_verbose} || die "test failed"
376 # @FUNCTION: perl-module_src_install
377 # @USAGE: perl-module_src_install
379 # Install a Perl ebuild.
380 # This function is to be called during the ebuild src_install() phase.
381 perl-module_src_install() {
382 debug-print-function $FUNCNAME "$@"
388 if [[ -f Build ]]; then
389 mytargets="${mytargets:-install}"
390 mbparams="${mbparams:---pure}"
391 einfo "./Build ${mytargets} ${mbparams}"
392 ./Build ${mytargets} ${mbparams} \
393 || die "./Build ${mytargets} ${mbparams} failed"
394 elif [[ -f Makefile ]]; then
395 case "${CATEGORY}" in
396 dev-perl|perl-core) mytargets="pure_install" ;;
397 *) mytargets="install" ;;
399 if [[ $(declare -p myinst 2>&-) != "declare -a myinst="* ]]; then
400 local myinst_local=(${myinst})
402 local myinst_local=("${myinst[@]}")
404 emake "${myinst_local[@]}" ${mytargets} \
405 || die "emake ${myinst_local[@]} ${mytargets} failed"
408 perl_delete_module_manpages
410 if [[ ${EAPI:-0} == 5 ]] ; then
414 perl_delete_emptybsdir
418 for f in Change* CHANGES README* TODO FAQ ${mydoc}; do
419 [[ -s ${f} ]] && dodoc ${f}
422 perl_link_duallife_scripts
425 # @FUNCTION: perl-module_pkg_postinst
426 # @USAGE: perl-module_pkg_postinst
428 # This function is to be called during the pkg_postinst() phase. It only does
429 # useful things for the perl-core category, where it handles the file renaming and symbolic
430 # links that prevent file collisions for dual-life packages installing scripts.
431 # In any other category it immediately exits.
432 perl-module_pkg_postinst() {
433 debug-print-function $FUNCNAME "$@"
434 if [[ ${CATEGORY} != perl-core ]] ; then
435 eerror "perl-module.eclass: You are calling perl-module_pkg_postinst outside the perl-core category."
436 die " This does not do anything; the call can be removed."
438 perl_link_duallife_scripts
441 # @FUNCTION: perl-module_pkg_postrm
442 # @USAGE: perl-module_pkg_postrm
444 # This function is to be called during the pkg_postrm() 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_postrm() {
449 debug-print-function $FUNCNAME "$@"
450 if [[ ${CATEGORY} != perl-core ]] ; then
451 eerror "perl-module.eclass: You are calling perl-module_pkg_postrm outside the perl-core category."
452 die " This does not do anything; the call can be removed."
454 perl_link_duallife_scripts