dnl
dnl  configure.in
dnl
AC_REVISION($Id: configure.in,v 1.8.4.2.2.14 2003/04/18 19:54:53 icastle Exp $)
dnl
dnl  Process this file with autoconf to produce a configure script.
dnl
dnl  Copyright (C) 1998 Cees A. de Groot
dnl

dnl
dnl  Credits: this autoconf script was largely "inspired" <g> by the
dnl  autoconf script around SP made by Henry Thompson.
dnl
AC_INIT(dsssl)
AC_CONFIG_AUX_DIR(config)
AM_INIT_AUTOMAKE( openjade, 1.3.3-pre1)
TOP=`pwd`
AC_SUBST(TOP)
dnl
dnl Location of OpenSP include files
dnl
AC_MSG_CHECKING(location of OpenSP include files)
AC_ARG_ENABLE(spincludedir,
[  --enable-spincludedir=pathlist
	location of OpenSP include files],
	[if test $enableval
	 then
           AC_MSG_RESULT($enableval)
           SPINCLUDEDIR="$enableval"
	 else
           for d in ${prefix}/include/OpenSP /usr/local/include/OpenSP \
             /usr/include/OpenSP; do
	     AC_CHECK_FILE($d, [SPINCLUDEDIR="$d"; break])
	   done
         fi],
        [for d in ${prefix}/include/OpenSP /usr/local/include/OpenSP \
           /usr/include/OpenSP; do
	   AC_CHECK_FILE($d, [SPINCLUDEDIR="$d"; break])
	 done])
if test x${SPINCLUDEDIR} = x; then
  AC_MSG_ERROR("OpenSP include files do not exist")
fi
AC_SUBST(SPINCLUDEDIR)

dnl
dnl Location of OpenSP library
dnl
case "${SPINCLUDEDIR}" in
  ${prefix}/include/OpenSP) osplibdir=${prefix}/lib ;;
  /usr/local/include/OpenSP) osplibdir=/usr/local/lib ;;
  *) osplibdir=/usr/lib ;;
esac
# On PPC64 libosp is to be found in /usr/lib64; thus
# fall back to this directory
test -d ${osplibdir}64 && osplibdir=${osplibdir}64
AC_MSG_CHECKING(location of OpenSP Library)
AC_ARG_ENABLE(splibdir,
[  --enable-splibdir=pathlist
	location of OpenSP library],
	[if test $enableval
	 then
           AC_MSG_RESULT($enableval)
           SPLIBDIR="$enableval"
	 else
	   AC_MSG_RESULT($osplibdir)
	   SPLIBDIR=$osplibdir
         fi],
        [ AC_MSG_RESULT($osplibdir)
          SPLIBDIR=$osplibdir])
unset osplibdir

AC_SUBST(SPLIBDIR)

dnl AC_ARG_PROGRAM

AC_CANONICAL_HOST

if test "$CXXFLAGS" = ""; then 
  CXXFLAGS="-O2"
fi

dnl
dnl  Backup original Makefiles, people may want to revert to it if
dnl  configure doesn't work.
dnl
echo 'saving distribution makefiles...'
test ! -f Makefile.dist && test -f Makefile && cp Makefile Makefile.dist
test ! -f Makefile.lib.dist && test -f Makefile.lib && cp Makefile.lib Makefile.lib.dist
test ! -f Makefile.prog.dist && test -f Makefile.prog && cp Makefile.prog Makefile.prog.dist
test ! -f Makefile.comm.dist && test -f Makefile.comm && cp Makefile.comm Makefile.comm.dist

dnl
dnl  Check for programs
dnl
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_CXX
AC_PATH_PROGS(PERL, perl, perl)
test "$INSTALL" = "./config/install-sh -c" && INSTALL=`pwd`"/config/install-sh -c"

dnl
dnl  Stuff special to GNU C++
dnl

case "${host}" in
  *-*-darwin*)
    LINKFLAGS="-no-undefined"
    ;;
  *)
    if test "$GXX"
    then
dnl FIXME these need tests for non-GNU compilers
       AC_CACHE_CHECK(whether GNU C++ supports automatic template instantiation,
              ac_cv_c_gnu_automatic_templates,
                  [AC_EGREP_CPP(yes,[
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 8)
  yes
#endif
                 ],
                    ac_cv_c_gnu_automatic_templates=yes,
                    ac_cv_c_gnu_automatic_templates=no)
                  ])
        if test "$ac_cv_c_gnu_automatic_templates" = yes; then
            AC_DEFINE(SP_DEFINE_TEMPLATES,1,
              [define this to include template definitions in the headers])
        else
            AC_DEFINE(SP_MANUAL_INST,1,
              [define this to compile explicit template instantiations])
            CXXFLAGS="$CXXFLAGS -fno-implicit-templates"
        fi
    fi
    ;;
esac

dnl
dnl  Checks for header files.
dnl
AC_HEADER_STDC
AC_CHECK_HEADERS(limits.h)

dnl
dnl  Checks for typedefs, structures, and compiler characteristics.
dnl
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_STRUCT_ST_BLKSIZE
AC_CACHE_CHECK(for sig_atomic_t in signal.h,
    ac_cv_have_sig_atomic_t,
    [AC_TRY_LINK([#include <signal.h>],sig_atomic_t x;,
	ac_cv_have_sig_atomic_t=yes,
	ac_cv_have_sig_atomic_t=no)])
if test "$ac_cv_have_sig_atomic_t" = "no"
then
    AC_CHECK_TYPE(sig_atomic_t,int)
fi

AC_CHECK_SIZEOF(size_t)
AC_CHECK_SIZEOF(unsigned int)

dnl
dnl  Checks for library functions.
dnl 
dnl AC_CHECK_FUNC(memmove,,LIBOBJS="$LIBOBJS memmove.o")
dnl AC_CHECK_FUNC(strerror,,LIBOBJS="$LIBOBJS strerror.o")
dnl AC_CHECK_FUNC(strtoul,,LIBOBJS="$LIBOBJS strtoul.o")

AC_CHECK_FUNC(setlocale,[AC_DEFINE(SP_HAVE_LOCALE)])
AC_CHECK_FUNC(towupper,[AC_DEFINE(SP_HAVE_WCHAR)])
AC_CHECK_FUNC(gettext,[AC_DEFINE(SP_HAVE_GETTEXT)],
  [AC_CHECK_LIB(intl,gettext,[AC_DEFINE(SP_HAVE_GETTEXT) LIBS="$LIBS -lintl"])])

dnl
dnl Check for thread support.
AC_CHECK_LIB(threads,cthread_fork,LIB_THREADS="-lthreads",LIB_THREADS="")
AC_SUBST(LIB_THREADS)

dnl
dnl Check if type of size_t is unsigned int
dnl
OJ_SIZE_T_IS_UINT

dnl
dnl the following tests require c++, not c; note that if you switch this
dnl earlier, AC_C_CONST will fail, at least
dnl
AC_LANG_CPLUSPLUS

AC_CACHE_CHECK(support for bool,
    ac_cv_typedef_bool,
    [AC_TRY_LINK(,bool x; x=(false | true);,
       	ac_cv_typedef_bool=yes,
	ac_cv_typedef_bool=no)])
if test "$ac_cv_typedef_bool" = "yes"
then
    AC_DEFINE(SP_HAVE_BOOL)
fi

dnl 
dnl  ANSI templates
dnl
AC_CACHE_CHECK(for ANSI template instantiation,
               ac_cv_c_template_ansi,
               [AC_TRY_LINK([
class foo {
};

template<class T> class test {
public:
 T *data();};
template class test<foo>;
],,ac_cv_c_template_ansi=yes,
   ac_cv_c_template_ansi=no)])
if test "$ac_cv_c_template_ansi" = "yes"
 then
  AC_DEFINE(SP_ANSI_CLASS_INST)
fi

dnl
dnl  optional backends
dnl
smr_SWITCH(mif, support for FrameMaker MIF output, on, JADE_MIF, DUMMY)
smr_SWITCH(html, support for HTML+CSS output, on, JADE_HTML, DUMMY)


dnl 
dnl  Other options
dnl
AC_DEFINE(SP_MULTI_BYTE)
dnl AC_SUBST(LIBOBJS)

AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)

dnl
dnl Darwin/Mac OS X requires some extra flags for libtool
dnl
AC_SUBST(LINKFLAGS)

AC_OUTPUT(Makefile Makefile.lib Makefile.prog Makefile.comm include/config.h)

