app=php
version=7.4.30
rrdversion=2.0.3
build=2sml
homepage="https://www.php.net/"
download="https://www.php.net/distributions/php-7.4.30.tar.xz"
desc="Scripting language suited for creating dynamic websites"
requires="enchant libgd db gmp icu libsodium libxslt sqlite curl libtool pcre2 postfix aspell openssl oniguruma libffi bzip2 zlib libexif intltool readline libsodium mariadb libwebp"

build() {
  mkandenterbuilddir
  rm -rf $app-$version

  tar xf $srcdir/$app-$version.tar.?z*
  cd $app-$version 
  fixbuilddirpermissions

  # Add the rrd graph module
  cd ext
  tar xf $srcdir/rrd-$rrdversion.tgz

  cd ..
  ./buildconf -f

  ./configure \
    --prefix="" \
    --sysconfdir=/etc/php \
    --sbindir=/bin \
    --localstatedir=/var \
    --mandir=/share/man \
    --enable-fpm \
    --with-fpm-user=nobody \
    --with-fpm-group=nogroup \
    --with-layout=PHP \
    --with-config-file-scan-dir=/etc/php \
    --with-config-file-path=/etc/php/conf.d \
    --enable-filter \
    --enable-mbstring \
    --enable-pcntl \
    --with-libxml \
    --with-expat \
    --with-jpeg \
    --with-xpm \
    --with-bz2=shared \
    --enable-calendar=shared \
    --with-ffi=shared \
    --with-openssl=shared \
    --with-external-pcre \
    --with-zlib=shared \
    --with-sqlite3=shared \
    --with-enchant=shared \
    --with-gmp=shared \
    --with-gettext=shared \
    --with-webp \
    --enable-exif=shared \
    --enable-intl=shared \
    --enable-gd=shared \
    --with-tsrm-pthreads \
    --with-sodium=shared \
    --with-readline \
    --enable-static=no \
    --enable-shared=yes \
    --with-pic \
    --enable-sockets \
    --enable-opcache \
    --with-imap-ssl \
    --disable-rpath \
    --with-pdo-sqlite=shared \
    --with-rrd=shared

  make
  make install INSTALL_ROOT=$pkg 

  install -Dm 644 sapi/fpm/init.d.php-fpm $pkg/etc/rc.d/rc.php-fpm.new
  install -Dm 644 $srcdir/php.ini $pkg/etc/php/php.ini.new

  # We do not package static extension libraries:
  rm -fv $pkg/lib/php/extensions/*.a  $pkg/lib/php/extensions/*/*.a

  (
   cd $pkg/etc/php
   mv php-fpm.conf.default php-fpm.conf.default.new
   cd php-fpm.d ; mv www.conf.default www.conf.default.new
  )

  # Session directory for PHP:
  mkdir -p $pkg/var/lib/php
  chmod 770 $pkg/var/lib/php
  chown root:www-data $pkg/var/lib/php

  # PHP sometimes puts junk in the root directory:
  ( cd $pkg/lib/php
    rm -rfv .channels .depdb .depdblock .filemap .lock .registry
    cd $pkg
    rm -rfv .channels .depdb .depdblock .filemap .lock .registry
    rm -rfv $pkg/php
  )

  mkfinalpkg
}

sha512sums="
7bce44a23c07193c10c57459f08b08fdce4e3a269d6829a61371d1b1f117ecf4e167805a40e1a5e7687f534aee9d5f5745a3f4dcb344e9e781c105bc964ed738  php-7.4.30.tar.xz
28679ccead54806d1e92accc6f5ebab582a41db802f95797ddb43e3e15690889be3437f22e2a14939d217422ac2700ef90ae0a9b36244ddead3856343b3e09b4  rrd-2.0.3.tgz
"
