dnl Process this file with autoconf to produce a configure script.

AC_INIT(install-sh)
AC_PREREQ([2.50])
AC_CONFIG_HEADER(config.h)

AC_SUBST(JAVA_HOME)
AC_SUBST(JAVALIBS)
AC_SUBST(JUNIT)
AC_SUBST(JPLCFLAGS)
AC_SUBST(JPLLDFLAGS)
AC_SUBST(LIBJPL)
AC_SUBST(CMDEXT)

m4_include([../ac_swi_c.m4])

CMDEXT=sh

if test "x$JAVALIBS" = "x"; then
  case "$PLARCH" in
     *darwin*)
	  JAVALIBS="-Wl,-framework,JavaVM"
	  ;;
     *powerpc-linux*)
	  JAVALIBS="-ljava -ljvm"
	  ;;
     *win32*|*win64*)
	  JAVALIBS="-ljvm"
	  CMDEXT=bat
	  ;;
     *)
	  JAVALIBS="-ljava -lverify -ljvm"
	  ;;
  esac
fi

case "$PLARCH" in
  *win32*|*win64*)
	LIBJPL=jpl
	;;
  *)
	LIBJPL=libjpl
	;;
esac

dnl ================================================================
dnl Java stuff
dnl ================================================================

AC_CANONICAL_HOST			dnl needed to get $host_os

m4_include([ac/ac_prog_java.m4])
m4_include([ac/ac_prog_java_works.m4])
m4_include([ac/ac_prog_javac.m4])
m4_include([ac/ac_prog_javac_works.m4])
m4_include([ac/ac_prog_javadoc.m4])
m4_include([ac/ac_jni_include_dirs.m4])
m4_include([ac/ac_prog_jar.m4])

java_abs_paths=no
AC_CHECKING(Java configuration)
if test -r /etc/java/java2.conf; then
  AC_MSG_RESULT(Using /etc/java/java2.conf)
  eval `grep '\(JAVA\|JRE\|JDK\|SDK\).*=' /etc/java/java2.conf | sed 's/ *= */=/'`
  if test ! -z "$JAVA_BINDIR"; then
    PATH="$PATH:$JAVA_BINDIR"
    java_abs_paths=yes
  fi
fi

AC_PROG_JAVAC(javac)
AC_PROG_JAVA(java)
AC_PROG_JAR(jar)
AC_PROG_JAVADOC(javadoc)

escape_space()
{ sed -e "s/Program Files/Program-SPACE-Files/g" -e "s/ (x86)/SPACEX86/g"
}

unescape_space()
{ sed -e "s/-SPACE-/ /g" -e "s/SPACEX86/ (x86)/g"
}

AC_JNI_INCLUDE_DIR
for d in $(echo $JNI_INCLUDE_DIRS | escape_space); do
  JPLCFLAGS="$JPLCFLAGS -I'$d'"
done
JPLCFLAGS="$(echo $JPLCFLAGS | unescape_space)"

for d in $(echo $JNI_CLIENT_DIRS | escape_space); do
  JPLLDFLAGS="$JPLLDFLAGS -L'$d'"
done
JPLLDFLAGS="$(echo $JPLLDFLAGS | unescape_space)"

if test "$java_abs_paths" = yes; then
  JAVA_CC="$JAVA_BINDIR/$JAVA_CC"
fi

AC_ARG_WITH(junit, [  --with-junit=PATH	  Specify location of the junit JAR file],
	    [case "$withval" in
		 yes) JUNIT=/usr/share/java/junit.jar
			;;
		 no) JUNIT=""
			;;
		 *) JUNIT="$withval"
			;;
	     esac
	     ],
	     [ if test "x$JUNIT" = "x" -a -r /usr/share/java/junit.jar; then
		  JUNIT=/usr/share/java/junit.jar
	       fi
	     ]
	     )

AC_CHECK_HEADERS(wchar.h)
AC_CHECK_SIZEOF(wchar_t, 4)
AC_CHECK_SIZEOF(void*, 4)
AC_CHECK_SIZEOF(long, 4)
AC_CHECK_SIZEOF(long long, 8)

AC_OUTPUT(Makefile src/java/Makefile)




