dev-qt/qtopengl: stable 5.14.2 for ppc, bug #719732
[gentoo.git] / eclass / perl-module.eclass
1 # Copyright 1999-2019 Gentoo Authors
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 # @SUPPORTED_EAPIS: 5 6 7
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|7)
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 # @DEFAULT_UNSET
37 # @DESCRIPTION:
38 # This variable controls whether a runtime and build time dependency on
39 # dev-lang/perl is automatically added by the eclass. It defaults to yes.
40 # Set to no to disable, set to noslotop to add a perl dependency without
41 # slot operator (EAPI=6). All packages installing into the vendor_perl
42 # path must use yes here.
43
44 case ${EAPI:-0} in
45         5)
46                 [[ ${CATEGORY} == perl-core ]] && \
47                         PERL_EXPF+=" pkg_postinst pkg_postrm"
48
49                 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
50                 yes)
51                         case "${GENTOO_DEPEND_ON_PERL_SUBSLOT:-yes}" in
52                         yes)
53                                 DEPEND="dev-lang/perl:=[-build(-)]"
54                                 ;;
55                         *)
56                                 DEPEND="dev-lang/perl[-build(-)]"
57                                 ;;
58                         esac
59                         RDEPEND="${DEPEND}"
60                         ;;
61                 esac
62
63                 case "${PERL_EXPORT_PHASE_FUNCTIONS:-yes}" in
64                         yes)
65                                 EXPORT_FUNCTIONS ${PERL_EXPF}
66                                 ;;
67                         no)
68                                 debug-print "PERL_EXPORT_PHASE_FUNCTIONS=no"
69                                 ;;
70                         *)
71                                 die "PERL_EXPORT_PHASE_FUNCTIONS=${PERL_EXPORT_PHASE_FUNCTIONS} is not supported by perl-module.eclass"
72                                 ;;
73                 esac
74                 ;;
75         6)
76                 [[ ${CATEGORY} == perl-core ]] && \
77                         PERL_EXPF+=" pkg_postinst pkg_postrm"
78
79                 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
80                         yes)
81                                 DEPEND="dev-lang/perl"
82                                 RDEPEND="dev-lang/perl:="
83                                 ;;
84                         noslotop)
85                                 DEPEND="dev-lang/perl"
86                                 RDEPEND="dev-lang/perl"
87                                 ;;
88                 esac
89
90                 if [[ "${GENTOO_DEPEND_ON_PERL_SUBSLOT:-yes}" != "yes" ]]; then
91                         eerror "GENTOO_DEPEND_ON_PERL_SUBSLOT=no is banned in EAPI=6 and later. If you don't want a slot operator"
92                         die    "set GENTOO_DEPEND_ON_PERL=noslotop instead."
93                 fi
94
95                 if [[ "${PERL_EXPORT_PHASE_FUNCTIONS}" ]]; then
96                         eerror "PERL_EXPORT_PHASE_FUNCTIONS is banned in EAPI=6 and later. Use perl-module.eclass if you need"
97                         die    "phase functions, perl-functions.eclass if not."
98                 fi
99
100                 EXPORT_FUNCTIONS ${PERL_EXPF}
101                 ;;
102         7)
103                 [[ ${CATEGORY} == perl-core ]] && \
104                         PERL_EXPF+=" pkg_postinst pkg_postrm"
105
106                 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
107                         yes)
108                                 DEPEND="dev-lang/perl"
109                                 BDEPEND="dev-lang/perl"
110                                 RDEPEND="dev-lang/perl:="
111                                 ;;
112                         noslotop)
113                                 DEPEND="dev-lang/perl"
114                                 BDEPEND="dev-lang/perl"
115                                 RDEPEND="dev-lang/perl"
116                                 ;;
117                 esac
118
119                 if [[ "${GENTOO_DEPEND_ON_PERL_SUBSLOT:-yes}" != "yes" ]]; then
120                         die "GENTOO_DEPEND_ON_PERL_SUBSLOT=no is banned in EAPI=6 and later."
121                 fi
122
123                 if [[ "${PERL_EXPORT_PHASE_FUNCTIONS}" ]]; then
124                         die "PERL_EXPORT_PHASE_FUNCTIONS is banned in EAPI=6 and later."
125                 fi
126
127                 EXPORT_FUNCTIONS ${PERL_EXPF}
128                 ;;
129         *)
130                 die "EAPI=${EAPI:-0} is not supported by perl-module.eclass"
131                 ;;
132 esac
133
134 LICENSE="${LICENSE:-|| ( Artistic GPL-1+ )}"
135
136 # @ECLASS-VARIABLE: DIST_NAME
137 # @DEFAULT_UNSET
138 # @DESCRIPTION:
139 # (EAPI=6 and later) This variable provides a way to override PN for the calculation of S,
140 # SRC_URI, and HOMEPAGE. If unset, defaults to PN.
141
142 # @ECLASS-VARIABLE: DIST_VERSION
143 # @DEFAULT_UNSET
144 # @DESCRIPTION:
145 # (EAPI=6 and later) This variable provides a way to override PV for the calculation of S and SRC_URI.
146 # Use it to provide the non-normalized, upstream version number. If unset, defaults to PV.
147 # Named MODULE_VERSION in EAPI=5.
148
149 # @ECLASS-VARIABLE: DIST_A_EXT
150 # @DEFAULT_UNSET
151 # @DESCRIPTION:
152 # (EAPI=6 and later) This variable provides a way to override the distfile extension for the calculation of
153 # SRC_URI. If unset, defaults to tar.gz. Named MODULE_A_EXT in EAPI=5.
154
155 # @ECLASS-VARIABLE: DIST_A
156 # @DEFAULT_UNSET
157 # @DESCRIPTION:
158 # (EAPI=6 and later) This variable provides a way to override the distfile name for the calculation of
159 # SRC_URI. If unset, defaults to ${DIST_NAME}-${DIST_VERSION}.${DIST_A_EXT} Named MODULE_A in EAPI=5.
160
161 # @ECLASS-VARIABLE: DIST_AUTHOR
162 # @DEFAULT_UNSET
163 # @DESCRIPTION:
164 # (EAPI=6 and later) This variable sets the module author name for the calculation of
165 # SRC_URI. Named MODULE_AUTHOR in EAPI=5.
166
167 # @ECLASS-VARIABLE: DIST_SECTION
168 # @DEFAULT_UNSET
169 # @DESCRIPTION:
170 # (EAPI=6 and later) This variable sets the module section for the calculation of
171 # SRC_URI. Only required in rare cases for very special snowflakes.
172 # Named MODULE_SECTION in EAPI=5.
173
174 # @ECLASS-VARIABLE: DIST_EXAMPLES
175 # @DEFAULT_UNSET
176 # @DESCRIPTION:
177 # (EAPI=6 and later) This Bash array allows passing a list of example files to be installed
178 # in /usr/share/doc/${PF}/examples. If set before inherit, automatically adds
179 # a use-flag examples, if not you'll have to add the useflag in your ebuild.
180 # Examples are installed only if the useflag examples exists and is activated.
181
182
183 if [[ ${EAPI:-0} == 5 ]]; then
184         if [[ -n ${MY_PN} || -n ${MY_PV} || -n ${MODULE_VERSION} ]] ; then
185                 : ${MY_P:=${MY_PN:-${PN}}-${MY_PV:-${MODULE_VERSION:-${PV}}}}
186                 S=${MY_S:-${WORKDIR}/${MY_P}}
187         fi
188         MODULE_NAME=${MY_PN:-${PN}}
189         MODULE_P=${MY_P:-${P}}
190
191         [[ -z "${SRC_URI}" && -z "${MODULE_A}" ]] && \
192                 MODULE_A="${MODULE_P}.${MODULE_A_EXT:-tar.gz}"
193         [[ -z "${SRC_URI}" && -n "${MODULE_AUTHOR}" ]] && \
194                 SRC_URI="mirror://cpan/authors/id/${MODULE_AUTHOR:0:1}/${MODULE_AUTHOR:0:2}/${MODULE_AUTHOR}/${MODULE_SECTION:+${MODULE_SECTION}/}${MODULE_A}"
195         [[ -z "${HOMEPAGE}" ]] && \
196                 HOMEPAGE="https://metacpan.org/release/${MODULE_NAME}"
197
198         SRC_TEST="skip"
199 else
200         DIST_NAME=${DIST_NAME:-${PN}}
201         DIST_P=${DIST_NAME}-${DIST_VERSION:-${PV}}
202         S=${WORKDIR}/${DIST_P}
203
204         [[ -z "${SRC_URI}" && -z "${DIST_A}" ]] && \
205                 DIST_A="${DIST_P}.${DIST_A_EXT:-tar.gz}"
206         [[ -z "${SRC_URI}" && -n "${DIST_AUTHOR}" ]] && \
207                 SRC_URI="mirror://cpan/authors/id/${DIST_AUTHOR:0:1}/${DIST_AUTHOR:0:2}/${DIST_AUTHOR}/${DIST_SECTION:+${DIST_SECTION}/}${DIST_A}"
208         [[ -z "${HOMEPAGE}" ]] && \
209                 HOMEPAGE="https://metacpan.org/release/${DIST_NAME}"
210
211         [[ -z "${DIST_EXAMPLES}" ]] || IUSE+=" examples"
212 fi
213
214 SRC_PREP="no"
215 PREFER_BUILDPL="yes"
216
217 pm_echovar=""
218
219 # @FUNCTION: perl-module_src_unpack
220 # @DESCRIPTION:
221 # Unpack the ebuild tarball(s).
222 # This function is to be called during the ebuild src_unpack() phase.
223 perl-module_src_unpack() {
224         debug-print-function $FUNCNAME "$@"
225         [[ ${EAPI:-0} == 5 ]] || die "perl-module_src_unpack is banned in EAPI=6 or later"
226         unpacker_src_unpack
227 }
228
229 # @FUNCTION: perl-module_src_prepare
230 # @DESCRIPTION:
231 # Get the ebuild sources ready.
232 # This function is to be called during the ebuild src_prepare() phase.
233 perl-module_src_prepare() {
234         debug-print-function $FUNCNAME "$@"
235
236         if [[ ${EAPI:-0} == 5 ]] ; then
237                 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
238                 debug-print "$FUNCNAME: applying user patches"
239                 epatch_user
240         else
241                 default
242         fi
243
244         if [[ ${PERL_RM_FILES[@]} ]]; then
245                 debug-print "$FUNCNAME: stripping unneeded files"
246                 perl_rm_files "${PERL_RM_FILES[@]}"
247         fi
248         perl_fix_osx_extra
249 }
250
251 # @FUNCTION: perl-module_src_configure
252 # @DESCRIPTION:
253 # Configure the ebuild sources.
254 # This function is to be called during the ebuild src_configure() phase.
255 perl-module_src_configure() {
256         debug-print-function $FUNCNAME "$@"
257
258         if [[ ${EAPI:-0} == 5 && ${SRC_PREP} == yes ]]; then
259                 return 0
260         fi
261         SRC_PREP="yes"
262
263         perl_check_env
264
265         perl_set_version
266
267         [[ -z ${pm_echovar} ]] && export PERL_MM_USE_DEFAULT=1
268         # Disable ExtUtils::AutoInstall from prompting
269         export PERL_EXTUTILS_AUTOINSTALL="--skipdeps"
270
271         if [[ $(declare -p myconf 2>&-) != "declare -a myconf="* ]]; then
272                 local myconf_local=(${myconf})
273         else
274                 local myconf_local=("${myconf[@]}")
275         fi
276
277         if [[ ( ${PREFER_BUILDPL} == yes || ! -f Makefile.PL ) && -f Build.PL ]] ; then
278                 if grep -q '\(use\|require\)\s*Module::Build::Tiny' Build.PL ; then
279                         einfo "Using Module::Build::Tiny"
280                         if [[ ${DEPEND} != *dev-perl/Module-Build-Tiny* && ${PN} != Module-Build-Tiny ]]; then
281                                 eerror "QA Notice: The ebuild uses Module::Build::Tiny but doesn't depend on it."
282                                 die    " Add dev-perl/Module-Build-Tiny to DEPEND!"
283                         fi
284                 else
285                         einfo "Using Module::Build"
286                         if [[ ${DEPEND} != *virtual/perl-Module-Build* && ${DEPEND} != *dev-perl/Module-Build* && ${PN} != Module-Build ]] ; then
287                                 eerror "QA Notice: The ebuild uses Module::Build but doesn't depend on it."
288                                 die    " Add dev-perl/Module-Build to DEPEND!"
289                         fi
290                 fi
291                 set -- \
292                         --installdirs=vendor \
293                         --libdoc= \
294                         --destdir="${D}" \
295                         --create_packlist=1 \
296                         "${myconf_local[@]}"
297                 einfo "perl Build.PL" "$@"
298                 perl Build.PL "$@" <<< "${pm_echovar}" \
299                                 || die "Unable to build!"
300         elif [[ -f Makefile.PL ]] ; then
301                 einfo "Using ExtUtils::MakeMaker"
302                 set -- \
303                         PREFIX=${EPREFIX}/usr \
304                         INSTALLDIRS=vendor \
305                         INSTALLMAN3DIR='none' \
306                         DESTDIR="${D}" \
307                         "${myconf_local[@]}"
308                 einfo "perl Makefile.PL" "$@"
309                 perl Makefile.PL "$@" <<< "${pm_echovar}" \
310                                 || die "Unable to build!"
311         fi
312         if [[ ! -f Build.PL && ! -f Makefile.PL ]] ; then
313                 einfo "No Make or Build file detected..."
314                 return
315         fi
316 }
317
318 # @FUNCTION: perl-module_src_compile
319 # @DESCRIPTION:
320 # Compile the ebuild sources.
321 # This function is to be called during the ebuild src_compile() phase.
322 perl-module_src_compile() {
323         debug-print-function $FUNCNAME "$@"
324         perl_set_version
325
326         if [[ $(declare -p mymake 2>&-) != "declare -a mymake="* ]]; then
327                 local mymake_local=(${mymake})
328         else
329                 local mymake_local=("${mymake[@]}")
330         fi
331
332         if [[ -f Build ]] ; then
333                 ./Build build \
334                         || die "Compilation failed"
335         elif [[ -f Makefile ]] ; then
336                 set -- \
337                         OTHERLDFLAGS="${LDFLAGS}" \
338                         "${mymake_local[@]}"
339                 einfo "emake" "$@"
340                 emake "$@" \
341                         || die "Compilation failed"
342 #                       OPTIMIZE="${CFLAGS}" \
343         fi
344 }
345
346 # @ECLASS-VARIABLE: DIST_TEST
347 # @DEFAULT_UNSET
348 # @DESCRIPTION:
349 # (EAPI=6 and later) Variable that controls if tests are run in the test phase
350 # at all, and if yes under which conditions. If unset, defaults to "do parallel"
351 # If neither "do" nor "parallel" is recognized, tests are skipped.
352 # (In EAPI=5 the variable is called SRC_TEST, defaults to "skip", and
353 # recognizes fewer options.)
354 # The following space-separated keywords are recognized:
355 #   do       : run tests
356 #   parallel : run tests in parallel
357 #   verbose  : increase test verbosity
358 #   network  : do not try to disable network tests
359
360 # @ECLASS-VARIABLE: DIST_TEST_OVERRIDE
361 # @DEFAULT_UNSET
362 # @DESCRIPTION:
363 # (EAPI=6 and later) Variable that controls if tests are run in the test phase
364 # at all, and if yes under which conditions. It is intended for use in
365 # make.conf or the environment by ebuild authors during testing, and
366 # accepts the same values as DIST_TEST. If set, it overrides DIST_TEST
367 # completely. DO NOT USE THIS IN EBUILDS!
368
369 # @FUNCTION: perl-module_src-test
370 # @DESCRIPTION:
371 # This code attempts to work out your threadingness and runs tests
372 # according to the settings of DIST_TEST using Test::Harness.
373 perl-module_src_test() {
374         debug-print-function $FUNCNAME "$@"
375         local my_test_control
376         local my_test_verbose
377
378         if [[ ${EAPI:-0} == 5 ]] ; then
379                 my_test_control=${SRC_TEST}
380                 my_test_verbose=${TEST_VERBOSE:-0}
381                 if has 'do' ${my_test_control} || has 'parallel' ${my_test_control} ; then
382                         if has "${my_test_verbose}" 0 && has 'parallel' ${my_test_control} ; then
383                                 export HARNESS_OPTIONS=j$(makeopts_jobs)
384                                 einfo "Test::Harness Jobs=$(makeopts_jobs)"
385                         fi
386                 else
387                         einfo Skipping tests due to SRC_TEST=${SRC_TEST}
388                         return 0
389                 fi
390         else
391                 [[ -n "${DIST_TEST_OVERRIDE}" ]] && ewarn DIST_TEST_OVERRIDE is set to ${DIST_TEST_OVERRIDE}
392                 my_test_control=${DIST_TEST_OVERRIDE:-${DIST_TEST:-do parallel}}
393
394                 if ! has 'do' ${my_test_control} && ! has 'parallel' ${my_test_control} ; then
395                         einfo Skipping tests due to DIST_TEST=${my_test_control}
396                         return 0
397                 fi
398
399                 if has verbose ${my_test_control} ; then
400                         my_test_verbose=1
401                 else
402                         my_test_verbose=0
403                 fi
404
405                 if has parallel ${my_test_control} ; then
406                         export HARNESS_OPTIONS=j$(makeopts_jobs)
407                         einfo "Test::Harness Jobs=$(makeopts_jobs)"
408                 fi
409
410                 # this might sometimes work...
411                 if ! has network ${my_test_control} ; then
412                         export NO_NETWORK_TESTING=1
413                 fi
414         fi
415
416         perl_set_version
417         if [[ -f Build ]] ; then
418                 ./Build test verbose=${my_test_verbose} || die "test failed"
419         elif [[ -f Makefile ]] ; then
420                 emake test TEST_VERBOSE=${my_test_verbose} || die "test failed"
421         fi
422 }
423
424 # @FUNCTION: perl-module_src_install
425 # @DESCRIPTION:
426 # Install a Perl ebuild.
427 # This function is to be called during the ebuild src_install() phase.
428 perl-module_src_install() {
429         debug-print-function $FUNCNAME "$@"
430
431         perl_set_version
432
433         local f
434
435         if [[ -f Build ]]; then
436                 mytargets="${mytargets:-install}"
437                 mbparams="${mbparams:---pure}"
438                 einfo "./Build ${mytargets} ${mbparams}"
439                 ./Build ${mytargets} ${mbparams} \
440                         || die "./Build ${mytargets} ${mbparams} failed"
441         elif [[ -f Makefile ]]; then
442                 case "${CATEGORY}" in
443                         dev-perl|perl-core) mytargets="pure_install" ;;
444                         *)                  mytargets="install" ;;
445                 esac
446                 if [[ $(declare -p myinst 2>&-) != "declare -a myinst="* ]]; then
447                         local myinst_local=(${myinst})
448                 else
449                         local myinst_local=("${myinst[@]}")
450                 fi
451                 emake "${myinst_local[@]}" ${mytargets} \
452                         || die "emake ${myinst_local[@]} ${mytargets} failed"
453         fi
454
455         perl_delete_module_manpages
456         perl_delete_localpod
457         if [[ ${EAPI:-0} == 5 ]] ; then
458                 perl_delete_packlist
459         else
460                 perl_fix_packlist
461                 perl_delete_emptybsdir
462         fi
463         perl_remove_temppath
464
465         for f in Change* CHANGES README* TODO FAQ ${mydoc}; do
466                 [[ -s ${f} ]] && dodoc ${f}
467         done
468
469         if [[ ${EAPI:-0} != 5 ]] ; then
470                 if in_iuse examples && use examples ; then
471                         [[ ${#DIST_EXAMPLES[@]} -eq 0 ]] || perl_doexamples "${DIST_EXAMPLES[@]}"
472                 fi
473         fi
474
475         perl_link_duallife_scripts
476 }
477
478 # @FUNCTION: perl-module_pkg_postinst
479 # @DESCRIPTION:
480 # This function is to be called during the pkg_postinst() phase. It only does
481 # useful things for the perl-core category, where it handles the file renaming and symbolic
482 # links that prevent file collisions for dual-life packages installing scripts.
483 # In any other category it immediately exits.
484 perl-module_pkg_postinst() {
485         debug-print-function $FUNCNAME "$@"
486         if [[ ${CATEGORY} != perl-core ]] ; then
487                 eerror "perl-module.eclass: You are calling perl-module_pkg_postinst outside the perl-core category."
488                 die    "   This does not do anything; the call can be removed."
489         fi
490         perl_link_duallife_scripts
491 }
492
493 # @FUNCTION: perl-module_pkg_postrm
494 # @DESCRIPTION:
495 # This function is to be called during the pkg_postrm() phase. It only does
496 # useful things for the perl-core category, where it handles the file renaming and symbolic
497 # links that prevent file collisions for dual-life packages installing scripts.
498 # In any other category it immediately exits.
499 perl-module_pkg_postrm() {
500         debug-print-function $FUNCNAME "$@"
501         if [[ ${CATEGORY} != perl-core ]] ; then
502                 eerror "perl-module.eclass: You are calling perl-module_pkg_postrm outside the perl-core category."
503                 die    "   This does not do anything; the call can be removed."
504         fi
505         perl_link_duallife_scripts
506 }