dnl
dnl Process this file with autoconf to produce a configure script.
dnl Autoconf script for Amaya and Thot.
dnl Daniel Veillard and Irene Vatton, 1997
dnl

dnl  ***************************************************************
dnl
dnl    GENERIC AUTOCONF STUFF : GUESS INFORMATIONS ON SYSTEM SETUP
dnl
dnl  ***************************************************************

AC_PREREQ(2.2)
AC_INIT(thotlib/internals/h/constpiv.h)
AC_REVISION

dnl
dnl Checks for platform information
dnl

AC_CANONICAL_SYSTEM
AC_CONFIG_HEADER(config.h)

dnl
dnl Initializing Automake
dnl

AC_PROG_MAKE_SET
AC_ARG_PROGRAM

dnl
dnl Checks for programs.
dnl

AC_PROG_YACC
AC_PROG_CC
AC_PROG_CPP
AC_PROG_LEX
AC_PROG_AWK
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PATH_PROG(CP, cp, /bin/cp, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(MV, mv, /bin/mv, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(RM, rm, /bin/rm, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(MKDIR, mkdir, /bin/mkdir, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(ECHO, echo, /bin/echo, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(CAT, cat, /bin/cat, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(CHMOD, chmod, /bin/chmod, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(SED, sed, /bin/sed, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(AR, ar, /usr/bin/ar, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(DIFF, diff, /usr/bin/diff, $PATH:/bin:/usr/bin:/usr/ucb/bin)

dnl
dnl Checks for libraries.
dnl

AC_CHECK_LIB(socket, socket, )
AC_CHECK_LIB(inet, connect)
AC_CHECK_LIB(nsl, t_accept)
AC_CHECK_LIB(dl, dlopen)
AC_PATH_X
AC_PATH_XTRA

dnl
dnl Checks for header files.
dnl

AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT

AC_CHECK_HEADERS(stdio.h)
AC_CHECK_HEADERS(sys/types.h types.h)
AC_CHECK_HEADERS(sys/unistd.h unistd.h)
AC_CHECK_HEADERS(sys/fcntl.h fcntl.h)
AC_CHECK_HEADERS(sys/limits.h limits.h)
AC_CHECK_HEADERS(sys/stat.h stat.h)
AC_CHECK_HEADERS(sys/file.h)
AC_CHECK_HEADERS(sys/ioctl.h)
AC_CHECK_HEADERS(sys/time.h time.h)
AC_CHECK_HEADERS(sys/systeminfo.h)
AC_CHECK_HEADERS(string.h strings.h)
AC_CHECK_HEADERS(syslog.h)
AC_CHECK_HEADERS(sys/socket.h socket.h)
AC_CHECK_HEADERS(appkit/appkit.h appkit.h)
AC_CHECK_HEADERS(netinet/in.h in.h)
AC_CHECK_HEADERS(dn.h)
AC_CHECK_HEADERS(sys/ipc.h)
AC_CHECK_HEADERS(net/errno.h sys/errno.h errno.h)
AC_CHECK_HEADERS(pwd.h)
AC_CHECK_HEADERS(grp.h)
AC_CHECK_HEADERS(arpa/inet.h inet.h)
AC_CHECK_HEADERS(netdb.h)
AC_CHECK_HEADERS(manifest.h)
AC_CHECK_HEADERS(bsdtypes.h)
AC_CHECK_HEADERS(stdefs.h)
AC_CHECK_HEADERS(bsdtime.h)
AC_CHECK_HEADERS(sys/select.h select.h)
AC_CHECK_HEADERS(dnetdb.h)
AC_CHECK_HEADERS(libc.h)
AC_CHECK_HEADERS(stdlib.h)
AC_CHECK_HEADERS(malloc.h)
AC_CHECK_HEADERS(memory.h)
AC_CHECK_HEADERS(unixlib.h)
AC_CHECK_HEADERS(ctype.h)
AC_CHECK_HEADERS(cursesX.h curses.h)
AC_CHECK_HEADERS(sys/resource.h resource.h)
AC_HEADER_DIRENT
AC_CHECK_HEADERS(dir.h direct.h) dnl AC_HEADER_DIRENT only checks for some..
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_HEADER_TIME
AC_HEADER_STAT

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

AC_C_CONST
AC_C_INLINE
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
AC_STRUCT_TIMEZONE
AC_TYPE_UID_T

dnl
dnl Checks for library functions.
dnl

AC_FUNC_ALLOCA
AC_TYPE_GETGROUPS
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MEMCMP
AC_FUNC_MMAP
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(getcwd gethostname gettimeofday getwd mkdir mktime putenv select socket strdup strerror strftime strstr strtod strtol uname)

dnl
dnl Checking for Motif libraries and includes
dnl
dnl Borrowed from Lesstif configure.in
dnl Lesstif is a Great Project (TM)
dnl

AC_DEFUN(AC_PATH_MOTIF_DIRECT,
[test -z "$motif_direct_test_library" && motif_direct_test_library=Xm
test -z "$motif_direct_test_function" && motif_direct_test_function=XmCreatePushButton
test -z "$motif_direct_test_include" && motif_direct_test_include=Xm/Xm.h
  for ac_dir in               \
    /usr/include/Motif1.2     \
    /usr/Motif1.2/include     \
                              \
    /usr/motif/include        \
                              \
    /usr/X11R6/include        \
    /usr/X11R5/include        \
                              \
    /usr/include/X11R6        \
    /usr/include/X11R5        \
                              \
    /usr/local/X11R6/include  \
    /usr/local/X11R5/include  \
                              \
    /usr/local/include/X11R6  \
    /usr/local/include/X11R5  \
                              \
    /usr/X11/include          \
    /usr/include/X11          \
    /usr/local/X11/include    \
    /usr/local/include/X11    \
                              \
    /usr/X386/include         \
    /usr/x386/include         \
    /usr/XFree86/include/X11  \
                              \
    /usr/dt/include           \
                              \
    /usr/include              \
    /usr/local/include        \
    /usr/unsupported/include  \
    /usr/athena/include       \
    /usr/local/x11r5/include  \
    /usr/lpp/Xamples/include  \
                              \
    /usr/lesstif/include      \
    /usr/local/lesstif/include\
    /usr/gnu/lesstif/include  \
    $HOME/lesstif/include     \
    ; \
  do
    if test -r "$ac_dir/$motif_direct_test_include"; then
      no_motif= ac_motif_includes=$ac_dir
      break
    fi
  done

# Check for the libraries.
# See if we find them without any special options.
# Don't add to $LIBS permanently.
ac_save_LIBS="$LIBS"
LIBS="-l$motif_direct_test_library $LIBS"
# First see if replacing the include by lib works.
for ac_dir in `echo "$ac_motif_includes" | sed s/include/lib/` \
    /usr/lib/Motif1.2     \
    /usr/Motif1.2/lib     \
                          \
    /usr/motif/lib        \
                          \
    /usr/X11R6/lib        \
    /usr/X11R5/lib        \
                          \
    /usr/lib/X11R6        \
    /usr/lib/X11R5        \
                          \
    /usr/local/X11R6/lib  \
    /usr/local/X11R5/lib  \
                          \
    /usr/local/lib/X11R6  \
    /usr/local/lib/X11R5  \
                          \
    /usr/X11/lib          \
    /usr/lib/X11          \
    /usr/local/X11/lib    \
                          \
    /usr/X386/lib         \
    /usr/x386/lib         \
    /usr/XFree86/lib/X11  \
                          \
    /usr/lib              \
    /usr/local/lib        \
    /usr/unsupported/lib  \
    /usr/athena/lib       \
    /usr/local/x11r5/lib  \
    /usr/lpp/Xamples/lib  \
                          \
    /usr/lesstif/lib      \
    /usr/local/lesstif/lib\
    /usr/gnu/lesstif/lib  \
    $HOME/lesstif/lib     \
    ; \
do
  for ac_extension in a so sl; do
    if test -r $ac_dir/lib${motif_direct_test_library}.$ac_extension; then
      no_motif= ac_motif_libraries=$ac_dir
      break 2
    fi
  done
done
LIBS="$ac_save_LIBS"
])

AC_DEFUN(AC_PATH_MOTIF,
[AC_REQUIRE_CPP()dnl

motif_includes=NONE
motif_libraries=NONE

AC_MSG_CHECKING(for Motif)
AC_ARG_WITH(motif, [  --with-motif            enable Motif tests])
if test "x$with_motif" = xno; then
  no_motif=yes
else
  if test "x$motif_includes" != xNONE && test "x$motif_libraries" != xNONE; then
    no_motif=
  else
AC_CACHE_VAL(ac_cv_path_motif,
[# One or both of these vars are not set, and there is no cached value.
no_motif=yes
AC_PATH_MOTIF_DIRECT

if test "$no_motif" = yes; then
  ac_cv_path_motif="no_motif=yes"
else
  ac_cv_path_motif="no_motif= ac_motif_includes=$ac_motif_includes ac_motif_libraries=$ac_motif_libraries"
fi])dnl
  fi
  eval "$ac_cv_path_motif"
fi # with_motif != no

if test "$no_motif" = yes; then
  AC_MSG_RESULT(no)
  MOTIF_INCLUDES=
  MOTIF_LIBRARIES=
else
  test "x$motif_includes" = xNONE && motif_includes=$ac_motif_includes
  test "x$motif_libraries" = xNONE && motif_libraries=$ac_motif_libraries
  ac_cv_path_motif="no_motif= ac_motif_includes=$motif_includes ac_motif_libraries=$motif_libraries"
  AC_MSG_RESULT([libraries $motif_libraries, headers $motif_includes])
  if test "$motif_includes" != "/usr/include" ; then
    MOTIF_INCLUDES="-I$motif_includes"
  fi
  if test "$motif_libraries" != "/usr/lib" ; then
    MOTIF_LIBRARIES="-L$motif_libraries"
    case "${host}" in
        *-*sun-solaris* )
         MOTIF_LIBRARIES="${MOTIF_LIBRARIES} -R$motif_libraries"
        ;;
    esac    
  fi
fi
AC_SUBST(MOTIF_INCLUDES)
AC_SUBST(MOTIF_LIBRARIES)
])

AC_PATH_MOTIF

dnl  ***************************************************************
dnl
dnl    SPECIFIC STUFF : CONFIGURATION OPTIONS FOR THOT AND AMAYA
dnl
dnl  ***************************************************************

THOT_VER="2.1d"
AMAYA_VER="1.1c"
KAFFE_VER="0.9.2"
LIBWWW_VER="5.0a"

dnl
dnl We use a special versoin of cextract patched for alignment
dnl to build the signatures of the modules functions located in f subdirs
dnl
CEXTRACT_VER="1.7"
CEXTRACT_FLAGS="+O"

dnl
dnl Check when building with Insure from Parasoft
dnl

AC_ARG_WITH(insure, [  --with-insure           Uses Insure Parasoft debugger])
if test "$with_insure" = "yes" ; then
    CC=insight
fi

dnl
dnl Adjust the some variables depending on the host and compiler
dnl Thot NEED signed chars !!!
dnl

KAFFE_ENGINE=""
if test "${CC}" = "gcc" ; then
  CFLAGS="${CFLAGS} -Wall "
  case "${host}" in
      *-*-irix5* | *-*irix6* )
         CFLAGS="${CFLAGS} -fsigned-char"
      ;;
  esac
fi

if test "$ac_cv_c_const" = "no" ; then
  CFLAGS="${CFLAGS} -DCONST= "
fi

dnl
dnl Check for availability of amaya and thot editor sources
dnl

AC_ARG_WITH(thot, [  --with-thot             Build the Thot editor])
AC_ARG_WITH(amaya, [  --with-amaya            Build the Amaya HTML browser/editor])

build_thot="yes"
build_amaya="yes"

if test "$with_thot" = "no" ; then
    build_thot="no"
fi
if test "$with_amaya" = "no" ; then
    build_amaya="no"
fi

if test ! -f $srcdir/thot/Makefile.in ; then
    AC_MSG_WARN(Thot editor sources not found, disabling Thot build !)
    build_thot="no"
fi
   
if test ! -f $srcdir/amaya/Makefile.in ; then
    AC_MSG_WARN(Amaya browser/editor sources not found, disabling Amaya build !)
    build_amaya="no"
fi

dnl
dnl Check for external, Thot related programs
dnl

build_misc="no"
if test "$build_thot" = "yes" ;  then
    if test -f $srcdir/misc/Makefile.in ; then
	build_misc="yes"
	build_annotations="no"
	if test -f $srcdir/misc/annotations/Makefile.in ; then
	    build_annotations="yes"
	fi
	if test -f $srcdir/misc/util/Makefile.in ; then
	    build_util="yes"
	    build_tableaux="no"
	    build_transform="no"
	    build_versions="no"
	    if test -f $srcdir/misc/util/tableaux/Makefile.in ; then
		build_tableaux="yes"
	    fi
	    if test -f $srcdir/misc/util/transform/Makefile.in ; then
		build_transform="yes"
	    fi
	    if test -f $srcdir/misc/util/versions/Makefile.in ; then
		build_versions="yes"
	    fi
	fi
    fi
fi

dnl
dnl Check for additionnal packages kaffe-xxx or libwww
dnl use AC_CONFIG_SUBDIRS to launch configure in the subdir
dnl

AC_ARG_ENABLE(java, [  --enable-java           Add Kaffe Java virtual machine])
AC_ARG_ENABLE(javaawt, [  --enable-java-awt       Add Kaffe Java Biss AWT])
AC_ARG_ENABLE(intr, [  --enable-intr           Use Kaffe Java Interpreter])
AC_ARG_ENABLE(jit, [  --enable-jit             Use Kaffe Java JIT Compiler])
AC_ARG_ENABLE(plugin, [  --enable-plugin       Add Netscape Plug-Ins support])
AC_ARG_ENABLE(math, [  --enable-math             Add Math support ])
AC_ARG_ENABLE(ilu, [  --enable-ilu            Add ILU support])

dnl
dnl Check for the Kaffe engine to use : interpreter or JIT
dnl

with_java=""
if test "$enable_intr" = "yes" ; then
    with_java="yes"
    KAFFE_ENGINE="--with-engine=intrp"
fi
if test "$enable_intr" = "no" ; then
    with_java="yes"
    KAFFE_ENGINE="--with-engine=jit"
fi
if test "$enable_jit" = "yes" ; then
    with_java="yes"
    KAFFE_ENGINE="--with-engine=jit"
fi
if test "$enable_jit" = "no" ; then
    with_java="yes"
    KAFFE_ENGINE="--with-engine=intr"
fi


dnl
dnl java is disabled by default
dnl

if test "$enable_java" = "yes" ; then
    with_java="yes"
fi

dnl
dnl if java, java-awt is enabled by default
dnl

if test "$enable_javaawt" = "no" ; then
    java_awt_option="-DJAVA_NO_AWT"
else
    java_awt_option=""
fi

dnl
dnl plugins support is disabled by default
dnl

if test "$with_plugin" = "" ; then
  if test "$enable_plugin" = "yes" ; then
    with_plugin="yes"
  else
    with_plugin="no"
  fi
fi  

dnl
dnl math is enabled by default
dnl
if test "$with_math" = "" ; then
    if test "$enable_math" = "no" ; then
	with_math="no"
    else
	with_math="yes"
    fi
fi

dnl
dnl ilu is disabled by default
dnl
if test "$with_ilu" = "" ; then
    if test "$enable_ilu" = "yes" ; then
	with_ilu="yes"
    else
	with_ilu="no"
    fi
fi

dnl
dnl Checking for ilu
dnl

ILUHOME=""
if test "$with_ilu" = "yes" ; then
    dnl
    dnl try to get first the path for the c-stubber
    dnl
    AC_PATH_PROG(CSTUBBER, c-stubber, c-stubber, $PATH:$ILUHOME/bin:/bin:/usr/bin:/usr/ucb/bin:/usr/ilu/bin:/usr/local/bin:/usr/local/ilu/bin:/opt/ilu/bin:$HOME/ilu/bin)
    case "$CSTUBBER" in
        /*/bin/c-stubber) 
	    ILU_BINARIES=`dirname $CSTUBBER`
	    ILUHOME=`dirname $ILU_BINARIES`
	    ILU_LIBRARIES=$ILUHOME/lib
	    ILU_INCLUDES=$ILUHOME/include
	    ;;
        /*/c-stubber) 
	    ILU_BINARIES=`dirname $CSTUBBER`
	    ILUHOME=`dirname $ILU_BINARIES`
	    ILU_LIBRARIES=$ILUHOME/lib
	    ILU_INCLUDES=$ILUHOME/include
	    ;;
    esac
    if test "$CSTUBBER" = "" -o "$CSTUBBER" = "c-stubber" ; then
	AC_MSG_WARN(ILU c-stubber binary not found, ILU disabled !)
	with_ilu="no"
    fi
fi

if test "$build_amaya" = "yes" ; then

    if test ! -f $srcdir/kaffe-$KAFFE_VER/Makefile.in ; then
	if test "$with_java" = "yes" ; then
	    AC_MSG_WARN(kaffe-$KAFFE_VER sources not found, disabling Java !)
	    with_java="no"
	fi
    fi

    if test "$with_java" = "yes" ; then
	#
	# Verify that Java code is available.
	# Look first for thotlib, amaya and jigsaw classes source code
	#
	if test -f $srcdir/classes/org/w3c/thotlib/Element.java -a \
		-f $srcdir/classes/org/w3c/amaya/amayaInit.java -a \
		-f $srcdir/classes/org/w3c/www/protocol/http/HttpURLConnection.java \
		; then
	    with_java_sources="yes"
	else
	    with_java_sources="no"
	fi 
	#
	# Verify that BISS AWT implemetation is available.
	#
	if test -f $srcdir/kaffe-$KAFFE_VER/packages/biss-net.com/APIawt/classes/biss.zip ; then
	    java_awt_option="$java_awt_option"
	else
	    java_awt_option="$java_awt_option -DJAVA_NO_AWT"
	fi 
	#
	# Then check for precompiled classes packages.
	#
	if test -f $srcdir/classes/thotlib.zip -a \
		-f $srcdir/classes/amaya.zip -a \
		-f $srcdir/classes/jigsaw.zip \
		; then
	    with_java_package="yes"
	else
	    with_java_package="no"
	fi 

	#
	# At least one of both should be available.
	#
	if test "$with_java_sources" = "no" -a "$with_java_package" = "no"
	then
	    AC_MSG_WARN(Amaya Java classes not found : disabling Java!)
            with_java="no"
	fi
    fi

    if test ! -f $srcdir/w3c-libwww-$LIBWWW_VER/Makefile.in ; then
	if test "$with_java" = "no" -a "$with_ilu" = "no" ; then
	    AC_MSG_WARN(w3c-libwww-$LIBWWW_VER sources not found !!)
	    AC_MSG_WARN(Disabling Amaya build !)
	    build_amaya="no"
	fi
    fi

    if test ! -f $srcdir/amaya/MathML.S ; then
	if test "$with_math" = "yes" ; then
	    AC_MSG_WARN(MathML sources not found !!)
	    AC_MSG_WARN(Disabling MATH build !)
	    with_math="no"
	    MATH_OPTIONS=
	fi
    fi
    if test "$with_java" = "yes" -a "$with_ilu" = "yes" ; then
        java_ilu_option="-DWITH_ILU"
        ilu_java_option="-DWITH_JAVA"
    fi
fi

dnl
dnl The options for each library or binary
dnl

THOT_OPTIONS=
AMAYA_OPTIONS="-DCOUGAR" $MATH_OPTIONS
PLUGIN_OPTIONS="-DPLUGIN_TRACE -DXP_UNIX"
dnl JAVA_OPTIONS="-DDEBUG_KAFFE -DDEBUG_LOCK -DDEBUG_SELECT -DDEBUG_SELECT_CHANNELS -DDEBUG_TIMING -DSYNC_DNS"
JAVA_OPTIONS="$java_ilu_option $java_awt_option"
ANNOTATIONS_OPTIONS=
IMGLIBS="-ljpeg -lpng -lz"
EXTRA_LIBS=

ILU_OPTIONS="$ilu_java_option"
ILU_INCLUDES=
ILU_LIBRARIES=

dnl
dnl Set up the PATHs needed
dnl

API="\$(THOTDIR)/thotlib/include"
VAR="\$(THOTDIR)/thotlib/internals/var"
INCL="\$(THOTDIR)/thotlib/internals/h"
FUNC="\$(THOTDIR)/thotlib/internals/f"
SCHEMAS="\$(THOTDIR)/schemas"
SCHEMASOPERA="\$(THOTDIR)/schemasOPERA"
JPEGINCL="-I\$(THOTDIR)/libjpeg"
PNGINCL="-I\$(THOTDIR)/libpng -I\$(THOTDIR)/libpng/zlib"

dnl
dnl Set up the include variables.
dnl

THOTINCLUDES="-I$API -I$VAR -I$INCL -I$FUNC -I$SCHEMAS -I$SCHEMASOPERA $JPEGINCL $PNGINCL"
APIINCLUDES=-I$API 
if test "$VPATHOPT" = "" ; then
	VPATHOPT="VPATH"
fi

dnl
dnl Exports the current values of the variables.
dnl

AC_SUBST(THOT_VER)
AC_SUBST(AMAYA_VER)
AC_SUBST(LIBWWW_VER)
AC_SUBST(KAFFE_VER)
AC_SUBST(CEXTRACT_VER)
AC_SUBST(CEXTRACT_FLAGS)

AC_SUBST(KAFFE_ENGINE)

AC_SUBST(THOTINCLUDES)
AC_SUBST(APIINCLUDES)
AC_SUBST(VPATHOPT)

AC_SUBST(THOT_OPTIONS)
AC_SUBST(AMAYA_OPTIONS)
AC_SUBST(PLUGIN_OPTIONS)
AC_SUBST(JAVA_OPTIONS)
AC_SUBST(ANNOTATIONS_OPTIONS)
AC_SUBST(IMGLIBS)
AC_SUBST(EXTRA_LIBS)

AC_SUBST(ILUHOME)
AC_SUBST(ILU_OPTIONS)
AC_SUBST(ILU_INCLUDES)
AC_SUBST(ILU_LIBRARIES)

dnl
dnl Include the option Makefile.xxx fragment for plugin and or Java options
dnl

if test "$with_plugin" = "yes" ; then
    AC_SUBST_FILE(plugin_frag)dnl
    plugin_frag=$srcdir/pluginlib/Makefile.plugin
else
    AC_SUBST_FILE(plugin_frag)
    plugin_frag=/dev/null
fi

if test "$with_java" = "yes" ; then
    AC_SUBST_FILE(java_frag)
    java_frag=$srcdir/javalib/Makefile.java
    AC_SUBST_FILE(www_frag)
    www_frag=/dev/null
    if test "$with_java_sources" = "yes" ; then
	AC_SUBST_FILE(javasrc_frag)
	javasrc_frag=$srcdir/javalib/Makefile.javasrc
	AC_SUBST_FILE(javanosrc_frag)
	javanosrc_frag=/dev/null
    else
	AC_SUBST_FILE(javasrc_frag)
	javasrc_frag=/dev/null
	AC_SUBST_FILE(javanosrc_frag)
	javanosrc_frag=$srcdir/javalib/Makefile.javanosrc
    fi
else if test "$with_ilu" = "yes" ; then
    AC_SUBST_FILE(java_frag)
    java_frag=/dev/null
    AC_SUBST_FILE(www_frag)
    www_frag=/dev/null
else
    AC_SUBST_FILE(java_frag)
    java_frag=/dev/null
    AC_SUBST_FILE(www_frag)dnl
    www_frag=$srcdir/amaya/Makefile.libwww
fi
fi

if test "$with_math" = "yes" ; then
    AC_SUBST_FILE(math_frag)
    math_frag=$srcdir/amaya/Makefile.math
else
    AC_SUBST_FILE(math_frag)
    math_frag=/dev/null
fi

if test "$with_ilu" = "yes" ; then
    AC_SUBST_FILE(ilu_frag)
    ilu_frag=$srcdir/ilulib/Makefile.ilu
else
    AC_SUBST_FILE(ilu_frag)
    ilu_frag=/dev/null
fi

dnl  ***************************************************************
dnl
dnl      FINAL STEP : PRODUCE ALL THE MAKEFILES AND CONFIG FILES
dnl
dnl  ***************************************************************

EXTRA_MAKEFILE_IN=
make_output="Makefile Options.orig:Options.in tools/Makefile \
       libjpeg/Makefile libpng/Makefile libpng/zlib/Makefile \
       tools/mkdep/Makefile \
       tools/cextract-1.7/Makefile thotlib/Makefile \
       thotlib/include/Makefile batch/Makefile tablelib/Makefile"

if test "$build_amaya" = "yes" ; then

    make_output="$make_output amaya/Makefile pluginlib/Makefile"
    EXTRA_MAKEFILE_IN="$srcdir/amaya/Makefile.in \
$srcdir/amaya/Makefile.libwww \
$srcdir/pluginlib/Makefile.in \
$srcdir/pluginlib/Makefile.plugin"

    if test "$with_java" = "yes" ; then
       make_output="$make_output tools/javastub/Makefile \
tools/dns_daemon/Makefile javalib/Makefile"
       EXTRA_MAKEFILE_IN="$srcdir/tools/javastub/Makefile.in \
$srcdir/tools/dns_daemon/Makefile.in \
$srcdir/javalib/Makefile.in"
    fi

    if test "$with_ilu" = "yes" ; then
       make_output="$make_output ilulib/Makefile tools/ilustub/Makefile"
       EXTRA_MAKEFILE_IN="$srcdir/ilulib/Makefile.in \
$srcdir/ilulib/Makefile.ilu \
$srcdir/tools/ilustub/Makefile.in"
    fi
fi

if test "$build_thot" = "yes" ; then

    make_output="$make_output thot/Makefile \
drawlib/Makefile indexlib/Makefile"
    EXTRA_MAKEFILE_IN="$EXTRA_MAKEFILE_IN \
$srcdir/thot/Makefile.in \
$srcdir/drawlib/Makefile.in \
$srcdir/indexlib/Makefile.in"

    if test "$build_misc" = "yes" ; then

	make_output="$make_output misc/Makefile"
	EXTRA_MAKEFILE_IN="$EXTRA_MAKEFILE_IN \
$srcdir/misc/Makefile.in"

	if test "$build_annotations" = "yes" ; then
	    make_output="$make_output misc/annotations/Makefile"
	    EXTRA_MAKEFILE_IN="$EXTRA_MAKEFILE_IN \
$srcdir/misc/annotations/Makefile.in"
	fi

	if test "$build_util" = "yes" ; then

	    make_output="$make_output misc/util/Makefile"
	    EXTRA_MAKEFILE_IN="$EXTRA_MAKEFILE_IN \
$srcdir/misc/util/Makefile.in"

	    if test "$build_tableaux" = "yes" ; then

		make_output="$make_output misc/util/tableaux/Makefile"
		EXTRA_MAKEFILE_IN="$EXTRA_MAKEFILE_IN \
$srcdir/misc/util/tableaux/Makefile.in"

	    fi
	    if test "$build_transform" = "yes" ; then

		make_output="$make_output misc/util/transform/Makefile"
		EXTRA_MAKEFILE_IN="$EXTRA_MAKEFILE_IN \
$srcdir/misc/util/transform/Makefile.in"

	    fi
	    if test "$build_versions" = "yes" ; then

		make_output="$make_output misc/util/versions/Makefile"
		EXTRA_MAKEFILE_IN="$EXTRA_MAKEFILE_IN \
$srcdir/misc/util/versions/Makefile.in"

	    fi
	fi
    fi
fi

AC_SUBST(EXTRA_MAKEFILE_IN)
AC_OUTPUT($make_output , [
dnl
dnl This fragment of shell code is executed after the
dnl Makefile(s) dump ...
dnl

echo timestamp > stamp-h

dnl
dnl Check for an upgrade in the Options numbers
dnl

if test -f Options ; then
   oldversion=`grep Version Options`
   newversion=`grep Version Options.orig`
   if test "$oldversion" != "$newversion" ; then
       echo WARNING : Options files have changed, old options saved to Options.old
       cp Options Options.old
       cp Options.orig Options
       exit 1
   fi
fi
])

if test "$build_thot" = "yes" ; then
    if test "$build_amaya" = "yes" ; then
	echo Amaya and Thot packages are now configured
    else
	echo Thot package is now configured
    fi
else
    if test "$build_amaya" = "yes" ; then
	echo Amaya package is now configured
    else
	echo Nor Amaya nor Thot package found, get the corresponding archive
    fi

fi

if test "$build_amaya" = "yes" ; then
    if test "$with_java" = "yes" -a "$with_plugin" = "yes" ; then
        AC_MSG_WARN(Amaya configured with both Java and Plugins support)
dnl        AC_MSG_WARN(Beware this combination doesn't work well)
    else
	if test "$with_java" = "yes" ; then
	    if test "$KAFFE_ENGINE" = "--with-engine=jit" ;  then
	       echo Amaya configured with Java JIT support
	    else
	        if test "$KAFFE_ENGINE" = "--with-engine=intr" ;  then
		    echo Amaya configured with Java interpreter support
	        else
		    echo Amaya configured with Java support
		fi
            fi
	    echo Using kaffe-$KAFFE_VER Java virtual machine
	else if test "$with_ilu" = "no" ; then
	    echo Amaya configured with libWWW
	fi
	fi
	if test "$with_plugin" = "yes" ; then
	    echo Amaya configured with Plugins support
	fi
    fi
    if test "$with_math" = "yes" ; then
	echo Amaya configured with Math support
    fi
    if test "$with_ilu" = "yes" ; then
	echo Amaya configured with ILU support
    fi
fi

if test "$no_motif" = yes ; then
    echo "Motif seems not installed on this machine"
    echo "Thot and Amaya need Motif 1.2 or 2.0"
    echo "Thot and Amaya probably won't compile"
else
if test "$motif_includes" = "" ; then
    echo "Motif includes were not found"
    echo "Thot and Amaya might not compile"
    echo "Edit your Option file"
else
if test "$motif_libraries" = "" ; then
    echo "Motif libraries were not found"
    echo "Thot and Amaya might not compile"
    echo "Edit your Option file"
fi
fi
fi

echo "Now start \"make all\" (GNU make preferably) to build the binaries"

