dnl Process this with autoconf to create configure
AC_INIT(doc/kawa.texi)

AM_MAINTAINER_MODE
AC_CANONICAL_SYSTEM

AM_INIT_AUTOMAKE(kawa, 1.7) dnl Also update build.xml.

AC_PROG_INSTALL
AC_PROG_LN_S

AC_EXEEXT
AC_OBJEXT

dnl AC_ARG_WITH(classpath,[  --with-classpath          Path to Java classes], classpath=$withval, classpath=$$CLASSPATH)
AC_ARG_ENABLE(kawa-frontend,
  [  --enable-kawa-frontend  Build "kawa" front-end program using readline],
  enable_kawa_frontend=$enableval, enable_kawa_frontend=no)

AC_ARG_WITH(gcj,
  [  --with-gjc              Compile Kawa using GCJ (GNU Compiler for Java)])

AC_ARG_ENABLE(xml,
  [  --disable-xml           Don't build support for XML processing],
  enable_xml=$enableval, enable_xml=yes)

AC_ARG_ENABLE(servlet,
  [  --enable-servlet        Build support for generating servlets],
  enable_servlet=$enableval, enable_servlet=no)

AC_ARG_WITH(swing,
  [  --with-swing            Assume Swing (Java Foundation Classes) is available])

AC_ARG_WITH(awt,
  [  --with-awt              Assume AWT is available (default on)])

AC_ARG_WITH(sax2,
  [  --with-sax2             Assume SAX2 is available])

AC_PROG_CC
AC_PROG_CXX
dnl AC_PROG_INSTALL
#AC_PROG_MAKE_SET

# AM_PROG_GCJ isn't good enough, we have to roll our own.
# AC_CHECK_TOOL(GCJ, gcj)
LT_AC_PROG_GCJ
test -z "$GCJ" && AC_MSG_ERROR([no acceptable gcj found in \$PATH])
if test "x${GCJFLAGS-unset}" = xunset; then
   GCJFLAGS="-g -O2"
fi

# dnl AC_SUBST(GCJFLAGS)

dnl We must have the absolute path to the build directory.

TOP_BUILDDIR=`pwd`

AC_PROG_LIBTOOL

case ${with_gcj} in
  yes)
    GCJ_COMPILED_SELECTED=ENABLE_GCJ_COMPILED
    GCJ_SELECTED=WITH_GCJ
    JAVA=${JAVA-gij}
    JAVAC=${JAVAC-"gcj -C"}

    # AM_PROG_GCJ isn't good enough, we have to roll our own.
    # AC_CHECK_TOOL(GCJ, gcj)
    LT_AC_PROG_GCJ
    test -z "$GCJ" && AC_MSG_ERROR([no acceptable gcj found in \$PATH])
    if test "x${GCJFLAGS-unset}" = xunset; then
       GCJFLAGS="-g -O2"
    fi
    AC_SUBST(GCJFLAGS)
    AC_LIBTOOL_GCJ

   _AM_DEPENDENCIES(GCJ)
    AC_SUBST(LIBTOOL_DEPS)

    test "${with_awt}" = "" && with_awt=no
    ;;
  *)
    GCJ_COMPILED_SELECTED=DISABLE_GCJ_COMPILED
    GCJ_SELECTED=WITHOUT_GCJ
    JAVA=${JAVA-java}
    JAVAC=${JAVAC-javac}
    test "${with_awt}" = "" && with_awt=yes
    dnl needed to match _AM_DEPENDENCIES
    am__fastdepGCJ_TRUE='#'
    ;;
esac

AM_CONDITIONAL(WITH_GCJ, test "$with_gcj" = "yes")
AM_CONDITIONAL(ENABLE_XML, test "$enable_xml" = "yes")
AM_CONDITIONAL(ENABLE_SERVLET, test "$enable_servlet" = "yes")
AM_CONDITIONAL(WITH_SWING, test "$with_swing" = "yes")
AM_CONDITIONAL(WITH_AWT, test "$with_awt" = "yes")
AM_CONDITIONAL(WITH_SAX2, test "$with_sax2" = "yes")
AM_CONDITIONAL(ENABLE_KAWA_FRONTEND, test "$enable_kawa_frontend" = "yes")

case ${with_swing} in
  yes)
    extra_java='$(java_SWING)'
    SWING_SELECTED=WITH_SWING
    ;;
  *)
    extra_java=''
    SWING_SELECTED=WITHOUT_SWING
    ;;
esac
  
case ${with_awt} in
  no) AWT_SELECTED=WITHOUT_AWT ;;
  *)  AWT_SELECTED=WITH_AWT ;;
esac

case ${enable_xml} in
  yes)  XML_SELECTED=XML_ENABLED ;;
  *)  XML_SELECTED=XML_DISABLED ;;
esac
  
JEMACS_VERSION=`echo $VERSION | sed  -e 's/^1/0/'`

pathsep=':'
filesep='/'
AC_SUBST(pathsep)
AC_SUBST(filesep)

AC_SUBST(JAVA)
AC_SUBST(JAVAC)
#These don't do anything, because Make-rules can't contain autoconf
#substitutions.  Perhaps fix when new automake is out.
#AC_SUBST(GCJ) AC_SUBST(GCJFLAGS)
AC_SUBST(XML_SELECTED)
AC_SUBST(AWT_SELECTED)
AC_SUBST(SWING_SELECTED)
AC_SUBST(GCJ_COMPILED_SELECTED)
AC_SUBST(GCJ_SELECTED)
AC_SUBST(extra_java)
AC_SUBST(TOP_BUILDDIR)
AC_SUBST(CC)
AC_SUBST(CFLAGS)
AC_SUBST(PACKAGE)
AC_SUBST(VERSION)
AC_SUBST(JEMACS_VERSION)
AC_SUBST(SHELL)
Make_rules="$srcdir/Make-rules"
AC_SUBST_FILE(Make_rules)
AC_LINK_FILES(gnu/xquery/testsuite/tab.xml.in, gnu/xquery/testsuite/tab.xml)
AC_LINK_FILES(gnu/xquery/testsuite/bib.xml.in, gnu/xquery/testsuite/bib.xml)
AC_LINK_FILES(gnu/xquery/testsuite/book1.xml.in, gnu/xquery/testsuite/book1.xml)
AC_LINK_FILES(gnu/xquery/testsuite/reviews.xml.in, gnu/xquery/testsuite/reviews.xml)
AC_LINK_FILES(gnu/xquery/testsuite/items.xml.in, gnu/xquery/testsuite/items.xml)
AC_LINK_FILES(gnu/xquery/testsuite/bids.xml.in, gnu/xquery/testsuite/bids.xml)
AC_LINK_FILES(gnu/xquery/testsuite/users.xml.in, gnu/xquery/testsuite/users.xml)
AC_LINK_FILES(testsuite/scribble.html.in, testsuite/scribble.html)

AC_OUTPUT(Makefile gnu/Makefile gnu/bytecode/Makefile gnu/math/Makefile
  gnu/lists/Makefile gnu/text/Makefile gnu/mapping/Makefile gnu/expr/Makefile
  gnu/kawa/Makefile gnu/kawa/util/Makefile gnu/kawa/reflect/Makefile 
  gnu/kawa/functions/Makefile gnu/kawa/servlet/Makefile
  gnu/xml/Makefile gnu/kawa/xml/Makefile
  gnu/kawa/xslt/Makefile gnu/kawa/sax/Makefile
  gnu/brl/Makefile gnu/kawa/brl/Makefile
  gnu/kawa/lispexpr/Makefile gnu/kawa/slib/Makefile gnu/ecmascript/Makefile
  gnu/commonlisp/Makefile gnu/commonlisp/lang/Makefile
  gnu/commonlisp/lisp/Makefile gnu/commonlisp/testsuite/Makefile
  gnu/jemacs/Makefile gnu/jemacs/lang/Makefile gnu/jemacs/buffer/Makefile
  gnu/jemacs/lisp/Makefile gnu/jemacs/testsuite/Makefile
  gnu/jemacs/swing/Makefile
  kawa/Makefile kawa/lang/Makefile kawa/standard/Makefile kawa/lib/Makefile
  gnu/xquery/Makefile gnu/xquery/lang/Makefile
  gnu/xquery/util/Makefile gnu/xquery/testsuite/Makefile
  gnu/kawa/ant/Makefile
  doc/Makefile testsuite/Makefile bin/Makefile)
