dnl $RCSfile: configure.in,v $
dnl $Revision: 1.16 $
dnl $Author: langer $
dnl $Date: 2001/10/25 21:14:54 $

dnl This software was produced by NIST, an agency of the U.S. government,
dnl and by statute is not subject to copyright in the United States.
dnl Recipients of this software assume all responsibilities associated
dnl with its operation, modification and maintenance. However, to
dnl facilitate maintenance we ask that before distributing modifed
dnl versions of this software, you first contact the authors at
dnl oof_manager@ctcms.nist.gov. 

dnl Process this file with autoconf to produce a configure script.

define([AC_INIT_NOTICE],
[#### Configuration script for XOOF
### $RCSfile: configure.in,v $
### $Revision: 1.16 $
### $Author: langer $
### $Date: 2001/10/25 21:14:54 $

#### Guess values for system-dependent variables and create Makefiles.
#### Generated automatically using autoconf version] AC_ACVERSION [

### Don't edit this script!
### This script was automatically generated by the `autoconf' program
### from the file `./configure.in'.
### To rebuild it, execute the command
###     autoconf
### in this directory.  You must have autoconf version 2.12 or later.

### This file is part of OOF

### This software was produced by NIST, an agency of the U.S. government,
### and by statute is not subject to copyright in the United States.
### Recipients of this software assume all responsibilities associated
### with its operation, modification and maintenance. However, to
### facilitate maintenance we ask that before distributing modifed
### versions of this software, you first contact the authors at
### oof_manager@ctcms.nist.gov. 

### For usage, run `./configure --help'
###
### If configure succeeds, it leaves its status in config.status.
### A log of configuration tests can be found in config.log.
### If configure fails after disturbing the status quo,
###     config.status is removed.
])

AC_INIT(XOOF/element.h)
#AC_CONFIG_HEADER(config.h)

AC_CANONICAL_HOST

CLEANUPCMD="rm -f *.o"
CXX_DEFAULT_FLAGS=""
CC_DEFAULT_FLAGS=""

dnl Default situation is to use optimization and not to use debugging
CXX_OPT="true"
CXX_OPT_FLAGS=""
CC_OPT="true"
CC_OPT_FLAGS=""
CXX_DEBUG=""
CXX_DEBUG_FLAGS=""
CC_DEBUG=""
CC_DEBUG_FLAGS=""

EXTRADEFS=""
NO_DEFAULT_FLAGS=""

AC_ARG_WITH(default-flags,
    [  --without-default-flags Don't automaticaly determine compilation flags],
    [
	if test "x$withval" = "xno" ; then
	    NO_DEFAULT_FLAGS="true"
	fi
    ]
)

AC_ARG_WITH(cxxflags,
    [  --with-cxxflags=FLAGS   C++ flags (others may be added)],
    [
	if test "x$withval" = "xno"; then
	    CXXFLAGS=""
	else
	    CXXFLAGS=$withval
	fi
    ]
)
CXX_INITIAL_FLAGS=$CXXFLAGS

AC_ARG_WITH(cflags,
    [  --with-cflags=FLAGS     C flags (others may be added)],
    [
	if test "x$withval" = "xno"; then
	    CFLAGS=""
	else
	    CFLAGS=$withval
	fi
    ]
)
CC_INITIAL_FLAGS=$CFLAGS

AC_ARG_WITH(cxxoptimize,
    [  --with-cxxoptimize[=FLAGS]  Optimize C++ compilation (will figure out optimization flags if none are given)],
    [
	if test "x$withval" = "xno" ; then
	    CXX_OPT=""
	else
	    CXX_OPT="true"
	    if test "x$withval" != "xyes"; then
		CXX_OPT_FLAGS=$withval
	    fi
	fi
    ]
)

AC_ARG_WITH(cxxdebug,
    [  --with-cxxdebug[=FLAGS] Turn on C++ debugging (will figure out flags if none are given)],
    [
	if test "x$withval" = "xno" ; then
	    CXX_DEBUG=""
	else
	    CXX_DEBUG="true"
	    if test "x$withval" != "xyes" ; then
		CXX_DEBUG_FLAGS=$withval
	    fi
	fi
    ]
)

AC_ARG_WITH(ccoptimize,
    [  --with-ccoptimize[=FLAGS]  Optimize C compilation (will figure out optimization flags if none are given)],
    [
	if test "x$withval" = "xno" ; then
	    CC_OPT=""
	else
	    CC_OPT="true"
	    if test "x$withval" != "xyes"; then
		CC_OPT_FLAGS=$withval
	    fi
	fi
    ]
)

AC_ARG_WITH(ccdebug,
    [  --with-ccdebug[=FLAGS] Turn on C debugging (will figure out flags if none are given)],
    [
	if test "x$withval" = "xno" ; then
	    CC_DEBUG=""
	else
	    CC_DEBUG="true"
	    if test ! -z "$withval" ; then
		CC_DEBUG_FLAGS=$withval
	    fi
	fi
    ]
)

dnl Use the flags we have to make sure the compilers work. Default flags
dnl we set below the compiler check should be known to work
CXXFLAGS="$CXX_INITIAL_FLAGS"
if test ! -z "$CXX_OPT"; then
    CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS"
fi
if test ! -z "$CXX_DEBUG"; then
    CXXFLAGS="$CXXFLAGS $CXX_DEBUG_FLAGS"
fi

CCFLAGS="$CC_INITIAL_FLAGS"
if test ! -z "$CC_OPT"; then
    CCFLAGS="$CCFLAGS $CC_OPT_FLAGS"
fi
if test ! -z "$CC_DEBUG"; then
    CCFLAGS="$CCFLAGS $CC_DEBUG_FLAGS"
fi

dnl Checks for compilers.
AC_PROG_CXX
AC_PROG_CC
if test -z "$NO_DEFAULT_FLAGS"; then
    if test "x$cross_compiling" = "xyes"; then
	AC_MSG_WARN([Add -DLITTLEENDIAN to CFLAGS and CXXFLAGS if the machine you're cross-compiling for is little-endian])
    else
	AC_C_BIGENDIAN
	if test "x$ac_cv_c_bigendian" = "xno"; then
	    CXX_DEFAULT_FLAGS="$CXX_DEFAULT_FLAGS -DLITTLEENDIAN"
	    CC_DEFAULT_FLAGS="$CC_DEFAULT_FLAGS -DLITTLEENDIAN"
	fi
    fi

    if test ! -z "$GXX"; then
	CXX_DEFAULT_FLAGS="$CXX_DEFAULT_FLAGS -Wno-non-template-friend"

	AC_MSG_CHECKING([whether -pipe flag works])
	CC_STORE_FLAGS="$CFLAGS"
	CFLAGS="-pipe"
	AC_TRY_COMPILE(,,
			[
			    AC_MSG_RESULT(["yes"])
			    CXX_DEFAULT_FLAGS="$CXX_DEFAULT_FLAGS -pipe"
			    CC_DEFAULT_FLAGS="$CC_DEFAULT_FLAGS -pipe"
			],
			[ AC_MSG_RESULT(["no"]) ]
		      )
	CFLAGS="$CC_STORE_FLAGS"
	if test -z "$CXX_OPT_FLAGS"; then
	    CXX_OPT_FLAGS="-O"
	fi
	if test -z "$CC_OPT_FLAGS"; then
	    CC_OPT_FLAGS="-O"
	fi
	if test -z "$CXX_DEBUG_FLAGS"; then
	    CXX_DEBUG_FLAGS="-g"
	fi
	if test -z "$CC_DEBUG_FLAGS"; then
	    CC_DEBUG_FLAGS="-g"
	fi
    else
	case "${host}" in
	    *-*-irix6.5)
		CXX_DEFAULT_FLAGS="$CXX_DEFAULT_FLAGS -ptv -LANG:ansi-for-init-scope=on -woff 3322"
		if test -z "$CXX_DEBUG_FLAGS"; then
		    CXX_DEBUG_FLAGS="-g -fullwarn -DEBUG:trap_uninitialized=ON"
		fi
		if test -z "$CXX_OPT_FLAGS"; then
		    CXX_OPT_FLAGS="-n32 -mips3 -OPT:Olimit=0 -O"
		fi
		if test -z "$CC_DEBUG_FLAGS"; then
		    CC_DEBUG_FLAGS="-g -fullwarn -DEBUG:trap_uninitialized=ON"
		fi
		if test -z "$CC_OPT_FLAGS"; then
		    CC_OPT_FLAGS="-n32 -mips3 -OPT:Olimit=0 -O"
		fi
	    ;;
	    *-*-irix*) # Older
		CXX_DEFAULT_FLAGS="$CXX_DEFAULT_FLAGS -ptv -DOLDCASTS"
		if test -z "$CXX_DEBUG_FLAGS"; then
		    CXX_DEBUG_FLAGS="-g -fullwarn"
		fi
		if test -z "$CXX_OPT_FLAGS"; then
		    CXX_OPT_FLAGS="-mips2 -O -Olimit 2400"
		fi
		if test -z "$CC_DEBUG_FLAGS"; then
		    CC_DEBUG_FLAGS="-g -fullwarn"
		fi
		if test -z "$CC_OPT_FLAGS"; then
		    CC_OPT_FLAGS="-mips2 -O -Olimit 2400"
		fi
	    ;;
	esac
    fi
fi

dnl Final compile-stage flag setting
CXXFLAGS="$CXX_INITIAL_FLAGS $CXX_DEFAULT_FLAGS"
if test ! -z "$CXX_OPT"; then
    CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS"
fi
if test ! -z "$CXX_DEBUG"; then
    CXXFLAGS="$CXXFLAGS $CXX_DEBUG_FLAGS -DDEBUG"
fi

CFLAGS="$CC_INITIAL_FLAGS $CC_DEFAULT_FLAGS"
if test ! -z "$CC_OPT"; then
    CCFLAGS="$CFLAGS $CC_OPT_FLAGS"
fi
if test ! -z "$CC_DEBUG"; then
    CCFLAGS="$CFLAGS $CC_DEBUG_FLAGS -DDEBUG"
fi

dnl Set up linker
LD=$CXX
LIBS=""
AC_ARG_WITH(ld,
    [  --with-ld=LINKER        Linker for C++ object files (C++ compiler by default)],
    [
	LD=$withval
    ]
)

LDFLAGS=$CXXFLAGS
AC_ARG_WITH(ldflags,
    [  --with-ldflags=FLAGS    Specify flags to pass to linker (overrides default C++ CXXFLAGS)],
    [
    if test "x$withval" != "xno" ; then
	LDFLAGS="$withval"
    else
	LDFLAGS=""
    fi
	]
)
AC_ARG_WITH(extra-ldflags,
    [  --with-extra-ldflags=FLAGS Specify extra flags to pass to linker],
    [
    if test "x$withval" != "xno" ; then
	LDFLAGS="$LDFLAGS $withval"
    fi
    ]
)

AC_ARG_WITH(libdirs,
    [  --with-libdirs=-L/dir   Specify where else to find libraries],
    [
	if test "x$withval" != "xno" ; then
	    LDFLAGS="$LDFLAGS $withval"
	fi
    ]
)
AC_ARG_WITH(extra-libs,
    [  --with-extra-libs=-lLIB       Specify additional libraries to link against],
    [
	if test "x$withval" != "xno" ; then
	    LIBS="$LIBS $withval"
	fi
    ]
)

dnl checks for programs
AC_PROG_RANLIB
AC_PROG_MAKE_SET
AC_LANG_CPLUSPLUS

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

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

AC_CHECK_HEADERS(ieeefp.h, EXTRADEFS="$EXTRADEFS -DHAVE_IEEEFP_H")
AC_CHECK_HEADERS(malloc.h, EXTRADEFS="$EXTRADEFS -DHAVE_MALLOC_H")

dnl Checks for library functions.

dnl AC_FUNC_SETVBUF_REVERSED
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(getcwd putenv select strdup strtod strtol strtoul)
AC_CHECK_LIB(m,ceil)

AC_CACHE_SAVE
case "${host}" in
    *-*-irix6.5)
	x_libraries=/usr/lib32
    ;;
esac

AC_PATH_XTRA

AC_CACHE_SAVE
dnl Checks for libraries.
AC_ARG_WITH(blas,
    [  --with-blas=-lblas      Specify library (or libraries) for BLAS],
    [
	if test "x$withval" != "xno" ; then
	    AC_MSG_WARN([This is a hack to see if blas will link])
	    AC_CHECK_LIB(m,dgemv_, ,
			 AC_MSG_ERROR([*** Supplied blas doesn't link ***]),
			 $withval
			)
	    LIBS="$LIBS $withval"
	    HAVE_LIBBLAS="true"
	fi
    ]
)

if test -z "$HAVE_LIBBLAS"; then
    case "${host}" in
	*-*-irix6*)
dnl			AC_CHECK_LIB(ftn,main, ,
dnl				AC_MSG_ERROR([*** Can't find fortran library (libftn) ***]))
	    AC_CHECK_LIB(blas,dgemv_, ,
			 AC_MSG_ERROR([*** Can't find libblas ***])
			)
	;;
	*-*-linux*)
	    AC_CHECK_LIB(g2c,z_abs, ,
			 AC_MSG_ERROR([*** Can't find fortran library (libg2c) ***])
			)
			AC_CHECK_LIB(blas,dgemv_, ,
				     AC_MSG_ERROR([*** Can't find libblas ***])
			)
	;;
	*-sun-*)
	    AC_CHECK_LIB(sunmath,main)
	    AC_CHECK_LIB(M77,main)
	    AC_CHECK_LIB(F77,main)
	    AC_CHECK_LIB(blas,dgemv_, ,
			 AC_MSG_ERROR([*** Can't find libblas ***]),
			 -lsunmath -lM77 -lF77
			)
	;;
	*)
	    AC_CHECK_LIB(blas,dgemv_, ,
			 AC_MSG_ERROR([*** Can't find libblas ***])
			)
	;;
    esac
fi

LDFLAGS="$LDFLAGS $X_PRE_LIBS $X_LIBS $X_EXTRA_LIBS"
AC_CHECK_LIB(X11,XDrawString)
AC_CACHE_SAVE
AC_LANG_C
AC_SEARCH_LIBS(fl_initialize,forms xforms, ,
	[
		AC_MSG_ERROR([*** Can't find XForms library ***])
	]
)

AC_LANG_CPLUSPLUS

dnl Use GNU readline if available
EDITLINE=""
EDITMAKE=""
EDITLINELIB=""
USEEDITLINE=""
AC_CHECK_LIB(edit,readline,,
    [
	AC_MSG_WARN([No GNU readline: using editline])
	EDITLINE=editline/libedit.a
	EDITMAKE="editline/Makefile editline/dependencies.mk"
	EDITLINELIB="../editline/libedit.a"
	EDITLINEDIR=editline
    ]
)

case "${host}" in
    *-*-irix*)
	CLEANUPCMD="rm -fr *.o ii_files"
    ;;
esac

dnl Custom variable mods in the Makefile
AC_SUBST(LD)
AC_SUBST(CLEANUPCMD)
AC_SUBST(EXTRADEFS)
AC_SUBST(EDITLINE)
AC_SUBST(EDITLINELIB)
AC_SUBST(EDITLINEDIR)

AC_OUTPUT(
	Makefile
	XOOF/Makefile
	XOOF/dependencies.mk
	XPPM2OOF/Makefile
	XPPM2OOF/dependencies.mk
	OOF2ABAQUS/Makefile
	OOF2ABAQUS/dependencies.mk
	$EDITMAKE)
