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