#!/bin/bash
# Copyright (c) 2000-2015 Synology Inc. All rights reserved.

case ${MakeClean} in
	[Yy][Ee][Ss])
		make distclean
		;;
esac

case ${CleanOnly} in
	[Yy][Ee][Ss])
		return
		;;
esac

phpconfig="
	--prefix=/usr \
	--exec-prefix=/usr \
	--sbindir=/usr/bin \
	--sysconfdir=/etc/php \
	--localstatedir=/var \
	--with-layout=Synology \
	--program-prefix="" \
	--with-config-file-path=/etc/php \
	--disable-rpath \
	--without-pear \
	"

export PKG_CONFIG_PATH="${SysRootLib}/openssl-3/pkgconfig:${PKG_CONFIG_PATH}"

phpextensions="
	--disable-all \
	--enable-bcmath \
	--enable-ctype \
	--enable-dom \
	--enable-filter \
	--enable-hash \
	--enable-json \
	--enable-libxml \
	--enable-mbstring \
	--enable-pdo \
	--enable-phar \
	--enable-pcntl \
	--enable-posix \
	--enable-session \
	--enable-shmop \
	--enable-simplexml \
	--enable-sockets \
	--enable-xml \
	--enable-xmlreader \
	--enable-xmlwriter \
	--enable-zip \
	--with-bz2=${SysRootPrefix} \
	--with-curl=${SysRootPrefix} \
	--with-iconv \
	--with-iconv-dir=${SysRootPrefix} \
	--with-ldap=${SysRootPrefix} \
	--with-ldap-sasl=${SysRootPrefix} \
	--with-libxml \
	--with-libxml-dir=${SysRootPrefix} \
	--with-openssl \
	--with-pdo-sqlite=${SysRootPrefix} \
	--with-readline=${SysRootPrefix} \
	--with-sqlite3=${SysRootPrefix} \
	--with-zlib=${SysRootPrefix} \
	"

LIBS="-ldl"


env	DEFINE_DSM_BUILD_SYSTEM="$DEFINE_DSM_BUILD_SYSTEM" \
	CC="$CC" CXX="$CXX" AR="$AR" LD="$LD" RANLIB="$RANLIB" STRIP="$STRIP" \
	CFLAGS="$CFLAGS" CPPFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \
	LIBS="$LIBS" \
	cross_compiling=yes \
	ac_cv_c_bigendian_php=no \
	ac_cv_lib_gd_gdImageCreateFromXpm=no \
	ac_cv_func_iconv_errno=yes \
	ac_cv_func_shm_ipc=yes \
	ac_cv_func_shm_mmap_anon=yes \
	ac_cv_func_shm_mmap_zero=yes \
	ac_cv_func_fnmatch_works=yes \
	ac_cv_func_strcasestr=yes \
	php_cv_libxml_build_works=yes \
	EXTENSION_DIR=/usr/lib/php/modules \
	PEAR_INSTALLDIR=/usr/share/pear \
	./configure ${ConfigOpt} \
		${phpconfig} \
		${phpextensions} \
		--enable-cli \
		--disable-cgi \
		--disable-fpm

make ${MAKE_FLAGS}
