Index: trunk/psLib/configure.ac
===================================================================
--- trunk/psLib/configure.ac	(revision 5318)
+++ trunk/psLib/configure.ac	(revision 5512)
@@ -1,3 +1,3 @@
-AC_PREREQ(2.57)
+AC_PREREQ(2.59)
 
 AC_INIT([pslib],[0.8.99],[http://pan-starrs.ifa.hawaii.edu/bugzilla])
@@ -6,5 +6,5 @@
 
 AM_INIT_AUTOMAKE([1.7 foreign dist-bzip2])
-AM_CONFIG_HEADER(src/config.h)
+AC_CONFIG_HEADERS([src/config.h])
 AM_MAINTAINER_MODE
 
@@ -12,11 +12,14 @@
 AC_SUBST(PSLIB_LT_VERSION,$PSLIB_LT_VERSION)
 
-dnl Determine the location of GNU sed
-AC_CHECK_PROGS([SED],[gsed sed])
-if test "${SED}" == ""
-then
-  AC_MSG_ERROR([GNU SED is required.])
-fi
-AC_SUBST(SED,[${SED}])
+dnl ------------------- PERL options ---------------------
+  AC_ARG_WITH(perl,
+    [AS_HELP_STRING(--with-perl=FILE,Specify location of PERL executable.)],
+    [AC_CHECK_PROG(PERL, $withval, $withval)],
+    [AC_CHECK_PROG(PERL, perl, `which perl`)])
+    if test "$PERL" == ""
+    then
+      AC_MSG_ERROR([PERL is required.  Use --with-perl to specify its install location.])
+    fi
+    AC_SUBST(PERL,$PERL)
 
 SUBDIR="etc src test" dnl don't include 'swig', as it is optional
@@ -24,7 +27,8 @@
 SRCPATH='${top_srcdir}/src'
 SRCDIRS="sys astro db fft fits imageops math mathtypes types xml"
-SRCINC=`echo "${SRCDIRS=}" | ${SED} "s|\(\\w\+\)|-I\${SRCPATH=}/\1|g"`
+# escape two escapes at this level so \\ gets passed to the shell and \ to perl
+SRCINC=`echo "${SRCDIRS=}" | ${PERL} -pe "s|(\w+)|-I\\\\${SRCPATH=}/\1|g"`
 SRCINC="-I${SRCPATH=} ${SRCINC=}"
-SRCSUBLIBS=`echo "${SRCDIRS=}" | ${SED} "s|\(\\w\+\)|\1/libpslib\1.la|g"`
+SRCSUBLIBS=`echo "${SRCDIRS=}" | ${PERL} -pe "s|(\w+)|\1/libpslib\1.la|g"`
 AC_SUBST(SRCSUBLIBS,${SRCSUBLIBS=})
 AC_SUBST(SRCINC,${SRCINC=})
@@ -49,11 +53,4 @@
 )
 
-case $host in
-  *-apple-darwin*)
-dnl    CFLAGS="${CFLAGS=} -Wno-long-double -fno-strict-aliasing"
-dnl GCC 4.0 on OSX seems to hate that.
-    ;;
-esac
-
 AC_LANG(C)
 AC_PROG_CC
@@ -69,15 +66,12 @@
 
 dnl check for standard language functionality
-AC_HEADER_STDC
-AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS([float.h limits.h stdint.h stdlib.h string.h sys/time.h unistd.h])
-AC_HEADER_STDBOOL
+AC_CHECK_HEADERS([fcntl.h float.h limits.h stdint.h stdlib.h string.h sys/time.h unistd.h])
 AC_C_CONST
 AC_C_INLINE
-AC_TYPE_PID_T
-AC_C_RESTRICT
-AC_TYPE_SIZE_T
+AC_HEADER_STDBOOL
+AC_HEADER_SYS_WAIT
 AC_HEADER_TIME
 AC_STRUCT_TM
+AC_TYPE_SIZE_T
 
 dnl Checks for library functions.
@@ -160,11 +154,32 @@
 [CFITSIO_LDFLAGS="-L$withval"])
 PSLIB_CFLAGS="${PSLIB_CFLAGS=} ${CFITSIO_CFLAGS}"
-PSLIB_LIBS="${PSLIB_LIBS=} $CFITSIO_LDFLAGS -lcfitsio"
+PSLIB_LIBS="${PSLIB_LIBS=} $CFITSIO_LDFLAGS -lcfitsio -lm"
+
+dnl Store off CFLAGS/LDFLAGS so that they can be restored after tests
 TMP_CFLAGS=${CFLAGS}
-CFLAGS=${CFITSIO_CFLAGS}
+TMP_LDFLAGS=${LDFLAGS}
+
+CFLAGS=${PSLIB_CFLAGS}
+LDFLAGS=${PSLIB_LIBS}
 AC_CHECK_HEADERS([fitsio.h],[],
-   [AC_MSG_ERROR([CFITSIO is required.  Obtain it at  http://heasarc.gsfc.nasa.gov/docs/software/fitsio or use --with-cfitsio to specify location.])])
+   [AC_MSG_ERROR([CFITSIO headers not found.  Obtain CFITSIO at  http://heasarc.gsfc.nasa.gov/docs/software/fitsio or use --with-cfitsio to specify location.])]
+)
+TMP_LIBS=${LIBS}
+AC_CHECK_LIB(cfitsio,ffopen,[],
+  [AC_MSG_ERROR([CFITSIO library not found.  Obtain it at  http://heasarc.gsfc.nasa.gov/docs/software/fitsio or use --with-cfitsio to specify location.])]
+)
+dnl Now check if CFITSIO supports fits_open_diskfile, i.e., is at least version 2.501
+AC_CHECK_LIB(cfitsio,ffdkopen,
+  [CFITSIO_DISKFILE=1],
+  [AC_MSG_WARN([The CFITSIO library version is rather old.  Suggested version is 2.501 or greater.])
+   CFITSIO_DISKFILE=0]
+)
+LIBS=${TMP_LIBS}
+
+dnl restore the CFLAGS/LDFLAGS
 CFLAGS=${TMP_CFLAGS}
-
+LDFLAGS=${TMP_LDFLAGS}
+
+AC_DEFINE_UNQUOTED([CFITSIO_DISKFILE],${CFITSIO_DISKFILE},[Define to 1 if you have fits_open_diskfile in CFITSIO])
 AC_SUBST([CFITSIO_CFLAGS])
 
@@ -182,9 +197,23 @@
 PSLIB_CFLAGS="${PSLIB_CFLAGS=} ${FFTW3_CFLAGS}"
 PSLIB_LIBS="${PSLIB_LIBS=} $FFTW3_LDFLAGS -lfftw3f"
+
+dnl Store off CFLAGS/LDFLAGS so that they can be restored after tests
 TMP_CFLAGS=${CFLAGS}
-CFLAGS=${FFTW3_CFLAGS}
+TMP_LDFLAGS=${LDFLAGS}
+
+CFLAGS="${TMP_CFLAGS} ${PSLIB_CFLAGS}"
+LDFLAGS="${TMP_LDFLAGS} ${PSLIB_LIBS}"
 AC_CHECK_HEADERS([fftw3.h],[],
-   [AC_MSG_ERROR([FFTW version 3 with float support is required.  Obtain it at http://www.fftw.org/or use --with-fftw3 to specify location.])])
+  [AC_MSG_ERROR([FFTW version 3 (--withfloat) headers not found.  Obtain it at http://www.fftw.org/or use --with-fftw3 to specify location.])]
+)
+TMP_LIBS=${LIBS}
+AC_CHECK_LIB(fftw3f,fftwf_plan_dft_2d,[],
+  [AC_MSG_ERROR([FFTW version 3 (--withfloat) library not found.  Obtain it at http://www.fftw.org/or use --with-fftw3 to specify location.])]
+)
+LIBS=${TMP_LIBS}
+
+dnl restore the CFLAGS/LDFLAGS
 CFLAGS=${TMP_CFLAGS}
+LDFLAGS=${TMP_LDFLAGS}
 
 AC_SUBST([FFTW3_CFLAGS])
@@ -197,9 +226,15 @@
 AC_CHECK_FILE($GSL_CONFIG,[],
     [AC_MSG_ERROR([GSL is required.  Obtain it at http://www.gnu.org/software/gsl or use --with-gsl-config to specify location.])])
+
 AC_MSG_CHECKING([GSL cflags])
 GSL_CFLAGS="`${GSL_CONFIG} --cflags`"
 AC_MSG_RESULT([${GSL_CFLAGS}])
+
+AC_MSG_CHECKING([GSL ldflags])
+GSL_LDFLAGS="`${GSL_CONFIG} --libs`"
+AC_MSG_RESULT([${GSL_LDFLAGS}])
+
 PSLIB_CFLAGS="${PSLIB_CFLAGS=} ${GSL_CFLAGS}"
-PSLIB_LIBS="${PSLIB_LIBS=} `${GSL_CONFIG} --libs`"
+PSLIB_LIBS="${PSLIB_LIBS=} ${GSL_LDFLAGS}"
 
 AC_SUBST([GSL_CFLAGS])
@@ -212,9 +247,15 @@
 AC_CHECK_FILE($XML_CONFIG,[],
     [AC_MSG_ERROR([GNOME XML C parser is required.  Obtain it at http://www.xmlsoft.org or use --with-xml2-config to specify location.])])
+
 AC_MSG_CHECKING([xml2 cflags])
 XML_CFLAGS="`${XML_CONFIG} --cflags`"
 AC_MSG_RESULT([${XML_CFLAGS}])
+
+AC_MSG_CHECKING([xml2 ldflags])
+XML_LDFLAGS="`${XML_CONFIG} --libs`"
+AC_MSG_RESULT([${XML_LDFLAGS}])
+
 PSLIB_CFLAGS="${PSLIB_CFLAGS=} ${XML_CFLAGS}"
-PSLIB_LIBS="${PSLIB_LIBS=} `${XML_CONFIG} --libs`"
+PSLIB_LIBS="${PSLIB_LIBS=} ${XML_LDFLAGS}"
 
 AC_SUBST([XML_CFLAGS])
@@ -239,15 +280,4 @@
   SUBDIR="${SUBDIR=} swig"
 
-dnl ------------------- PERL options ---------------------
-  AC_ARG_WITH(perl,
-    [AS_HELP_STRING(--with-perl=FILE,Specify location of PERL executable.)],
-    [AC_CHECK_PROG(PERL, $withval, $withval)],
-    [AC_CHECK_PROG(PERL, perl, `which perl`)])
-    if test "$PERL" == ""
-    then
-      AC_MSG_ERROR([PERL is required.  Use --with-perl to specify its install location.])
-    fi
-    AC_SUBST(PERL,$PERL)
-
 dnl ---------------- PERLPREFIX option -------------------
   AC_ARG_WITH(perlprefix,
@@ -262,15 +292,20 @@
 fi
 
-dnl for MacOSX, check if sqrtf is in mx library.
+dnl for MacOSX suppport -- check if sqrtf is in mx library.
+TMP_LIBS=${LIBS}
 AC_CHECK_LIB(mx,sqrtf,
   [PSLIB_LIBS="${PSLIB_LIBS=} -lmx"])
+LIBS=${TMP_LIBS}
 AC_CHECK_FUNC(atoll, [],
-  [AC_MSG_ERROR([The C99 function, atoll, is required; update your compiler?])])
-
-DOXYGEN="doxygen Doxyfile"
-AC_CHECK_PROG(DOXYGEN,doxygen,[echo Doxygen not detected in configure stage.])
-AC_SUBST(DOXYGEN,$DOXYGEN)
-
-CFLAGS="${CFLAGS=} -Wall -Werror"
+  [AC_MSG_ERROR([The C99 function, atoll, is required; update your compiler version?])])
+
+AC_CHECK_PROG(doxygen,[doxygen],[true],[false])
+AM_CONDITIONAL(DOXYGEN, test x$doxygen = xtrue)
+
+
+dnl ------- restore CFLAGS / LDFLAGS (tests done) --------
+CFLAGS="${CFLAGS} -Wall -Werror"
+AC_MSG_RESULT([CFLAGS is ${CFLAGS}])
+AC_MSG_RESULT([LDFLAGS is ${LDFLAGS}])
 
 dnl ---------------- export variables --------------------
