distributable:
  url: https://www.php.net/distributions/php-{{ version }}.tar.gz
  strip-components: 1

versions:
  github: php/php-src/tags
  strip: /^php-/

dependencies:
  gnu.org/bison: '*'
  re2c.org: '*'
  apache.org/apr: '*'
  apache.org/apr-util: '*'
  bcrypt.sourceforge.net: '*'
  gnu.org/autoconf: '*'
  curl.se: '*'
  gnu.org/gettext: '*'
  gnu.org/gmp: '*'
  libsodium.org: '<1.0.19' # dylib version changed from 23 > 26
  libzip.org: ~1.9
  github.com/kkos/oniguruma: '*'
  openssl.org: '*'
  pcre.org/v2: '>=10.30'
  sqlite.org: '*'
  unicode.org: ^71
  gnu.org/libiconv: '*'
  kerberos.org: '*'
  gnome.org/libxml2: '>=2.9.0'
  thrysoee.dk/editline: '*'
  sourceware.org/libffi: '>=3.0.11'
  gnome.org/libxslt: '>=1.1.0'
  gnu.org/gcc: <13
  libpng.org: '*'
  google.com/webp: '*'
  ijg.org: '*'
  gnu.org/sed: ^4 # phpize requires this
  darwin:
    sourceware.org/bzip2: '*'
    zlib.net: '*'

build:
  dependencies:
    freedesktop.org/pkg-config: '*'
    freetype.org: '*'
    darwin:
      tukaani.org/xz: '*'
    linux:
      gnu.org/make: '*'

  script:
    - ./configure $ARGS
    - make --jobs {{ hw.concurrency }} install
    - run: |
        sed -i.bak \
            -e's|^prefix=.*|prefix="$(dirname "$(dirname "$0")")"|g' \
            -e's|^datarootdir=.*|datarootdir="${prefix}/share"|g' \
            -e's|^ini_path=.*|ini_path="${prefix}/etc"|g' \
            -e's|^extension_dir='\''{{prefix}}\(.*\)'\''|extension_dir="${prefix}\1"|g' \
            -e's|^SED=.*|SED="$(dirname "$(dirname "$(dirname "$(dirname "$0")")")")/gnu.org/sed/v4/bin/sed"|g' \
            -e's|#{{prefix}}#|#$(dirname "$(dirname "$0")")#|g' \
            -e's|{{pkgx.prefix}}|${prefix}/../..|g' \
            php-config \
            phpize
        rm php-config.bak phpize.bak

        fix-shebangs.ts "{{prefix}}/bin/phar"

        sed -i.bak \
            -e's|{{prefix}}|$(dirname "$(dirname "$0")")|g' \
            pear peardev pecl
        rm pear.bak peardev.bak pecl.bak
      working-directory: ${{prefix}}/bin
  env:
    ARGS:
      - --prefix={{prefix}}
      - --enable-bcmath
      - --enable-calendar
      - --enable-dba
      - --enable-exif
      - --enable-ftp
      - --enable-fpm
      - --enable-gd
      - --enable-intl
      - --enable-mbregex
      - --enable-mbstring
      - --enable-mysqlnd
      - --enable-pcntl
      - --enable-phpdbg
      - --enable-phpdbg-readline
      - --enable-shmop
      - --enable-soap
      - --enable-sockets
      - --enable-sysvmsg
      - --enable-sysvsem
      - --enable-sysvshm
      - --with-pear
      - --with-curl
      - --with-external-pcre
      - --with-ffi
      - --with-gettext={{deps.gnu.org/gettext.prefix}}
      - --with-gmp={{deps.gnu.org/gmp.prefix}}
      - --with-iconv={{deps.gnu.org/libiconv.prefix}}
      - --with-kerberos
      - --with-layout=GNU
      - --with-libxml
      - --with-libedit
      - --with-openssl
      - --with-pdo-sqlite
      - --with-pic
      - --with-sodium
      - --with-sqlite3
      - --with-xsl
      - --with-zlib
      - --disable-dtrace
      - --without-ldap-sasl
      - --without-ndbm
      - --without-gdbm
      - CC=gcc
    linux:
      LDFLAGS: -Wl,-rpath,{{pkgx.prefix}}
    darwin:
      # ... we need to link with headerpad...
      LDFLAGS: -Wl,-rpath,{{pkgx.prefix}},-headerpad_max_install_names
      ARGS:
        # FIXME: we'd like zip support for linux, but libzip's zip.h is using
        # clang _Nullable and gcc doesn't like it.
        - --with-zip
        - --enable-dtrace
        - --with-ldap-sasl

provides:
  - bin/pear
  - bin/pecl
  - bin/phar
  - bin/php
  - bin/php-cgi
  - bin/php-config
  - bin/phpdbg
  - bin/phpize

test: |
  php --version | grep {{ version }}
  php -r 'echo "Hello World!\n";'
