net-p2p/amule: Resolve merge conflicts.
[gentoo.git] / eclass / perl-module.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: perl-module.eclass
6 # @MAINTAINER:
7 # perl@gentoo.org
8 # @AUTHOR:
9 # Seemant Kulleen <seemant@gentoo.org>
10 # Andreas K. Hüttel <dilfridge@gentoo.org>
11 # @BLURB: eclass for installing Perl module distributions
12 # @DESCRIPTION:
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
19 # instead.
20
21 case ${EAPI:-0} in
22         5)
23                 inherit eutils multiprocessing unpacker perl-functions
24                 PERL_EXPF="src_unpack src_prepare src_configure src_compile src_test src_install"
25                 ;;
26         6)
27                 inherit multiprocessing perl-functions
28                 PERL_EXPF="src_prepare src_configure src_compile src_test src_install"
29                 ;;
30         *)
31                 die "EAPI=${EAPI} is not supported by perl-module.eclass"
32                 ;;
33 esac
34
35 # @ECLASS-VARIABLE: GENTOO_DEPEND_ON_PERL
36 # @DESCRIPTION:
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.
42
43 case ${EAPI:-0} in
44         5)
45                 [[ ${CATEGORY} == perl-core ]] && \
46                         PERL_EXPF+=" pkg_postinst pkg_postrm"
47
48                 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
49                 yes)
50                         case "${GENTOO_DEPEND_ON_PERL_SUBSLOT:-yes}" in
51                         yes)
52                                 DEPEND="dev-lang/perl:=[-build(-)]"
53                                 ;;
54                         *)
55                                 DEPEND="dev-lang/perl[-build(-)]"
56                                 ;;
57                         esac
58                         RDEPEND="${DEPEND}"
59                         ;;
60                 esac
61
62                 case "${PERL_EXPORT_PHASE_FUNCTIONS:-yes}" in
63                         yes)
64                                 EXPORT_FUNCTIONS ${PERL_EXPF}
65                                 ;;
66                         no)
67                                 debug-print "PERL_EXPORT_PHASE_FUNCTIONS=no"
68                                 ;;
69                         *)
70                                 die "PERL_EXPORT_PHASE_FUNCTIONS=${PERL_EXPORT_PHASE_FUNCTIONS} is not supported by perl-module.eclass"
71                                 ;;
72                 esac
73                 ;;
74         6)
75                 [[ ${CATEGORY} == perl-core ]] && \
76                         PERL_EXPF+=" pkg_postinst pkg_postrm"
77
78                 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
79                         yes)
80                                 DEPEND="dev-lang/perl:="
81                                 RDEPEND="dev-lang/perl:="
82                                 ;;
83                         noslotop)
84                                 DEPEND="dev-lang/perl"
85                                 RDEPEND="dev-lang/perl"
86                                 ;;
87                 esac
88
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."
92                 fi
93
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."
97                 fi
98
99                 EXPORT_FUNCTIONS ${PERL_EXPF}
100                 ;;
101         *)
102                 die "EAPI=${EAPI:-0} is not supported by perl-module.eclass"
103                 ;;
104 esac
105
106 LICENSE="${LICENSE:-|| ( Artistic GPL-1+ )}"
107
108 # @ECLASS-VARIABLE: DIST_NAME
109 # @DESCRIPTION:
110 # (EAPI=6) This variable provides a way to override PN for the calculation of S,
111 # SRC_URI, and HOMEPAGE. Defaults to PN.
112
113 # @ECLASS-VARIABLE: DIST_VERSION
114 # @DESCRIPTION:
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.
118
119 # @ECLASS-VARIABLE: DIST_A_EXT
120 # @DESCRIPTION:
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.
123
124 # @ECLASS-VARIABLE: DIST_A
125 # @DESCRIPTION:
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.
128
129 # @ECLASS-VARIABLE: DIST_AUTHOR
130 # @DESCRIPTION:
131 # (EAPI=6) This variable sets the module author name for the calculation of
132 # SRC_URI. Named MODULE_AUTHOR in EAPI=5.
133
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}}
138         fi
139         MODULE_NAME=${MY_PN:-${PN}}
140         MODULE_P=${MY_P:-${P}}
141
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}/"
148
149         SRC_TEST="skip"
150 else
151         DIST_NAME=${DIST_NAME:-${PN}}
152         DIST_P=${DIST_NAME}-${DIST_VERSION:-${PV}}
153         S=${WORKDIR}/${DIST_P}
154
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}/"
161 fi
162
163 SRC_PREP="no"
164 PREFER_BUILDPL="yes"
165
166 pm_echovar=""
167
168 # @FUNCTION: perl-module_src_unpack
169 # @USAGE: perl-module_src_unpack
170 # @DESCRIPTION:
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"
176         unpacker_src_unpack
177 }
178
179 # @FUNCTION: perl-module_src_prepare
180 # @USAGE: perl-module_src_prepare
181 # @DESCRIPTION:
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 "$@"
186
187         if [[ ${EAPI:-0} == 5 ]] ; then
188                 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
189                 debug-print "$FUNCNAME: applying user patches"
190                 epatch_user
191         else
192                 default
193         fi
194
195         if [[ ${PERL_RM_FILES[@]} ]]; then
196                 debug-print "$FUNCNAME: stripping unneeded files"
197                 perl_rm_files "${PERL_RM_FILES[@]}"
198         fi
199         perl_fix_osx_extra
200 }
201
202 # @FUNCTION: perl-module_src_configure
203 # @USAGE: perl-module_src_configure
204 # @DESCRIPTION:
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 "$@"
209
210         if [[ ${EAPI:-0} == 5 && ${SRC_PREP} == yes ]]; then
211                 return 0
212         fi
213         SRC_PREP="yes"
214
215         perl_check_env
216
217         perl_set_version
218
219         [[ -z ${pm_echovar} ]] && export PERL_MM_USE_DEFAULT=1
220         # Disable ExtUtils::AutoInstall from prompting
221         export PERL_EXTUTILS_AUTOINSTALL="--skipdeps"
222
223         if [[ $(declare -p myconf 2>&-) != "declare -a myconf="* ]]; then
224                 local myconf_local=(${myconf})
225         else
226                 local myconf_local=("${myconf[@]}")
227         fi
228
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!"
235                         fi
236                 else
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!"
241                         fi
242                 fi
243                 set -- \
244                         --installdirs=vendor \
245                         --libdoc= \
246                         --destdir="${D}" \
247                         --create_packlist=1 \
248                         "${myconf_local[@]}"
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"
254                 set -- \
255                         PREFIX=${EPREFIX}/usr \
256                         INSTALLDIRS=vendor \
257                         INSTALLMAN3DIR='none' \
258                         DESTDIR="${D}" \
259                         "${myconf_local[@]}"
260                 einfo "perl Makefile.PL" "$@"
261                 perl Makefile.PL "$@" <<< "${pm_echovar}" \
262                                 || die "Unable to build!"
263         fi
264         if [[ ! -f Build.PL && ! -f Makefile.PL ]] ; then
265                 einfo "No Make or Build file detected..."
266                 return
267         fi
268 }
269
270 # @FUNCTION: perl-module_src_compile
271 # @USAGE: perl-module_src_compile
272 # @DESCRIPTION:
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 "$@"
277         perl_set_version
278
279         if [[ $(declare -p mymake 2>&-) != "declare -a mymake="* ]]; then
280                 local mymake_local=(${mymake})
281         else
282                 local mymake_local=("${mymake[@]}")
283         fi
284
285         if [[ -f Build ]] ; then
286                 ./Build build \
287                         || die "Compilation failed"
288         elif [[ -f Makefile ]] ; then
289                 set -- \
290                         OTHERLDFLAGS="${LDFLAGS}" \
291                         "${mymake_local[@]}"
292                 einfo "emake" "$@"
293                 emake "$@" \
294                         || die "Compilation failed"
295 #                       OPTIMIZE="${CFLAGS}" \
296         fi
297 }
298
299 # @ECLASS-VARIABLE: DIST_TEST
300 # @DESCRIPTION:
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:
307 #   do       : run tests
308 #   parallel : run tests in parallel
309 #   verbose  : increase test verbosity
310 #   network  : do not try to disable network tests
311
312 # @ECLASS-VARIABLE: DIST_TEST_OVERRIDE
313 # @DESCRIPTION:
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!
319
320 # @FUNCTION: perl-module_src-test
321 # @USAGE: perl-module_src_test()
322 # @DESCRIPTION:
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
329
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)"
337                         fi
338                 else
339                         einfo Skipping tests due to SRC_TEST=${SRC_TEST}
340                         return 0
341                 fi
342         else
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}}
345
346                 if ! has 'do' ${my_test_control} && ! has 'parallel' ${my_test_control} ; then
347                         einfo Skipping tests due to DIST_TEST=${my_test_control}
348                         return 0
349                 fi
350
351                 if has verbose ${my_test_control} ; then
352                         my_test_verbose=1
353                 else
354                         my_test_verbose=0
355                 fi
356
357                 if has parallel ${my_test_control} ; then
358                         export HARNESS_OPTIONS=j$(makeopts_jobs)
359                         einfo "Test::Harness Jobs=$(makeopts_jobs)"
360                 fi
361
362                 # this might sometimes work...
363                 if ! has network ${my_test_control} ; then
364                         export NO_NETWORK_TESTING=1
365                 fi
366         fi
367
368         perl_set_version
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"
373         fi
374 }
375
376 # @FUNCTION: perl-module_src_install
377 # @USAGE: perl-module_src_install
378 # @DESCRIPTION:
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 "$@"
383
384         perl_set_version
385
386         local f
387
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" ;;
398                 esac
399                 if [[ $(declare -p myinst 2>&-) != "declare -a myinst="* ]]; then
400                         local myinst_local=(${myinst})
401                 else
402                         local myinst_local=("${myinst[@]}")
403                 fi
404                 emake "${myinst_local[@]}" ${mytargets} \
405                         || die "emake ${myinst_local[@]} ${mytargets} failed"
406         fi
407
408         perl_delete_module_manpages
409         perl_delete_localpod
410         if [[ ${EAPI:-0} == 5 ]] ; then
411                 perl_delete_packlist
412         else
413                 perl_fix_packlist
414                 perl_delete_emptybsdir
415         fi
416         perl_remove_temppath
417
418         for f in Change* CHANGES README* TODO FAQ ${mydoc}; do
419                 [[ -s ${f} ]] && dodoc ${f}
420         done
421
422         perl_link_duallife_scripts
423 }
424
425 # @FUNCTION: perl-module_pkg_postinst
426 # @USAGE: perl-module_pkg_postinst
427 # @DESCRIPTION:
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."
437         fi
438         perl_link_duallife_scripts
439 }
440
441 # @FUNCTION: perl-module_pkg_postrm
442 # @USAGE: perl-module_pkg_postrm
443 # @DESCRIPTION:
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."
453         fi
454         perl_link_duallife_scripts
455 }