kde-apps/ksirk: x86 stable (bug #661810)
[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
4 # @ECLASS: perl-module.eclass
5 # @MAINTAINER:
6 # perl@gentoo.org
7 # @AUTHOR:
8 # Seemant Kulleen <seemant@gentoo.org>
9 # Andreas K. Hüttel <dilfridge@gentoo.org>
10 # @BLURB: eclass for installing Perl module distributions
11 # @DESCRIPTION:
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
18 # instead.
19
20 case ${EAPI:-0} in
21         5)
22                 inherit eutils multiprocessing unpacker perl-functions
23                 PERL_EXPF="src_unpack src_prepare src_configure src_compile src_test src_install"
24                 ;;
25         6)
26                 inherit multiprocessing perl-functions
27                 PERL_EXPF="src_prepare src_configure src_compile src_test src_install"
28                 ;;
29         *)
30                 die "EAPI=${EAPI} is not supported by perl-module.eclass"
31                 ;;
32 esac
33
34 # @ECLASS-VARIABLE: GENTOO_DEPEND_ON_PERL
35 # @DEFAULT_UNSET
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:-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."
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 # @DEFAULT_UNSET
131 # @DESCRIPTION:
132 # (EAPI=6) This variable sets the module author name for the calculation of
133 # SRC_URI. Named MODULE_AUTHOR in EAPI=5.
134
135 # @ECLASS-VARIABLE: DIST_SECTION
136 # @DEFAULT_UNSET
137 # @DESCRIPTION:
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.
141
142 # @ECLASS-VARIABLE: DIST_EXAMPLES
143 # @DEFAULT_UNSET
144 # @DESCRIPTION:
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.
149
150
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}}
155         fi
156         MODULE_NAME=${MY_PN:-${PN}}
157         MODULE_P=${MY_P:-${P}}
158
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}/"
165
166         SRC_TEST="skip"
167 else
168         DIST_NAME=${DIST_NAME:-${PN}}
169         DIST_P=${DIST_NAME}-${DIST_VERSION:-${PV}}
170         S=${WORKDIR}/${DIST_P}
171
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}/"
178
179         [[ -z "${DIST_EXAMPLES}" ]] || IUSE+=" examples"
180 fi
181
182 SRC_PREP="no"
183 PREFER_BUILDPL="yes"
184
185 pm_echovar=""
186
187 # @FUNCTION: perl-module_src_unpack
188 # @DESCRIPTION:
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"
194         unpacker_src_unpack
195 }
196
197 # @FUNCTION: perl-module_src_prepare
198 # @DESCRIPTION:
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 "$@"
203
204         if [[ ${EAPI:-0} == 5 ]] ; then
205                 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
206                 debug-print "$FUNCNAME: applying user patches"
207                 epatch_user
208         else
209                 default
210         fi
211
212         if [[ ${PERL_RM_FILES[@]} ]]; then
213                 debug-print "$FUNCNAME: stripping unneeded files"
214                 perl_rm_files "${PERL_RM_FILES[@]}"
215         fi
216         perl_fix_osx_extra
217 }
218
219 # @FUNCTION: perl-module_src_configure
220 # @DESCRIPTION:
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 "$@"
225
226         if [[ ${EAPI:-0} == 5 && ${SRC_PREP} == yes ]]; then
227                 return 0
228         fi
229         SRC_PREP="yes"
230
231         perl_check_env
232
233         perl_set_version
234
235         [[ -z ${pm_echovar} ]] && export PERL_MM_USE_DEFAULT=1
236         # Disable ExtUtils::AutoInstall from prompting
237         export PERL_EXTUTILS_AUTOINSTALL="--skipdeps"
238
239         if [[ $(declare -p myconf 2>&-) != "declare -a myconf="* ]]; then
240                 local myconf_local=(${myconf})
241         else
242                 local myconf_local=("${myconf[@]}")
243         fi
244
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!"
251                         fi
252                 else
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!"
257                         fi
258                 fi
259                 set -- \
260                         --installdirs=vendor \
261                         --libdoc= \
262                         --destdir="${D}" \
263                         --create_packlist=1 \
264                         "${myconf_local[@]}"
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"
270                 set -- \
271                         PREFIX=${EPREFIX}/usr \
272                         INSTALLDIRS=vendor \
273                         INSTALLMAN3DIR='none' \
274                         DESTDIR="${D}" \
275                         "${myconf_local[@]}"
276                 einfo "perl Makefile.PL" "$@"
277                 perl Makefile.PL "$@" <<< "${pm_echovar}" \
278                                 || die "Unable to build!"
279         fi
280         if [[ ! -f Build.PL && ! -f Makefile.PL ]] ; then
281                 einfo "No Make or Build file detected..."
282                 return
283         fi
284 }
285
286 # @FUNCTION: perl-module_src_compile
287 # @DESCRIPTION:
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 "$@"
292         perl_set_version
293
294         if [[ $(declare -p mymake 2>&-) != "declare -a mymake="* ]]; then
295                 local mymake_local=(${mymake})
296         else
297                 local mymake_local=("${mymake[@]}")
298         fi
299
300         if [[ -f Build ]] ; then
301                 ./Build build \
302                         || die "Compilation failed"
303         elif [[ -f Makefile ]] ; then
304                 set -- \
305                         OTHERLDFLAGS="${LDFLAGS}" \
306                         "${mymake_local[@]}"
307                 einfo "emake" "$@"
308                 emake "$@" \
309                         || die "Compilation failed"
310 #                       OPTIMIZE="${CFLAGS}" \
311         fi
312 }
313
314 # @ECLASS-VARIABLE: DIST_TEST
315 # @DESCRIPTION:
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:
322 #   do       : run tests
323 #   parallel : run tests in parallel
324 #   verbose  : increase test verbosity
325 #   network  : do not try to disable network tests
326
327 # @ECLASS-VARIABLE: DIST_TEST_OVERRIDE
328 # @DEFAULT_UNSET
329 # @DESCRIPTION:
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!
335
336 # @FUNCTION: perl-module_src-test
337 # @DESCRIPTION:
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
344
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)"
352                         fi
353                 else
354                         einfo Skipping tests due to SRC_TEST=${SRC_TEST}
355                         return 0
356                 fi
357         else
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}}
360
361                 if ! has 'do' ${my_test_control} && ! has 'parallel' ${my_test_control} ; then
362                         einfo Skipping tests due to DIST_TEST=${my_test_control}
363                         return 0
364                 fi
365
366                 if has verbose ${my_test_control} ; then
367                         my_test_verbose=1
368                 else
369                         my_test_verbose=0
370                 fi
371
372                 if has parallel ${my_test_control} ; then
373                         export HARNESS_OPTIONS=j$(makeopts_jobs)
374                         einfo "Test::Harness Jobs=$(makeopts_jobs)"
375                 fi
376
377                 # this might sometimes work...
378                 if ! has network ${my_test_control} ; then
379                         export NO_NETWORK_TESTING=1
380                 fi
381         fi
382
383         perl_set_version
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"
388         fi
389 }
390
391 # @FUNCTION: perl-module_src_install
392 # @DESCRIPTION:
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 "$@"
397
398         perl_set_version
399
400         local f
401
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" ;;
412                 esac
413                 if [[ $(declare -p myinst 2>&-) != "declare -a myinst="* ]]; then
414                         local myinst_local=(${myinst})
415                 else
416                         local myinst_local=("${myinst[@]}")
417                 fi
418                 emake "${myinst_local[@]}" ${mytargets} \
419                         || die "emake ${myinst_local[@]} ${mytargets} failed"
420         fi
421
422         perl_delete_module_manpages
423         perl_delete_localpod
424         if [[ ${EAPI:-0} == 5 ]] ; then
425                 perl_delete_packlist
426         else
427                 perl_fix_packlist
428                 perl_delete_emptybsdir
429         fi
430         perl_remove_temppath
431
432         for f in Change* CHANGES README* TODO FAQ ${mydoc}; do
433                 [[ -s ${f} ]] && dodoc ${f}
434         done
435
436         if [[ ${EAPI:-0} != 5 ]] ; then
437                 if in_iuse examples && use examples ; then
438                         [[ ${#DIST_EXAMPLES[@]} -eq 0 ]] || perl_doexamples "${DIST_EXAMPLES[@]}"
439                 fi
440         fi
441
442         perl_link_duallife_scripts
443 }
444
445 # @FUNCTION: perl-module_pkg_postinst
446 # @DESCRIPTION:
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."
456         fi
457         perl_link_duallife_scripts
458 }
459
460 # @FUNCTION: perl-module_pkg_postrm
461 # @DESCRIPTION:
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."
471         fi
472         perl_link_duallife_scripts
473 }