# Process this file with autoconf to produce a configure script.
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_SRCDIR([src/erserver.c])
AC_CONFIG_HEADER([config.h])
AC_PREFIX_DEFAULT(/usr/local/erserver)

AC_CANONICAL_HOST

template=
AC_MSG_CHECKING([which template to use])

case $host_os in
     aix*) template=aix ;;
    beos*) template=beos ;;
    bsdi*) template=bsdi ;;
  cygwin*) template=win ;;
  darwin*) template=darwin ;;
    dgux*) template=dgux ;;
 freebsd*) template=freebsd ;;
    hpux*) template=hpux ;;
    irix*) template=irix5 ;;
   linux*) template=linux ;;
  netbsd*) template=netbsd ;;
nextstep*) template=nextstep ;;
 openbsd*) template=openbsd ;;
     osf*) template=osf ;;
     qnx*) template=qnx4 ;;
     sco*) template=sco ;;
 solaris*) template=solaris ;;
   sunos*) template=sunos4 ;;
 sysv4.2*)
        case $host_vendor in
          univel) template=univel ;;
        esac ;;
   sysv4*) template=svr4 ;;
   sysv5*) template=unixware ;;
  ultrix*) template=ultrix4 ;;
esac

AC_MSG_RESULT([$template])

# Checks for programs.
AC_PROG_CC
AC_PROG_LD
AC_SUBST(LD)
AC_SUBST(with_gnu_ld)

if test "x$JAVA_HOME" = x ; then
  AC_MSG_ERROR([
                ******************************
                JAVA_HOME env variable not set
                ******************************])
fi

AC_PATH_PROG(JAVA, java)

if test "x$JAVA" = x ; then
  AC_MSG_ERROR([
                *****************************************
                Location of Java compiler not found!
                
                Make sure that your path is set properly,
                as well as JAVA_HOME.
                *****************************************])
fi

# Checks for libraries.

# Checks for header files.

AC_ARG_WITH(pgincludes, [  --with-pgincludes=<dir> Location for PgSQL Include Files], AC_SUBST(PGINC, $with_pgincludes))

if test "x$with_pgincludes" = x ; then
  AC_MSG_ERROR([
                ****************************************
                Location of PgSQL include files required
                
                       Use --with-pgincludes option                    
                ****************************************])
else
  if test ! -f "$with_pgincludes/executor/spi.h" ; then
    AC_MSG_ERROR($with_pgincludes/executor/spi.h NOT found)
  fi
fi

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_HEADER_STDC
AC_CHECK_FUNCS([strchr strpbrk])

AC_CONFIG_FILES([
	Makefile.global 
	bin/ers_setup
	bin/ers_ctl
	bin/ers_remove
	bin/ers_addtable
	bin/ers_addslave
	perl/eRServer.pm
	templates/ers_setvars-template
])

AC_CONFIG_LINKS([
  Makefile.port:makefiles/Makefile.${template}
])


AC_OUTPUT
