dnl Process this with autoconf to create configure
AC_INIT([kawa],[1.7.91]) dnl Also update build.xml.
AC_CONFIG_SRCDIR([doc/kawa.texi])

AM_MAINTAINER_MODE
AC_CANONICAL_TARGET([])

AM_INIT_AUTOMAKE

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,
  AS_HELP_STRING(--with-gcj,Compile Kawa using GCJ (GNU Compiler for Java)))

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

AC_ARG_WITH(servlet,
  AS_HELP_STRING(--with-servlet@<:@=servlet-api.jar@:>@,Build support for generating servlets),
  with_servlet=$withval, with_servlet=no)

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

AC_ARG_WITH(swt,
  AS_HELP_STRING(--with-swt,Assume SWT is available))

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

AC_ARG_WITH(sax2,
  AS_HELP_STRING(--with-sax2,Assume SAX2 is available))

AC_ARG_WITH(java-source,
  AS_HELP_STRING(--with-java-source=NUM,Assume functionality of given Java/JDK version))

case "/${with_java_source}/" in
  /1/) JAVA_SOURCE=1 ;;
  /2/) JAVA_SOURCE=2 ;;
  /5/) JAVA_SOURCE=5 ;;
  /1.1*/) JAVA_SOURCE=1 ;;
  /1.2*/) JAVA_SOURCE=2 ;;
  /1.3*/) JAVA_SOURCE=2 ;;
  /1.4*/) JAVA_SOURCE=2 ;;
  //) JAVA_SOURCE=2 ;;
  /*/) AC_MSG_ERROR([Invalid version for --with-java-version.
  (Must be 1, 2, 5, or a JDK version such as 1.4.)]) ;;
esac
AC_SUBST(JAVA_SOURCE)

AC_PROG_INSTALL
AC_PROG_LN_S

AC_EXEEXT
AC_OBJEXT

AC_PROG_CC
AC_PROG_CXX

TOP_BUILDDIR=`pwd`

LT_INIT

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

# Partly for compatibility (--enable/--disable-servlet was the old option);
# partly to allow --with-servlet=path-to-jar 0--disable-servlet.
# we essentially default enable-servlet to with-servlet. But we don't
# want to clutter up configure --help with --enable-servlet.
enable_servlet=${enable_servlet-${with_servlet}}

AM_CONDITIONAL(WITH_GCJ, test "$with_gcj" = "yes")
AM_CONDITIONAL(ENABLE_XML, test "$enable_xml" = "yes")
AM_CONDITIONAL(ENABLE_SERVLET,
  test "$enable_servlet" != "" -a "$enable_servlet" != "no")
AM_CONDITIONAL(WITH_SWING, test "$with_swing" = "yes")
AM_CONDITIONAL(WITH_SWT, test "$with_swt" = "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/'`
BYTECODE_VERSION="$VERSION"

pathsep=':'
filesep='/'

case ${with_servlet} in
  yes) ;;
  no) ;;
  "") ;;
  *) conf_classpath=${with_servlet}${pathsep}$conf_classpath ;;
esac

AC_SUBST(conf_classpath)
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(BYTECODE_VERSION)
AC_SUBST(SHELL)
Make_rules="$srcdir/Make-rules"
AC_SUBST_FILE(Make_rules)
AC_CONFIG_LINKS(
  gnu/xquery/testsuite/outline.xml:gnu/xquery/testsuite/outline.xml.in
  gnu/xquery/testsuite/tab.xml:gnu/xquery/testsuite/tab.xml.in
  gnu/xquery/testsuite/bib.xml:gnu/xquery/testsuite/bib.xml.in
  gnu/xquery/testsuite/auction.xml:gnu/xquery/testsuite/auction.xml.in
  gnu/xquery/testsuite/book1.xml:gnu/xquery/testsuite/book1.xml.in
  gnu/xquery/testsuite/report1.xml:gnu/xquery/testsuite/report1.xml.in
  gnu/xquery/testsuite/reviews.xml:gnu/xquery/testsuite/reviews.xml.in
  gnu/xquery/testsuite/items.xml:gnu/xquery/testsuite/items.xml.in
  gnu/xquery/testsuite/bids.xml:gnu/xquery/testsuite/bids.xml.in
  gnu/xquery/testsuite/users.xml:gnu/xquery/testsuite/users.xml.in
  testsuite/scribble.html:testsuite/scribble.html.in)

AC_CONFIG_FILES([Makefile gnu/bytecode/Makefile gnu/math/Makefile
  gnu/lists/Makefile gnu/text/Makefile gnu/mapping/Makefile gnu/expr/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 gnu/jemacs/swt/Makefile
  kawa/Makefile kawa/lang/Makefile kawa/standard/Makefile kawa/lib/Makefile
  gnu/q2/Makefile gnu/q2/lang/Makefile
  gnu/xquery/Makefile gnu/xquery/lang/Makefile
  gnu/xquery/util/Makefile gnu/xquery/testsuite/Makefile
  gnu/kawa/ant/Makefile
  gnu/kawa/models/Makefile gnu/kawa/swingviews/Makefile
  doc/Makefile testsuite/Makefile bin/Makefile])
AC_OUTPUT
