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