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