dnl ## $Id$ -*- sh -*-
dnl ## Process this file with autoconf to produce a configure script.

divert(1)

AC_INIT(README.CVS-RULES)

PHP_FAST_OUTPUT(sapi/Makefile ext/Makefile Makefile pear/Makefile main/Makefile)

if test "$with_shared_apache" != "no" && test -n "$with_shared_apache" ; then
  AC_MSG_ERROR(--with-shared-apache is not supported. Please refer to the documentation for using APXS)
fi

if test -n "$with_apache" && test -n "$with_apxs"; then
  AC_MSG_ERROR(--with-apache and --with-apxs cannot be used together)
fi

cwd=`pwd`

PHP_CONFIG_NICE(config.nice)

for arg in $0 "$@"; do
    CONFIGURE_COMMAND="$CONFIGURE_COMMAND '$arg'"
done

php_shtool=$srcdir/build/shtool
T_MD=`$php_shtool echo -n -e %B`
T_ME=`$php_shtool echo -n -e %b`

dnl Because ``make install'' is often performed by the superuser,
dnl we create the libs subdirectory as the user who configures PHP.
dnl Otherwise, the current user will not be able to delete libs
dnl or the contents of libs.

$php_shtool mkdir -p libs
rm -f libs/*

dnl ## Diversion 2 is the initial checking of OS features, programs,
dnl ## libraries and so on.

dnl ## In diversion 3 we check for compile-time options to the PHP
dnl ## core and how to deal with different system dependencies.  This
dnl ## includes what regex library is used and whether debugging or short
dnl ## tags are enabled, and the default behaviour of php.ini options.
dnl ## This is also where an SAPI interface is selected (choosing between
dnl ## Apache module, CGI etc.)

dnl ## In diversion 4 we check which extensions should be compiled.
dnl ## All of these are normally in the extension directories.

dnl ## Diversion 5 is the last one.  Here we generate files and clean up.

dnl ## This is where the version number is changed from now on!
AM_INIT_AUTOMAKE(php, 4.0.7-dev, nodefine)

PHP_VERSION=$VERSION
echo "/* automatically generated by configure */" > php_version.h.new
echo "/* edit configure.in to change version number */" >> php_version.h.new
echo "#define PHP_VERSION \"$PHP_VERSION\"" >> php_version.h.new
cmp php_version.h.new php_version.h >/dev/null 2>&1
if test $? -ne 0 ; then
    rm -f php_version.h && mv php_version.h.new php_version.h && \
    echo 'Updated php_version.h'
else
	rm -f php_version.h.new
fi

AM_CONFIG_HEADER(main/php_config.h)
AM_MAINTAINER_MODE
AC_CANONICAL_HOST

dnl We want this one before the checks, so the checks can modify CFLAGS.
test -z "$CFLAGS" && auto_cflags=1

dnl Checks for programs.
AC_PROG_AWK
AC_PROG_YACC
if test "$YACC" != "bison -y"; then
    AC_MSG_WARN(You will need bison if you want to regenerate the PHP parsers.)
else
    AC_MSG_CHECKING(bison version)
    oldIFS=$IFS; IFS=.
    set `bison -V | sed -e 's/^GNU Bison version //'`
    IFS=$oldIFS
    if test "$1" = "1" -a "$2" -lt "25"; then
        AC_MSG_WARN(Bison 1.25 or newer needed to regenerate parsers (found $1.$2).)
    fi
    AC_MSG_RESULT($1.$2 (ok))
fi

AC_PROG_CC
AC_AIX

BSD_MAKEFILE=no

case $host_alias in
*solaris*)
    CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
    if test "${enable_libgcc+set}" != "set" && test "$GCC" = "yes"; then
      enable_libgcc=yes
    fi
    ;;
*dgux*)
    CPPFLAGS="$CPPFLAGS -D_BSD_TIMEOFDAY_FLAVOR";;
*darwin*|*rhapsody*)
    CPPFLAGS="$CPPFLAGS -traditional-cpp";;
*bsdi*)
    BSD_MAKEFILE=yes;;
*beos*)
	beos_threads=1
	LIBS="$LIBS -lbe -lroot";;
*mips*)
	CPPFLAGS="$CPPFLAGS -D_XPG_IV";;
esac

AM_PROG_CC_STDC

AC_PROG_RANLIB
AC_PROG_CC_C_O
AC_PROG_LN_S

AC_PROG_LEX
if test -n "$LEX"; then
  AC_DECL_YYTEXT
fi

dnl ## Make flex scanners use const if they can, even if __STDC__ is not
dnl ## true, for compilers like Sun's that only set __STDC__ true in
dnl ## "limit-to-ANSI-standard" mode, not in "ANSI-compatible" mode
AC_C_CONST
if test "$ac_cv_c_const" = "yes" ; then
  LEX_CFLAGS="-DYY_USE_CONST"
fi

abs_srcdir=`(cd $srcdir; pwd)`
abs_builddir=`pwd`

sinclude(Zend/acinclude.m4)
sinclude(Zend/Zend.m4)
sinclude(TSRM/tsrm.m4)

divert(2)

PTHREADS_CHECK

PHP_SHLIB_SUFFIX_NAME

PHP_SAPI=cgi
PHP_BUILD_PROGRAM
dnl paths to the targets are relative to the build directory
SAPI_PROGRAM=php
SAPI_SHARED=libs/libphp4.$SHLIB_SUFFIX_NAME
SAPI_STATIC=libs/libphp4.a
SAPI_LIBTOOL=libphp4.la

PHP_CONFIGURE_PART(Configuring SAPI modules)

esyscmd(./scripts/config-stubs sapi)

AC_MSG_CHECKING(for chosen SAPI module)
AC_MSG_RESULT($PHP_SAPI)

if test "$enable_experimental_zts" = "yes"; then
  PTHREADS_ASSIGN_VARS
  PTHREADS_FLAGS
fi

divert(3)

PHP_CONFIGURE_PART(Running system checks)

PHP_MISSING_TIME_R_DECL

dnl check for -R, etc. switch
AC_MSG_CHECKING(whether compiler supports -R)
AC_CACHE_VAL(php_cv_cc_dashr,[
	SAVE_LIBS=$LIBS
	LIBS="-R /usr/lib $LIBS"
	AC_TRY_LINK([], [], php_cv_cc_dashr=yes, php_cv_cc_dashr=no)
	LIBS=$SAVE_LIBS])
AC_MSG_RESULT($php_cv_cc_dashr)
if test $php_cv_cc_dashr = "yes"; then
	ld_runpath_switch=-R
else
	AC_MSG_CHECKING([whether compiler supports -Wl,-rpath,])
	AC_CACHE_VAL(php_cv_cc_rpath,[
		SAVE_LIBS=$LIBS
		LIBS="-Wl,-rpath,/usr/lib $LIBS"
		AC_TRY_LINK([], [], php_cv_cc_rpath=yes, php_cv_cc_rpath=no)
		LIBS=$SAVE_LIBS])
	AC_MSG_RESULT($php_cv_cc_rpath)
	if test $php_cv_cc_rpath = "yes"; then
		ld_runpath_switch=-Wl,-rpath,
	else
		dnl something innocuous
		ld_runpath_switch=-L
	fi
fi

PHP_PROG_SENDMAIL

dnl Check whether the system uses EBCDIC (not ASCII) as its native codeset
PHP_EBCDIC

dnl
dnl Check for /usr/pkg/{lib,include} which is where NetBSD puts binary
dnl and source packages.  This should be harmless on other OSs.
dnl
if test -d /usr/pkg/include -a -d /usr/pkg/lib ; then
       CPPFLAGS="$CPPFLAGS -I/usr/pkg/include"
       LDFLAGS="$LDFLAGS -L/usr/pkg/lib"
fi

INCLUDES="$INCLUDES -I\$(top_builddir)/Zend"


AC_CHECK_LIB(socket, socket, [
 PHP_ADD_LIBRARY(socket)
 AC_DEFINE(HAVE_LIBSOCKET,1,[ ]) ], [
  AC_CHECK_LIB(socket, htonl, [
   PHP_ADD_LIBRARY(socket)
   ])])

dnl Some systems (OpenServer 5) dislike -lsocket -lnsl, so we try
dnl to avoid -lnsl checks, if we already have the functions which
dnl are usually in libnsl

unset ac_cv_func_yp_get_default_domain
AC_CHECK_FUNC(yp_get_default_domain,
 [php_no_nsl_checks=yes],[ ])
unset ac_cv_func_yp_get_default_domain

if test "$php_no_nsl_checks" != "yes"; then

AC_CHECK_LIB(nsl, gethostname, [
 PHP_ADD_LIBRARY(nsl)
 AC_DEFINE(HAVE_LIBNSL,1,[ ]) ],[
 AC_CHECK_LIB(nsl, gethostbyaddr, [
  PHP_ADD_LIBRARY(nsl)
  AC_DEFINE(HAVE_LIBNSL,1,[ ]) ], [])
])

fi

AC_CHECK_LIB(dl, dlopen,[PHP_ADD_LIBRARY(dl)])

dnl The sin may be in a library which need not be specifed
dnl as well as res_search resides in libsocket
AC_CHECK_LIB(m, sin)

dnl Only include libbind if inet_aton is not found in 
dnl libresolv.
AC_CHECK_LIB(resolv, inet_aton, [], [
  AC_CHECK_LIB(bind, inet_aton, [], [
    AC_CHECK_LIB(bind, __inet_aton)
  ])
])

dnl The res_search may be in libsocket as well, and if it is
dnl make sure to check for dn_skipname in libresolv, or if res_search
dnl is in neither of these libs, still check for dn_skipname in libresolv
AC_CHECK_LIB(socket, res_search, [
 AC_CHECK_LIB(resolv, dn_skipname)
 AC_CHECK_LIB(resolv, __dn_skipname)
 LIBS="$LIBS -lsocket"
 AC_DEFINE(HAVE_LIBSOCKET,1,[ ]) ], [
 AC_CHECK_LIB(resolv, res_search, [
  LIBS="$LIBS -lresolv"
  AC_DEFINE(HAVE_LIBRESOLV,1,[ ]) 
 ], [
  AC_CHECK_LIB(resolv, dn_skipname)
  AC_CHECK_LIB(resolv, __dn_skipname)
 ]) 
])

dnl Checks for header files.
AC_HEADER_STDC

dnl In QNX opendir resides in libc but dirent.h is still required
if test "`uname -s 2>/dev/null`" != "QNX"; then
	AC_HEADER_DIRENT
else
	AC_CHECK_HEADERS(dirent.h)
fi
PHP_MISSING_FCLOSE_DECL
dnl QNX requires unix.h to allow functions in libunix to work properly
AC_CHECK_HEADERS(
alloca.h \
arpa/inet.h \
arpa/nameser.h \
crypt.h \
fcntl.h \
grp.h \
ieeefp.h \
langinfo.h \
limits.h \
locale.h \
netinet/in.h \
pwd.h \
resolv.h \
signal.h \
stdarg.h \
stdlib.h \
string.h \
syslog.h \
sysexits.h \
sys/file.h \
sys/mman.h \
sys/mount.h \
sys/resource.h \
sys/select.h \
sys/socket.h \
sys/statfs.h \
sys/statvfs.h \
sys/sysexits.h \
sys/time.h \
sys/types.h \
sys/varargs.h \
sys/wait.h \
unistd.h \
unix.h \
utime.h \
)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_STRUCT_TM
AC_STRUCT_TIMEZONE

PHP_TM_GMTOFF
PHP_STRUCT_FLOCK
PHP_SOCKLEN_T

AC_CHECK_SIZEOF(long, 8)
AC_CHECK_SIZEOF(int, 4)

test -d /usr/ucblib && PHP_ADD_LIBPATH(/usr/ucblib)

dnl Check for members of the stat structure
AC_STRUCT_ST_BLKSIZE
dnl AC_STRUCT_ST_BLOCKS will screw QNX because fileblocks.o does not exists
dnl The WARNING_LEVEL required because cc in QNX hates -w option without an argument
if test "`uname -s 2>/dev/null`" != "QNX"; then
	AC_STRUCT_ST_BLOCKS
else
    AC_MSG_WARN(warnings level for cc set to 0)
	WARNING_LEVEL=0
fi
AC_STRUCT_ST_RDEV

dnl Checks for types
AC_TYPE_SIZE_T
AC_TYPE_UID_T

dnl Check for IPv6 support
AC_CACHE_CHECK([for IPv6 support], ac_cv_ipv6_support,
[AC_TRY_COMPILE([ #include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>], [struct sockaddr_in6 s; int i=AF_INET6; s],
  ac_cv_ipv6_support=yes, ac_cv_ipv6_support=no)])
if test "$ac_cv_ipv6_support" = yes; then
  AC_DEFINE(HAVE_IPV6,1,[Whether you have IPv6 support])
fi

dnl Checks for library functions.
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(
asctime_r \
chroot \
ctime_r \
cuserid \
crypt \
flock \
gai_strerror \
gcvt \
getlogin \
gethostbyaddr \
getprotobyname \
getprotobynumber \
getservbyname \
getservbyport \
getrusage \
gettimeofday \
gmtime_r \
inet_aton \
isascii \
link \
localtime_r \
lockf \
lrand48 \
memcpy \
memmove \
mkstemp \
mmap \
nl_langinfo \
putenv \
random \
rand_r \
regcomp \
res_search \
setitimer \
setlocale \
localeconv \
setsockopt \
setvbuf \
shutdown \
sin \
snprintf \
srand48 \
srandom \
statfs \
statvfs \
std_syslog \
strcasecmp \
strcoll \
strdup \
strerror \
strftime \
strstr \
strtok_r \
symlink \
tempnam \
tzset \
unsetenv \
usleep \
utime \
vsnprintf \
)

dnl Check for getaddrinfo, should be a better way, but...
AC_CACHE_CHECK([for getaddrinfo], ac_cv_func_getaddrinfo,
[AC_TRY_COMPILE([#include <netdb.h>],
                [struct addrinfo *g,h;g=&h;getaddrinfo("","",g,&g);],
  ac_cv_func_getaddrinfo=yes, ac_cv_func_getaddrinfo=no)])
if test "$ac_cv_func_getaddrinfo" = yes; then
  AC_DEFINE(HAVE_GETADDRINFO,1,[Define if you have the getaddrinfo function])
fi

AC_REPLACE_FUNCS(strlcat strlcpy getopt)
AC_FUNC_UTIME_NULL
AC_FUNC_ALLOCA
PHP_AC_BROKEN_SPRINTF
PHP_DECLARED_TIMEZONE
PHP_TIME_R_TYPE
PHP_READDIR_R_TYPE

dnl AIX keeps in_addr_t in /usr/include/netinet/in.h
dnl AC_MSG_CHECKING(for in_addr_t)
AC_CACHE_VAL(ac_cv_type_$1,
[AC_EGREP_CPP(dnl
changequote(<<,>>)dnl
<<in_addr_t[^a-zA-Z_0-9]>>dnl
changequote([,]), [#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif], ac_cv_type_in_addr_t=yes, ac_cv_type_in_addr_t=no)])dnl

dnl AC_MSG_RESULT($ac_cv_type_in_addr_t)
if test $ac_cv_type_in_addr_t = no; then
  AC_DEFINE(in_addr_t, u_int, [ ])
fi

divert(4)

PHP_ARG_ENABLE(debug, whether to include debugging symbols,
[  --enable-debug          Compile with debugging symbols.], no)

if test "$PHP_DEBUG" = "yes"; then
  PHP_DEBUG=1
  ZEND_DEBUG=yes
else
  PHP_DEBUG=0
  ZEND_DEBUG=no
fi

PHP_ARG_WITH(layout,[layout of installed files],
[  --with-layout=TYPE      Sets how installed files will be laid out.  Type is
                          one of "PHP" (default) or "GNU"], PHP)

PHP_ARG_WITH(config-file-path,[path to configuration file],
[  --with-config-file-path=PATH  
                          Sets the path in which to look for php.ini,
                          defaults to PREFIX/lib], DEFAULT)

if test "$PHP_CONFIG_FILE_PATH" = "DEFAULT"; then
  case $PHP_LAYOUT in
    GNU)
      PHP_CONFIG_FILE_PATH=$sysconfdir
      oldstyleextdir=no;;
    *)
      PHP_CONFIG_FILE_PATH=$libdir
      oldstyleextdir=yes;;
  esac
fi

# compatibility
if test "x$with_pear" = "x" -a "x$enable_pear" = "xno"; then
    with_pear=no
fi

PHP_ARG_WITH(pear, [whether to install PEAR, and where],
[  --with-pear=DIR         Install PEAR in DIR (default PREFIX/lib/php)
  --without-pear          Do not install PEAR], DEFAULT)

if test "$PHP_PEAR" != "no"; then
  PEAR_DIR=pear
fi

if test "$PHP_PEAR" = "DEFAULT"; then
  case $PHP_LAYOUT in
    GNU) PEAR_INSTALLDIR=$datadir/pear;;
    *)   PEAR_INSTALLDIR=$libdir/php;;
  esac
fi

test -n "$DEBUG_CFLAGS" && CFLAGS="$CFLAGS $DEBUG_CFLAGS"

PHP_ARG_ENABLE(safe-mode, whether to enable safe mode by default,
[  --enable-safe-mode      Enable safe mode by default.])

if test "$PHP_SAFE_MODE" = "yes"; then
  AC_DEFINE(PHP_SAFE_MODE,1,[ ])
else
  AC_DEFINE(PHP_SAFE_MODE,0,[ ])
fi

AC_MSG_CHECKING(for safe mode exec dir)
AC_ARG_WITH(exec-dir,
[  --with-exec-dir[=DIR]   Only allow executables in DIR when in safe mode
                          defaults to /usr/local/php/bin],
[
  if test "$withval" != "no"; then
  	if test "$withval" = "yes"; then
		AC_DEFINE(PHP_SAFE_MODE_EXEC_DIR,"/usr/local/php/bin", [ ])
    	AC_MSG_RESULT(/usr/local/php/bin)
   	else
		AC_DEFINE_UNQUOTED(PHP_SAFE_MODE_EXEC_DIR,"$withval", [ ])
    	AC_MSG_RESULT($withval)
   	fi
  else
	AC_DEFINE(PHP_SAFE_MODE_EXEC_DIR,"/usr/local/php/bin", [ ])
   	AC_MSG_RESULT(/usr/local/php/bin)
  fi
],[
	AC_DEFINE(PHP_SAFE_MODE_EXEC_DIR,"/usr/local/php/bin", [ ])
   	AC_MSG_RESULT(/usr/local/php/bin)
])

PHP_ARG_WITH(openssl,for OpenSSL support,
[  --with-openssl[=DIR]    Include OpenSSL support (requires OpenSSL >= 0.9.5) ])
if test "$PHP_OPENSSL" = "yes"; then
  PHP_OPENSSL="/usr/local/ssl /usr/local /usr /usr/local/openssl"
fi

if test "$PHP_OPENSSL" != "no"; then
  PHP_SETUP_OPENSSL
fi

PHP_ARG_ENABLE(sigchild,whether to enable PHP's own SIGCHLD handler,
[  --enable-sigchild       Enable PHP's own SIGCHLD handler.],no)

if test "$PHP_SIGCHILD" = "yes"; then
  AC_DEFINE(PHP_SIGCHILD, 1, [ ])
else
  AC_DEFINE(PHP_SIGCHILD, 0, [ ])
fi

PHP_ARG_ENABLE(magic-quotes,whether to enable magic quotes by default,
[  --enable-magic-quotes   Enable magic quotes by default.])

if test "$PHP_MAGIC_QUOTES" = "yes"; then
  AC_DEFINE(MAGIC_QUOTES, 1, [ ])
else
  AC_DEFINE(MAGIC_QUOTES, 0, [ ])
fi

PHP_ARG_ENABLE(rpath, whether to enable runpaths,
[  --disable-rpath         Disable passing additional runtime library
                          search paths], yes)

PHP_ARG_ENABLE(libgcc, whether to explicitly link against libgcc,
[  --enable-libgcc         Enable explicitly linking against libgcc])

if test "$PHP_LIBGCC" = "yes"; then
  PHP_LIBGCC_LIBPATH(gcc)
  if test -z "$libgcc_libpath"; then
    AC_MSG_ERROR(Cannot locate libgcc. Make sure that gcc is in your path)
  fi
  PHP_ADD_LIBPATH($libgcc_libpath)
  PHP_ADD_LIBRARY(gcc, yes)
fi

PHP_ARG_ENABLE(short-tags,whether to enable short tags by default,
[  --disable-short-tags    Disable the short-form <? start tag by default.],yes)

if test "$PHP_SHORT_TAGS" = "yes"; then
  AC_DEFINE(DEFAULT_SHORT_OPEN_TAG,"1",[ ])
else
  AC_DEFINE(DEFAULT_SHORT_OPEN_TAG,"0",[ ])
fi


PHP_ARG_ENABLE(dmalloc,whether to enable dmalloc,
[  --enable-dmalloc        Enable dmalloc])

if test "$PHP_DMALLOC" = "yes"; then
  AC_DEFINE(HAVE_DMALLOC,1,[Whether you have dmalloc])
  PHP_ADD_LIBRARY(dmalloc)
  CPPFLAGS="$CPPFLAGS -DDMALLOC_FUNC_CHECK"
fi

# temporary until streams are better integrated
PHP_ARG_ENABLE(php-streams,whether to enable php streams,
[  --enable-php-streams    Include experimental php streams.
                          Do not use unless you are testing the code!])

if test "$PHP_PHP_STREAMS" = "yes"; then
  AC_DEFINE(HAVE_PHP_STREAM, 1, [Whether to use php streams])
fi

AC_CHECK_LIB(crypt, crypt, [
  PHP_ADD_LIBRARY(crypt)
  AC_DEFINE(HAVE_CRYPT,1,[ ]) 
])

divert(5)

PHP_CONFIGURE_PART(Configuring extensions)

# reading config stubs
esyscmd(./scripts/config-stubs ext)

PHP_FAST_OUTPUT(sapi/$PHP_SAPI/Makefile)

AC_MSG_CHECKING(whether to enable versioning)
AC_ARG_ENABLE(versioning,
[  --enable-versioning     Export only required symbols.
                          See INSTALL for more information],[
  PHP_VERSIONING=$enableval
],[
  PHP_VERSIONING=no
])
AC_MSG_RESULT($PHP_VERSIONING)

if test "$PHP_VERSIONING" = "yes"; then
  test -z "$PHP_SYM_FILE" && PHP_SYM_FILE="$abs_srcdir/sapi/$PHP_SAPI/php.sym"
  if test -f "$PHP_SYM_FILE"; then
    EXTRA_LDFLAGS="-export-symbols $PHP_SYM_FILE"
  fi
fi

divert(6)

enable_shared=yes
enable_static=yes
unset with_pic

case $php_build_target in
program|static)
    standard_libtool_flag='-prefer-non-pic -static'
    if test "$lib_build_shared" != "yes"; then
        enable_shared=no
    fi
    PHP_COMPILE='$(CC) $(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) -c $< && touch $@'
    CXX_PHP_COMPILE='$(CXX) $(COMMON_FLAGS) $(CXXFLAGS_CLEAN) $(EXTRA_CXXFLAGS)  -c $< && touch $@'
;;
shared)
    enable_static=no
    standard_libtool_flag=-prefer-pic
    EXTRA_LDFLAGS="$EXTRA_LDFLAGS -avoid-version"
;;
esac

if test "$PHP_SAPI" = "cgi"; then
  PHP_PROGRAM=php
fi

if test "$PHP_SAPI" = "fastcgi"; then
  PHP_PROGRAM=php
fi


PHP_REGEX

PHP_CONFIGURE_PART(Configuring Zend)
LIBZEND_BASIC_CHECKS
LIBZEND_OTHER_CHECKS

TSRM_LIB='TSRM/libtsrm.la'
TSRM_DIR=TSRM
CPPFLAGS="$CPPFLAGS -I\$(top_builddir)/TSRM"

if test "$ZEND_EXPERIMENTAL_ZTS" = "yes"; then
  AC_DEFINE(ZTS,1,[ ])
  PHP_THREAD_SAFETY=yes
else
  PHP_THREAD_SAFETY=no
fi

if test "$abs_srcdir" != "$abs_builddir"; then
  INCLUDES="$INCLUDES -I\$(top_srcdir)/main -I\$(top_srcdir)/Zend"
  INCLUDES="$INCLUDES -I\$(top_srcdir)/TSRM"
fi

EXTRA_LIBS="$EXTRA_LIBS $DLIBS $LIBS"
unset LIBS LDFLAGS

PHP_CONFIGURE_PART(Configuring TSRM)
TSRM_BASIC_CHECKS
if test "$PHP_THREAD_SAFETY" = "yes"; then
  TSRM_THREADS_CHECKS
fi
EXTRA_LDFLAGS="$EXTRA_LDFLAGS $LDFLAGS"
EXTRA_LIBS="$EXTRA_LIBS $LIBS"
unset LIBS LDFLAGS

test "$prefix" = "NONE" && prefix=/usr/local
test "$exec_prefix" = "NONE" && exec_prefix='${prefix}'

case $libdir in
  '${exec_prefix}/lib')
    libdir=$libdir/php
    ;;
esac
case $datadir in
  '${prefix}/share')
    datadir=$datadir/php
    ;;
  *) ;;
esac

phplibdir=`pwd`/modules
$php_shtool mkdir -p $phplibdir
phptempdir=`pwd`/libs

old_exec_prefix=$exec_prefix
old_libdir=$libdir
old_datadir=$datadir
exec_prefix=`eval echo $exec_prefix`
libdir=`eval echo $libdir`
datadir=`eval echo $datadir`

dnl Build extension directory path

ZEND_MODULE_API_NO=`egrep '#define ZEND_MODULE_API_NO ' $srcdir/Zend/zend_modules.h|sed 's/#define ZEND_MODULE_API_NO //'`

if test -z "$EXTENSION_DIR"; then
  extbasedir=$ZEND_MODULE_API_NO
  if test "$oldstyleextdir" = "yes"; then
    if test "$PHP_DEBUG" = "1"; then
      part1=debug
    else
      part1=no-debug
    fi
    if test "$enable_experimental_zts" = "yes"; then
      part2=zts
    else
      part2=non-zts
    fi
    extbasedir=$part1-$part2-$extbasedir
  	EXTENSION_DIR=$libdir/extensions/$extbasedir
  else
  	if test "$enable_experimental_zts" = "yes"; then
  	  extbasedir=$extbasedir-zts
  	fi
  	
  	if test "$PHP_DEBUG" = "1"; then
  	  extbasedir=$extbasedir-debug
  	fi
  	EXTENSION_DIR=$libdir/$extbasedir
  fi
fi

dnl Expand all directory names for use in macros/constants
EXPANDED_PEAR_INSTALLDIR=`eval echo $PEAR_INSTALLDIR`
EXPANDED_EXTENSION_DIR=`eval echo $EXTENSION_DIR`
EXPANDED_LOCALSTATEDIR=`eval echo $localstatedir`
EXPANDED_BINDIR=`eval echo $bindir`
EXPANDED_LIBDIR=$libdir
EXPANDED_SYSCONFDIR=`eval echo $sysconfdir`
EXPANDED_DATADIR=$datadir
EXPANDED_PHP_CONFIG_FILE_PATH=`eval echo "$PHP_CONFIG_FILE_PATH"`
INCLUDE_PATH=.:$EXPANDED_PEAR_INSTALLDIR

exec_prefix=$old_exec_prefix
libdir=$old_libdir
datadir=$old_datadir

AC_SUBST(INCLUDE_PATH)
AC_SUBST(EXPANDED_PEAR_INSTALLDIR)
AC_SUBST(EXPANDED_EXTENSION_DIR)
AC_SUBST(EXPANDED_BINDIR)
AC_SUBST(EXPANDED_LIBDIR)
AC_SUBST(EXPANDED_DATADIR)
AC_SUBST(EXPANDED_SYSCONFDIR)
AC_SUBST(EXPANDED_LOCALSTATEDIR)
AC_SUBST(EXPANDED_PHP_CONFIG_FILE_PATH)

PHP_BUILD_RPATH

PHP_REMOVE_USR_LIB(PHP_LDFLAGS)
PHP_REMOVE_USR_LIB(LDFLAGS)

EXTRA_LDFLAGS="$EXTRA_LDFLAGS $PHP_LDFLAGS"

PHP_BUILD_DATE=`date '+%Y-%m-%d'`
AC_DEFINE_UNQUOTED(PHP_BUILD_DATE,"$PHP_BUILD_DATE",[PHP build date])
PHP_UNAME=`uname -a`
AC_DEFINE_UNQUOTED(PHP_UNAME,"$PHP_UNAME",[uname -a output])
PHP_OS=`uname`
AC_DEFINE_UNQUOTED(PHP_OS,"$PHP_OS",[uname output])


PHP_SUBST_OLD(abs_builddir)
PHP_SUBST_OLD(abs_srcdir)
PHP_SUBST(bindir)
PHP_SUBST(exec_prefix)
PHP_SUBST(includedir)
PHP_SUBST(libdir)
PHP_SUBST(phplibdir)
PHP_SUBST(phptempdir)
PHP_SUBST(prefix)
PHP_SUBST(localstatedir)
PHP_SUBST(datadir)
PHP_SUBST(sysconfdir)

PHP_SUBST(AWK)
PHP_SUBST(CC)
PHP_SUBST(CFLAGS)
PHP_SUBST(CFLAGS_CLEAN)
PHP_SUBST_OLD(CONFIGURE_COMMAND)
PHP_SUBST(CPP)
PHP_SUBST(CPPFLAGS)
PHP_SUBST(CXX)
PHP_SUBST(CXXFLAGS)
PHP_SUBST(CXXFLAGS_CLEAN)
PHP_SUBST(CXX_PHP_COMPILE)
PHP_SUBST_OLD(DEBUG_CFLAGS)
PHP_SUBST(DEFS)
PHP_SUBST_OLD(EXTENSION_DIR)
PHP_SUBST(EXTRA_LDFLAGS)
PHP_SUBST_OLD(EXTRA_LIBS)
PHP_SUBST(INCLUDES)
PHP_SUBST_OLD(INCLUDE_PATH)
PHP_SUBST_OLD(INSTALL_IT)
PHP_SUBST(LEX)
PHP_SUBST(LEX_OUTPUT_ROOT)
PHP_SUBST(LFLAGS)
PHP_SUBST(LIBTOOL)
PHP_SUBST(LN_S)
PHP_SUBST_OLD(NATIVE_RPATHS)
PHP_SUBST(PEAR_DIR)
PHP_SUBST_OLD(PEAR_INSTALLDIR)
PHP_SUBST(PHP_BUILD_DATE)
PHP_SUBST(PHP_COMPILE)
PHP_SUBST_OLD(PHP_LDFLAGS)
PHP_SUBST_OLD(PHP_LIBS)
PHP_SUBST(PHP_PROGRAM)
PHP_SUBST(PHP_RPATHS)
PHP_SUBST(PHP_SAPI)
PHP_SUBST(PHP_VERSION)
PHP_SUBST(PROG_SENDMAIL)
PHP_SUBST(SHELL)
PHP_SUBST(SHARED_LIBTOOL)
PHP_SUBST(TSRM_DIR)
PHP_SUBST(TSRM_LIB)
PHP_SUBST(WARNING_LEVEL)
PHP_SUBST_OLD(YACC)

PHP_CONFIGURE_PART(Configuring libtool)

old_CC=$CC

if test "$PHP_THREAD_SAFETY" = "yes" && test -n "$ac_cv_pthreads_cflags"; then
  CXXFLAGS="$CXXFLAGS $ac_cv_pthreads_cflags"
  INLINE_CFLAGS="$INLINE_CFLAGS $ac_cv_pthreads_cflags"
  cat >meta_ccld<<EOF
#! /bin/sh
exec $CC $ac_cv_pthreads_cflags \$@
EOF
  CC="$abs_builddir/meta_ccld"
  chmod +x meta_ccld
fi

dnl This will go away, if we have a facility to run per-extension code
dnl after the thread_safety decision was done
if test "$PHP_THREAD_SAFETY" = "yes" && test "$PHP_MYSQL" = "yes"; then
  CPPFLAGS="$CPPFLAGS -DTHREAD=1"
fi

AM_PROG_LIBTOOL
if test "$enable_debug" != "yes"; then
  AM_SET_LIBTOOL_VARIABLE([--silent])
fi


test -z "$PHP_COMPILE" && PHP_COMPILE='$(LIBTOOL) --mode=compile $(COMPILE) -c $<'
test -z "$CXX_PHP_COMPILE" && CXX_PHP_COMPILE='$(LIBTOOL) --mode=compile $(CXX_COMPILE) -c $<'
SHARED_LIBTOOL='$(LIBTOOL)'

CC=$old_CC

PHP_CONFIGURE_PART(Generating files)

CXXFLAGS_CLEAN=$CXXFLAGS
CFLAGS_CLEAN=$CFLAGS
CFLAGS="$CFLAGS $standard_libtool_flag"
INLINE_CFLAGS="$INLINE_CFLAGS $standard_libtool_flag"
CXXFLAGS="$CXXFLAGS $standard_libtool_flag"

PHP_GEN_CONFIG_VARS

$php_shtool mkdir -p pear/scripts
ALL_OUTPUT_FILES="php4.spec Zend/Makefile main/build-defs.h \
pear/scripts/pear pear/scripts/phpize pear/scripts/php-config \
pear/scripts/pearize TSRM/Makefile $PHP_OUTPUT_FILES"

AC_OUTPUT($ALL_OUTPUT_FILES, [], [

if test "\$CONFIG_FILES" = "$ALL_OUTPUT_FILES"; then
  REDO_ALL=yes
fi

if test -n "\$REDO_ALL"; then
  PHP_GEN_MAKEFILES($PHP_FAST_OUTPUT_FILES)
fi
		   
if test ! -f $srcdir/ext/bcmath/number.c; then
	echo "creating number.c"
	echo "/* Dummy File */" > $srcdir/ext/bcmath/number.c
	echo "creating number.h"
	echo "/* Dummy File */" > $srcdir/ext/bcmath/number.h
fi

################################################################
# Create configuration headers
#

if test -d TSRM; then
  echo '#include "../main/php_config.h"' > TSRM/tsrm_config.h
fi

cat >Zend/zend_config.h <<FEO
#include "../main/php_config.h"
#if defined(APACHE) && defined(PHP_API_VERSION)
#undef HAVE_DLFCN_H
#endif
FEO

# run this only when generating all the files?
if test -n "\$REDO_ALL"; then
  # Hacking while airborne considered harmful.
  #
  echo "creating main/internal_functions.c"
  extensions="$EXT_STATIC"
dnl mv -f main/internal_functions.c main/internal_functions.c.old 2>/dev/null
  sh $srcdir/build/genif.sh $srcdir/main/internal_functions.c.in $srcdir "$EXTRA_MODULE_PTRS" $AWK \$extensions > main/internal_functions.c
dnl  if cmp main/internal_functions.c.old main/internal_functions.c > /dev/null 2>&1; then
dnl      echo "main/internal_functions.c is unchanged"
dnl      mv main/internal_functions.c.old main/internal_functions.c
dnl  else
dnl      rm -f main/internal_functions.c.old
dnl  fi

  if test -n "$PHP_APXS_BROKEN"; then
    echo "+--------------------------------------------------------------------+"
    echo "| WARNING: Your $APXS script is most likely broken."
    echo "|                                                                    |"
    echo "| Please go read http://www.php.net/FAQ.php#6.11 and make the        |"
    echo "| changes described there and try again.                             |"
  fi

  # Warn about CGI version with no extra security options.
  if test "$PHP_SAPI" = "cgi"; then
    if test "$REDIRECT" = "0"; then
      if test "$DISCARD_PATH" = "0"; then
        echo "+--------------------------------------------------------------------+"
        echo "|                        *** WARNING ***                             |"
        echo "|                                                                    |"
        echo "| You will be compiling the CGI version of PHP without any           |"
        echo "| redirection checking.  By putting this cgi binary somewhere in     |"
        echo "| your web space, users may be able to circumvent existing .htaccess |"
        echo "| security by loading files directly through the parser.  See        |"
        echo "| http://www.php.net/manual/security.php for more details.           |"
      fi
    fi
  fi


  if test -n "$DEBUG_LOG"; then
    rm -f config.cache
cat <<X
+--------------------------------------------------------------------+
|                       *** ATTENTION ***                            |
|                                                                    |
| Something is likely to be messed up here, because the configure    |
| script was not able to detect a simple feature on your platform.   |
| This is often caused by incorrect configuration parameters. Please |
| see the file debug.log for error messages.                         |
|                                                                    |
| If you are unable to fix this, send the file debug.log to the      |
| php-install@lists.php.net mailing list and include appropiate      |
| information about your setup.                                      |
X
  fi

  if test "$MYSQL_MODULE_TYPE" = "builtin" ; then
cat <<X
+--------------------------------------------------------------------+
|                        *** WARNING ***                             |
|                                                                    |
| You chose to compile PHP with the built-in MySQL support.  If you  |
| are compiling a server module, and intend to use other server      |
| modules that also use MySQL (e.g, mod_auth_mysql, PHP 3.0,         |
| mod_perl) you must NOT rely on PHP's built-in MySQL support, and   |
| instead build it with your local MySQL support files, by adding    |
| --with-mysql=/path/to/mysql to your configure line.                |
X
  fi

  # Warn about linking Apache with libpthread if oci8 extension is enabled on linux.
  if test "$PHP_OCI8" != "no" -o "$PHP_ORACLE" != "no"; then
    if test "$PHP_SAPI" = "apache"; then
      if test `uname` = "Linux"; then
cat <<X
+--------------------------------------------------------------------+
|                        *** WARNING ***                             |
|                                                                    |
| Please check that your Apache (httpd) is linked with libpthread.   |
| If not, you have to recompile Apache with pthread. For more        |
| details, see this page: http://www.php.net/manual/ref.oci8.php     |
X
      fi
    fi

    if test "$PHP_SIGCHILD" != "yes"; then
cat <<X
+--------------------------------------------------------------------+
| Notice:                                                            |
| If you encounter <defunc> processes when using a local Oracle-DB   |
| please recompile PHP and specify --enable-sigchild when configuring|
| (This problem has been reported under Linux using Oracle >= 8.1.5) |
X
    fi
  fi

cat<<X
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

X

fi
])

dnl ## Local Variables:
dnl ## tab-width: 4
dnl ## End: