kde-plasma/breeze-gtk: x86 stable wrt bug #613144
[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 # @DESCRIPTION:
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.
41
42 case ${EAPI:-0} in
43         5)
44                 [[ ${CATEGORY} == perl-core ]] && \
45                         PERL_EXPF+=" pkg_postinst pkg_postrm"
46
47                 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
48                 yes)
49                         case "${GENTOO_DEPEND_ON_PERL_SUBSLOT:-yes}" in
50                         yes)
51                                 DEPEND="dev-lang/perl:=[-build(-)]"
52                                 ;;
53                         *)
54                                 DEPEND="dev-lang/perl[-build(-)]"
55                                 ;;
56                         esac
57                         RDEPEND="${DEPEND}"
58                         ;;
59                 esac
60
61                 case "${PERL_EXPORT_PHASE_FUNCTIONS:-yes}" in
62                         yes)
63                                 EXPORT_FUNCTIONS ${PERL_EXPF}
64                                 ;;
65                         no)
66                                 debug-print "PERL_EXPORT_PHASE_FUNCTIONS=no"
67                                 ;;
68                         *)
69                                 die "PERL_EXPORT_PHASE_FUNCTIONS=${PERL_EXPORT_PHASE_FUNCTIONS} is not supported by perl-module.eclass"
70                                 ;;
71                 esac
72                 ;;
73         6)
74                 [[ ${CATEGORY} == perl-core ]] && \
75                         PERL_EXPF+=" pkg_postinst pkg_postrm"
76
77                 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
78                         yes)
79                                 DEPEND="dev-lang/perl:="
80                                 RDEPEND="dev-lang/perl:="
81                                 ;;
82                         noslotop)
83                                 DEPEND="dev-lang/perl"
84                                 RDEPEND="dev-lang/perl"
85                                 ;;
86                 esac
87
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."
91                 fi
92
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."
96                 fi
97
98                 EXPORT_FUNCTIONS ${PERL_EXPF}
99                 ;;
100         *)
101                 die "EAPI=${EAPI:-0} is not supported by perl-module.eclass"
102                 ;;
103 esac
104
105 LICENSE="${LICENSE:-|| ( Artistic GPL-1+ )}"
106
107 # @ECLASS-VARIABLE: DIST_NAME
108 # @DESCRIPTION:
109 # (EAPI=6) This variable provides a way to override PN for the calculation of S,
110 # SRC_URI, and HOMEPAGE. Defaults to PN.
111
112 # @ECLASS-VARIABLE: DIST_VERSION
113 # @DESCRIPTION:
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.
117
118 # @ECLASS-VARIABLE: DIST_A_EXT
119 # @DESCRIPTION:
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.
122
123 # @ECLASS-VARIABLE: DIST_A
124 # @DESCRIPTION:
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.
127
128 # @ECLASS-VARIABLE: DIST_AUTHOR
129 # @DESCRIPTION:
130 # (EAPI=6) This variable sets the module author name for the calculation of
131 # SRC_URI. Named MODULE_AUTHOR in EAPI=5.
132
133 # @ECLASS-VARIABLE: DIST_SECTION
134 # @DESCRIPTION:
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.
138
139 # @ECLASS-VARIABLE: DIST_EXAMPLES
140 # @DESCRIPTION:
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.
145
146
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}}
151         fi
152         MODULE_NAME=${MY_PN:-${PN}}
153         MODULE_P=${MY_P:-${P}}
154
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}/"
161
162         SRC_TEST="skip"
163 else
164         DIST_NAME=${DIST_NAME:-${PN}}
165         DIST_P=${DIST_NAME}-${DIST_VERSION:-${PV}}
166         S=${WORKDIR}/${DIST_P}
167
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}/"
174
175         [[ -z "${DIST_EXAMPLES}" ]] || IUSE+=" examples"
176 fi
177
178 SRC_PREP="no"
179 PREFER_BUILDPL="yes"
180
181 pm_echovar=""
182
183 # @FUNCTION: perl-module_src_unpack
184 # @USAGE: perl-module_src_unpack
185 # @DESCRIPTION:
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"
191         unpacker_src_unpack
192 }
193
194 # @FUNCTION: perl-module_src_prepare
195 # @USAGE: perl-module_src_prepare
196 # @DESCRIPTION:
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 "$@"
201
202         if [[ ${EAPI:-0} == 5 ]] ; then
203                 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
204                 debug-print "$FUNCNAME: applying user patches"
205                 epatch_user
206         else
207                 default
208         fi
209
210         if [[ ${PERL_RM_FILES[@]} ]]; then
211                 debug-print "$FUNCNAME: stripping unneeded files"
212                 perl_rm_files "${PERL_RM_FILES[@]}"
213         fi
214         perl_fix_osx_extra
215 }
216
217 # @FUNCTION: perl-module_src_configure
218 # @USAGE: perl-module_src_configure
219 # @DESCRIPTION:
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 "$@"
224
225         if [[ ${EAPI:-0} == 5 && ${SRC_PREP} == yes ]]; then
226                 return 0
227         fi
228         SRC_PREP="yes"
229
230         perl_check_env
231
232         perl_set_version
233
234         [[ -z ${pm_echovar} ]] && export PERL_MM_USE_DEFAULT=1
235         # Disable ExtUtils::AutoInstall from prompting
236         export PERL_EXTUTILS_AUTOINSTALL="--skipdeps"
237
238         if [[ $(declare -p myconf 2>&-) != "declare -a myconf="* ]]; then
239                 local myconf_local=(${myconf})
240         else
241                 local myconf_local=("${myconf[@]}")
242         fi
243
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!"
250                         fi
251                 else
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!"
256                         fi
257                 fi
258                 set -- \
259                         --installdirs=vendor \
260                         --libdoc= \
261                         --destdir="${D}" \
262                         --create_packlist=1 \
263                         "${myconf_local[@]}"
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"
269                 set -- \
270                         PREFIX=${EPREFIX}/usr \
271                         INSTALLDIRS=vendor \
272                         INSTALLMAN3DIR='none' \
273                         DESTDIR="${D}" \
274                         "${myconf_local[@]}"
275                 einfo "perl Makefile.PL" "$@"
276                 perl Makefile.PL "$@" <<< "${pm_echovar}" \
277                                 || die "Unable to build!"
278         fi
279         if [[ ! -f Build.PL && ! -f Makefile.PL ]] ; then
280                 einfo "No Make or Build file detected..."
281                 return
282         fi
283 }
284
285 # @FUNCTION: perl-module_src_compile
286 # @USAGE: 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 # @DESCRIPTION:
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!
334
335 # @FUNCTION: perl-module_src-test
336 # @USAGE: 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 # @USAGE: perl-module_src_install
393 # @DESCRIPTION:
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 "$@"
398
399         perl_set_version
400
401         local f
402
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" ;;
413                 esac
414                 if [[ $(declare -p myinst 2>&-) != "declare -a myinst="* ]]; then
415                         local myinst_local=(${myinst})
416                 else
417                         local myinst_local=("${myinst[@]}")
418                 fi
419                 emake "${myinst_local[@]}" ${mytargets} \
420                         || die "emake ${myinst_local[@]} ${mytargets} failed"
421         fi
422
423         perl_delete_module_manpages
424         perl_delete_localpod
425         if [[ ${EAPI:-0} == 5 ]] ; then
426                 perl_delete_packlist
427         else
428                 perl_fix_packlist
429                 perl_delete_emptybsdir
430         fi
431         perl_remove_temppath
432
433         for f in Change* CHANGES README* TODO FAQ ${mydoc}; do
434                 [[ -s ${f} ]] && dodoc ${f}
435         done
436
437         if [[ ${EAPI:-0} != 5 ]] ; then
438                 if in_iuse examples && use examples ; then
439                         [[ ${#DIST_EXAMPLES[@]} -eq 0 ]] || perl_doexamples "${DIST_EXAMPLES[@]}"
440                 fi
441         fi
442
443         perl_link_duallife_scripts
444 }
445
446 # @FUNCTION: perl-module_pkg_postinst
447 # @USAGE: perl-module_pkg_postinst
448 # @DESCRIPTION:
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."
458         fi
459         perl_link_duallife_scripts
460 }
461
462 # @FUNCTION: perl-module_pkg_postrm
463 # @USAGE: perl-module_pkg_postrm
464 # @DESCRIPTION:
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."
474         fi
475         perl_link_duallife_scripts
476 }