dev-perl/HTML-Template: Cleanup old version 2.950.0
[gentoo.git] / dev-lang / php / php-7.0.31.ebuild
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 inherit flag-o-matic eapi7-ver systemd
7
8 DESCRIPTION="The PHP language runtime engine"
9 HOMEPAGE="https://secure.php.net/"
10 SRC_URI="https://secure.php.net/distributions/${P}.tar.xz"
11
12 LICENSE="PHP-3.01
13         BSD
14         Zend-2.0
15         bcmath? ( LGPL-2.1+ )
16         fpm? ( BSD-2 )
17         gd? ( gd )
18         unicode? ( BSD-2 LGPL-2.1 )"
19
20 SLOT="$(ver_cut 1-2)"
21 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~x86-fbsd ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos"
22
23 # We can build the following SAPIs in the given order
24 SAPIS="embed cli cgi fpm apache2 phpdbg"
25
26 # SAPIs and SAPI-specific USE flags (cli SAPI is default on):
27 IUSE="${IUSE}
28         ${SAPIS/cli/+cli}
29         threads"
30
31 IUSE="${IUSE} acl bcmath berkdb bzip2 calendar cdb cjk
32         coverage crypt +ctype curl debug
33         enchant exif +fileinfo +filter firebird
34         flatfile ftp gd gdbm gmp +hash +iconv imap inifile
35         intl iodbc ipv6 +json kerberos ldap ldap-sasl libedit libressl
36         mhash mssql mysql mysqli nls
37         oci8-instant-client odbc +opcache pcntl pdo +phar +posix postgres qdbm
38         readline recode selinux +session sharedmem
39         +simplexml snmp soap sockets spell sqlite ssl
40         sysvipc systemd tidy +tokenizer truetype unicode wddx webp
41         +xml xmlreader xmlwriter xmlrpc xpm xslt zip zlib"
42
43 # The supported (that is, autodetected) versions of BDB are listed in
44 # the ./configure script. Other versions *work*, but we need to stick to
45 # the ones that can be detected to avoid a repeat of bug #564824.
46 COMMON_DEPEND="
47         >=app-eselect/eselect-php-0.9.1[apache2?,fpm?]
48         >=dev-libs/libpcre-8.32[unicode]
49         fpm? ( acl? ( sys-apps/acl ) )
50         apache2? ( || ( >=www-servers/apache-2.4[apache2_modules_unixd,threads=]
51                 <www-servers/apache-2.4[threads=] ) )
52         berkdb? ( || ( sys-libs/db:5.3
53                                         sys-libs/db:5.1
54                                         sys-libs/db:4.8
55                                         sys-libs/db:4.7
56                                         sys-libs/db:4.6
57                                         sys-libs/db:4.5 ) )
58         bzip2? ( app-arch/bzip2:0= )
59         cdb? ( || ( dev-db/cdb dev-db/tinycdb ) )
60         cjk? ( !gd? (
61                 virtual/jpeg:0
62                 media-libs/libpng:0=
63                 sys-libs/zlib:0=
64         ) )
65         coverage? ( dev-util/lcov )
66         crypt? ( >=dev-libs/libmcrypt-2.4 )
67         curl? ( >=net-misc/curl-7.10.5 )
68         enchant? ( app-text/enchant )
69         exif? ( !gd? (
70                 virtual/jpeg:0
71                 media-libs/libpng:0=
72                 sys-libs/zlib:0=
73         ) )
74         firebird? ( dev-db/firebird )
75         gd? ( virtual/jpeg:0 media-libs/libpng:0= sys-libs/zlib:0= )
76         gdbm? ( >=sys-libs/gdbm-1.8.0:0= )
77         gmp? ( dev-libs/gmp:0= )
78         iconv? ( virtual/libiconv )
79         imap? ( virtual/imap-c-client[kerberos=,ssl=] )
80         intl? ( <dev-libs/icu-61.1:= )
81         iodbc? ( dev-db/libiodbc )
82         kerberos? ( virtual/krb5 )
83         ldap? ( >=net-nds/openldap-1.2.11 )
84         ldap-sasl? ( dev-libs/cyrus-sasl >=net-nds/openldap-1.2.11 )
85         libedit? ( || ( sys-freebsd/freebsd-lib dev-libs/libedit ) )
86         mssql? ( dev-db/freetds[mssql] )
87         nls? ( sys-devel/gettext )
88         oci8-instant-client? ( dev-db/oracle-instantclient-basic )
89         odbc? ( >=dev-db/unixODBC-1.8.13 )
90         postgres? ( dev-db/postgresql:* )
91         qdbm? ( dev-db/qdbm )
92         readline? ( sys-libs/readline:0= )
93         recode? ( app-text/recode )
94         sharedmem? ( dev-libs/mm )
95         simplexml? ( >=dev-libs/libxml2-2.6.8 )
96         snmp? ( >=net-analyzer/net-snmp-5.2 )
97         soap? ( >=dev-libs/libxml2-2.6.8 )
98         spell? ( >=app-text/aspell-0.50 )
99         sqlite? ( >=dev-db/sqlite-3.7.6.3 )
100         ssl? (
101                 !libressl? ( dev-libs/openssl:0= )
102                 libressl? ( dev-libs/libressl:0= )
103         )
104         tidy? ( app-text/htmltidy )
105         truetype? (
106                 =media-libs/freetype-2*
107                 !gd? (
108                         virtual/jpeg:0 media-libs/libpng:0= sys-libs/zlib:0= )
109         )
110         unicode? ( dev-libs/oniguruma:= )
111         wddx? ( >=dev-libs/libxml2-2.6.8 )
112         webp? ( media-libs/libwebp:0= )
113         xml? ( >=dev-libs/libxml2-2.6.8 )
114         xmlrpc? ( >=dev-libs/libxml2-2.6.8 virtual/libiconv )
115         xmlreader? ( >=dev-libs/libxml2-2.6.8 )
116         xmlwriter? ( >=dev-libs/libxml2-2.6.8 )
117         xpm? (
118                 x11-libs/libXpm
119                 virtual/jpeg:0
120                 media-libs/libpng:0= sys-libs/zlib:0=
121         )
122         xslt? ( dev-libs/libxslt >=dev-libs/libxml2-2.6.8 )
123         zip? ( sys-libs/zlib:0= )
124         zlib? ( sys-libs/zlib:0= )
125 "
126
127 RDEPEND="${COMMON_DEPEND}
128         virtual/mta
129         fpm? (
130                 selinux? ( sec-policy/selinux-phpfpm )
131                 systemd? ( sys-apps/systemd ) )"
132
133 DEPEND="${COMMON_DEPEND}
134         app-arch/xz-utils
135         >=sys-devel/bison-3.0.1
136         sys-devel/flex
137         >=sys-devel/m4-1.4.3
138         >=sys-devel/libtool-1.5.18"
139
140 # Without USE=readline or libedit, the interactive "php -a" CLI will hang.
141 REQUIRED_USE="
142         || ( cli cgi fpm apache2 embed phpdbg )
143         cli? ( ^^ ( readline libedit ) )
144         truetype? ( gd zlib )
145         webp? ( gd zlib )
146         cjk? ( gd zlib )
147         exif? ( gd zlib )
148         xpm? ( gd zlib )
149         gd? ( zlib )
150         simplexml? ( xml )
151         soap? ( xml )
152         wddx? ( xml )
153         xmlrpc? ( || ( xml iconv ) )
154         xmlreader? ( xml )
155         xslt? ( xml )
156         ldap-sasl? ( ldap )
157         mhash? ( hash )
158         phar? ( hash )
159         qdbm? ( !gdbm )
160         readline? ( !libedit )
161         recode? ( !imap !mysqli !mysql )
162         sharedmem? ( !threads )
163         mysql? ( || ( mysqli pdo ) )
164 "
165
166 PATCHES=(
167         "${FILESDIR}/mbstring-oniguruma-6.8.patch"
168         # hopefully upstream will include the same version check fixes in upcoming releases
169         # patch added 20180429
170         "${FILESDIR}/libressl-compatibility.patch"
171         "${FILESDIR}/php-freetype-2.9.1.patch"
172 )
173
174 PHP_MV="$(ver_cut 1)"
175
176 php_install_ini() {
177         local phpsapi="${1}"
178
179         # work out where we are installing the ini file
180         php_set_ini_dir "${phpsapi}"
181
182         # Always install the production INI file, bug 611214.
183         local phpinisrc="php.ini-production-${phpsapi}"
184         cp php.ini-production "${phpinisrc}" || die
185
186         # default to /tmp for save_path, bug #282768
187         sed -e 's|^;session.save_path .*$|session.save_path = "'"${EPREFIX}"'/tmp"|g' -i "${phpinisrc}" || die
188
189         # Set the extension dir
190         sed -e "s|^extension_dir .*$|extension_dir = ${extension_dir}|g" \
191                 -i "${phpinisrc}" || die
192
193         # Set the include path to point to where we want to find PEAR packages
194         sed -e 's|^;include_path = ".:/php/includes".*|include_path = ".:'"${EPREFIX}"'/usr/share/php'${PHP_MV}':'"${EPREFIX}"'/usr/share/php"|' -i "${phpinisrc}" || die
195
196         dodir "${PHP_INI_DIR#${EPREFIX}}"
197         insinto "${PHP_INI_DIR#${EPREFIX}}"
198         newins "${phpinisrc}" php.ini
199
200         elog "Installing php.ini for ${phpsapi} into ${PHP_INI_DIR#${EPREFIX}}"
201         elog
202
203         dodir "${PHP_EXT_INI_DIR#${EPREFIX}}"
204         dodir "${PHP_EXT_INI_DIR_ACTIVE#${EPREFIX}}"
205
206         if use opcache; then
207                 elog "Adding opcache to $PHP_EXT_INI_DIR"
208                 echo "zend_extension=${PHP_DESTDIR}/$(get_libdir)/opcache.so" >> \
209                          "${D}/${PHP_EXT_INI_DIR}"/opcache.ini
210                 dosym "${PHP_EXT_INI_DIR#${EPREFIX}}/opcache.ini" \
211                           "${PHP_EXT_INI_DIR_ACTIVE#${EPREFIX}}/opcache.ini"
212         fi
213
214         # SAPI-specific handling
215         if [[ "${sapi}" == "fpm" ]] ; then
216                 einfo "Installing FPM config files php-fpm.conf and www.conf"
217                 insinto "${PHP_INI_DIR#${EPREFIX}}"
218                 doins sapi/fpm/php-fpm.conf
219                 insinto "${PHP_INI_DIR#${EPREFIX}}/fpm.d"
220                 doins sapi/fpm/www.conf
221         fi
222
223         dodoc php.ini-{development,production}
224 }
225
226 php_set_ini_dir() {
227         PHP_INI_DIR="${EPREFIX}/etc/php/${1}-php${SLOT}"
228         PHP_EXT_INI_DIR="${PHP_INI_DIR}/ext"
229         PHP_EXT_INI_DIR_ACTIVE="${PHP_INI_DIR}/ext-active"
230 }
231
232 src_prepare() {
233         default
234
235         # In php-7.x, the FPM pool configuration files have been split off
236         # of the main config. By default the pool config files go in
237         # e.g. /etc/php-fpm.d, which isn't slotted. So here we move the
238         # include directory to a subdirectory "fpm.d" of $PHP_INI_DIR. Later
239         # we'll install the pool configuration file "www.conf" there.
240         php_set_ini_dir fpm
241         sed -i "s~^include=.*$~include=${PHP_INI_DIR}/fpm.d/*.conf~" \
242                 sapi/fpm/php-fpm.conf.in \
243                 || die 'failed to move the include directory in php-fpm.conf'
244 }
245
246 src_configure() {
247         addpredict /usr/share/snmp/mibs/.index #nowarn
248         addpredict /var/lib/net-snmp/mib_indexes #nowarn
249
250         PHP_DESTDIR="${EPREFIX}/usr/$(get_libdir)/php${SLOT}"
251
252         # The php-fpm config file wants localstatedir to be ${EPREFIX}/var
253         # and not the Gentoo default ${EPREFIX}/var/lib. See bug 572002.
254         local our_conf=(
255                 --prefix="${PHP_DESTDIR}"
256                 --mandir="${PHP_DESTDIR}/man"
257                 --infodir="${PHP_DESTDIR}/info"
258                 --libdir="${PHP_DESTDIR}/lib"
259                 --with-libdir="$(get_libdir)"
260                 --localstatedir="${EPREFIX}/var"
261                 --without-pear
262                 $(use_enable threads maintainer-zts)
263         )
264
265         our_conf+=(
266                 $(use_enable bcmath bcmath)
267                 $(use_with bzip2 bz2 "${EPREFIX}/usr")
268                 $(use_enable calendar calendar)
269                 $(use_enable coverage gcov)
270                 $(use_enable ctype ctype)
271                 $(use_with curl curl "${EPREFIX}/usr")
272                 $(use_enable xml dom)
273                 $(use_with enchant enchant "${EPREFIX}/usr")
274                 $(use_enable exif exif)
275                 $(use_enable fileinfo fileinfo)
276                 $(use_enable filter filter)
277                 $(use_enable ftp ftp)
278                 $(use_with nls gettext "${EPREFIX}/usr")
279                 $(use_with gmp gmp "${EPREFIX}/usr")
280                 $(use_enable hash hash)
281                 $(use_with mhash mhash "${EPREFIX}/usr")
282                 $(use_with iconv iconv \
283                         $(use elibc_glibc || use elibc_musl || use elibc_FreeBSD || echo "${EPREFIX}/usr"))
284                 $(use_enable intl intl)
285                 $(use_enable ipv6 ipv6)
286                 $(use_enable json json)
287                 $(use_with kerberos kerberos "${EPREFIX}/usr")
288                 $(use_enable xml libxml)
289                 $(use_with xml libxml-dir "${EPREFIX}/usr")
290                 $(use_enable unicode mbstring)
291                 $(use_with crypt mcrypt "${EPREFIX}/usr")
292                 $(use_with unicode onig "${EPREFIX}/usr")
293                 $(use_with ssl openssl "${EPREFIX}/usr")
294                 $(use_with ssl openssl-dir "${EPREFIX}/usr")
295                 $(use_enable pcntl pcntl)
296                 $(use_enable phar phar)
297                 $(use_enable pdo pdo)
298                 $(use_enable opcache opcache)
299                 $(use_with postgres pgsql "${EPREFIX}/usr")
300                 $(use_enable posix posix)
301                 $(use_with spell pspell "${EPREFIX}/usr")
302                 $(use_with recode recode "${EPREFIX}/usr")
303                 $(use_enable simplexml simplexml)
304                 $(use_enable sharedmem shmop)
305                 $(use_with snmp snmp "${EPREFIX}/usr")
306                 $(use_enable soap soap)
307                 $(use_enable sockets sockets)
308                 $(use_with sqlite sqlite3 "${EPREFIX}/usr")
309                 $(use_enable sysvipc sysvmsg)
310                 $(use_enable sysvipc sysvsem)
311                 $(use_enable sysvipc sysvshm)
312                 $(use_with tidy tidy "${EPREFIX}/usr")
313                 $(use_enable tokenizer tokenizer)
314                 $(use_enable wddx wddx)
315                 $(use_enable xml xml)
316                 $(use_enable xmlreader xmlreader)
317                 $(use_enable xmlwriter xmlwriter)
318                 $(use_with xmlrpc xmlrpc)
319                 $(use_with xslt xsl "${EPREFIX}/usr")
320                 $(use_enable zip zip)
321                 $(use_with zlib zlib "${EPREFIX}/usr")
322                 $(use_enable debug debug)
323         )
324
325         # DBA support
326         if use cdb || use berkdb || use flatfile || use gdbm || use inifile \
327                 || use qdbm ; then
328                 our_conf+=( "--enable-dba${shared}" )
329         fi
330
331         # DBA drivers support
332         our_conf+=(
333                 $(use_with cdb cdb)
334                 $(use_with berkdb db4 "${EPREFIX}/usr")
335                 $(use_enable flatfile flatfile)
336                 $(use_with gdbm gdbm "${EPREFIX}/usr")
337                 $(use_enable inifile inifile)
338                 $(use_with qdbm qdbm "${EPREFIX}/usr")
339         )
340
341         # Support for the GD graphics library
342         our_conf+=(
343                 $(use_with truetype freetype-dir "${EPREFIX}/usr")
344                 $(use_enable cjk gd-jis-conv)
345                 $(use_with gd jpeg-dir "${EPREFIX}/usr")
346                 $(use_with gd png-dir "${EPREFIX}/usr")
347                 $(use_with xpm xpm-dir "${EPREFIX}/usr")
348         )
349         if use webp; then
350                 our_conf+=( --with-webp-dir="${EPREFIX}/usr" )
351         fi
352         # enable gd last, so configure can pick up the previous settings
353         our_conf+=( $(use_with gd gd) )
354
355         # IMAP support
356         if use imap ; then
357                 our_conf+=(
358                         $(use_with imap imap "${EPREFIX}/usr")
359                         $(use_with ssl imap-ssl "${EPREFIX}/usr")
360                 )
361         fi
362
363         # Interbase/firebird support
364         our_conf+=( $(use_with firebird interbase "${EPREFIX}/usr") )
365
366         # LDAP support
367         if use ldap ; then
368                 our_conf+=(
369                         $(use_with ldap ldap "${EPREFIX}/usr")
370                         $(use_with ldap-sasl ldap-sasl "${EPREFIX}/usr")
371                 )
372         fi
373
374         # MySQL support
375         local mysqllib="mysqlnd"
376         local mysqlilib="mysqlnd"
377
378         our_conf+=( $(use_with mysqli mysqli "${mysqlilib}") )
379
380         local mysqlsock="${EPREFIX}/var/run/mysqld/mysqld.sock"
381         if use mysql || use mysqli ; then
382                 our_conf+=( $(use_with mysql mysql-sock "${mysqlsock}") )
383         fi
384
385         # ODBC support
386         our_conf+=(
387                 $(use_with odbc unixODBC "${EPREFIX}/usr")
388                 $(use_with iodbc iodbc "${EPREFIX}/usr")
389         )
390
391         # Oracle support
392         our_conf+=( $(use_with oci8-instant-client oci8) )
393
394         # PDO support
395         if use pdo ; then
396                 our_conf+=(
397                         $(use_with mssql pdo-dblib "${EPREFIX}/usr")
398                         $(use_with mysql pdo-mysql "${mysqllib}")
399                         $(use_with postgres pdo-pgsql)
400                         $(use_with sqlite pdo-sqlite "${EPREFIX}/usr")
401                         $(use_with firebird pdo-firebird "${EPREFIX}/usr")
402                         $(use_with odbc pdo-odbc "unixODBC,${EPREFIX}/usr")
403                         $(use_with oci8-instant-client pdo-oci)
404                 )
405         fi
406
407         # readline/libedit support
408         our_conf+=(
409                 $(use_with readline readline "${EPREFIX}/usr")
410                 $(use_with libedit libedit "${EPREFIX}/usr")
411         )
412
413         # Session support
414         if use session ; then
415                 our_conf+=( $(use_with sharedmem mm "${EPREFIX}/usr") )
416         else
417                 our_conf+=( $(use_enable session session) )
418         fi
419
420         # Use pic for shared modules such as apache2's mod_php
421         our_conf+=( --with-pic )
422
423         # we use the system copy of pcre
424         # --with-pcre-regex affects ext/pcre
425         # --with-pcre-dir affects ext/filter and ext/zip
426         our_conf+=(
427                 --with-pcre-regex="${EPREFIX}/usr"
428                 --with-pcre-dir="${EPREFIX}/usr"
429         )
430
431         # Catch CFLAGS problems
432         # Fixes bug #14067.
433         # Changed order to run it in reverse for bug #32022 and #12021.
434         replace-cpu-flags "k6*" "i586"
435
436         # Cache the ./configure test results between SAPIs.
437         our_conf+=( --cache-file="${T}/config.cache" )
438
439         # Support user-passed configuration parameters
440         our_conf+=( ${EXTRA_ECONF:-} )
441
442         # Support the Apache2 extras, they must be set globally for all
443         # SAPIs to work correctly, especially for external PHP extensions
444
445         mkdir -p "${WORKDIR}/sapis-build" || die
446         for one_sapi in $SAPIS ; do
447                 use "${one_sapi}" || continue
448                 php_set_ini_dir "${one_sapi}"
449
450                 # The BUILD_DIR variable is used to determine where to output
451                 # the files that autotools creates. This was all originally
452                 # based on the autotools-utils eclass.
453                 BUILD_DIR="${WORKDIR}/sapis-build/${one_sapi}"
454                 cp -a "${S}" "${BUILD_DIR}" || die
455                 cd "${BUILD_DIR}" || die
456
457                 local sapi_conf=(
458                         --with-config-file-path="${PHP_INI_DIR}"
459                         --with-config-file-scan-dir="${PHP_EXT_INI_DIR_ACTIVE}"
460                 )
461
462                 for sapi in $SAPIS ; do
463                         case "$sapi" in
464                                 cli|cgi|embed|fpm|phpdbg)
465                                         if [[ "${one_sapi}" == "${sapi}" ]] ; then
466                                                 sapi_conf+=( "--enable-${sapi}" )
467                                                 if [[ "fpm" == "${sapi}" ]] ; then
468                                                         sapi_conf+=(
469                                                                 $(use_with acl fpm-acl)
470                                                                 $(use_with systemd fpm-systemd)
471                                                         )
472                                                 fi
473                                         else
474                                                 sapi_conf+=( "--disable-${sapi}" )
475                                         fi
476                                         ;;
477
478                                 apache2)
479                                         if [[ "${one_sapi}" == "${sapi}" ]] ; then
480                                                 sapi_conf+=( --with-apxs2="${EPREFIX}/usr/bin/apxs" )
481                                         else
482                                                 sapi_conf+=( --without-apxs2 )
483                                         fi
484                                         ;;
485                         esac
486                 done
487
488                 # Construct the $myeconfargs array by concatenating $our_conf
489                 # (the common args) and $sapi_conf (the SAPI-specific args).
490                 local myeconfargs=( "${our_conf[@]}" )
491                 myeconfargs+=( "${sapi_conf[@]}" )
492
493                 pushd "${BUILD_DIR}" > /dev/null || die
494                 econf "${myeconfargs[@]}"
495                 popd > /dev/null || die
496         done
497 }
498
499 src_compile() {
500         # snmp seems to run during src_compile, too (bug #324739)
501         addpredict /usr/share/snmp/mibs/.index #nowarn
502         addpredict /var/lib/net-snmp/mib_indexes #nowarn
503
504         for sapi in ${SAPIS} ; do
505                 if use "${sapi}"; then
506                         cd "${WORKDIR}/sapis-build/$sapi" || \
507                                 die "Failed to change dir to ${WORKDIR}/sapis-build/$1"
508                         emake
509                 fi
510         done
511 }
512
513 src_install() {
514         # see bug #324739 for what happens when we don't have that
515         addpredict /usr/share/snmp/mibs/.index #nowarn
516
517         # grab the first SAPI that got built and install common files from there
518         local first_sapi=""
519         for sapi in $SAPIS ; do
520                 if use $sapi ; then
521                         first_sapi=$sapi
522                         break
523                 fi
524         done
525
526         # Makefile forgets to create this before trying to write to it...
527         dodir "${PHP_DESTDIR#${EPREFIX}}/bin"
528
529         # Install php environment (without any sapis)
530         cd "${WORKDIR}/sapis-build/$first_sapi" || die
531         emake INSTALL_ROOT="${D}" \
532                 install-build install-headers install-programs
533
534         local extension_dir="$("${ED}/${PHP_DESTDIR#${EPREFIX}}/bin/php-config" --extension-dir)"
535
536         # Create the directory where we'll put version-specific php scripts
537         keepdir "/usr/share/php${PHP_MV}"
538
539         local sapi="", file=""
540         local sapi_list=""
541
542         for sapi in ${SAPIS}; do
543                 if use "${sapi}" ; then
544                         einfo "Installing SAPI: ${sapi}"
545                         cd "${WORKDIR}/sapis-build/${sapi}" || die
546
547                         if [[ "${sapi}" == "apache2" ]] ; then
548                                 # We're specifically not using emake install-sapi as libtool
549                                 # may cause unnecessary relink failures (see bug #351266)
550                                 insinto "${PHP_DESTDIR#${EPREFIX}}/apache2/"
551                                 newins ".libs/libphp${PHP_MV}$(get_libname)" \
552                                            "libphp${PHP_MV}$(get_libname)"
553                                 keepdir "/usr/$(get_libdir)/apache2/modules"
554                         else
555                                 # needed each time, php_install_ini would reset it
556                                 local dest="${PHP_DESTDIR#${EPREFIX}}"
557                                 into "${dest}"
558                                 case "$sapi" in
559                                         cli)
560                                                 source="sapi/cli/php"
561                                                 ;;
562                                         cgi)
563                                                 source="sapi/cgi/php-cgi"
564                                                 ;;
565                                         fpm)
566                                                 source="sapi/fpm/php-fpm"
567                                                 ;;
568                                         embed)
569                                                 source="libs/libphp${PHP_MV}$(get_libname)"
570                                                 ;;
571                                         phpdbg)
572                                                 source="sapi/phpdbg/phpdbg"
573                                                 ;;
574                                         *)
575                                                 die "unhandled sapi in src_install"
576                                                 ;;
577                                 esac
578
579                                 if [[ "${source}" == *"$(get_libname)" ]]; then
580                                         dolib.so "${source}"
581                                 else
582                                         dobin "${source}"
583                                         local name="$(basename ${source})"
584                                         dosym "${dest}/bin/${name}" "/usr/bin/${name}${SLOT}"
585                                 fi
586                         fi
587
588                         php_install_ini "${sapi}"
589
590                         # construct correct SAPI string for php-config
591                         # thanks to ferringb for the bash voodoo
592                         if [[ "${sapi}" == "apache2" ]]; then
593                                 sapi_list="${sapi_list:+${sapi_list} }apache2handler"
594                         else
595                                 sapi_list="${sapi_list:+${sapi_list} }${sapi}"
596                         fi
597                 fi
598         done
599
600         # Installing opcache module
601         if use opcache ; then
602                 into "${PHP_DESTDIR#${EPREFIX}}"
603                 dolib.so "modules/opcache$(get_libname)"
604         fi
605
606         # Install env.d files
607         newenvd "${FILESDIR}/20php5-envd" "20php${SLOT}"
608         sed -e "s|/lib/|/$(get_libdir)/|g" -i "${ED}/etc/env.d/20php${SLOT}" || die
609         sed -e "s|php5|php${SLOT}|g" -i "${ED}/etc/env.d/20php${SLOT}" || die
610
611         # set php-config variable correctly (bug #278439)
612         sed -e "s:^\(php_sapis=\)\".*\"$:\1\"${sapi_list}\":" -i \
613                 "${ED}/usr/$(get_libdir)/php${SLOT}/bin/php-config" || die
614
615         if use fpm ; then
616                 if use systemd; then
617                         systemd_newunit "${FILESDIR}/php-fpm_at.service" \
618                                                         "php-fpm@${SLOT}.service"
619                 else
620                         systemd_newunit "${FILESDIR}/php-fpm_at-simple.service" \
621                                                         "php-fpm@${SLOT}.service"
622                 fi
623         fi
624 }
625
626 src_test() {
627         echo ">>> Test phase [test]: ${CATEGORY}/${PF}"
628         PHP_BIN="${WORKDIR}/sapis-build/cli/sapi/cli/php"
629         if [[ ! -x "${PHP_BIN}" ]] ; then
630                 ewarn "Test phase requires USE=cli, skipping"
631                 return
632         else
633                 export TEST_PHP_EXECUTABLE="${PHP_BIN}"
634         fi
635
636         if [[ -x "${WORKDIR}/sapis-build/cgi/sapi/cgi/php-cgi" ]] ; then
637                 export TEST_PHP_CGI_EXECUTABLE="${WORKDIR}/sapis-build/cgi/sapi/cgi/php-cgi"
638         fi
639
640         if [[ -x "${WORKDIR}/sapis-build/phpdbg/sapi/phpdbg/phpdbg" ]] ; then
641                 export TEST_PHPDBG_EXECUTABLE="${WORKDIR}/sapis-build/phpdbg/sapi/phpdbg/phpdbg"
642         fi
643
644         REPORT_EXIT_STATUS=1 "${TEST_PHP_EXECUTABLE}" -n  -d \
645                                           "session.save_path=${T}" \
646                                           "${WORKDIR}/sapis-build/cli/run-tests.php" -n -q -d \
647                                           "session.save_path=${T}"
648
649         for name in ${EXPECTED_TEST_FAILURES}; do
650                 mv "${name}.out" "${name}.out.orig" 2>/dev/null || die
651         done
652
653         local failed="$(find -name '*.out')"
654         if [[ ${failed} != "" ]] ; then
655                 ewarn "The following test cases failed unexpectedly:"
656                 for name in ${failed}; do
657                         ewarn "  ${name/.out/}"
658                 done
659         else
660                 einfo "No unexpected test failures, all fine"
661         fi
662
663         if [[ ${PHP_SHOW_UNEXPECTED_TEST_PASS} == "1" ]] ; then
664                 local passed=""
665                 for name in ${EXPECTED_TEST_FAILURES}; do
666                         [[ -f "${name}.diff" ]] && continue
667                         passed="${passed} ${name}"
668                 done
669                 if [[ ${passed} != "" ]] ; then
670                         einfo "The following test cases passed unexpectedly:"
671                         for name in ${passed}; do
672                                 ewarn "  ${passed}"
673                         done
674                 else
675                         einfo "None of the known-to-fail tests passed, all fine"
676                 fi
677         fi
678 }
679
680 pkg_postinst() {
681         # Output some general info to the user
682         if use apache2 ; then
683                 elog
684                 elog "To enable PHP in apache, you will need to add \"-D PHP\" to"
685                 elog "your apache2 command. OpenRC users can append that string to"
686                 elog "APACHE2_OPTS in /etc/conf.d/apache2."
687                 elog
688                 elog "The apache module configuration file 70_mod_php.conf is"
689                 elog "provided (and maintained) by eselect-php."
690                 elog
691         fi
692
693         # Create the symlinks for php
694         for m in ${SAPIS}; do
695                 [[ ${m} == 'embed' ]] && continue;
696                 if use $m ; then
697                         local ci=$(eselect php show $m)
698                         if [[ -z $ci ]]; then
699                                 eselect php set $m php${SLOT} || die
700                                 einfo "Switched ${m} to use php:${SLOT}"
701                                 einfo
702                         elif [[ $ci != "php${SLOT}" ]] ; then
703                                 elog "To switch $m to use php:${SLOT}, run"
704                                 elog "    eselect php set $m php${SLOT}"
705                                 elog
706                         fi
707                 fi
708         done
709
710         # Remove dead symlinks for SAPIs that were just disabled. For
711         # example, if the user has the cgi SAPI enabled, then he has an
712         # eselect-php symlink for it. If he later reinstalls PHP with
713         # USE="-cgi", that symlink will break. This call to eselect is
714         # supposed to remove that dead link per bug 572436.
715         eselect php cleanup || die
716
717         if ! has "php${SLOT/./-}" ${PHP_TARGETS}; then
718            elog "To build extensions for this version of PHP, you will need to"
719            elog "add php${SLOT/./-} to your PHP_TARGETS USE_EXPAND variable."
720            elog
721         fi
722
723         # Warn about the removal of PHP_INI_VERSION if the user has it set.
724         if [[ -n "${PHP_INI_VERSION}" ]]; then
725                 ewarn 'The PHP_INI_VERSION variable has been phased out. You may'
726                 ewarn 'remove it from your configuration at your convenience. See'
727                 ewarn
728                 ewarn '  https://bugs.gentoo.org/611214'
729                 ewarn
730                 ewarn 'for more information.'
731         fi
732
733         elog "For details on how version slotting works, please see"
734         elog "the wiki:"
735         elog
736         elog "  https://wiki.gentoo.org/wiki/PHP"
737         elog
738 }
739
740 pkg_postrm() {
741         # This serves two purposes. First, if we have just removed the last
742         # installed version of PHP, then this will remove any dead symlinks
743         # belonging to eselect-php. Second, if a user upgrades slots from
744         # (say) 5.6 to 7.0 and depcleans the old slot, then this will update
745         # his existing symlinks to point to the new 7.0 installation. The
746         # latter is bug 432962.
747         #
748         # Note: the eselect-php package may not be installed at this point,
749         # so we can't die() if this command fails.
750         eselect php cleanup
751 }