# Definitions
#define([psi],[Psi])
define([psi_mmm_version],[3.2.1])
define([psi_buildid],[stable])
define([psi_so_version],[1:0:0])
define([psi_email],[psi3@psicode.org])

# Process this file with autoconf to produce a configure script.
define([AC_CACHE_LOAD], )dnl for debugging configure.in
define([AC_CACHE_SAVE], )dnl for debugging configure.in
AC_PREREQ(2.52)
AC_INIT(psi,psi_mmm_version,psi_email)
AC_CONFIG_SRCDIR(aclocal.m4)
AC_CONFIG_HEADER(include/psiconfig.h)
AC_SET_MAKE

# Make srcdir an absolute path
srcdir=`(cd $srcdir; pwd)`

# That's where extra scripts necessary for configuration (config.guess, etc.) are located
AC_CONFIG_AUX_DIR(bin)

# Set up the default paths.
AC_PREFIX_DEFAULT(/usr/local/psi)

incdir=$includedir
docdir='$(prefix)/doc'
mandir='$(docdir)/man'
txtdir='$(docdir)/txt'
htmldir='$(docdir)/html'
dvidir='$(docdir)/dvi'

# To make a "make all" at the top level work before the utilities
# and include files are installed, the include files
# will be put into an objincdir and the utilities will be accessed
# from src/util in the object directory.

objincdir='$(top_objdir)/include'
AC_SUBST(objincdir)

AC_SUBST(bindir)
AC_SUBST(libdir)
AC_SUBST(docdir)
AC_SUBST(mandir)
AC_SUBST(htmldir)
AC_SUBST(dvidir)
AC_SUBST(txtdir)
AC_SUBST(datadir)
AC_SUBST(incdir)
AC_SUBST(top_objdir)

PSI_MMM_VERSION=psi_mmm_version
PSI_BUILDID=psi_buildid
AC_SUBST(PSI_MMM_VERSION)
AC_SUBST(PSI_BUILDID)

# get the target
AC_CANONICAL_TARGET
cpu=$target_cpu
vendor=$target_vendor
os=$target_os
AC_SUBST(target)


#########################################
#
# Package-specific arguments and checks
#
#########################################

LIBINT_NEW_AM=8
LIBINT_OPT_AM=4
AC_ARG_WITH(max-am-eri,[  --with-max-am-eri       Maximum ERI AM],[ 
    LIBINT_NEW_AM=$((2*($withval)))
    LIBINT_OPT_AM=$(($withval))
])
AC_SUBST(LIBINT_NEW_AM,$LIBINT_NEW_AM)
AC_SUBST(LIBINT_OPT_AM,$LIBINT_OPT_AM)

LIBDERIV_NEW_AM1=6
AC_ARG_WITH(max-am-deriv1,[  --with-max-am-deriv1    Maximum deriv1 ERI AM],[
    LIBDERIV_NEW_AM1=$((2*($withval)))
])
AC_SUBST(LIBDERIV_NEW_AM1)
LIBDERIV_NEW_AM2=4
AC_ARG_WITH(max-am-deriv2,[  --with-max-am-deriv2    Maximum deriv2 ERI AM],[
    LIBDERIV_NEW_AM2=$((2*($withval)))
])
AC_SUBST(LIBDERIV_NEW_AM2)

LIBR12_NEW_AM=6
LIBR12_OPT_AM=6
AC_ARG_WITH(max-am-r12,[  --with-max-am-r12       Maximum R12 AM],[
    LIBR12_NEW_AM=$((2*($withval)))
    LIBR12_OPT_AM=$((2*($withval)))
])
AC_SUBST(LIBR12_NEW_AM)
AC_SUBST(LIBR12_OPT_AM)

######################
#
# Check for programs
#
######################

# potential names of compilers
FC_LIST="g77 f77 fc f2c"
CC_LIST="gcc cc"
CXX_LIST="g++ c++ cxx"

# set up os specific options
case $os in
  aix*)
    FC_LIST="xlf_r $FC_LIST"
    CC_LIST="cc_r gcc"
    CXX_LIST="xlC_r g++ c++"
    ;;
  irix*)
    FC_LIST="f77 $FC_LIST"
    CC_LIST="cc gcc"
    CXX_LIST="CC g++ c++"
    ;;
esac

AC_ARG_WITH(cc,[  --with-cc               which cc command to use],[
case $withval in
  yes)
    CC='cc'
    ;;
  no)
    CC=''
    ;;
  *)
    CC=$withval
    ;;
esac
])

AC_ARG_WITH(cxx,[  --with-cxx              which cxx command to use],[
case $withval in
  yes)
    CXX='c++'
    ;;
  no)
    CXX=''
    ;;
  *)
    CXX=$withval
    ;;
esac
])

AC_ARG_WITH(fc,[  --with-fc               which fortran compiler to use],[
case $withval in
  yes)
    FC='fc'
    ;;
  no)
    FC=''
    ;;
  *)
    FC=$withval
    ;;
esac
])

AC_ARG_WITH(ranlib,
[  --with-ranlib           Gives the name of the ranlib program.],
RANLIB=$withval
)

AC_CHECK_PROGS(AR,ar,ar)
AC_ARG_WITH(ar,
[  --with-ar               Names the archive creator.],
AR=$withval
)
AC_SUBST(AR)

ARFLAGS=r
AC_ARG_WITH(ar-flags,
[  --with-ar-flags         Flags for the the archive creator.],
ARFLAGS=$withval
)
# set up os specific archiver options
case $os in
  aix*)
    ARFLAGS="-X32_64 $ARFLAGS"
    ;;
esac
AC_SUBST(ARFLAGS)

AC_ARG_WITH(ld,
[  --with-ld               Names the object linker.],
LD=$withval
)
AC_SUBST(LD)

EXTRAINCDIRS=
CPPFLAGS=
AC_ARG_WITH(incdirs,
[  --with-incdirs          Specifies include directories (-Idir1 -Idir2).],
EXTRAINCDIRS=$withval
CPPFLAGS=$withval
echo Using extra include directories: $withval
)

AC_ARG_WITH(libs,
[  --with-libs             Specifies libraries (-llib1 -llib2).],
LDLIBS=$withval
echo Using extra libraries: $withval
)
AC_SUBST(LDLIBS)

LDFLAGS=
LIBDIRS=
AC_ARG_WITH(libdirs,
[  --with-libdirs          Specifies library directories (-Ldir1 -Ldir2).],
LIBDIRS=$withval
LDFLAGS=$withval
echo Using extra library directories: $withval
)

AC_PATH_PROG(PERL, perl, , $PATH:/usr/bin:/usr/local/bin)
AC_ARG_WITH(perl,
[  --with-perl             Names the Perl interpreter.],
PERL=$withval
)
AC_SUBST(PERL)

# Find out which compilers are available.
if test -z "$FC"; then
  AC_PROGRAMS_CHECK(FC,$FC_LIST,f77)
fi

F77=$FC

if test -z "$CC"; then
  AC_PROGRAMS_CHECK(CC,$CC_LIST,cc)
fi

if test -z "$CXX"; then
  AC_PROGRAMS_CHECK(CXX,$CXX_LIST,c++)
fi

# Figure out libraries needed to link Fortran programs in C ..
AC_F77_LIBRARY_LDFLAGS
# .. and check if they work
AC_CHECK_LIB(c,exit,[],[
FLIBS=
AC_MSG_WARN([F77 libraries don't seem to link with C programs])
],$FLIBS)

# Get info on the utility programs.
AC_PROG_CPP()
AC_PROG_CXXCPP()
AC_PROG_YACC()
AC_PROG_RANLIB()
if test "X$RANLIB" = "Xfalse"; then
  RANLIB=":"
fi
AC_PROG_INSTALL()
AC_PROG_LN_S()
INSTALL_INCLUDE='$(top_srcdir)/bin/installinc.sh' AC_SUBST(INSTALL_INCLUDE)
MKDIRS='$(top_srcdir)/bin/mkdirs.sh' AC_SUBST(MKDIRS)

# check if some of the programs are missing
if test "X$PERL" = "X"; then
  AC_MSG_ERROR([Could not find the program perl. It can be obtained at www.gnu.org])
fi

# Under AIX we use lex rather than flex -- the latter didn't work well in 64-bit
# environment (as of 1998)
if echo $os | grep aix >/dev/null 2>&1; then
    test -z "$LEX" && AC_PATH_PROG(LEX,lex) AC_SUBST(LEX)
    test -z "$LEXLIB" && LEXLIB=`echo $LEX|sed "s bin/lex.* lib/libl.a "`
    if test -n "$LEXLIB" && test -f "$LEXLIB"; then
      test -n "$verbose" && echo "setting LEXLIB to $LEXLIB"
    fi
else
    AC_PROG_LEX()
fi

# If we got flex but didn't get LEXLIB try to find LEXLIB
case "$LEX" in
  flex*)
    if test -z "$LEXLIB"; then
      AC_PROGRAM_PATH(FLEXPATH,flex)
      FLEXLIBPATH=`echo $FLEXPATH|sed "s bin/flex.* lib/libfl.a "`
      if test -n "$FLEXLIBPATH" && test -f "$FLEXLIBPATH"; then
        LEXLIB=$FLEXLIBPATH
        test -n "$verbose" && echo "setting LEXLIB to $LEXLIB"
      fi
    fi
  ;;
  *)
  ;;
esac

# Figure out the suffix used for fortran for files (as $(FC) needs
# them--not F since that is psipp's input suffix).
test -z "$F77SUF" && F77SUF=f AC_SUBST(F77SUF)

# Figure out the library suffix.
test -z "$LIBSUF" && LIBSUF=a AC_SUBST(LIBSUF)

# Figure out the object file suffix.
test -z "$OBJSUF" && OBJSUF=o AC_SUBST(OBJSUF)

# See if the C compiler can do dependency checking.
AC_CC_PROCESS_CHECK(C dependency processing,[
#include "nosuchincludefile.h"
],-M,CCDEPEND='$(CC) -M'; DODEPEND=yes,CCDEPEND=":"; DODEPEND=no)
AC_SUBST(CCDEPEND)
AC_SUBST(DODEPEND)
AC_MSG_RESULT(CCDEPEND is $CCDEPEND)
AC_MSG_RESULT(DODEPEND is $DODEPEND)

# find the c libraries
AC_CHECK_LIB(m,exit,CLIBS="$CLIBS -lm")
AC_CHECK_LIB(bsd,exit,CLIBS="$CLIBS -lbsd")
AC_MSG_RESULT(c libs: $CLIBS)

AC_SUBST(CLIBS)

# some c libraries are also c++ libraries
AC_CHECK_LIB(m,exit,CXXLIBS="$CXXLIBS -lm")
AC_MSG_RESULT(c++ libs: $CXXLIBS)

AC_SUBST(CXXLIBS)

# find BLAS and LAPACK libraries
AC_LANG_PUSH(Fortran 77)
AC_ARG_WITH(blas,[  --with-blas             which blas library to use],[
case $withval in
  yes)
    BLAS='-lblas'
    ;;
  no)
    BLAS=''
    ;;
  *)
    BLAS=$withval
    ;;
esac
])
if test "X$BLAS" = X; then
  AC_CHECK_LIB(essl, DGEMM, BLAS="-lessl")
fi
if test "X$BLAS" = X; then
  AC_CHECK_LIB(scs, DGEMM, BLAS="-lscs")
fi
if test "X$BLAS" = X; then
  AC_CHECK_LIB(atlas, DGEMM, BLAS="-latlas")
fi
if test "X$BLAS" = X; then
  AC_CHECK_LIB(blas, DGEMM, BLAS="-lblas")
fi
if test "X$BLAS" = X; then
 AC_MSG_ERROR("Did not find a BLAS library")
fi
AC_SUBST(BLAS)

AC_ARG_WITH(lapack,[  --with-lapack           which lapack library to use],[
case $withval in
  yes)
    LAPACK='-llapack'
    ;;
  no)
    LAPACK=''
    ;;
  *)
    LAPACK=" $withval"
    ;;
esac
])
# first test if BLAS-containing library contains LAPACK as well
if test "X$LAPACK" = X; then
  CURRENT_LIBS=$LIBS
  LIBS="$BLAS $LIBS"
  AC_MSG_CHECKING(whether BLAS library contains LAPACK)
  AC_TRY_LINK_FUNC(DGEEV,[LAPACK=" ";AC_MSG_RESULT(yes)],AC_MSG_RESULT(no))
  LIBS=$CURRENT_LIBS
fi
if test "X$LAPACK" = X; then
  AC_CHECK_LIB(lapack,DGEEV, LAPACK="-llapack",,$BLAS)
fi
if test "X$LAPACK" = X; then
 AC_MSG_ERROR("Did not find a LAPACK library")
fi
AC_SUBST(LAPACK)
AC_LANG_POP(Fortran 77)

############################################################################
# Set up compiler flags:
#
# FDBG   Fortran debug flags.
# FOPT   Fortran opt flags.
# FDEF   Fortran defines (for psipp).
# FINC   Fortran include directories (for psipp).
# FOTH   Other fortran flags.
# CDBG   C debug flags.
# COPT   C opt flags.
# CDEF   C defines.
# COTH   Other C flags.
# CINC   C include directories (with -I in front).
# CXXDBG C++ debug flags.
# CXXOPT C++ opt flags.
# CXXDEF C++ defines.
# CXXOTH Other C++ flags.
# CXXINC C++ include directories (with -I in front).

PSICPPFLAGS='-I. -I$(objincdir) -I$(top_srcdir)/include -I$(top_srcdir)/src/lib -I$(top_objdir)/src/lib' AC_SUBST(PSICPPFLAGS)
FDBG='-g' AC_SUBST(FDBG)
FOPT='-O' AC_SUBST(FOPT)
FDEF='' AC_SUBST(FDEF)
FOTH='' AC_SUBST(FOTH)
FSTATIC='' AC_SUBST(FSTATIC)
FINC='$(CPPFLAGS) $(PSICPPFLAGS)' AC_SUBST(FINC)
CDBG='-g' AC_SUBST(CDBG)
COPT='-O2' AC_SUBST(COPT)
CDEF='' AC_SUBST(CDEF)
COTH='' AC_SUBST(COTH)
CINC='$(CPPFLAGS) $(PSICPPFLAGS)' AC_SUBST(CINC)
CXXDBG='-g' AC_SUBST(CXXDBG)
CXXOPT='-O2' AC_SUBST(CXXOPT)
CXXDEF='' AC_SUBST(CXXDEF)
CXXOTH='' AC_SUBST(CXXOTH)
CXXINC='$(CPPFLAGS) $(PSICPPFLAGS)' AC_SUBST(CXXINC)

#check for const
AC_C_CONST()

# check for header files
AC_HAVE_HEADERS(errno.h fcntl.h unistd.h stdint.h sys/types.h sys/times.h sys/param.h)

# check for C++ headers
AC_CXX_PROCESS_CHECK([cmath],[#include <cmath>],,[HAVE_CMATH=1],[HAVE_CMATH=0]) CXXDEF="$CXXDEF -DHAVE_CMATH=$HAVE_CMATH"
AC_CXX_PROCESS_CHECK([cstdio],[#include <cstdio>],,[HAVE_CSTDIO=1],[HAVE_CSTDIO=0]) CXXDEF="$CXXDEF -DHAVE_CSTDIO=$HAVE_CSTDIO"
AC_CXX_PROCESS_CHECK([cstdlib],[#include <cstdlib>],,[HAVE_CSTDLIB=1],[HAVE_CSTDLIB=0]) CXXDEF="$CXXDEF -DHAVE_CSTDLIB=$HAVE_CSTDLIB"
AC_CXX_PROCESS_CHECK([cstring],[#include <cstring>],,[HAVE_CSTRING=1],[HAVE_CSTRING=0]) CXXDEF="$CXXDEF -DHAVE_CSTRING=$HAVE_CSTRING"
AC_CXX_PROCESS_CHECK([cstddef],[#include <cstddef>],,[HAVE_CSTDDEF=1],[HAVE_CSTDDEF=0]) CXXDEF="$CXXDEF -DHAVE_CSTDDEF=$HAVE_CSTDDEF"

/bin/rm -f a.out

#check to see if void* is allowed
AC_MSG_CHECKING(for void pointers)
psi_ac_voidptr=yes
AC_TRY_COMPILE(,[
;}
void *func(void*ptr) { return ptr;
],,psi_ac_voidptr=no)
AC_MSG_RESULT($psi_ac_voidptr)
if test $psi_ac_voidptr = "no"; then
  CDEF="$CDEF -DNO_VOID_PTR"
fi

AC_CHECK_DECLS([putenv],[extradef="-DHAVE_DECL_PUTENV=1"])
CDEF="$CDEF $extradef"
CXXDEF="$CXXDEF $extradef"
AC_CHECK_FUNC(putenv,[extradef="-DHAVE_PUTENV=1"])
CDEF="$CDEF $extradef"
CXXDEF="$CXXDEF $extradef"

AC_CHECK_DECLS([setenv],[extradef="-DHAVE_DECL_SETENV=1"])
CDEF="$CDEF $extradef"
CXXDEF="$CXXDEF $extradef"
AC_CHECK_FUNC(setenv,[extradef="-DHAVE_SETENV=1"])
CDEF="$CDEF $extradef"
CXXDEF="$CXXDEF $extradef"

AC_CHECK_LIB(m,isinf,[extradef="-DHAVE_FUNC_ISINF=1"],[extradef=""])
if test X$extradef = X; then
  AC_CHECK_LIB(m,finite,[extradef="-DHAVE_FUNC_FINITE=1"],[extradef=""])
fi
if test X$extradef = X; then
  AC_ERROR([Did not find isinf() or finite() functions.])
else
  CDEF="$CDEF $extradef"
  CXXDEF="$CXXDEF $extradef"
fi

# set up cpu specific flags
AC_MSG_CHECKING([for architecture/compiler specific optimization flags])
case $cpu in
  rs6000)
    if test "$FC" = xlf_r ; then
      FOPT="-O2 -qarch=com -qxflag=xalias -qdpc -qfloat=fold -qfloat=maf -qmaxmem=-1"
    fi
    if test "$CC" = xlc_r -o "$CC" = cc_r ; then
      COPT="-O2 -qarch=com -qfloat=maf -qfloat=fold -qmaxmem=-1"
    fi
    if test "$CXX" = xlC_r ; then
      CXXOPT="-O2 -qarch=com -qfloat=maf -qfloat=fold -qmaxmem=-1"
    fi
    ;;
  powerpc)
    if test "$FC" = xlf_r ; then
      FOPT="-O2 -qarch=ppc -qxflag=xalias -qdpc -qfloat=fold -qmaxmem=-1 -qfloat=maf"
    fi
    if test "$CC" = xlc_r -o "$CC" = cc_r ; then
      COPT="-O2 -qarch=ppc -qfloat=maf -qfloat=fold -qmaxmem=-1"
    fi
    if test "$CXX" = xlC_r ; then
      CXXOPT="-O2 -qarch=ppc -qfloat=maf -qfloat=fold -qmaxmem=-1"
    fi
    ;;
  i686)
    if test "$FC" = g77 ; then
      FOPT="-O2 -march=pentiumpro"
    fi
    if test "$CC" = gcc -o "$CC" = cc ; then
      COPT="-O2 -march=pentiumpro"
    fi
    if test "$CXX" = g++ -o "$CXX" = c++ -o "$CXX" = gcc ; then
      CXXOPT="-O2 -march=pentiumpro"
    fi
    ;;
esac
AC_MSG_RESULT([C optimization flags: $COPT])
AC_MSG_RESULT([C++ optimization flags: $CXXOPT])

# OS specific flags
AC_MSG_CHECKING([for OS specific flags])
case $os in
  aix*)
# _ALL_SOURCE is required because some include files on AIX don't seem to work with pure POSIX
    EXTRADEFS="-DAIX -D_LARGE_FILES -D_ALL_SOURCE"
    FDEF="$FDEF $EXTRADEFS"
    CDEF="$CDEF $EXTRADEFS"
    CXXDEF="$CXXDEF $EXTRADEFS"
    ;;
  linux*)
    EXTRADEFS="-DLinux -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE"
    FDEF="$FDEF $EXTRADEFS"
    CDEF="$CDEF $EXTRADEFS"
    CXXDEF="$CXXDEF $EXTRADEFS"
    ;;
esac
AC_MSG_RESULT([C preprocessor directives: $CDEF])
AC_MSG_RESULT([C++ preprocessor directives: $CXXDEF])

# Set up CFLAGS and FFLAGS.

CFLAGS='$(CDBG) $(COPT) $(CDEF) $(COTH) $(CINC)' AC_SUBST(CFLAGS)
CXXFLAGS='$(CXXDBG) $(CXXOPT) $(CXXDEF) $(CXXOTH) $(CXXINC)' AC_SUBST(CXXFLAGS)
FFLAGS='$(FDBG) $(FOPT) $(FOTH) $(FSTATIC)' AC_SUBST(FFLAGS)

# Adjust the debug flags.
# The default is to not debug.  --with-debug will turn on debugging.
AC_ARG_WITH(debug,[  --with-debug            will turn on debugging],[
case $withval in
  yes)
    ;;
  no)
    CDBG=''
    CXXDBG=''
    FDBG=''
    ;;
  *)
    CDBG="$withval"
    CXXDBG="$withval"
    FDBG="$withval"
    ;;
esac
],CDBG='' CXXDBG='' FDBG='')

# Adjust the optimize flags.
# The default is to optimize.  --with-opt=no or --without-opt will turn
# off optimization.
AC_ARG_WITH(opt,[  --with-opt              --with-opt=no will turn off optimization],[
case $withval in
  yes)
    ;;
  no)
    COPT=''
    CXXOPT=''
    FOPT=''
    ;;
  *)
    COPT="$withval"
    CXXOPT="$withval"
    FOPT="$withval"
    ;;
esac
])

# Adjust the flags dealing with strictness of the compilers.
# The default is to disable strict language checks.  --with-opt=no or --without-opt will turn
# off optimization.
AC_ARG_WITH(strict,[  --with-strict           --with-strict=yes will turn on strict compiler warnings],[
case $withval in
  yes)
    # "Strict" flags only known for GNU compilers
    if test "$G77" = yes ; then
      FOTH="$FOTH -Wall"
    fi
    if test "$GCC" = yes ; then
      COTH="$COTH -Wall -ansi"
    fi
    if test "$GXX" = yes ; then
      CXXOTH="$CXXOTH -Wall -ansi"
    fi
    ;;
  no)
    ;;
esac
])
AC_MSG_RESULT([C extra flags: $COTH])
AC_MSG_RESULT([C++ extra flags: $CXXOTH])

# check Fortran symbol convention
AC_MSG_CHECKING(fortran symbols)
if test -n "$FC" ; then
  /bin/rm -f ffunc.f flink.c
  echo "      subroutine ffunc()" > ffunc.f
  echo "      return" >> ffunc.f
  echo "      end" >> ffunc.f
  $FC -c ffunc.f 1>/dev/null 2>/dev/null
  echo "main(){ FF(); return 0; }" > flink.c
  if $CC -o flink -DFF=ffunc flink.c ffunc.o $LDFLAGS $LIBS 1>/dev/null 2>/dev/null; then
    AC_MSG_RESULT(same as C)
    FC_SYMBOL=1
  elif $CC -o flink -DFF=ffunc_ flink.c ffunc.o $LDFLAGS $LIBS 1>/dev/null 2>/dev/null; then
    AC_MSG_RESULT(lowercase with underscore)
    FC_SYMBOL=2
  elif $CC -o flink -DFF=FFUNC flink.c ffunc.o $LDFLAGS $LIBS 1>/dev/null 2>/dev/null; then
    AC_MSG_RESULT(uppercase)
    FC_SYMBOL=3
  elif $CC -o flink -DFF=FFUNC_ flink.c ffunc.o $LDFLAGS $LIBS 1>/dev/null 2>/dev/null; then
    AC_MSG_RESULT(uppercase with underscore)
    FC_SYMBOL=4
  else
    AC_MSG_RESULT(giving up)
    AC_MSG_ERROR(could not determine fortran symbol names)
  fi
  /bin/rm -f ffunc.f ffunc.o flink flink.c flink.o ffunc
else
  FC_SYMBOL=2
  AC_MSG_RESULT(guessing lowercase with underscore)
fi
AC_SUBST(FC_SYMBOL)

#
# Check for LaTeX, DVIPS, and LaTeX2HTML
#
AC_PROG_LATEX()
AC_PROG_DVIPS()
AC_PROG_LATEX2HTML()

#
# Support for dependency rules
#

# The GNU compilers work with:
CCDEPENDSUF=none
CXXDEPENDSUF=none
CCDEPENDFLAGS=-M
CXXDEPENDFLAGS=-M

/bin/rm -f depcheck.u depcheck.c depcheck.o depcheck.cc

# Check for an IBM visual age C compiler
echo "#include <stdio.h>" > depcheck.c
$CC $CPPFLAGS $CFLAGS -M depcheck.c > /dev/null 2>&1
if test -f depcheck.u; then
  CCDEPENDSUF=u
fi
/bin/rm -f depcheck.u depcheck.c depcheck.o depcheck.cc

# Check for an IBM visual age C++ compiler
echo "#include <iostream>" > depcheck.cc
$CXX $CPPFLAGS $CXXFLAGS -M -E depcheck.cc > /dev/null 2>&1
if test -f depcheck.u; then
  CXXDEPENDSUF=u
  CXXDEPENDFLAGS="-M -E"
fi
/bin/rm -f depcheck.u depcheck.c depcheck.o depcheck.cc

AC_SUBST(CCDEPENDSUF)
AC_SUBST(CXXDEPENDSUF)
AC_SUBST(CCDEPENDFLAGS)
AC_SUBST(CXXDEPENDFLAGS)

AC_OUTPUT(include/sizeof.h include/Makefile
          include/chkpt_params.h
          Makefile lib/Makefile src/Makefile
          src/lib/Makefile src/lib/MakeRules src/lib/MakeVars
          src/util/Makefile src/util/MakeRules src/util/MakeVars

          src/util/tocprint/Makefile
          src/util/psi2molden/Makefile

          src/lib/libciomr/Makefile
          src/lib/libciomr/iomrparam.h
          src/lib/libipv1/Makefile
          src/lib/libchkpt/Makefile

          src/lib/libderiv/Makefile
          src/lib/libderiv/MakeVars
          src/lib/libderiv/libderiv_config.h
          src/lib/libdpd/Makefile
          src/lib/libint/Makefile
          src/lib/libint/MakeVars
	  src/lib/libint/libint_config.h
          src/lib/libiwl/Makefile
          src/lib/libpsio/Makefile
          src/lib/libqt/Makefile
          src/lib/libr12/Makefile
          src/lib/libr12/MakeVars
          src/lib/libr12/libr12_config.h
	  src/lib/libbasis/Makefile
          src/bin/Makefile src/bin/MakeRules src/bin/MakeVars

          src/bin/cphf/Makefile
          src/bin/psi3/Makefile
          src/bin/ccdensity/Makefile
          src/bin/ccenergy/Makefile
          src/bin/cchbar/Makefile
          src/bin/cclambda/Makefile
          src/bin/ccsort/Makefile
          src/bin/cctriples/Makefile
          src/bin/cceom/Makefile
          src/bin/cceom-d/Makefile
          src/bin/ccresponse/Makefile
          src/bin/cints/Makefile
          src/bin/cis/Makefile
          src/bin/clag/Makefile
          src/bin/cscf/Makefile
          src/bin/detci/Makefile
          src/bin/detcas/Makefile
          src/bin/detcasman/Makefile
          src/bin/extrema/Makefile
          src/bin/geom/Makefile
          src/bin/input/Makefile
          src/bin/mp2/Makefile
          src/bin/mp2r12/Makefile
          src/bin/oeprop/Makefile
          src/bin/optking/Makefile
          src/bin/psiclean/Makefile
          src/bin/transqt/Makefile
          src/bin/mvo/Makefile
          src/bin/dboc/Makefile
          src/bin/cusp/Makefile
          src/bin/mocube/Makefile
          src/bin/localize/Makefile
          src/bin/stable/Makefile
          src/bin/response/Makefile

          tests/Makefile
          tests/MakeVars
          tests/MakeRules
          tests/runtest.pl
          tests/scf-opt/Makefile
          tests/scf-opt2/Makefile
          tests/scf-opt3/Makefile
          tests/scf-opt4/Makefile
          tests/scf-opt5/Makefile
          tests/scf-opt6/Makefile
          tests/scf-opt7/Makefile
          tests/scf-opt8/Makefile
          tests/scf-opt9/Makefile
          tests/scf-opt10/Makefile
          tests/scf-opt11/Makefile
          tests/scf-opt-numer/Makefile
          tests/scf-freq/Makefile
          tests/scf-freq-numer/Makefile
          tests/scf-freq-symm-numer/Makefile
          tests/scf-polar/Makefile
          tests/rhf-oeprop/Makefile
          tests/rhf-stab/Makefile
          tests/rhf-stab/rhf-stab.pl
          tests/uhf-stab/Makefile
          tests/uhf-stab/uhf-stab.pl
          tests/rohf-stab/Makefile
          tests/rohf-stab/rohf-stab.pl
          tests/cis-sp/Makefile
          tests/cisd-sp/Makefile
          tests/cisd-opt-numer/Makefile
          tests/casscf-sp/Makefile
          tests/mp2-sp/Makefile
          tests/mp2-direct-sp/Makefile
          tests/mp2-oeprop/Makefile
          tests/cc1/Makefile
          tests/cc2/Makefile
          tests/cc3/Makefile
          tests/cc4/Makefile
          tests/cc5/Makefile
          tests/cc6/Makefile
          tests/cc7/Makefile
          tests/cc8/Makefile
          tests/cc9/Makefile
          tests/cc10/Makefile
          tests/cc11/Makefile
          tests/cc12/Makefile
          tests/cc13/Makefile
          tests/cc14/Makefile
          tests/cc15/Makefile
          tests/cc16/Makefile
          tests/cc17/Makefile
          tests/cc18/Makefile
          tests/cc19/Makefile
          tests/dboc-rhf1/Makefile
          tests/dboc-rohf1/Makefile
          tests/dboc-uhf1/Makefile
          tests/dboc-rcisd1/Makefile
          tests/dboc-rocisd1/Makefile
          tests/extrema-zmat/Makefile
          tests/extrema-zmat/extrema-zmat.pl
          tests/extrema-deloc/Makefile
          tests/extrema-deloc/extrema-deloc.pl
	  tests/mp2r12-sp1/Makefile
	  tests/mp2-opt-numer/Makefile
          tests/rhf-lindep1/Makefile
          tests/rohf-lindep1/Makefile
          tests/uhf-lindep1/Makefile
	  tests/psi_start/Makefile
	  tests/psi_start/psi_start.pl

          doc/MakeVars doc/MakeRules doc/Makefile
          doc/macros.tex
          doc/installation/Makefile
          doc/progman/Makefile doc/userman/Makefile
          )
# The following should be added to config_files/ac_output for 
# libmathtools/ccman.  You have to move those lines up above this
# comment.
#         src/lib/libmathtools/Makefile
#         src/lib/libmathtools/containers/templates/Makefile
#         src/lib/libmathtools/solvers/templates/Makefile
#         src/lib/libmathtools/general/Makefile
#         src/lib/libmathtools/tensor/Makefile
#         src/bin/ccman/Makefile
