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
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.
36 # A typical PEAR (pure PHP) module package looks like this:
41 # NAME="php-Archive_Tar"
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."
51 # # these are loaded only conditionally
52 # php_Archive_Tar_REQUIRES="php-bz2 php-zlib"
54 # PECL extensions (written in C) are similarly straightforward:
63 # SUMMARY="PHP ncurses extension"
64 # DESCRIPTION="Terminal screen handling extension for PHP (cli-mode only)"
66 # CYGCONF_ARGS="--enable-ncursesw"
68 # Third-party PEAR channels are also easily handled by setting PHP_CHANNEL:
70 # PHP_CHANNEL="pear.phpunit.de"
77 # SUMMARY="PHP unit testing framework"
78 # DESCRIPTION="An open source framework for test-driven development with the
79 # PHP programming language."
85 # cross-compiling is not (yet?) supported
86 __cross_compiling_error
88 check_prog_req php-config php-devel
90 #****d* php.cygclass/PHP
92 # Absolute path to the PHP interpreter.
94 PHP=$(__host_prefix)/bin/php
96 #****d* php.cygclass/PHP_CONFIG
98 # Absolute path to the PHP configuration script.
100 PHP_CONFIG=${PHP%/*}/php-config
102 #****d* php.cygclass/PHPIZE
104 # Absolute path to the PHP extension buildsystem preparation script.
106 PHPIZE=${PHP%/*}/phpize
108 #****d* php.cygclass/PEAR
110 # Absolute path to the PHP script extension manager.
114 #****d* php.cygclass/PECL
116 # Absolute path to the PHP C extension manager.
120 #****d* php.cygclass/PHP_VERSION
122 # Version of the PHP interpreter.
124 PHP_VERSION=$(${PHP_CONFIG} --version)
126 #****d* php.cygclass/PHP_INI_DIR
128 # Path to the PHP configuration snippets directory.
130 PHP_INI_DIR=$(__host_sysconfdir)/php.d
132 #****d* php.cygclass/PHP_EXTENSION_DIR
134 # Installation directory for PHP C extensions.
136 PHP_EXTENSION_DIR=$(${PHP_CONFIG} --extension-dir)
138 #****d* php.cygclass/PHP_PEAR_PHP_DIR
140 # Installation directory for PHP script extensions.
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
148 # Installation directory for PHP extension metadata.
150 PHP_PEAR_METADATA_DIR=$(${PEAR} config-get metadata_dir)
152 #****d* php.cygclass/LIBPHP
154 # Link library for the PHP interpreter C library.
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
162 LIBPHP=$(${PHP_CONFIG} --libs)
164 #****v* php.cygclass/PHP_CHANNEL
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/ .
174 ORIG_PN=${ORIG_PN:-${PN#php-}}
176 #****o* php.cygclass/CATEGORY (php)
180 # This is defined only if PN begins with "php-".
182 #****o* php.cygclass/SUMMARY (php)
184 SUMMARY="PHP ${ORIG_PN} extension"
186 # This is defined only if PN begins with "php-".
191 #****o* php.cygclass/HOMEPAGE (php)
193 # Web address for the PHP extension. This variable is defined only if
194 # PHP_CHANNEL was defined before inherit()ing php.cygclass.
196 #****o* php.cygclass/SRC_URI (php)
198 # Download location for the PHP extension sources. This variable is defined
199 # only if PHP_CHANNEL was defined before inherit()ing php.cygclass.
202 __php_channel_fixup() {
205 if ! defined PHP_CHANNEL
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" ;;
273 PHP_CHANNEL=$(__php_channel_fixup)
275 case "${PHP_CHANNEL}" in
278 HOMEPAGE="https://pear.php.net/package/${ORIG_PN}/"
279 SRC_URI="http://download.pear.php.net/package/${ORIG_PN}-${PV}.tgz"
282 HOMEPAGE="https://pecl.php.net/package/${ORIG_PN}/"
283 SRC_URI="https://pecl.php.net/get/${ORIG_PN}-${PV}.tgz"
286 if ! $(${PEAR} list-channels | grep -q "^${PHP_CHANNEL} ")
288 if ! $(${PEAR} channel-discover ${PHP_CHANNEL} &> /dev/null)
290 error "php: channel not found: ${PHP_CHANNEL}"
293 HOMEPAGE="http://${PHP_CHANNEL%%/*}"
294 SRC_URI="http://${PHP_CHANNEL}/get/${ORIG_PN}-${PV}.tgz"
299 if [ -f ${S}/config.m4 ]
307 #****C* php.cygclass/php_autoreconf
313 # Runs PHPIZE to prepare the PHP extension build system. This function must
314 # be run from the directory containing config.m4.
317 if [ ! -e config.m4 ]
319 error "config.m4 not found"
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
335 # php_compile [OPTIONS]
337 # Configures the PHP extension with cygconf, then compiles it with cygmake.
338 # Arguments, if any, are passed as configure flags to cygconf.
343 test -e configure && CYGCONF_SOURCE=$PWD
345 --enable-${ORIG_PN}=shared --with-${ORIG_PN}=shared \
352 #****I* php.cygclass/php_install
357 # Installs the PHP extension into $D.
364 cygmake -j1 install INSTALL_ROOT=${D}
370 dodir ${PHP_PEAR_METADATA_DIR}
371 # FIXME: this won't register the binary extension file location
373 --force --loose --nobuild --nodeps --offline --packagingroot=${D} \
375 || error "${PEXX} install failed"
378 #****I* php.cygclass/php_postinst
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.
392 if [ -d ${D}${PHP_EXTENSION_DIR} ]
394 dodir ${PHP_INI_DIR}/conf.d
396 for x in ${D}${PHP_EXTENSION_DIR}/*.dll
399 if $(${OBJDUMP} -p ${x} | grep -q zend_startup_module)
401 echo "zend_extension = ${PHP_EXTENSION_DIR}/${xf}" >> ${D}${PHP_INI_DIR}/conf.d/${xf%.dll}.ini
403 echo "extension = ${xf}" >> ${D}${PHP_INI_DIR}/conf.d/${xf%.dll}.ini
408 case "${PHP_CHANNEL}" in
409 pear.php.net|pecl.php.net) ;;
411 *) dodir /etc/postinstall
412 cat >> ${D}/etc/postinstall/${PN}.sh <<-_EOF
413 ${PEAR} channel-discover ${PHP_CHANNEL} || true
419 if [ -d ${D}${PHP_PEAR_METADATA_DIR} ]
421 pushd ${D}${PHP_PEAR_METADATA_DIR}
422 rm -fr .channels/ .depdb .depdblock .filemap .lock
429 #****I* php.cygclass/php_fix_shebang
431 # php_fix_shebang SCRIPT [SCRIPT ...]
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.
440 __fix_shebang ${PHP} ${D}/${f#${D}}
444 #****o* php.cygclass/src_compile (php)
446 # Copies $S into $B with lndirs, then, if the package is a PHP C extension,
447 # calls php_autoreconf and php_compile.
451 # http://pear.php.net/news/package.xml.1.0.php
452 if [ -f ${S}/../package2.xml ]
454 ln -sf ${S}/../package2.xml ${B}/package.xml
456 ln -sf ${S}/../package.xml ${B}/package.xml
467 #****o* php.cygclass/src_install (php)
476 readonly -f __php_is_binary php_autoreconf php_compile php_install php_postinst \