#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.57])
AC_INIT([mst_envs],[1.13.4],[opticsoft@head.cfa.harvard.edu],[mst_envs])
AM_INIT_AUTOMAKE([ check-news  silent-rules color-tests parallel-tests subdir-objects ])
AC_CONFIG_SRCDIR([utils/mst_envs.pl.in])
AC_CONFIG_MACRO_DIRS([m4])

# Checks for programs.
AC_PROG_INSTALL
AC_PROG_LN_S

MST_DOSUBST

MST_PERL_LIBDIR

MST_POD_GEN_DOCS

MST_DEV_INIT
MST_DEV_PROG_SYSARCH

AC_ARG_VAR(MST_PGHOST, [PostgreSQL host name])
AC_ARG_VAR(MST_SYBASE, [SYBASE directory])

AC_ARG_WITH([CXC],
        [AS_HELP_STRING([--with-CXC], [setup for use at CXC @<:@default=check@:>@])],
        [],
        [: m4_divert_text([DEFAULTS], [with_CXC=check])])

AT_CXC=
AS_IF([test "x$with_CXC" != xno],
      [ AS_IF( [
               AC_MSG_CHECKING([if on the CXC LAN])
               test -d /proj/cxcoptics],
               [AC_MSG_RESULT([yes])
                AC_SUBST([AT_CXC],[yes])], dnl found it
               [AC_MSG_RESULT([no])
                AS_IF([test "x$with_CXC" != xcheck],
                      [AC_MSG_FAILURE([--with-CXC was given, but test for being at the CXC failed])],
                      [AC_SUBST([AT_CXC],[no])]
                )]
             )],
      [AC_SUBST([AT_CXC],[no])]
)

AS_IF([test "x$AT_CXC" = xyes],
     AS_IF([ test "x$MST_PGHOST" = x], [AC_MSG_ERROR([Must specify MST_PGHOST])])
     AS_IF([ test "x$MST_SYBASE" = x], [AC_MSG_ERROR([Must specify MST_SYBASE])])
)

AS_IF([test "x$MST_PGHOST" = x],
      [AC_MSG_NOTICE([MST_PGHOST is not set])],
      [AC_MSG_NOTICE([using MST_PGHOST = '$MST_PGHOST'])]
)

AS_IF([test "x$MST_SYBASE" = x],
      [AC_MSG_NOTICE([MST_SYBASE is not set])],
      [AC_MSG_NOTICE([using MST_SYBASE = '$MST_SYBASE'])]
)

MST_TESTDEP_SETUP

MST_PROG_TESTSHELL
PKG_CHECK_MODULES([testlib_sh],
                  [testlib_sh],
                  [MST_TESTDEP_FLAG([yes])],
                  [MST_TESTDEP_FLAG([no])]
                  )

MST_TESTDEP_STATUS

AC_PROG_PERL_MODULES(
                        SysArch=2.2.5
                        Pod::Usage
                        , ,
                        AC_MSG_ERROR([Need those Perl Modules!]) )

AC_CONFIG_FILES([Makefile
                 mst_envs.pc
                 share/config.site
                 share/mst_envs.sh
                ])

m4_foreach([file],
           [
             [utils/perldoc],
            ],
           [AC_CONFIG_FILES(file, chmod +x file )]
            )

AC_OUTPUT
