Sync Mk with ports
[dports.git] / Mk / bsd.php.mk
1 #
2 # bsd.php.mk - Support for PHP-based ports.
3 #
4 # Created by: Alex Dupre <ale@FreeBSD.org>
5 #
6 # For FreeBSD committers:
7 # Please send all suggested changes to the maintainer instead of committing
8 # them to SVN yourself.
9 #
10 # $FreeBSD: Mk/bsd.php.mk 332106 2013-10-30 13:28:00Z ale $
11 #
12 # Adding 'USE_PHP=yes' to a port includes this Makefile after bsd.ports.pre.mk.
13 # If the port requires a predefined set of PHP extensions, they can be
14 # listed in this way:
15 #
16 # USE_PHP=      ext1 ext2 ext3
17 #
18 # The port can set these options in its Makefile before bsd.port.pre.mk:
19 #
20 # DEFAULT_PHP_VER=N - Use PHP version N if PHP is not yet installed.
21 # IGNORE_WITH_PHP=N - The port doesn't work with PHP version N.
22 # USE_PHPIZE=yes    - Use to build a PHP extension.
23 # USE_PHPEXT=yes    - Use to build, install and register a PHP extension.
24 # USE_ZENDEXT=yes   - Use to build, install and register a Zend extension.
25 # USE_PHP_BUILD=yes - Set PHP also as a build dependency.
26 # WANT_PHP_CLI=yes  - Want the CLI version of PHP.
27 # WANT_PHP_CGI=yes  - Want the CGI version of PHP.
28 # WANT_PHP_MOD=yes  - Want the Apache Module for PHP.
29 # WANT_PHP_WEB=yes  - Want the Apache Module or the CGI version of PHP.
30 # WANT_PHP_EMB=yes  - Want the embedded library version of PHP.
31 #
32 # You may combine multiple WANT_PHP_* knobs.
33 # Don't specify any WANT_PHP_* knob if your port will work with every PHP SAPI.
34 #
35
36 .if !defined(_PHPMKINCLUDED)
37
38 PHP_Include_MAINTAINER= ale@FreeBSD.org
39
40 _PHPMKINCLUDED= yes
41
42 PHPBASE?=       ${LOCALBASE}
43 .if exists(${PHPBASE}/etc/php.conf)
44 .include "${PHPBASE}/etc/php.conf"
45 PHP_EXT_DIR!=   ${PHPBASE}/bin/php-config --extension-dir | ${SED} -ne 's,^${PHPBASE}/lib/php/\(.*\),\1,p'
46
47 .else
48 DEFAULT_PHP_VER?=       5
49
50 PHP_VER?=       ${DEFAULT_PHP_VER}
51 .if ${PHP_VER}  == 52
52 PHP_EXT_DIR=    20060613
53 .elif ${PHP_VER}  == 53
54 PHP_EXT_DIR=    20090626
55 PHP_EXT_INC=    pcre spl
56 .elif ${PHP_VER}  == 55
57 PHP_EXT_DIR=    20121212
58 PHP_EXT_INC=    pcre spl
59 .else
60 PHP_EXT_DIR=    20100525
61 PHP_EXT_INC=    pcre spl
62 .endif
63
64 HTTPD?=         ${LOCALBASE}/sbin/httpd
65 .if exists(${HTTPD})
66 APACHE_THR!=    ${HTTPD} -V | ${GREP} threaded
67 .       if ${APACHE_THR:Myes}
68 PHP_EXT_DIR:=   ${PHP_EXT_DIR}-zts
69 .       endif
70 .elif defined(APACHE_PORT) && (${APACHE_PORT:M*worker*} != "" || ${APACHE_PORT:M*event*} != "")
71 PHP_EXT_DIR:=   ${PHP_EXT_DIR}-zts
72 .elif defined(WITH_MPM) && (${WITH_MPM} == "worker" || ${WITH_MPM} == "event")
73 PHP_EXT_DIR:=   ${PHP_EXT_DIR}-zts
74 .endif
75
76 .if defined(WITH_DEBUG)
77 PHP_EXT_DIR:=   ${PHP_EXT_DIR}-debug
78 .endif
79 PHP_SAPI?=      ""
80 .endif  # .if exists(${PHPBASE}/etc/php.conf)
81 PHP_EXT_INC?=   ""
82
83 PHP5_LAST_VER=  54
84
85 .if defined(IGNORE_WITH_PHP)
86 .       for VER in ${IGNORE_WITH_PHP}
87 .               if ${PHP_VER} == "${VER}"
88 IGNORE=         cannot be installed: doesn't work with lang/php${PHP_VER} port\
89                 (doesn't support PHP ${IGNORE_WITH_PHP:C/^5$/${PHP5_LAST_VER}/:C/^5/5./})
90 .               endif
91 .       endfor
92 .endif
93
94 .if defined(WANT_PHP_WEB)
95 .       if defined(WANT_PHP_CGI) || defined(WANT_PHP_MOD)
96 check-makevars::
97                 @${ECHO_CMD} "If you define WANT_PHP_WEB you cannot set also WANT_PHP_CGI"
98                 @${ECHO_CMD} "or WANT_PHP_MOD. Use only one of them."
99                 @${FALSE}
100 .       elif defined(PHP_VERSION) && ${PHP_SAPI:Mcgi} == "" && ${PHP_SAPI:Mfpm} == "" && ${PHP_SAPI:Mmod} == ""
101 check-makevars::
102                 @${ECHO_CMD} "This port requires the Apache Module or the CGI version of PHP, but you have"
103                 @${ECHO_CMD} "already installed a PHP port without them."
104                 @${FALSE}
105 .       endif
106 .endif
107
108 .if defined(WANT_PHP_CGI)
109 .       if defined(PHP_VERSION) && ${PHP_SAPI:Mcgi} == "" && ${PHP_SAPI:Mfpm} == ""
110 check-makevars::
111                 @${ECHO_CMD} "This port requires the CGI version of PHP, but you have already"
112                 @${ECHO_CMD} "installed a PHP port without CGI."
113                 @${FALSE}
114 .       endif
115 .endif
116
117 .if defined(WANT_PHP_CLI)
118 .       if defined(PHP_VERSION) && ${PHP_SAPI:Mcli} == ""
119 check-makevars::
120                 @${ECHO_CMD} "This port requires the CLI version of PHP, but you have already"
121                 @${ECHO_CMD} "installed a PHP port without CLI."
122                 @${FALSE}
123 .       endif
124 .endif
125
126 .if defined(WANT_PHP_MOD)
127 .       if defined(PHP_VERSION) && ${PHP_SAPI:Mmod} == ""
128 check-makevars::
129                 @${ECHO_CMD} "This port requires the Apache Module for PHP, but you have already"
130                 @${ECHO_CMD} "installed a PHP port without the Apache Module."
131                 @${FALSE}
132 .       endif
133 .endif
134
135 .if defined(WANT_PHP_EMB)
136 .       if defined(PHP_VERSION) && ${PHP_SAPI:Membed} == ""
137 check-makevars::
138                 @${ECHO_CMD} "This port requires the embedded library version of PHP, but you have already"
139                 @${ECHO_CMD} "installed a PHP port without the embedded library."
140                 @${FALSE}
141 .       endif
142 .endif
143
144 PHP_PORT?=      lang/php${PHP_VER}
145
146 .if defined(USE_PHP_BUILD)
147 BUILD_DEPENDS+= ${PHPBASE}/include/php/main/php.h:${PORTSDIR}/${PHP_PORT}
148 .endif
149 RUN_DEPENDS+=   ${PHPBASE}/include/php/main/php.h:${PORTSDIR}/${PHP_PORT}
150
151 PLIST_SUB+=     PHP_EXT_DIR=${PHP_EXT_DIR}
152 SUB_LIST+=      PHP_EXT_DIR=${PHP_EXT_DIR}
153
154 .if defined(USE_PHPIZE) || defined(USE_PHPEXT) || defined(USE_ZENDEXT)
155 BUILD_DEPENDS+= ${PHPBASE}/bin/phpize:${PORTSDIR}/${PHP_PORT}
156 GNU_CONFIGURE=  yes
157 USE_AUTOTOOLS+= autoconf:env
158 CONFIGURE_ARGS+=--with-php-config=${PHPBASE}/bin/php-config
159
160 configure-message: phpize-message do-phpize
161
162 phpize-message:
163         @${ECHO_MSG} "===>  PHPizing for ${PKGNAME}"
164
165 do-phpize:
166         @(cd ${WRKSRC}; ${SETENV} ${SCRIPTS_ENV} ${PHPBASE}/bin/phpize)
167 .endif
168
169 .endif
170
171 .if defined(_POSTMKINCLUDED) && (defined(USE_PHPEXT) || defined(USE_ZENDEXT))
172 PHP_MODNAME?=   ${PORTNAME}
173 PHP_HEADER_DIRS?=       ""
174
175 do-install:
176         @${MKDIR} ${STAGEDIR}${PREFIX}/lib/php/${PHP_EXT_DIR}
177         @${INSTALL_DATA} ${WRKSRC}/modules/${PHP_MODNAME}.so \
178                 ${STAGEDIR}${PREFIX}/lib/php/${PHP_EXT_DIR}
179 .       for header in . ${PHP_HEADER_DIRS}
180                 @${MKDIR} ${STAGEDIR}${PREFIX}/include/php/ext/${PHP_MODNAME}/${header}
181                 @${INSTALL_DATA} ${WRKSRC}/${header}/*.h \
182                         ${STAGEDIR}${PREFIX}/include/php/ext/${PHP_MODNAME}/${header}
183 .       endfor
184         @${RM} -f ${STAGEDIR}${PREFIX}/include/php/ext/${PHP_MODNAME}/config.h
185         @${GREP} "#define \(COMPILE\|HAVE\|USE\)_" ${WRKSRC}/config.h \
186                 > ${STAGEDIR}${PREFIX}/include/php/ext/${PHP_MODNAME}/config.h
187         @${MKDIR} ${STAGEDIR}${PREFIX}/etc/php
188 .if defined(NO_STAGE)
189         @${ECHO_CMD} \#include \"ext/${PHP_MODNAME}/config.h\" \
190                 >> ${PREFIX}/include/php/ext/php_config.h
191 .if defined(USE_ZENDEXT)
192         @${ECHO_CMD} zend_extension=${PREFIX}/lib/php/${PHP_EXT_DIR}/${PHP_MODNAME}.so \
193                 >> ${PREFIX}/etc/php/extensions.ini
194 .else
195         @${ECHO_CMD} extension=${PHP_MODNAME}.so \
196                 >> ${PREFIX}/etc/php/extensions.ini
197 .endif
198 .endif
199
200 add-plist-info: add-plist-phpext
201 add-plist-phpext:
202         @${ECHO_CMD} "lib/php/${PHP_EXT_DIR}/${PHP_MODNAME}.so" \
203                 >> ${TMPPLIST}
204         @${ECHO_CMD} "@unexec rmdir %D/lib/php/${PHP_EXT_DIR} 2> /dev/null || true" \
205                 >> ${TMPPLIST}
206         @${FIND} -P ${STAGEDIR}${PREFIX}/include/php/ext/${PHP_MODNAME} ! -type d 2>/dev/null | \
207                 ${SED} -ne 's,^${STAGEDIR}${PREFIX}/,,p' >> ${TMPPLIST}
208         @${FIND} -P -d ${STAGEDIR}${PREFIX}/include/php/ext/${PHP_MODNAME} -type d 2>/dev/null | \
209                 ${SED} -ne 's,^${STAGEDIR}${PREFIX}/,@dirrm ,p' >> ${TMPPLIST}
210         @${ECHO_CMD} "@exec echo \#include \\\"ext/${PHP_MODNAME}/config.h\\\" >> %D/include/php/ext/php_config.h" \
211                 >> ${TMPPLIST}
212         @${ECHO_CMD} "@unexec cp %D/include/php/ext/php_config.h %D/include/php/ext/php_config.h.orig" \
213                 >> ${TMPPLIST}
214         @${ECHO_CMD} "@unexec grep -v ext/${PHP_MODNAME}/config.h %D/include/php/ext/php_config.h.orig > %D/include/php/ext/php_config.h || true" \
215                 >> ${TMPPLIST}
216         @${ECHO_CMD} "@unexec rm %D/include/php/ext/php_config.h.orig" \
217                 >> ${TMPPLIST}
218         @${ECHO_CMD} "@exec mkdir -p %D/etc/php" \
219                 >> ${TMPPLIST}
220 .if defined(USE_ZENDEXT)
221         @${ECHO_CMD} "@exec echo zend_extension=%D/lib/php/${PHP_EXT_DIR}/${PHP_MODNAME}.so >> %D/etc/php/extensions.ini" \
222                 >> ${TMPPLIST}
223 .else
224         @${ECHO_CMD} "@exec echo extension=${PHP_MODNAME}.so >> %D/etc/php/extensions.ini" \
225                 >> ${TMPPLIST}
226 .endif
227         @${ECHO_CMD} "@unexec cp %D/etc/php/extensions.ini %D/etc/php/extensions.ini.orig" \
228                 >> ${TMPPLIST}
229 .if defined(USE_ZENDEXT)
230         @${ECHO_CMD} "@unexec grep -v zend_extension=%D/lib/php/${PHP_EXT_DIR}/${PHP_MODNAME}\\\.so %D/etc/php/extensions.ini.orig > %D/etc/php/extensions.ini || true" \
231                 >> ${TMPPLIST}
232 .else
233         @${ECHO_CMD} "@unexec grep -v extension=${PHP_MODNAME}\\\.so %D/etc/php/extensions.ini.orig > %D/etc/php/extensions.ini || true" \
234                 >> ${TMPPLIST}
235 .endif
236         @${ECHO_CMD} "@unexec rm %D/etc/php/extensions.ini.orig" \
237                 >> ${TMPPLIST}
238         @${ECHO_CMD} "@unexec [ -s %D/etc/php/extensions.ini ] || rm %D/etc/php/extensions.ini" \
239                 >> ${TMPPLIST}
240         @${ECHO_CMD} "@unexec rmdir %D/etc/php 2> /dev/null || true" \
241                 >> ${TMPPLIST}
242
243 package-message: php-ini
244
245 php-ini:
246         @${ECHO_CMD} "****************************************************************************"
247         @${ECHO_CMD} ""
248         @${ECHO_CMD} "The following line has been added to your ${PREFIX}/etc/php/extensions.ini"
249         @${ECHO_CMD} "configuration file to automatically load the installed extension:"
250         @${ECHO_CMD} ""
251 .if defined(USE_ZENDEXT)
252         @${ECHO_CMD} "zend_extension=${PREFIX}/lib/php/${PHP_EXT_DIR}/${PHP_MODNAME}.so"
253 .else
254         @${ECHO_CMD} "extension=${PHP_MODNAME}.so"
255 .endif
256         @${ECHO_CMD} ""
257         @${ECHO_CMD} "****************************************************************************"
258 .endif
259
260 # Extensions
261 .if defined(_POSTMKINCLUDED) && ${USE_PHP:tl} != "yes"
262 # non-version specific components
263 _USE_PHP_ALL=   apc bcmath bitset bz2 calendar ctype curl dba dom \
264                 exif fileinfo filter ftp gd gettext gmp \
265                 hash iconv igbinary imap interbase intl json ldap mbstring mcrypt \
266                 memcache mssql mysql mysqli odbc opcache \
267                 openssl pcntl pcre pdf pdo pdo_dblib pdo_firebird pdo_mysql \
268                 pdo_odbc pdo_pgsql pdo_sqlite pgsql posix \
269                 pspell radius readline recode session shmop simplexml snmp soap\
270                 sockets spl sybase_ct sysvmsg sysvsem sysvshm \
271                 tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zip zlib
272 # version specific components
273 _USE_PHP_VER5=  ${_USE_PHP_ALL} phar sqlite3
274 _USE_PHP_VER52= ${_USE_PHP_ALL} dbase mhash ming ncurses oci8 sqlite
275 _USE_PHP_VER53= ${_USE_PHP_ALL} phar sqlite sqlite3
276 _USE_PHP_VER55= ${_USE_PHP_ALL} phar sqlite3
277
278 apc_DEPENDS=    www/pecl-APC
279 bcmath_DEPENDS= math/php${PHP_VER}-bcmath
280 bitset_DEPENDS= math/pecl-bitset
281 bz2_DEPENDS=    archivers/php${PHP_VER}-bz2
282 calendar_DEPENDS=       misc/php${PHP_VER}-calendar
283 ctype_DEPENDS=  textproc/php${PHP_VER}-ctype
284 curl_DEPENDS=   ftp/php${PHP_VER}-curl
285 dba_DEPENDS=    databases/php${PHP_VER}-dba
286 dbase_DEPENDS=  databases/php${PHP_VER}-dbase
287 dom_DEPENDS=    textproc/php${PHP_VER}-dom
288 exif_DEPENDS=   graphics/php${PHP_VER}-exif
289 .if ${PHP_VER} == 52
290 fileinfo_DEPENDS=       sysutils/pecl-fileinfo
291 .else
292 fileinfo_DEPENDS=       sysutils/php${PHP_VER}-fileinfo
293 .endif
294 filter_DEPENDS= security/php${PHP_VER}-filter
295 ftp_DEPENDS=    ftp/php${PHP_VER}-ftp
296 gd_DEPENDS=     graphics/php${PHP_VER}-gd
297 gettext_DEPENDS=devel/php${PHP_VER}-gettext
298 gmp_DEPENDS=    math/php${PHP_VER}-gmp
299 hash_DEPENDS=   security/php${PHP_VER}-hash
300 iconv_DEPENDS=  converters/php${PHP_VER}-iconv
301 igbinary_DEPENDS=       converters/igbinary
302 imap_DEPENDS=   mail/php${PHP_VER}-imap
303 interbase_DEPENDS=      databases/php${PHP_VER}-interbase
304 intl_DEPENDS=   devel/pecl-intl
305 json_DEPENDS=   devel/php${PHP_VER}-json
306 ldap_DEPENDS=   net/php${PHP_VER}-ldap
307 mbstring_DEPENDS=       converters/php${PHP_VER}-mbstring
308 mcrypt_DEPENDS= security/php${PHP_VER}-mcrypt
309 memcache_DEPENDS=       databases/pecl-memcache
310 mhash_DEPENDS=  security/php${PHP_VER}-mhash
311 mssql_DEPENDS=  databases/php${PHP_VER}-mssql
312 mysql_DEPENDS=  databases/php${PHP_VER}-mysql
313 mysqli_DEPENDS= databases/php${PHP_VER}-mysqli
314 ncurses_DEPENDS=devel/php${PHP_VER}-ncurses
315 odbc_DEPENDS=   databases/php${PHP_VER}-odbc
316 oci8_DEPENDS=   databases/php${PHP_VER}-oci8
317 .if ${PHP_VER} == 55
318 opcache_DEPENDS=        www/php${PHP_VER}-opcache
319 .else
320 opcache_DEPENDS=        www/pecl-zendopcache
321 .endif  
322 openssl_DEPENDS=security/php${PHP_VER}-openssl
323 pcntl_DEPENDS=  devel/php${PHP_VER}-pcntl
324 pcre_DEPENDS=   devel/php${PHP_VER}-pcre
325 pdf_DEPENDS=    print/pecl-pdflib
326 pdo_DEPENDS=    databases/php${PHP_VER}-pdo
327 pdo_dblib_DEPENDS=      databases/php${PHP_VER}-pdo_dblib
328 pdo_firebird_DEPENDS=   databases/php${PHP_VER}-pdo_firebird
329 pdo_mysql_DEPENDS=      databases/php${PHP_VER}-pdo_mysql
330 pdo_odbc_DEPENDS=       databases/php${PHP_VER}-pdo_odbc
331 pdo_pgsql_DEPENDS=      databases/php${PHP_VER}-pdo_pgsql
332 pdo_sqlite_DEPENDS=     databases/php${PHP_VER}-pdo_sqlite
333 pgsql_DEPENDS=  databases/php${PHP_VER}-pgsql
334 phar_DEPENDS=   archivers/php${PHP_VER}-phar
335 posix_DEPENDS=  sysutils/php${PHP_VER}-posix
336 pspell_DEPENDS= textproc/php${PHP_VER}-pspell
337 radius_DEPENDS= net/pecl-radius
338 readline_DEPENDS=       devel/php${PHP_VER}-readline
339 recode_DEPENDS= converters/php${PHP_VER}-recode
340 session_DEPENDS=www/php${PHP_VER}-session
341 shmop_DEPENDS=  devel/php${PHP_VER}-shmop
342 simplexml_DEPENDS=      textproc/php${PHP_VER}-simplexml
343 snmp_DEPENDS=   net-mgmt/php${PHP_VER}-snmp
344 soap_DEPENDS=   net/php${PHP_VER}-soap
345 sockets_DEPENDS=net/php${PHP_VER}-sockets
346 spl_DEPENDS=    devel/php${PHP_VER}-spl
347 sqlite_DEPENDS= databases/php${PHP_VER}-sqlite
348 sqlite3_DEPENDS=databases/php${PHP_VER}-sqlite3
349 sybase_ct_DEPENDS=      databases/php${PHP_VER}-sybase_ct
350 sysvmsg_DEPENDS=devel/php${PHP_VER}-sysvmsg
351 sysvsem_DEPENDS=devel/php${PHP_VER}-sysvsem
352 sysvshm_DEPENDS=devel/php${PHP_VER}-sysvshm
353 tidy_DEPENDS=   www/php${PHP_VER}-tidy
354 tokenizer_DEPENDS=      devel/php${PHP_VER}-tokenizer
355 wddx_DEPENDS=   textproc/php${PHP_VER}-wddx
356 xml_DEPENDS=    textproc/php${PHP_VER}-xml
357 xmlreader_DEPENDS=      textproc/php${PHP_VER}-xmlreader
358 xmlrpc_DEPENDS= net/php${PHP_VER}-xmlrpc
359 xmlwriter_DEPENDS=      textproc/php${PHP_VER}-xmlwriter
360 xsl_DEPENDS=    textproc/php${PHP_VER}-xsl
361 zip_DEPENDS=    archivers/php${PHP_VER}-zip
362 zlib_DEPENDS=   archivers/php${PHP_VER}-zlib
363
364 .       for extension in ${USE_PHP}
365 .               if ${_USE_PHP_VER${PHP_VER}:M${extension}} != ""
366 .                       if ${PHP_EXT_INC:M${extension}} == ""
367 .                               if defined(USE_PHP_BUILD)
368 BUILD_DEPENDS+= ${PHPBASE}/lib/php/${PHP_EXT_DIR}/${extension}.so:${PORTSDIR}/${${extension}_DEPENDS}
369 .                               endif
370 RUN_DEPENDS+=   ${PHPBASE}/lib/php/${PHP_EXT_DIR}/${extension}.so:${PORTSDIR}/${${extension}_DEPENDS}
371 .                       endif
372 .               else
373 ext=            ${extension}
374 .                       if ${ext} == "mhash"
375 .                               if defined(USE_PHP_BUILD)
376 BUILD_DEPENDS+= ${PHPBASE}/lib/php/${PHP_EXT_DIR}/hash.so:${PORTSDIR}/${hash_DEPENDS}
377 .                               endif
378 RUN_DEPENDS+=   ${PHPBASE}/lib/php/${PHP_EXT_DIR}/hash.so:${PORTSDIR}/${hash_DEPENDS}
379 .                       elif ${ext:tl} != "yes"
380 check-makevars::
381                         @${ECHO_CMD} "Unknown extension ${extension} for PHP ${PHP_VER}."
382                         @${FALSE}
383 .                       endif
384 .               endif
385 .       endfor
386 .endif