This is a follow-up to

  https://sourceware.org/pipermail/cygwin/2020-July/245623.html

As I explained there, a patch applied to the Cygwin build causes php to often call mmap with MAP_FIXED, and some of these calls fail. Removing the relevant hunk of the patch fixes the reported problem, and I don't see any reason why that hunk should be needed.

Obviously Yaakov had a reason for applying that hunk, and I'm guessing (hoping) that the reason is no longer applicable.

Ideally, someone should ITA php and deal with this. That person will not be me. I don't use php and I know nothing about it. If no one steps forward, I would be willing to do a one-time non-maintainer upload.

I'm attaching the revised patch and a revised cygport file. (It's Yaakov's cygport file, modified to account for the patch change, with a BUILD_REQUIRES added.)

Ken
inherit httpd

NAME="php"
VERSION=7.3.7
RELEASE=2
CATEGORY="PHP"
SUMMARY="PHP Hypertext Preprocessor"
DESCRIPTION="PHP (recursive acronym for 'PHP: Hypertext Preprocessor')
is a widely-used Open Source general-purpose scripting language that is
especially suited for Web development and can be embedded into HTML."
HOMEPAGE="http://www.php.net/";
SRC_URI="http://www.php.net/distributions/php-${VERSION}.tar.xz";
SRC_URI+=" template-builtin.reg template-ext.reg php-fpm.init"
PATCH_URI="
        fedora/php-7.2.0-includedir.patch
        fedora/php-5.3.0-recode.patch
        fedora/php-7.2.0-libdb.patch
        fedora/php-7.3.3-systzdata-v18.patch
        fedora/php-7.2.3-ldap_r.patch
        fedora/php-7.3.0-phpize.patch
        fedora/php-5.6.3-phpinfo.patch
        fedora/php-5.6.3-datetests.patch
        fedora/php-7.2.4-fixheader.patch
        7.0.13-cygwin-build.patch
        7.2.4-curl-ssl.patch
        5.3.4-dba-gdbm_compat.patch
        5.4.10-imap-cygwin.patch
        7.2.5-intl-libstdc.patch
        7.2.5-intl-icu61.patch
        7.2.5-mbstring-onig.patch
        5.3.4-pspell-libpspell.patch
        5.3.10-sybase-cygwin.patch
        7.3.3-posix-ttyname_r.patch
        7.3.3-configure-implicit-decls.patch
        5.4.20-libmbfl-implicit-decls.patch
        5.6.6-fix-libtoolize.patch
        5.6.9-apache2handler-zts.patch
        7.0.17-pcre-jit-off.patch
        7.3.7-malloc-cygwin.patch
        7.2.4-zip-pcre.patch
"

# From https://sourceware.org/pipermail/cygwin/2017-May/232903.html,
# with some additions/corrections.
BUILD_REQUIRES=" \
httpd-devel \
libGL-devel \
libLASi-devel \
libapr1-devel \
libaprutil1-devel \
libargon2-devel \
libaspell-devel \
libattr-devel \
libc-client-devel \
libcroco0.6-devel \
libcurl-devel \
libedit-devel \
libenchant-devel \
libfam-devel \
libffi-devel \
libgd-devel \
libgdbm-devel \
libgnutls-devel \
libgs-devel \
libgtk2.0-devel \
libgts-devel \
libguile1.8-devel \
libguile2.0-devel \
libgvc-devel \
libhunspell-devel \
libicu-devel \
libidn2-devel \
libisl-devel \
libjasper-devel \
libkrb5-devel \
liblcms-devel \
liblmdb-devel \
libllvm-devel \
liblzo2-devel \
libmcrypt-devel \
libming-devel \
libmpc-devel \
libmpfr-devel \
libnghttp2-devel \
libnss-devel \
libonig-devel \
libopenjp2-devel \
libopenjpeg-devel \
libpcre2-devel \
libpng12-devel \
libpoppler-devel \
libpq-devel \
libpsl-devel \
libreadline-devel \
librsvg2-devel \
libsigsegv-devel \
libsodium-devel \
libsqlite3-devel \
libssh2-devel \
libsybdb-devel \
libthai-devel \
libtidy-devel \
libtxc_dxtn-devel \
libunistring-devel \
libvoikko-devel \
libwebp-devel \
libxslt-devel \
libzip-devel \
recode \
"

DIFF_EXCLUDES="aclocal.m4 configure generated_lists libtool.m4 lt*.m4 ltmain.sh 
php_config.h.in php_version.h tests zend_ini_parser.*"

# EXTENSIONS:
#
# The following modules are deps for others, and hence MUST be builtin:
# date: intl
# dom: xmlreader
# filter, hash, spl: (mandatory built-in)
# hash: phar, session
# libxml: dom, simplexml, soap, xml, xmlreader, xsl
# mysqlnd: mysqli, pdo_mysql (if configured to use mysqlnd)
# openssl: phar
# pcre: filter, opcache, spl, zip
# pdo: pdo_*
# readline: phpdbg
# session: hash, soap, wddx, memcache (PECL)
# xml: xmlrpc

# location of php.ini files
inidir=/etc/php.d

# required for all configure runs
common_args="
  --cache-file=../config.cache
  --libdir=/usr/lib/php
  --datadir=/usr/share/php

  --disable-static
  --disable-rpath
  --with-config-file-path=/etc
  --with-config-file-scan-dir=${inidir}
  --with-layout=GNU
  --with-system-tzdata

  --enable-dom=yes
  --enable-filter=yes
  --enable-hash=yes
  --with-mhash
  --enable-libxml=yes
  --with-openssl=yes
  --with-system-ciphers
  --enable-pdo=yes
  --with-readline=no
  --with-libedit=yes
  --enable-session=yes
  --enable-xml=yes
  --with-password-argon2=/usr
  --with-libxml-dir=/usr
  --with-openssl-dir=/usr
  --with-pcre-dir=/usr
  --with-pcre-regex=/usr

  ac_cv_func_ttyname_r_works=yes
"

cli_args="
  --without-pear

  --enable-bcmath=shared
  --with-bz2=shared,/usr
  --enable-calendar=shared
  --enable-ctype=shared
  --with-curl=shared,/usr
  --enable-dba=shared
  --with-gdbm=/usr
  --with-ndbm=/usr
  --with-db4=/usr
  --with-dbm=/usr
  --with-lmdb=/usr
  --with-cdb
  --enable-inifile
  --enable-flatfile
  --with-enchant=shared,/usr
  --enable-exif=shared
  --enable-fileinfo=shared
  --enable-ftp=shared
  --with-gd=shared,/usr
  --with-webp-dir=/usr
  --with-jpeg-dir=/usr
  --with-png-dir=/usr
  --with-zlib-dir=/usr
  --with-xpm-dir=/usr
  --with-freetype-dir=/usr
  --with-gettext=shared
  --with-gmp=shared,/usr
  --with-iconv=shared,/usr
  --with-imap=shared,/usr
  --with-kerberos=yes
  --with-imap-ssl=yes
  --with-interbase=no
  --enable-json=shared
  --with-ldap=shared,/usr
  --with-ldap-sasl=/usr
  --enable-intl=shared
  --with-icu-dir=/usr
  --enable-mbstring=shared
  --with-onig=/usr
  --enable-mbregex=yes
  --enable-mbregex_backtrack=yes
  --with-mysql-sock=/var/run/mysql.sock
  --with-mysqli=shared,mysqlnd
  --enable-embedded_mysqli=no
  --with-oci8=no
  --with-adabas=no
  --with-sapdb=no
  --with-solid=no
  --with-ibm-db2=no
  --with-ODBCRouter=no
  --with-empress=no
  --with-empress-bcs=no
  --with-birdstep=no
  --with-custom-odbc=no
  --with-iodbc=shared,/usr
  --with-esoob=no
  --with-unixODBC=no
  --with-dbmaker=no
  --enable-opcache=shared
  --enable-pcntl=no
  --with-pdo-dblib=shared,/usr
  --with-pdo-firebird=no
  --with-pdo-mysql=shared,mysqlnd
  --with-pdo-oci=no
  --with-pdo-odbc=shared,iodbc,/usr
  --with-pdo-pgsql=shared,/usr
  --with-pdo-sqlite=shared,/usr
  --with-pgsql=shared,/usr
  --enable-phar=shared
  --enable-posix=shared
  --with-pspell=shared,/usr
  --with-recode=shared,/usr
  --with-mm=no
  --enable-shmop=shared
  --enable-simplexml=shared
  --with-snmp=no
  --enable-soap=shared
  --with-sodium=shared,/usr
  --with-sqlite3=shared,/usr
  --enable-sockets=shared
  --enable-sysvmsg=shared
  --enable-sysvsem=shared
  --enable-sysvshm=shared
  --with-tidy=shared,/usr
  --enable-tokenizer=shared
  --enable-wddx=shared
  --enable-xmlreader=shared
  --with-xmlrpc=shared
  --with-iconv-dir=/usr
  --enable-xmlwriter=shared
  --with-xsl=shared,/usr
  --enable-zip=shared
  --with-libzip=/usr
  --with-zlib=shared
"

# packaging
#
PKG_NAMES="${NAME} ${NAME}-devel httpd-mod_php${VERSION%%.*}"
php_CATEGORY="Interpreters PHP"
# previously shared extensions moved into core, or obsolete
php_OBSOLETES="php-mcrypt php-readline php-session"
php_CONTENTS="
        --exclude=${inidir#/}/*.ini
        etc/defaults${HTTPD_SYSCONFDIR}/php7.conf
        etc/defaults/etc/php*
        ${inidir#/}
        etc/p*/php.sh
        etc/rc.d/init.d/php-fpm
        usr/bin/cygphp7-*.dll
        usr/bin/php.exe
        usr/bin/php-cgi.exe
        usr/bin/phpdbg.exe
        usr/sbin/php-fpm.exe
        usr/share/doc/php/
        usr/share/man/man1/php.1*
        usr/share/man/man1/php-cgi.1*
        usr/share/man/man1/phpdbg.1*
        usr/share/man/man8/php-fpm.8*
        usr/share/php/
        usr/share/doc/pear/filter/CREDITS
        usr/share/doc/pear/hash/CREDITS
        usr/share/doc/pear/pdo/CREDITS
        usr/share/doc/pear/readline/CREDITS
        usr/share/doc/pear/session/CREDITS
        var/lib/pear/.registry/.channel.*/filter.reg
        var/lib/pear/.registry/.channel.*/hash.reg
        var/lib/pear/.registry/.channel.*/pdo.reg
        var/lib/pear/.registry/.channel.*/readline.reg
        var/lib/pear/.registry/.channel.*/session.reg
        var/lib/rebase/dynpath.d/php
"
php_devel_CATEGORY=${php_CATEGORY}
php_devel_REQUIRES="autoconf gcc-core make"
php_devel_CONTENTS="
        usr/bin/php-config
        usr/bin/phpize
        usr/include/php/
        usr/lib/libphp7.dll.a
        usr/lib/php/build/
        usr/share/man/man1/php-config.*
        usr/share/man/man1/phpize.*
"
httpd_mod_php7_OBSOLETES="httpd-mod_php5"
httpd_mod_php7_CONTENTS="${HTTPD_SYSCONFMODULESDIR#/} ${HTTPD_LIBEXECDIR#/}"
httpd_mod_php7_SUMMARY="Embedded PHP for Apache HTTP Server"

# This method provides 50+ modules, so better automate this:
for ext in $(echo ${cli_args} | sed -e 's# #\n#g' | grep shared \
             | sed -e 's#^--[a-z]*-##g' -e 's#=.*##g' -e 's#-#_#g' -e 
's#[a-z]*odbc#odbc#')
do
        PKG_NAMES+=" php-${ext}"
        declare php_${ext}_CONTENTS="${inidir#/}/${ext}.ini
                                     usr/lib/php/*/${ext}.dll
                                     usr/share/doc/pear/${ext}/
                                     
var/lib/pear/.registry/.channel.*/${ext}.reg"
        declare php_${ext}_SUMMARY="PHP ${ext} extension"
done
unset ext
php_phar_CONTENTS+=" usr/bin/phar* usr/share/man/man1/phar*"
# obsoleted by php7
php_debuginfo_OBSOLETES="php-jsonc-debuginfo"
php_json_OBSOLETES="php-jsonc"
php_mysqli_OBSOLETES="php-mysql"
php_pdo_dblib_OBSOLETES="php-mssql php-sybase_ct"

src_compile() {
        cd ${S}

        #
        # autotoolize
        #
        rm -f build/libtool.m4
        libtoolize --copy --force || error "libtoolize failed"
        cat /usr/share/aclocal/libtool.m4 
/usr/share/aclocal/lt{options,sugar,version,~obsolete}.m4 > build/libtool.m4

        cygmake -j1 -B -f build/build.mk ZENDDIR="Zend"
        # these are shipped and used by phpize
        gnuconfigize .

        # Hack to work around configure adding to hard-coded include_path
        # only when bundled PEAR is enabled (we package it separately)
        export PEAR_INSTALLDIR=/usr/share/pear

        #
        # build runtime and executable SAPIs (CLI, CGI, FPM)
        #
        mkdir -p ${B}/embed
        cd ${B}/embed
        CYGCONF_SOURCE="${S}" cygconf ${common_args} ${cli_args} \
                --enable-cgi --enable-cli \
                --enable-fpm --with-fpm-acl \
                --enable-embed --enable-phpdbg

        sed -e '/^LTCFLAGS=/d' -i libtool
        sed -e 's/ -lphp7 / libphp7.la /g' -i Makefile

        # first make the common sources library
        # enabling zip with system libzip somehow clobbers -lpcre
        cygmake libphp${VERSION%%.*}.la \
                EXTRA_LDFLAGS="-release ${VERSION%.*} -avoid-version -module 
-no-undefined -lpcre2-8"

        sed -e 's#link=yes#link=no#' -i libphp${VERSION%%.*}.la

        # then make everything else
        # c-client is static only so we need to circumvent libtool to link
        cygmake -j1 \
                
IMAP_SHARED_LIBADD='-Wl,-lc-client,-lssl,-lcrypto,-lgssapi_krb5,-lkrb5' \
                PHP_GLOBAL_OBJS='' \
                ZEND_EXTRA_LIBS="${B}/embed/libphp${VERSION%%.*}.la"


        #
        # Apache2 mod_php7 SAPI
        #
        mkdir -p ${B}/apache2
        cd ${B}/apache2

        CYGCONF_SOURCE="${S}" cygconf \
                --disable-all --disable-cli --with-apxs2=${HTTPD_APXS} 
${common_args}

        # the -a flag adds the module to httpd.conf
        sed -e 's#-prefer-non-pic -static##g' \
                -e 's#-prefer-pic##g' \
                -e 's#-i -a -n#-i -n#g' \
                -i Makefile

        # HTTPD expects mods to have .so suffix on all platforms
        cygmake libphp${VERSION%%.*}.la \
                PHP_GLOBAL_OBJS='' \
                ZEND_EXTRA_LIBS="${B}/embed/libphp${VERSION%%.*}.la"
}

src_test() {
        export PATH="${B}/embed/.libs:$PATH"

        cd ${B}/embed
        cygmake -j1 test
}

src_install() {
        local n sapi x xdir

        # install the Apache SAPI
        cd ${B}/apache2
        cygmake -j1 install-sapi INSTALL_ROOT=${D} PHP_GLOBAL_OBJS=''

        # install the other SAPIs, build environment, and everything else
        cd ${B}/embed
        cygmake -j1 install INSTALL_ROOT=${D} INSTALL_IT=
        # install the shared lib (normally done by INSTALL_IT)
        dobin libs/cygphp7-*.dll
        dolib libs/libphp7.dll.a

        # install the real executables, not the libtool stubs
        cd ${B}
        dobin embed/sapi/[cp]*/*.exe
        dosbin embed/sapi/fpm/php-fpm.exe

        # sanitize php-config
        sed -e "s#^libs=.*#libs=\"-lphp${VERSION%%.*}\"#" \
                -e 's#^php_sapis=.*#php_sapis="cli cgi embed fpm 
apache2handler"#' \
                -i ${D}/usr/bin/php-config

        # provide default php.ini
        insinto /etc
        newins ${S}/php.ini-production php.ini
        make_etc_defaults /etc/php.ini

        mv ${D}/etc/php-fpm.conf{.default,}
        mv ${D}/etc/php-fpm.d/www.conf{.default,}
        make_etc_defaults /etc/php-fpm.{conf,d}

        exeinto /etc/rc.d/init.d
        newexe ${S}/php-fpm.init php-fpm

        # add .ini files for each extension, so that it's loaded once installed
        local date=$(date +%F)
        local time=$(date +%T)
        local timestamp=$(date +%s)
        local regdir=/var/lib/pear/.registry/.channel.pecl.php.net
        local xdir=$(${D}/usr/bin/php-config --extension-dir)
        local dll ext docdir path_len summary_len p

        keepdir ${inidir}
        dodir ${regdir}

        for x in ${D}${xdir}/*.dll
        do
                dll=${x##*/}
                ext=${dll%.dll}
                docdir=/usr/share/doc/pear/${ext}
                doc_len=$((${#docdir} + 8))     # /CREDITS
                path_len=$((${#xdir} + ${#dll} + 1))
                summary_len=$((${#ext} + 14))   # PHP ___ extension

                # create .ini file for automatic extension loading
                if $(${OBJDUMP} -p ${x} | grep -q zend_startup_module)
                then
                        echo "zend_extension = ${xdir}/${dll}" >> 
${D}${inidir}/${ext}.ini
                else
                        echo "extension = ${dll}" >> ${D}${inidir}/${ext}.ini
                fi

                # register extension with pecl to prevent accidental
                # installation of obsolete versions
                insinto ${docdir}
                touch ${S}/ext/${ext}/CREDITS
                doins ${S}/ext/${ext}/CREDITS

                sed -e "s,@DATE@,${date},g;
                        s,@DOCDIR@,${docdir},g;
                        s,@DOC_LEN@,${doc_len},g;
                        s,@DLL@,${dll},g;
                        s,@DLL_LEN@,${#dll},g;
                        s,@EXT@,${ext},g;
                        s,@EXT_LEN@,${#ext},g;
                        s,@PATH@,${xdir}/${dll},g;
                        s,@PATH_LEN@,${path_len},g;
                        s,@SUMMARY_LEN@,${summary_len},g;
                        s,@TIME@,${time},g;
                        s,@VERSION@,${VERSION},g;
                        s,@VERSION_LEN@,${#VERSION},g;
                        s,@TIMESTAMP@,${timestamp}," \
                        ${S}/template-ext.reg > ${D}${regdir}/${ext}.reg
        done

        # builtin extensions
        # when adding, be sure to update php_CONTENTS
        for ext in filter hash pdo readline session
        do
                docdir=/usr/share/doc/pear/${ext}
                doc_len=$((${#docdir} + 8))     # /CREDITS
                summary_len=$((${#ext} + 22))   # PHP ___ builtin extension

                # register extension with pecl to prevent accidental
                # installation of obsolete versions
                insinto ${docdir}
                doins ${S}/ext/${ext}/CREDITS

                sed -e "s,@DATE@,${date},g;
                        s,@DOCDIR@,${docdir},g;
                        s,@DOC_LEN@,${doc_len},g;
                        s,@EXT@,${ext},g;
                        s,@EXT_LEN@,${#ext},g;
                        s,@SUMMARY_LEN@,${summary_len},g;
                        s,@TIME@,${time},g;
                        s,@VERSION@,${VERSION},g;
                        s,@VERSION_LEN@,${#VERSION},g;
                        s,@TIMESTAMP@,${timestamp}," \
                        ${S}/template-builtin.reg > ${D}${regdir}/${ext}.reg
        done

        dodir ${HTTPD_SYSCONFMODULESDIR}
        cat > ${D}${HTTPD_SYSCONFMODULESDIR}/mod_php7.conf <<_EOF
# mod_php7 is not thread-safe
<IfModule prefork.c>
  LoadModule php7_module modules/libphp7.so
</IfModule>
_EOF

        # Add httpd.conf snippet
        dodir ${HTTPD_SYSCONFDIR}
        cat > ${D}${HTTPD_SYSCONFDIR}/php7.conf <<_EOF
AddType text/html .php
DirectoryIndex index.php

<IfModule mod_php7.c>
    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch \.phps$>
        SetHandler application/x-httpd-php-source
    </FilesMatch>
</IfModule>

# if using a thread-safe MPM, or mod_php7 is not installed, use php-fpm instead
# requires: mod_proxy, mod_proxy_fcgi
<IfModule !mod_php7.c>
    <FilesMatch \.php$>
        # value depends on /etc/php-fpm.conf:listen=; this is the default
        SetHandler "proxy:fcgi://localhost:9000"
    </FilesMatch>
</IfModule>
_EOF
        make_etc_defaults ${HTTPD_SYSCONFDIR}/php7.conf

        dodir /var/lib/rebase/dynpath.d
        echo $(${D}/usr/bin/php-config --extension-dir) > 
${D}/var/lib/rebase/dynpath.d/php
}
https://cygwin.com/ml/cygwin/2017-05/msg00350.html

--- origsrc/php-7.1.13/Zend/zend_stream.c       2018-01-02 20:32:22.000000000 
-0600
+++ src/php-7.1.13/Zend/zend_stream.c   2018-01-09 01:42:30.871472500 -0600
@@ -29,7 +29,9 @@
 #if HAVE_MMAP
 # if HAVE_UNISTD_H
 #  include <unistd.h>
-#  if defined(_SC_PAGESIZE)
+#  if defined(__CYGWIN__)
+#    define REAL_PAGE_SIZE 4096
+#  elif defined(_SC_PAGESIZE)
 #    define REAL_PAGE_SIZE sysconf(_SC_PAGESIZE);
 #  elif defined(_SC_PAGE_SIZE)
 #    define REAL_PAGE_SIZE sysconf(_SC_PAGE_SIZE);
--- origsrc/php-7.1.13/main/main.c      2018-01-02 20:32:22.000000000 -0600
+++ src/php-7.1.13/main/main.c  2018-01-09 01:42:57.670125500 -0600
@@ -97,7 +97,9 @@
 #if HAVE_MMAP || defined(PHP_WIN32)
 # if HAVE_UNISTD_H
 #  include <unistd.h>
-#  if defined(_SC_PAGESIZE)
+#  if defined(__CYGWIN__)
+#    define REAL_PAGE_SIZE 4096
+#  elif defined(_SC_PAGESIZE)
 #    define REAL_PAGE_SIZE sysconf(_SC_PAGESIZE);
 #  elif defined(_SC_PAGE_SIZE)
 #    define REAL_PAGE_SIZE sysconf(_SC_PAGE_SIZE);

Reply via email to