SUMMARY="A popular general-purpose scripting language"
DESCRIPTION="PHP is a popular general-purpose scripting language that is \
especially suited to web development.
Fast, flexible and pragmatic, PHP powers everything from your blog to the most \
popular websites in the world."
HOMEPAGE="https://php.net/"
COPYRIGHT="2001-2020 PHP Group"
LICENSE="PHP License v3.01"
REVISION="3"
SOURCE_URI="https://php.net/get/php-$portVersion.tar.bz2/from/this/mirror"
CHECKSUM_SHA256="85710f007cfd0fae94e13a02a3a036f4e81ef43693260cae8a2e1ca93659ce3e"
SOURCE_FILENAME="php-$portVersion.tar.bz2"
PATCHES="php-$portVersion.patchset"
ADDITIONAL_FILES="userlaunch.in"

ARCHITECTURES="all !x86_gcc2 ?x86"
SECONDARY_ARCHITECTURES="x86"

GLOBAL_WRITABLE_FILES="
        settings/php7 directory keep-old
        "

commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

PROVIDES="
	php$secondaryArchSuffix = $portVersion
	cmd:pear
	cmd:peardev
	cmd:pecl
	cmd:phar
	cmd:phar.phar
	cmd:php
	cmd:phpdbg
	cmd:php_cgi
	cmd:php_config
	cmd:phpize
	cmd:php_fpm
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libicuuc$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libnghttp2$secondaryArchSuffix
	lib:libonig$secondaryArchSuffix
	lib:libpcre$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libsqlite3$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libwebp$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libzip$secondaryArchSuffix
	"

BUILD_REQUIRES="
	devel:libbz2$secondaryArchSuffix
	devel:libcrypto$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libgd$secondaryArchSuffix
	devel:libicuuc$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libnghttp2$secondaryArchSuffix
	devel:libonig$secondaryArchSuffix
	devel:libpcre$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libpq$secondaryArchSuffix
	devel:libsqlite3$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libwebp$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:libzip$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:aclocal
	cmd:autoreconf
	cmd:awk
	cmd:bison
	cmd:freetype_config$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	cmd:icu_config$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:xargs
	cmd:xml2_config$secondaryArchSuffix
	"

BUILD()
{
	autoreconf
	autoconf
	runConfigure --omit-dirs "binDir sbinDir" ./configure \
		--bindir=$commandBinDir \
		--sbindir=$commandBinDir \
		--sysconfdir=$settingsDir/php7 \
		--with-config-file-path=$settingsDir/php7 \
		--with-config-file-scan-dir=$settingsDir/php7 \
		--with-zip=shared \
		--with-zlib-dir=`finddir B_SYSTEM_DIRECTORY` --with-zlib=shared \
		--with-openssl \
		--with-curl \
		--disable-opcache \
		--enable-intl \
		--enable-ftp \
		--enable-soap \
		--without-iconv \
		--enable-fpm \
		--enable-gd \
		--with-mysqli \
		--enable-bcmath \
		--enable-mbstring \
		--with-freetype \
		--with-jpeg \
		--with-webp \
		--enable-exif \
		--enable-calendar \
		--disable-debug
	make $jobArgs
}

INSTALL()
{
	make install
	rm -rf $libDir/build # Only garbage is installed here.
	mkdir -p $dataDir/user_launch
	sed \
		-e "s|@APP@|php-fpm|" \
		-e "s|@BIN@|"$binDir"/php-fpm|" \
		$portDir/additional-files/userlaunch.in > $dataDir/user_launch/php-fpm
}

TEST()
{
	make test
}
