AC_INIT([Rdisop], 0.4) dnl package name, version
AC_PREREQ(2.50) dnl require version 2.5+ of autoconf

dnl the CC and CFLAGS variables control configure tests, and they need to
dnl be the same as what will be used when the package is built. There is
dnl no need to place these flags in Makevars, and if no configure tests are
dnl done they are not needed here (see "Writing R Extensions" manual).
: ${R_HOME=`R RHOME`}
if test -z "${R_HOME}"; then
    echo "Could not determine R home directory"
    exit 1
fi
CXX=`"${R_HOME}/bin/R" CMD config CXX`
CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXXFLAGS`

AC_LANG(C++) dnl using C++

AC_REQUIRE_CPP

dnl configure IMS include/load flags and copy sample source to inst/doc
PKG_CHECK_MODULES(IMS, [libims >= 0.5.0], [echo OK], [
dnl if IMS not found via PKG, use included static Version

#echo "Building libims.a in imslib..."
( cd src/imslib ; ./configure )
#./autogen.sh
#make ./src/libims.la
#cd ..

IMS_CFLAGS=-I./imslib/src/
IMS_LIBS="-L./imslib/src/.libs/ -lims"
])

AC_SUBST([CPPFLAGS], ["${CPPFLAGS} -I../RcppSrc $IMS_CFLAGS"])
AC_SUBST([LDFLAGS], ["${LDFLAGS} -L../RcppSrc -lRcpp $IMS_LIBS"])
AC_SUBST([LIBS], ["${LIBS} -lRcpp $IMS_LIBS"])
AC_SUBST([WANT_IMS_TRUE], ["libims"])


echo "Building libRcpp.a in RcppSrc..."
cd RcppSrc
make RHOME=${R_HOME}
cd ..

echo "Debugging Library stuff"
find ${DPKG}/libs/

if test \! -d inst
then
    mkdir inst
fi
cp RcppSrc/Rcpp-license.txt inst

AC_SUBST(WANT_MSI_TRUE)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(LIBS)
AC_OUTPUT(src/Makevars)