1 ################################################################################
3 # perl.cygclass - functions for building CPAN Perl modules
5 # Part of cygport - Cygwin packaging application
6 # Copyright (C) 2006-2020 Cygport authors
7 # Provided by the Cygwin project <https://cygwin.com/>
9 # cygport is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # cygport is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with cygport. If not, see <https://www.gnu.org/licenses/>.
22 ################################################################################
24 #****h* Cygclasses/perl.cygclass
26 # [CPAN_AUTHOR="username"]
29 # Perl is an interpreted programming language used in a variety of software,
30 # particularly text processing, network programming, system administration,
31 # and CGI scripting. It is easily extendible with modules written in Perl
32 # and/or C/C++. Thousands of such modules are centrally hosted on the
33 # Comprehensive Perl Archive Network (CPAN).
35 # This cygclass provides definitions for building Perl dependent packages,
36 # and functions for building Perl module packages.
38 # A typical CPAN extension package looks like this:
43 # NAME="perl-Archive-Zip"
47 # SUMMARY="Perl module for working with Zip archives"
48 # DESCRIPTION="This module allows a Perl program to create, manipulate, read,
49 # and write Zip archive files. Zip archives can be created, or you can read
50 # from existing zip files. Once created, they can be written to files, streams,
53 # Occasionaly, a CPAN module tries to ask questions while configuring the
54 # build, in which case you can override that in src_compile:
59 # # answer 'y' to all questions from Makefile.PL
63 # Perl modules which provide XML::SAX parser engines require an additional
64 # step during src_install, e.g.:
69 # perl_sax_parser_register XML::LibXML::SAX
78 # cross-compiling is not (yet?) supported
79 __cross_compiling_error
83 #****d* perl.cygclass/PERL
85 # Absolute path to the Perl interpreter.
87 PERL=$(__host_prefix)/bin/perl
89 #****d* perl.cygclass/PERL_VERSION
91 # The major.minor version of the Perl interpreter.
93 PERL_VERSION=$(${PERL} -MConfig -e 'print $Config{api_revision}.".".$Config{api_version};')
95 #****d* perl.cygclass/PERL_LIB
97 # Absolute path to the Perl arch-independent standard library.
99 # Third-party packages must not be installed here; use PERL_VENDORLIB instead.
101 PERL_LIB=$(${PERL} -MConfig -e 'print $Config{privlib};')
103 #****d* perl.cygclass/PERL_ARCHLIB
105 # Absolute path to the Perl arch-specific standard library.
107 # Third-party packages must not be installed here; use PERL_VENDORARCH instead.
109 PERL_ARCHLIB=$(${PERL} -MConfig -e 'print $Config{archlib};')
111 #****d* perl.cygclass/PERL_VENDORLIB
113 # Installation path for third-party arch-independent Perl modules.
115 PERL_VENDORLIB=$(${PERL} -MConfig -e 'print $Config{vendorlib};')
117 #****d* perl.cygclass/PERL_VENDORARCH
119 # Installation path for third-party arch-specific Perl modules.
121 PERL_VENDORARCH=$(${PERL} -MConfig -e 'print $Config{vendorarch};')
124 PERL_SITELIB=$(${PERL} -MConfig -e 'print $Config{sitelib};')
126 #****d* perl.cygclass/LIBPERL
128 # Link flags for the Perl C library.
130 LIBPERL="-L${PERL_ARCHLIB}/CORE -lperl"
133 perl-*) ORIG_PN=${ORIG_PN:-${PN#perl-}} ;;
136 #****v* perl.cygclass/CPAN_AUTHOR
138 # The CPAN username of the Perl module's author. This variable must be set
139 # before inherit()ing perl.cygclass to have any effect. If set, the package
140 # HOMEPAGE and SRC_URI are set to their usual locations on CPAN.
142 #****v* perl.cygclass/CPAN_SUBDIR
144 # An optional directory component in the CPAN URL. Some packages have an
145 # additional subdirectory component, which can be specified with this variable.
147 #****v* perl.cygclass/CPAN_VERSION
149 # The published version of the Perl module on CPAN. It is sometimes
150 # necessary for VERSION to not match due to CPAN versioning not conforming to
151 # the version rules used elsewhere. For example, a package may go from
152 # 0.12->0.1201->0.1202...->0.13, instead of 0.12->0.12.1->0.12.2...->0.13 as
153 # one would expect elsewhere. The last change would be viewed as a downgrade
154 # (1202 > 13) by setup. Depending on what currently exists in the distribution,
155 # either use e.g. CPAN_VERSION=0.1201 with VERSION=0.12.1, or CPAN_VERSION=0.13
156 # with VERSION=0.1300, in order to workaround this.
158 # This variable, when needed, must be set before inherit()ing perl.cygclass to
159 # have any effect. If set, this overrides VERSION in SRC_URI and SRC_DIR.
162 if defined CPAN_AUTHOR
164 #****o* perl.cygclass/CATEGORY (perl)
168 # This variable is set only if CPAN_AUTHOR is defined before inherit()ing
171 #****o* perl.cygclass/SUMMARY (perl)
173 SUMMARY="Perl distribution ${ORIG_PN}"
175 # This variable is set only if CPAN_AUTHOR is defined before inherit()ing
178 #****o* perl.cygclass/HOMEPAGE (perl)
180 # Web address for the Perl module on CPAN.
182 # This variable is set only if CPAN_AUTHOR is defined before inherit()ing
185 HOMEPAGE="${HOMEPAGE-https://metacpan.org/dist/${ORIG_PN}}"
187 #****o* perl.cygclass/SRC_URI (perl)
189 # Download location for the Perl module on CPAN.
191 # This variable is set only if CPAN_AUTHOR is defined before inherit()ing
196 cpan_author_ftp=${CPAN_AUTHOR^^}
197 cpan_author_ver=${CPAN_VERSION:-${VERSION}}
198 SRC_URI="mirror://cpan/authors/id/${cpan_author_ftp:0:1}/${cpan_author_ftp:0:2}/${cpan_author_ftp}${CPAN_SUBDIR+/}${CPAN_SUBDIR}/${ORIG_PN}-${cpan_author_ver}.${CPAN_TARBALL_SUFFIX:-tar.gz}"
199 SRC_DIR="${ORIG_PN}-${cpan_author_ver}"
200 unset cpan_author_ftp cpan_author_ver
202 fi # defined CPAN_AUTHOR
204 #****C* perl.cygclass/perl_compile
207 # perl_compile [OPTIONS]
209 # Configures and builds a Perl module package. Options, if any, are passed
210 # during the configure phase.
215 ${PERL} Build.PL --installdirs=vendor "${@}" || error "Module::Build creation failed"
216 ${PERL} Build || error "Module::Build build failed"
217 elif [ -e Makefile.PL ]
219 ${PERL} Makefile.PL "${@}" PREFIX=$(__host_prefix) INSTALLDIRS=vendor || error "Perl Makefile creation failed"
220 cygmake all manifypods OPTIMIZE="${CFLAGS}"
222 error "No Perl module detected"
226 #****T* perl.cygclass/perl_test
231 # Runs the test suite for the Perl module.
241 error "No Perl module detected"
245 #****I* perl.cygclass/perl_install
248 # perl_install [OPTIONS]
250 # Installs the Perl module into $D. Options, if any, are passed to the
256 ${PERL} Build install --destdir=${D} "${@}" || error "Module::Build install failed"
261 error "No Perl module detected"
265 # Functionality moved to __prepperl; this remains for backwards compatibility
266 perl_postinst() { :; }
268 #****I* perl.cygclass/perl_fix_shebang
270 # perl_fix_shebang SCRIPT [SCRIPT ...]
272 # Fixes the designated interpreter of SCRIPT to PERL. This would be necessary
273 # if the original uses an incorrect path (e.g. /usr/local/bin) or an
274 # incorrectly versioned binary. SCRIPT need not be prefixed by $D.
279 __fix_shebang ${PERL} ${D}/${f#${D}}
283 #****I* perl.cygclass/perl_sax_parser_register
285 # perl_sax_parser_register PARSER_CLASS [PARSER_CLASS ...]
287 # Generates postinstall and preremove scripts to handle registration of
288 # XML::SAX parser drivers with XML::SAX's ParserDetails.ini file.
290 perl_sax_parser_register() {
293 dodir /etc/postinstall /etc/preremove
296 cat >> ${D}/etc/postinstall/${NAME}.sh <<-_EOF
297 ${PERL} -MXML::SAX -e "XML::SAX->add_parser(q($parser))->save_parsers()"
299 cat >> ${D}/etc/preremove/${NAME}.sh <<-_EOF
300 ${PERL} -MXML::SAX -e "XML::SAX->remove_parser(q($parser))->save_parsers()"
305 #****o* perl.cygclass/src_compile (perl)
314 #****o* perl.cygclass/src_test (perl)
322 #****o* perl.cygclass/src_install (perl)
330 readonly -f perl_compile perl_test perl_install perl_postinst \
331 perl_fix_shebang perl_sax_parser_register