AC_INIT(
[PHP/Java Bridge], 
m4_bpatsubst(m4_include([../VERSION]),[
]), 
[php-java-bridge-users@lists.sourceforge.net], 
[php-java-bridge])
AC_CONFIG_AUX_DIR(.)
AC_CONFIG_LINKS(protocol.h:../protocol.h)

dnl autoconf >2.53
AC_PREREQ(2.53)
AC_CONFIG_SRCDIR(natcJavaBridge.c)

dnl automake >1.6.3
AM_INIT_AUTOMAKE([1.6.3])
AM_CONFIG_HEADER(config.h)

AC_PROG_CC
AC_PROG_CPP
AM_PROG_GCJ
AC_PROG_LIBTOOL
AC_STDC_HEADERS

AC_ARG_WITH(java,  [  --with-java[[=JAVA_HOME]]	Include java support], PHP_JAVA="$withval", PHP_JAVA="yes")
AC_ARG_WITH(mono,  [  --with-mono[[=ikvmc.exe location]]             Include mono support], PHP_MONO="$withval", PHP_MONO="no")
AC_ARG_WITH(extdir,  [  --with-extdir[[=DIR]]	Directory which contains the shared java extension], EXTENSION_DIR="$withval", EXTENSION_DIR="`php-config --extension-dir`")
AC_ARG_ENABLE(servlet,  [  --enable-servlet[[=JAR]]	JAR must be j2ee.jar or servlet.jar which contains the servlet classes], SERVLET="$enableval", SERVLET="yes")
AC_ARG_ENABLE(script,  [  --enable-script[[=JAR]]	If you use JDK < 1.6 JAR must be script-api.jar which contains the jsr223 script api], SCRIPT="$enableval", SCRIPT="yes")
AC_ARG_ENABLE(faces,  [  --enable-faces[[=JAR]]	JAR must be jsf-api.jar which contains the java server faces api], FACES="$enableval", FACES="yes")


JAVA_FUNCTION_CHECKS
PTHREADS_CHECK
PTHREADS_ASSIGN_VARS
PTHREADS_FLAGS
JAVA_CHECK_BROKEN_STDIO_BUFFERING
JAVA_CHECK_ABSTRACT_NAMESPACE
JAVA_CHECK_STRUCT_UCRED

AM_CPPFLAGS="${AM_CPPFLAGS} -DEXTENSION_DIR=\"\\\"\$(EXTENSION_DIR)\\\"\""
if test "$PHP_JAVA" != "yes"; then
AM_CPPFLAGS="${AM_CPPFLAGS} `for i in \`find $PHP_JAVA/include -follow -type d -print\`; do echo -n "-I$i "; done`"
fi

TCP_SOCKETNAME="9167"
EXTENSION_DISPLAY_NAME="MonoBridge"
MONO_BRIDGE_EXE=MonoBridge.exe
VM_BINARIES="${MONO_BRIDGE_EXE} RunMonoBridge"

if test "$PHP_MONO" = "no"; then
  MONO_BRIDGE_EXE=
  TCP_SOCKETNAME="9267"
  EXTENSION_DISPLAY_NAME="JavaBridge"
  VM_BINARIES="java RunJavaBridge"
  MONO_BRIDGE_EXE=
fi
if test "$PHP_MONO" = "yes"; then
  PHP_MONO="`locate ikvmc.exe | head -1`"
  if test X$PHP_MONO = X; then 
   echo "ikvmc.exe not found, skipping mono JavaBridge.exe creation" >2
   PHP_MONO=
   MONO_BRIDGE_EXE=
  fi
fi

# optional faces, requires script, servlet
JAVA_BRIDGE_FACES_JAR="php-faces.jar"
if test "$FACES" = "no"; then
  JAVA_BRIDGE_FACES_JAR=""
else
  if test "$SCRIPT" = "no"; then
  SCRIPT="yes";
  fi
  if test "$SERVLET" = "no"; then
  SERVLET="yes";
  fi
fi
if test "$FACES" = "yes"; then
  FACES="../unsupported/myfaces-api.jar"
fi

# optional script, requires servlet
JAVA_BRIDGE_SCRIPT_JAR="php-script.jar"
if test "$SCRIPT" = "no"; then
  JAVA_BRIDGE_SCRIPT_JAR=""
else
  if test "$SERVLET" = "no"; then
  SERVLET="yes";
  fi
fi
if test "$SCRIPT" = "yes"; then
  SCRIPT="../unsupported/script-api.jar"
fi


# optional JavaBridge.war, requires servlet
JAVA_BRIDGE_SERVLET_JAR="php-servlet.jar"
JAVA_BRIDGE_WAR="JavaBridge.war"
if test "$SERVLET" = "no"; then
  JAVA_BRIDGE_WAR=
  JAVA_BRIDGE_SERVLET_JAR=""
fi
if test "$SERVLET" = "yes"; then
  SERVLET="../unsupported/servlet-api.jar"
  if test X$SERVLET = X; then 
   echo "servlet-api.jar not found, skipping servlet JavaBridge.war creation" >2
   SERVLET=
   JAVA_BRIDGE_WAR=
  fi
fi

AC_CONFIG_FILES([RunJavaBridge.c RunMonoBridge.c php/java/bridge/global.properties])
AC_SUBST(AM_CPPFLAGS)
AC_SUBST(EXTENSION_DIR)
AC_SUBST(PHP_JAVA)
AC_SUBST(PHP_MONO)
AC_SUBST(TCP_SOCKETNAME)
AC_SUBST(EXTENSION_DISPLAY_NAME)
AC_SUBST(VM_BINARIES)
AC_SUBST(MONO_BRIDGE_EXE)
AC_SUBST(SERVLET)
AC_SUBST(JAVA_BRIDGE_WAR)
AC_SUBST(JAVA_BRIDGE_SERVLET_JAR)

# optional script
AC_SUBST(SCRIPT)
AC_SUBST(JAVA_BRIDGE_SCRIPT_JAR)
# optional faces
AC_SUBST(FACES)
AC_SUBST(JAVA_BRIDGE_FACES_JAR)
AM_CONDITIONAL([COND_GCJ], [test "$PHP_MONO" != "no" || test "$PHP_JAVA" = "yes"])
AC_OUTPUT(Makefile)

