AC_INIT(configure.in)

AM_CONFIG_HEADER(src/config.h)
AM_INIT_AUTOMAKE(psModule, 0.1)

AC_LANG(C)
AC_PROG_CC

dnl AC_SUBST(LDFLAGS)
AC_SUBST(CFLAGS)

CFLAGS="${CFLAGS=} -g2 -Wall -std=c99 -D_GNU_SOURCE"

AC_PROG_INSTALL
AM_PROG_LIBTOOL

AC_ARG_WITH(psLib,
[  --with-psLib=DIR        Specify location of psLib files],[
CFLAGS="${CFLAGS=} -I$withval/include"
LDFLAGS="${LDFLAGS=} -L$withval/lib"
],[
CFLAGS="${CFLAGS=} -I$PSLIB_ROOT/include"
LDFLAGS="${LDFLAGS=} -L$PSLIB_ROOT/lib"
])

AC_ARG_WITH(sla,
[  --with-sla=DIR          Specify location of SLA.],[
CFLAGS="${CFLAGS=} -I$withval/include"
LDFLAGS="${LDFLAGS=} -L$withval/lib"
])

AC_ARG_WITH(cfitsio,
[  --with-cfitsio=DIR      Specify location of CFITSIO.],[
CFLAGS="${CFLAGS=} -I$withval/include"
LDFLAGS="${LDFLAGS=} -L$withval/lib"
])

AC_ARG_WITH(fftw3,
[  --with-fftw3=DIR        Specify location of FFTW version 3.],[
CFLAGS="${CFLAGS=} -I$withval/include"
LDFLAGS="${LDFLAGS=} -L$withval/lib"
])

AC_ARG_WITH(gsl,
[  --with-gsl=DIR          Specify location of GSL.],[
AC_CHECK_PROG(GSL_CONFIG, $withval/bin/gsl-config, $withval/bin/gsl-config)
],[
AC_CHECK_PROG(GSL_CONFIG, gsl-config, `which gsl-config`)
])
if test "$GSL_CONFIG" != ""
then
    LDFLAGS="${LDFLAGS=} `${GSL_CONFIG} --libs`"
    CFLAGS="${CFLAGS=} `${GSL_CONFIG} --cflags`"
fi

dnl Check the libraries to see if they exist, etc.
AC_CHECK_LIB(sla,main,,AC_MSG_ERROR(SLA library required))
AC_CHECK_LIB(cfitsio,main,,AC_MSG_ERROR(CFITSIO library required))
AC_CHECK_LIB(fftw3f,main,,AC_MSG_ERROR(FFTW3 library required))
AC_CHECK_LIB(gsl,main,,AC_MSG_ERROR(GSL library required))
AC_CHECK_LIB(gslcblas,main,,AC_MSG_ERROR(GSL CBLAS library required))
AC_CHECK_LIB(pslib,main,,AC_MSG_ERROR(psLib library required))

dnl for MacOSX, where sqrtf is in mx
AC_CHECK_LIB(mx,sqrtf)

AC_OUTPUT(Makefile src/Makefile test/Makefile)
