Bump version to 0.36.9
[cygport.git] / cygclass / php.cygclass
blob1346013c959a8fe0fb063a179474733c60fb0be1
1 ################################################################################
3 # php.cygclass - functions for building PHP (PECL and PEAR) extensions
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/php.cygclass
25 #  SYNOPSIS
26 #  [PHP_CHANNEL="..."]
27 #  inherit php
28 #  DESCRIPTION
29 #  PHP is a programming language most commonly used as an HTML preprocessor
30 #  for creating dynamic web pages.  The interpreter comes in three forms, known
31 #  as SAPIs: command-line, CGI, and Apache Web Server DSO.  Extensions written
32 #  in either PHP or C can be installed to provide additional functionality.
34 #  This cygclass is meant for building PHP extension packages.
35 #  EXAMPLES
36 #  A typical PEAR (pure PHP) module package looks like this:
38 #    PHP_CHANNEL=pear
39 #    inherit php
40 #    
41 #    NAME="php-Archive_Tar"
42 #    VERSION=1.3.11
43 #    RELEASE=1
44 #    CATEGORY="PHP"
45 #    SUMMARY="PHP class for creating and managing tarballs"
46 #    DESCRIPTION="The Archive_Tar class helps in creating and managing GNU tar
47 #    format files compressed by Gzip or not. The class offers basic functions
48 #    like creating an archive, adding files in the archive, extracting files
49 #    from the archive and listing the archive content."
50 #    
51 #    # these are loaded only conditionally
52 #    php_Archive_Tar_REQUIRES="php-bz2 php-zlib"
54 #  PECL extensions (written in C) are similarly straightforward:
56 #    PHP_CHANNEL=pecl
57 #    inherit php
58 #    
59 #    NAME="php-ncurses"
60 #    VERSION=1.0.2
61 #    RELEASE=1
62 #    CATEGORY="PHP"
63 #    SUMMARY="PHP ncurses extension"
64 #    DESCRIPTION="Terminal screen handling extension for PHP (cli-mode only)"
65 #    
66 #    CYGCONF_ARGS="--enable-ncursesw"
68 #  Third-party PEAR channels are also easily handled by setting PHP_CHANNEL:
70 #    PHP_CHANNEL="pear.phpunit.de"
71 #    inherit php
72 #    
73 #    NAME="php-PHPUnit"
74 #    VERSION=3.7.21
75 #    RELEASE=1
76 #    CATEGORY="PHP"
77 #    SUMMARY="PHP unit testing framework"
78 #    DESCRIPTION="An open source framework for test-driven development with the
79 #    PHP programming language."
81 #  REQUIRES
82 #  php, php-PEAR
83 #****
85 # cross-compiling is not (yet?) supported
86 __cross_compiling_error
88 check_prog_req php-config php-devel
90 #****d* php.cygclass/PHP
91 #  DESCRIPTION
92 #  Absolute path to the PHP interpreter.
93 #****
94 PHP=$(__host_prefix)/bin/php
96 #****d* php.cygclass/PHP_CONFIG
97 #  DESCRIPTION
98 #  Absolute path to the PHP configuration script.
99 #****
100 PHP_CONFIG=${PHP%/*}/php-config
102 #****d* php.cygclass/PHPIZE
103 #  DESCRIPTION
104 #  Absolute path to the PHP extension buildsystem preparation script.
105 #****
106 PHPIZE=${PHP%/*}/phpize
108 #****d* php.cygclass/PEAR
109 #  DESCRIPTION
110 #  Absolute path to the PHP script extension manager.
111 #****
112 PEAR=${PHP%/*}/pear
114 #****d* php.cygclass/PECL
115 #  DESCRIPTION
116 #  Absolute path to the PHP C extension manager.
117 #****
118 PECL=${PHP%/*}/pecl
120 #****d* php.cygclass/PHP_VERSION
121 #  DESCRIPTION
122 #  Version of the PHP interpreter.
123 #****
124 PHP_VERSION=$(${PHP_CONFIG} --version)
126 #****d* php.cygclass/PHP_INI_DIR
127 #  DESCRIPTION
128 #  Path to the PHP configuration snippets directory.
129 #****
130 PHP_INI_DIR=$(__host_sysconfdir)/php.d
132 #****d* php.cygclass/PHP_EXTENSION_DIR
133 #  DESCRIPTION
134 #  Installation directory for PHP C extensions.
135 #****
136 PHP_EXTENSION_DIR=$(${PHP_CONFIG} --extension-dir)
138 #****d* php.cygclass/PHP_PEAR_PHP_DIR
139 #  DESCRIPTION
140 #  Installation directory for PHP script extensions.
141 #****
142 PHP_PEAR_PHP_DIR=$(${PEAR} config-get php_dir)
143 # backwards compatibility
144 PHP_PEAR_DIR=${PHP_PEAR_PHP_DIR}
146 #****d* php.cygclass/PHP_PEAR_METADATA_DIR
147 #  DESCRIPTION
148 #  Installation directory for PHP extension metadata.
149 #****
150 PHP_PEAR_METADATA_DIR=$(${PEAR} config-get metadata_dir)
152 #****d* php.cygclass/LIBPHP
153 #  DESCRIPTION
154 #  Link library for the PHP interpreter C library.
155 #  NOTE
156 #  This link library is Cygwin specific.  On ELF platforms, PHP modules are
157 #  linked with undefined symbols, which are resolved at runtime by the SAPI
158 #  in use.  Since the PE/COFF format used on Cygwin requires that all symbols
159 #  be resolved at link time, a library is used which all SAPIs and extensions
160 #  link against.
161 #****
162 LIBPHP=$(${PHP_CONFIG} --libs)
164 #****v* php.cygclass/PHP_CHANNEL
165 #  DESCRIPTION
166 #  Domain name, or well-known alias, of the PEAR/PECL server on which the PHP
167 #  extension is hosted. This variable must be defined before inherit()ing
168 #  php.cygclass to have any effect.
170 #  A list of known channels is available at https://pear.php.net/channels/ .
171 #****
173 case ${PN} in php-*)
174 ORIG_PN=${ORIG_PN:-${PN#php-}}
176 #****o* php.cygclass/CATEGORY (php)
177 #  DEFINITION
178 CATEGORY="PHP"
179 #  NOTE
180 #  This is defined only if PN begins with "php-".
181 #****
182 #****o* php.cygclass/SUMMARY (php)
183 #  DEFINITION
184 SUMMARY="PHP ${ORIG_PN} extension"
185 #  NOTE
186 #  This is defined only if PN begins with "php-".
187 #****
189 esac
191 #****o* php.cygclass/HOMEPAGE (php)
192 #  DESCRIPTION
193 #  Web address for the PHP extension.  This variable is defined only if
194 #  PHP_CHANNEL was defined before inherit()ing php.cygclass.
195 #****
196 #****o* php.cygclass/SRC_URI (php)
197 #  DESCRIPTION
198 #  Download location for the PHP extension sources.  This variable is defined
199 #  only if PHP_CHANNEL was defined before inherit()ing php.cygclass.
200 #****
202 __php_channel_fixup() {
203         local channel
205         if ! defined PHP_CHANNEL
206         then
207                 return 0
208         fi
210         case ${PHP_CHANNEL,,} in
211                 11abacus)       channel="pear.11abacus.com" ;;
212                 agavi)          channel="pear.agavi.org" ;;
213                 arbit)          channel="pear.arbittracker.org" ;;
214                 aws)            channel="pear.amazonwebservices.com" ;;
215                 complexml)      channel="pear.complexml.org" ;;
216                 crisscott)      channel="pear.crisscott.com" ;;
217                 deepend)        channel="pear.survivethedeepend.com" ;;
218                 docblox)        channel="pear.docblox-project.org" ;;
219                 doctrine)       channel="pear.doctrine-project.org" ;;
220                 domain51)       channel="pear.domain51.com" ;;
221                 dotsunited)     channel="pear.dotsunited.de" ;;
222                 erebot)         channel="pear.erebot.net" ;;
223                 eveyron)        channel="pear.eveyron.com" ;;
224                 ezc)            channel="components.ez.no" ;;
225                 fluentdom)      channel="pear.fluentdom.org" ;;
226                 geometria-lab)  channel="pear.geometria-lab.net" ;;
227                 horde)          channel="pear.horde.org" ;;
228                 invenzzia)      channel="pear.invenzzia.org" ;;
229                 michelf)        channel="pear.michelf.com" ;;
230                 openpear)       channel="openpear.org" ;;
231                 pat)            channel="pear.php-tools.net" ;;
232                 pdepend)        channel="pear.pdepend.org" ;;
233                 pear)           channel="pear.php.net" ;;
234                 pearflex)       channel="pear.pearplex.net" ;;
235                 pearhub)        channel="pearhub.org" ;;
236                 pecl)           channel="pecl.php.net" ;;
237                 phergie)        channel="pear.phergie.org" ;;
238                 phing)          channel="pear.phing.info" ;;
239                 phpdocs)        channel="doc.php.net" ;;
240                 phpmd)          channel="pear.phpmd.org" ;;
241                 phpseclib)      channel="phpseclib.sourceforge.net" ;;
242                 phpspec)        channel="pear.phpspec.net" ;;
243                 phpuc)          channel="pear.phpundercontrol.org" ;;
244                 phpunit)        channel="pear.phpunit.de" ;;
245                 piece)          channel="pear.piece-framework.com" ;;
246                 pirum)          channel="pear.pirum-project.org" ;;
247                 psx)            channel="pear.phpsx.org" ;;
248                 qubit)          channel="pear.qubit-toolkit.org" ;;
249                 querypath)      channel="pear.querypath.org" ;;
250                 ragnaroek)      channel="ragnaroek.pear.midgard-project.org" ;;
251                 sabredav)       channel="pear.sabredav.org" ;;
252                 sc)             channel="semanticscuttle.sourceforge.net" ;;
253                 sikz)           channel="pear.si.kz" ;;
254                 smarty)         channel="pear-smarty.googlecode.com/svn" ;;
255                 solar)          channel="solarphp.com" ;;
256                 sugar)          channel="pear.php-sugar.net" ;;
257                 swift)          channel="pear.swiftmailer.org" ;;
258                 symfony)        channel="pear.symfony-project.com" ;;
259                 symfony2)       channel="pear.symfony.com" ;;
260                 timj)           channel="pear.timj.co.uk" ;;
261                 twig)           channel="pear.twig-project.org" ;;
262                 typo3)          channel="pear.typo3.org" ;;
263                 zend)           channel="zend.googlecode.com/svn" ;;
264                 zero.mq)        channel="pear.zero.mq" ;;
265                 *.*)            channel=${PHP_CHANNEL} ;;
266                 # possible fallback; if non-existant, will error out later
267                 *)              channel="${PHP_CHANNEL}.pearfarm.org" ;;
268         esac
270         echo -n ${channel}
273 PHP_CHANNEL=$(__php_channel_fixup)
275 case "${PHP_CHANNEL}" in
276 '') ;;
277 pear.php.net)
278         HOMEPAGE="https://pear.php.net/package/${ORIG_PN}/"
279         SRC_URI="http://download.pear.php.net/package/${ORIG_PN}-${PV}.tgz"
280         ;;
281 pecl.php.net)
282         HOMEPAGE="https://pecl.php.net/package/${ORIG_PN}/"
283         SRC_URI="https://pecl.php.net/get/${ORIG_PN}-${PV}.tgz"
284         ;;
286         if ! $(${PEAR} list-channels | grep -q "^${PHP_CHANNEL} ")
287         then
288                 if ! $(${PEAR} channel-discover ${PHP_CHANNEL} &> /dev/null)
289                 then
290                         error "php: channel not found: ${PHP_CHANNEL}"
291                 fi
292         fi
293         HOMEPAGE="http://${PHP_CHANNEL%%/*}"
294         SRC_URI="http://${PHP_CHANNEL}/get/${ORIG_PN}-${PV}.tgz"
295         ;;
296 esac
298 __php_is_binary() {
299         if [ -f ${S}/config.m4 ]
300         then
301                 return 0
302         else
303                 return 1
304         fi
307 #****C* php.cygclass/php_autoreconf
308 #  SYNOPSIS
309 #  lndirs
310 #  cd $B
311 #  php_autoreconf
312 #  DESCRIPTION
313 #  Runs PHPIZE to prepare the PHP extension build system.  This function must
314 #  be run from the directory containing config.m4.
315 #****
316 php_autoreconf() {
317         if [ ! -e config.m4 ]
318         then
319                 error "config.m4 not found"
320         fi
322         __config_set with_aclocal 1
323         __config_set with_autoconf 1
324         __config_set with_autoheader 1
325         __config_set with_automake 1
326         __config_set with_libtool 1
328         ${PHPIZE} || error "phpize failed"
329         # phpize uses its own copy of gnuconfig, no need to gnuconfigize here
332 #****C* php.cygclass/php_compile
333 #  SYNOPSIS
334 #  cd $B
335 #  php_compile [OPTIONS]
336 #  DESCRIPTION
337 #  Configures the PHP extension with cygconf, then compiles it with cygmake.
338 #  Arguments, if any, are passed as configure flags to cygconf.
339 #****
340 php_compile() {
341         if __php_is_binary
342         then
343                 test -e configure && CYGCONF_SOURCE=$PWD
344                 cygconf \
345                         --enable-${ORIG_PN}=shared --with-${ORIG_PN}=shared \
346                         "${@}"
348                 cygmake
349         fi
352 #****I* php.cygclass/php_install
353 #  SYNOPSIS
354 #  cd $B
355 #  php_install
356 #  DESCRIPTION
357 #  Installs the PHP extension into $D.
358 #****
359 php_install() {
360         local PEXX
362         if __php_is_binary
363         then
364                 cygmake -j1 install INSTALL_ROOT=${D}
365                 PEXX=PECL
366         else
367                 PEXX=PEAR
368         fi
370         dodir ${PHP_PEAR_METADATA_DIR}
371         # FIXME: this won't register the binary extension file location
372         ${!PEXX} install \
373                 --force --loose --nobuild --nodeps --offline --packagingroot=${D} \
374                 ./package.xml \
375                 || error "${PEXX} install failed"
378 #****I* php.cygclass/php_postinst
379 #  SYNOPSIS
380 #  php_postinst
381 #  DESCRIPTION
382 #  Performs the following steps:
383 #  * If the package contains C extensions, creates configuration files which
384 #    will cause the extensions to be loaded by PHP automatically.
385 #  * If PHP_CHANNEL is other than 'pear' or 'pecl', a postinstall script is
386 #    created to register the channel with the installed PHP.
387 #  * Cleans up files which will collide with those already on the system.
388 #****
389 php_postinst() {
390         local x
392         if [ -d ${D}${PHP_EXTENSION_DIR} ]
393         then
394                 dodir ${PHP_INI_DIR}/conf.d
396                 for x in ${D}${PHP_EXTENSION_DIR}/*.dll
397                 do
398                         xf=${x##*/}
399                         if $(${OBJDUMP} -p ${x} | grep -q zend_startup_module)
400                         then
401                                 echo "zend_extension = ${PHP_EXTENSION_DIR}/${xf}" >> ${D}${PHP_INI_DIR}/conf.d/${xf%.dll}.ini
402                         else
403                                 echo "extension = ${xf}" >> ${D}${PHP_INI_DIR}/conf.d/${xf%.dll}.ini
404                         fi
405                 done
406         fi
408         case "${PHP_CHANNEL}" in
409         pear.php.net|pecl.php.net) ;;
410         '') ;;
411         *)      dodir /etc/postinstall
412                 cat >> ${D}/etc/postinstall/${PN}.sh <<-_EOF
413                         ${PEAR} channel-discover ${PHP_CHANNEL} || true
415                         _EOF
416                 ;;
417         esac
419         if [ -d ${D}${PHP_PEAR_METADATA_DIR} ]
420         then
421                 pushd ${D}${PHP_PEAR_METADATA_DIR}
422                 rm -fr .channels/ .depdb .depdblock .filemap .lock
423                 popd
424         fi
426         rm -fr ${D}/tmp/pear
429 #****I* php.cygclass/php_fix_shebang
430 #  SYNOPSIS
431 #  php_fix_shebang SCRIPT [SCRIPT ...]
432 #  DESCRIPTION
433 #  Fixes the designated interpreter of SCRIPT to PHP.  This would be necessary
434 #  if the original uses an incorrect path (e.g. /usr/local/bin) or an
435 #  incorrectly versioned binary.  SCRIPT need not be prefixed by $D.
436 #****
437 php_fix_shebang() {
438         for f
439         do
440                 __fix_shebang ${PHP} ${D}/${f#${D}}
441         done
444 #****o* php.cygclass/src_compile (php)
445 #  DESCRIPTION
446 #  Copies $S into $B with lndirs, then, if the package is a PHP C extension,
447 #  calls php_autoreconf and php_compile.
448 #****
449 src_compile() {
450         lndirs
451         # http://pear.php.net/news/package.xml.1.0.php
452         if [ -f ${S}/../package2.xml ]
453         then
454                 ln -sf ${S}/../package2.xml ${B}/package.xml
455         else
456                 ln -sf ${S}/../package.xml ${B}/package.xml
457         fi
459         if __php_is_binary
460         then
461                 cd ${B}
462                 php_autoreconf
463                 php_compile
464         fi
467 #****o* php.cygclass/src_install (php)
468 #  DEFINITION
469 src_install() {
470         cd ${B}
471         php_install
472         php_postinst
474 #****
476 readonly -f __php_is_binary php_autoreconf php_compile php_install php_postinst \
477             php_fix_shebang