#! /usr/bin/zsh -f
#
# $Id$
#
# SUMMARY:      
# USAGE:        <script-name>
#
# AUTHOR:       Christophe Prud'homme $Author$
# ORG:          
# ORIG-DATE:    26-Apr-89
# LAST-MOD:     23-Mar-94 at 00:35:50 by Christophe Prud'homme
# DESCRIPTION:  
#
# $Log$
# DESCRIP-END.

AC_REVISION($Id: configure.in,v 1.3 1997/09/09 21:18:46 prudhomm Exp $)dnl

AC_INIT(./Makefile.am) 

dnl Where are the files for the configure script
AC_CONFIG_AUX_DIR(config)

dnl What the current system and host
AC_CANONICAL_HOST
AC_CANONICAL_SYSTEM

# for DejaGNU

srctrigger="freefem.0"
srcname="The DejaGnu freefem tests"
          
# everything defaults to unix for a target
target_abbrev=unix
     
AC_ARG_PROGRAM

dnl Automake doc recommends to do this only here.
AM_INIT_AUTOMAKE(kfem/gfem, 3.5) dnl searches for some needed programs
   
dnl generate the config header
AM_CONFIG_HEADER(config.h) dnl at the distribution this done

dnl make $KDEDIR the default for the installation
AC_PREFIX_DEFAULT(${KDEDIR:-/usr/local/kde})


dnl checks, if the debug code is wanted
AC_CHECK_FLAGS
  
AC_LANG_CPLUSPLUS
AC_PROG_CXX
AC_PROG_CXXCPP
AC_PROG_CC
AC_PROG_CPP


AC_PROG_MAKE_SET
AC_PROG_INSTALL
AC_PROG_RANLIB

AC_CHECK_PROG(LATEX,latex,latex)
AC_CHECK_PROG(LATEX2HTML,hyperlatex,hyperlatex)

AC_CHECK_TOOL(INSTALL_INFO, install-info, $srcdir/config/install-info)


dnl Where is EMacs ??
AM_PATH_LISPDIR

dnl Checks for libraries.
AC_PATH_KDE

dnl Checks for libraries. 
AC_CHECK_LIB(socket, socket, [LIBSOCKET="-lsocket -lnsl"]) dnl for Solaris
AC_SUBST(LIBSOCKET)

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h sys/time.h unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_HEADER_TIME

dnl check if the compiler has bool
AC_CHECK_BOOL
AC_C_LONG_DOUBLE
AC_CHECK_KSIZE_T
AC_CHECK_SETENV


LDFLAGS="${LDFLAGS} $X_LIBS"
AC_CHECK_LIB(X11, XOpenDisplay)

CPPFLAGS="${CPPFLAGS} -I\$(srcdir)"


#
# Are we using the adaptation package
#
enable_adapt=yes
AC_ARG_ENABLE(adapt,[--enable-adapt              Use mesh adaptation library],
    CPPFLAGS="${CPPFLAGS}  -DADAPT -I\$(top_srcdir)/adapt"
    LDFLAGS="${LDFLAGS} -L\$(top_builddir)/adapt"
    LIBS="-ladapt ${LIBS}"
    LIBADAPT=adapt
)
#
# Do we want some optimisation in the generated code
#
enable_kde=yes
AC_ARG_ENABLE(kde,[--with-kde    compile with kde support freefem will be a library: libfem.a],[
    CPPFLAGS="${CPPFLAGS} -DKDE_SUPPORT"
])
    
#
# Are we using the  gfem package
# When gfem is enabled adapt is enabled also
#
AC_ARG_WITH(gfem,[--with-gfem               Use freefem and gfem in conjonction via sockets (adaptation package is enabled: no need to use --with-adapt)],
    CPPFLAGS="${CPPFLAGS} -DXGFEM -DADAPT -I\$(top_srcdir)/comm -I\$(top_srcdir)/adapt"
    LDFLAGS="${LDFLAGS} -L\$(top_builddir)/comm -L\$(top_builddir)/adapt"
    LIBS="-lcomm -ladapt $LIBS"
    LIBADAPT=adapt
    LIBCOMM=comm
)
AC_ARG_WITH(optimization,[--with-optimization       Experimental add additional flags to optimize the code. Depends on the compiler],[
dnl
dnl case g++ or linux machine 
dnl
    if test "$CXX" = "g++" || test "$CXX" = "c++" || test "$host_os" = "linux" ; then
	CXXFLAGS="-O3 -fforce-mem -fforce-addr -fomit-frame-pointer"
    fi
dnl
dnl case hpux system
dnl
    if test "$CXX" = "CC" && test "$host_os" = "hpux" ; then
	CXXFLAGS="+O3 +a1"
    fi
dnl
dnl case silicon graphics system
dnl
    if test "$CXX" = "CC" && test "$host_os" = "irix" ; then
	CXXFLAGS="-O3"
    fi],[
	if test "$CXX" = "CC" && test "$host_os" = "hpux" ; then
		CXXFLAGS="+a1"
    	fi])
#
# see $(top_srcdir)/Makefile.am
# if LIBADAPT is defined as adapt then compile libadapt.a
# if LIBCOMM is defined as adapt then compile libcomm.a
#
AC_SUBST(LIBADAPT)dnl
AC_SUBST(LIBCOMM)dnl

CXXFLAGS="${CXXFLAGS} ${X_CFLAGS}"

dnl show the results
echo "** Here are the make variables for $host"
echo "* Compiler:"
echo "**  CXX=$CXX"
echo "* Compilation options:"
echo "**  DEFS=$DEFS"
echo "**  CPPFLAGS=$CPPFLAGS"
echo "**  CXXFLAGS=$CXXFLAGS"
echo "**  X_CFLAGS=$X_CFLAGS"
echo "* Linking:"
echo "**  LDFLAGS=$LDFLAGS"
echo "**  LIBS=$LIBS"
echo "**  X_PRE_LIBS=$X_PRE_LIBS"
echo "**  X_LIBS=$X_LIBS"
echo "**  X_EXTRA_LIBS=$X_EXTRA_LIBS"


dnl now create the Makefile 
AC_OUTPUT(Makefile src/Makefile adapt/Makefile comm/Makefile config/Makefile doc/Makefile doc/html/Makefile examples/Makefile testsuite/Makefile testsuite/config/Makefile testsuite/freefem.0/Makefile testsuite/lib/Makefile contrib/Makefile contrib/Sadaka/Makefile contrib/Emacs/Makefile)


