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