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