. "${GRIMOIRE}/FUNCTIONS" &&

depends flex &&

# Officially these are optional, but we require them because some other
# optional extensions depend on it, and they're omnipresent anyway
depends readline "--with-readline" &&
depends zlib "--with-zlib" &&

# This is required since PHP5
depends libxml2 "--enable-xml --enable-dom --with-xmlrpc" &&

case "${PHP5_APACHE}" in
    handler) depends APACHE;;
    filter) depends APACHE2;;
esac &&

if [[ "${PHP5_GD}" == "external" ]]; then
    depends gd "--with-gd=${INSTALL_ROOT}/usr --enable-gd-native-ttf" 
fi &&

# Query for external PCRE library if PCRE support is enabled
if list_find "${PHP5_OPTS}" "--with-pcre-regex"; then
    optional_depends pcre \
                     "--with-pcre-dir=${INSTALL_ROOT}/usr" "" \
                     "to use an external PCRE library"
fi &&

optional_depends C-CLIENT \
                 "--with-imap=${INSTALL_ROOT}/usr" "--without-imap" \
                 "for IMAP support" &&

optional_depends MAIL-TRANSPORT-AGENT \
                  "" "" \
                  "for SMTP support" &&

optional_depends bzip2 \
                 "--with-bz2" "--without-bz2" \
                 "for compression support" &&

optional_depends aspell \
                 "--with-pspell" "--without-pspell" \
                 "for spelling functions" &&

optional_depends mhash \
                 "--with-mhash" "--without-mhash" \
                 "for hash functions support" &&

optional_depends libmcrypt \
                 "--with-mcrypt" "--without-mcrypt" \
                 "for crypto library" &&

optional_depends curl \
                 "--with-curl" "--without-curl" \
                 "for cURL URL stream functions" &&

if is_depends_enabled $SPELL curl; then
    config_query_option PHP5_OPTS "Do you want to use cURL for URL streams in core PHP functions?" n \
                        "--with-curlwrappers" "--without-curlwrappers"
fi &&

optional_depends gmp \
                 "--with-gmp" "--without-gmp" \
                 "GNU multi-precision library support" &&

optional_depends openssl \
                 "--with-openssl" "--without-openssl" \
                 "for OpenSSL support" &&

optional_depends gettext \
                 "--with-gettext" "--without-gettext" \
                 "for GNU gettext support" &&

optional_depends firebird \
                 "--with-pdo-firebird=${INSTALL_ROOT}/opt/firebird" "--without-pdo-firebird" \
                 "for native Firebird support" &&

optional_depends unixodbc \
                 "--with-unixODBC=${INSTALL_ROOT}/usr" "--without-unixODBC" \
                 "for ODBC database support" &&

if is_depends_enabled $SPELL unixodbc && list_find "${PHP5_OPTS}" "--enable-pdo"; then
    config_query_option PHP5_OPTS "Do you also want to build the unixODBC PDO driver?" n \
                        "--with-pdo-odbc=unixODBC,${INSTALL_ROOT}/usr" "--without-pdo-odbc"
fi &&

optional_depends libiodbc \
                 "--with-iodbc" "--without-iodbc" \
                 "for ODBC database support" &&

optional_depends postgresql \
                 "--with-pgsql" "--without-pgsql" \
                 "for native Postgresql support" &&

if is_depends_enabled $SPELL postgresql && list_find "${PHP5_OPTS}" "--enable-pdo"; then
    config_query_option PHP5_OPTS "Do you also want to build the PostgreSQL PDO driver?" n \
                        "--with-pdo-pgsql" "--without-pdo-pgsql"
fi &&

optional_depends mysql \
                 "" "" \
                 "for MySQL support" &&

if is_depends_enabled $SPELL mysql && [[ "${VERSION:0:3}" == "5.3" ]]; then
    config_query PHP5_MYSQLND "Do you want to use the MySQL Native Driver [mysqlnd]? (experimental)" y &&

    if [[ "${PHP5_MYSQLND}" == "y" ]]; then
        PHP5_OPTS="${PHP5_OPTS} --with-mysql=mysqlnd"
    else
        PHP5_OPTS="${PHP5_OPTS} --with-mysql"
    fi
elif is_depends_enabled $SPELL mysql && [[ "${VERSION:0:3}" != "5.3" ]]; then
    PHP5_OPTS="${PHP5_OPTS} --with-mysql"
else
    PHP5_OPTS="${PHP5_OPTS} --without-mysql"
fi &&

if is_depends_enabled $SPELL mysql && list_find "${PHP5_OPTS}" "--enable-pdo"; then
    if [[ "${VERSION:0:3}" == "5.3" ]] && [[ "${PHP5_MYSQLND}" == "y" ]]; then
        config_query_option PHP5_OPTS "Do you want to build the MySQLi extension?" n \
                            "--with-mysqli=mysqlnd" "--without-mysqli" &&

        config_query_option PHP5_OPTS "Do you also want to build the MySQL PDO driver?" n \
                            "--with-pdo-mysql=mysqlnd" "--without-pdo-mysql"
    else
        config_query_option PHP5_OPTS "Do you want to build the MySQLi extension?" n \
                            "--with-mysqli" "--without-mysqli" &&
        config_query_option PHP5_OPTS "Do you also want to build the MySQL PDO driver?" n \
                            "--with-pdo-mysql" "--without-pdo-mysql"
    fi
fi &&

optional_depends gdbm \
                 "--with-gdbm" "--without-gdbm" \
                 "database routines that use extensive hashing" &&

optional_depends sqlite2 \
                 "--with-sqlite=${INSTALL_ROOT}/usr --enable-sqlite-utf8" "--without-sqlite" \
                 "for SQLite 2.x support" &&

if list_find "${PHP5_OPTS}" "--enable-pdo"; then
    config_query_option PHP5_OPTS "Do you also want to build the SQLite 3.x PDO driver (requires: sqlite)?" y \
                        "--with-pdo-sqlite=${INSTALL_ROOT}/usr" "--without-pdo-sqlite" &&

    if ! list_find "${PHP5_OPTS}" "--without-pdo-sqlite"; then
        depends sqlite
    fi
fi &&

optional_depends mm \
                 "--with-mm" "--without-mm" \
                 "for sharing memory between related processes" &&

optional_depends openldap \
                 "--with-ldap" "--without-ldap" \
                 "for LDAP support" &&

optional_depends tidy \
                 "--with-tidy" "--without-tidy" \
                 "for HTML Tidy support" &&

optional_depends libxslt \
                 "--with-xsl" "--without-xsl" \
                 "for XSLT support" &&

optional_depends t1lib \
                 "--with-t1lib" "--without-t1lib" \
                 "for T1lib support" &&

optional_depends re2c \
                 "" "" \
                 "to regenerate PHP parsers" &&

optional_depends libexif \
                 "--enable-exif" "--disable-exif" \
                 "for image metadata support" &&

if [[ "${PHP5_GD}" != "none" ]]; then
    if [[ "${PHP5_X11LIBS}" == "y" ]]; then
        depends xorg-libs &&
        depends libxpm "--with-xpm-dir=${INSTALL_ROOT}/usr"
    fi &&

    optional_depends jpeg \
                     "--with-jpeg-dir=${INSTALL_ROOT}/usr" "--without-jpeg-dir" \
                     "for JPEG support (for GD)" &&

    optional_depends libpng \
                     "--with-png-dir=${INSTALL_ROOT}/usr" "--without-png-dir" \
                     "for PNG support (for GD)" &&

    optional_depends freetype2 \
                     "--with-freetype-dir=${INSTALL_ROOT}/usr" "--without-freetype-dir" \
                     "for freetype2 support"
fi
