dnl Process this file with autoconf to produce a configure script.
dnl Use autoconf-2.59 or later... it might not work anymore with
dnl the older 2.1x versions - jrm21 12/2004
AC_INIT(src/lib/text_t.h)
AC_CONFIG_HEADER(config.h)




PACKAGE=gsdl
VERSION=2.x-svn
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
AC_SUBST(PACKAGE)
AC_SUBST(VERSION)

dnl
dnl Set use of fast cgi
dnl
USE_FASTCGI=0
if test USE_FASTCGI = 1; then
AC_DEFINE(USE_FASTCGI)
AC_SUBST(USE_FASTCGI)
fi

dnl
dnl Set use of langaction
dnl
dnl USE_LANGACTION=0
if test USE_LANGACTION = 1; then
AC_DEFINE(USE_LANGACTION)
AC_SUBST(USE_LANGACTION)
fi

dnl
dnl Set use of corba
dnl
AC_ARG_ENABLE(corba, [  --enable-corba          Enable CORBA support], USE_CORBA=$enableval, USE_CORBA=no)
if test $USE_CORBA = "yes" -o $USE_CORBA = "1" ; then
  USE_CORBA=1
  AC_DEFINE(USE_CORBA,[])
else
  USE_CORBA=0
fi
AC_SUBST(USE_CORBA)

AC_ARG_WITH(micodir, [  --with-micodir          Use installed MICO directory], MICO_DIR=$withval, MICO_DIR="default")
AC_DEFINE_UNQUOTED(MICO_DIR, "$MICO_DIR")
AC_SUBST(MICO_DIR)

dnl
dnl Set use of z39.50
dnl
AC_ARG_ENABLE(z3950, [  --enable-z3950          Enable Z39.50 client support], USE_Z3950=$enableval, USE_Z3950=no)
if test $USE_Z3950 = "yes" -o $USE_Z3950 = "1" ; then
  USE_Z3950=1
  AC_DEFINE(USE_Z3950,[])
else
  USE_Z3950=0
fi
AC_SUBST(USE_Z3950)

dnl
dnl Set use of yaz - now compiled by default even when z3950 support not required
dnl
AC_ARG_ENABLE(yaz, [  --disable-yaz           Disable YAZ compilation], USE_YAZ=$enableval, USE_YAZ=yes)
if test $USE_YAZ = "yes" -o $USE_YAZ = "1" ; then
  USE_YAZ=1
  AC_DEFINE(USE_YAZ,[])
else
  USE_YAZ=0
fi
AC_SUBST(USE_YAZ)

dnl
dnl Disable all Java compilation
dnl
AC_ARG_ENABLE(java, [  --disable-java          Disable Java compilation], ENABLE_JAVA=$enableval, ENABLE_JAVA=yes)
if test $ENABLE_JAVA = "yes" -o $ENABLE_JAVA = "1" ; then
  ENABLE_JAVA=1
  if test "x$JAVA_HOME" != "x" ; then
    echo "Detected JAVA_HOME is set, however this will not be used during compilation"
    echo "To control the version of 'javac' and 'java' set environment variables JAVAC"
    echo "and JAVA respectively"
    export JAVA_HOME=
  fi
else
  ENABLE_JAVA=0
fi
AC_SUBST(ENABLE_JAVA)

dnl
dnl Set use of JDBM (enabled by default)
dnl
AC_ARG_ENABLE(jdbm, [  --disable-jdbm        Disable JDBM compilation], USE_JDBM=$enableval, USE_JDBM=yes)
if test $ENABLE_JAVA = "1" -a \( $USE_JDBM = "yes" -o $USE_JDBM = "1" \) ; then
  USE_JDBM=1
  AC_DEFINE(USE_JDBM,[])
else
  USE_JDBM=0
fi
AC_SUBST(USE_JDBM)

dnl
dnl Set use of GDBM (enabled by default)
dnl
AC_ARG_ENABLE(gdbm, [  --disable-gdbm        Disable GDBM compilation], USE_GDBM=$enableval, USE_GDBM=yes)
if test $USE_GDBM = "yes" -o $USE_GDBM = "1" ; then
  USE_GDBM=1
  AC_DEFINE(USE_GDBM,[])
else
  USE_GDBM=0
fi
AC_SUBST(USE_GDBM)

dnl 
dnl disable compilation of accent folding stuff for mgpp (and one day mg)
dnl
AC_ARG_ENABLE(accentfold, [  --disable-accentfold    Disable Accent Folding for MGPP], ENABLE_ACCENTFOLD=$enableval, ENABLE_ACCENTFOLD=yes)
if test $ENABLE_ACCENTFOLD = "yes" -o $ENABLE_ACCENTFOLD = "1" ; then
  ENABLE_ACCENTFOLD=1
  AC_DEFINE(ENABLE_ACCENTFOLD,[])
else
  ENABLE_ACCENTFOLD=0
fi
AC_SUBST(ENABLE_ACCENTFOLD)


dnl
dnl Set use of SQLite (enabled by default)
dnl
AC_ARG_ENABLE(sqlite, [  --disable-sqlite        Disable SQLite support], USE_SQLITE=$enableval, USE_SQLITE=yes)
if test $USE_SQLITE = "yes" -o $USE_SQLITE = "1" ; then
  USE_SQLITE=1
  AC_DEFINE(USE_SQLITE,[])
else
  USE_SQLITE=0
fi
AC_SUBST(USE_SQLITE)

dnl
dnl Set compilation of JNI parts of MG and MGPP indexers (disabled by default, which is GS2's default behaviour)
dnl
AC_ARG_ENABLE(jni, [  --enable-jni    Enable JNI compilation], ENABLE_JNI=$enableval, ENABLE_JNI=no)
if test $ENABLE_JAVA = "1" -a \( $ENABLE_JNI = "yes" -o $ENABLE_JNI = "1" \) ; then
  ENABLE_JNI=1
  AC_DEFINE(ENABLE_JNI,[])
else
  ENABLE_JNI=0
fi
AC_SUBST(ENABLE_JNI)

dnl
dnl Set compilation of MG (enabled by default)
dnl
AC_ARG_ENABLE(mg, [  --disable-mg        Disable MG compilation], ENABLE_MG=$enableval, ENABLE_MG=yes)
if test $ENABLE_MG = "yes" -o $ENABLE_MG = "1" ; then
  ENABLE_MG=1
  AC_DEFINE(ENABLE_MG,[])
else
  ENABLE_MG=0
fi
AC_SUBST(ENABLE_MG)

dnl
dnl Set compilation of MGPP (enabled by default)
dnl
AC_ARG_ENABLE(mgpp, [  --disable-mgpp        Disable MGPP compilation], ENABLE_MGPP=$enableval, ENABLE_MGPP=yes)
if test $ENABLE_MGPP = "yes" -o $ENABLE_MGPP = "1" ; then
  ENABLE_MGPP=1
  AC_DEFINE(ENABLE_MGPP,[])
else
  ENABLE_MGPP=0
fi
AC_SUBST(ENABLE_MGPP)

dnl
dnl Set compilation of lucene (enabled by default)
dnl
AC_ARG_ENABLE(lucene, [  --disable-lucene        Disable Lucene compilation], ENABLE_LUCENE=$enableval, ENABLE_LUCENE=yes)
if test $ENABLE_JAVA = "1" -a \( $ENABLE_LUCENE = "yes" -o $ENABLE_LUCENE = "1" \) ; then
  ENABLE_LUCENE=1
  AC_DEFINE(ENABLE_LUCENE,[])
else
  ENABLE_LUCENE=0
fi
AC_SUBST(ENABLE_LUCENE)


dnl Checks for programs.
LDFLAGS=$LDFLAGS
AC_SUBST(LDFLAGS)
dnl only set CFLAGS if not already set in environment
if test -z "$CFLAGS"; then
CFLAGS=-O2
fi
AC_SUBST(CFLAGS)


AC_PROG_CC
AC_PROG_CXX
if test $ENABLE_JAVA = "1" ; then
  AC_PROG_JAVA
  AC_PROG_JAVAC
fi
AC_PROG_AWK
AC_PROG_YACC
dnl get $target_cpu, $target_vendor, and $target_os
dnl (as well as host_*)
AC_CANONICAL_SYSTEM
dnl do we actually want this? It adds a prefix based on host, system etc
dnl AC_ARG_PROGRAM
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_CHECK_TOOL([STRIP],[strip])

AC_MSG_CHECKING(to see if architecture is 64-bit)
arch_64bit=no
case "$host_cpu" in
x86_64) arch_64bit=yes ;;
esac

if test "$arch_64bit" = yes; then
  AC_MSG_RESULT(yes)
  if test -z "$ARCH_DEP_FLAGS" ; then
    ARCH_DEP_FLAGS="-fPIC"
    gsdlarch='64'
  fi
else
  AC_MSG_RESULT(no)
  if test -z "$ARCH_DEP_FLAGS" ; then
    ARCH_DEP_FLAGS=
    gsdlarch='32'
  fi
fi

export ARCH_DEP_FLAGS
AC_SUBST(ARCH_DEP_FLAGS)


#moved CORBA MICO directory test to get version of MICO
if test $USE_CORBA = 1; then

if test $MICO_DIR = "default"; then
#do something
MICO_INC="-I packages/mico/mico/include"
else
#build the micotest program
MICO_INC= ""
if test $MICO_DIR != yes; then
MICO_INC="-I $MICO_DIR"
fi
fi

#get MICO_VER value
sh -c "$CC -c micotest.cpp -o micotest.o $MICO_INC 2>&1" > /dev/null
sh -c "$CC -o micotest micotest.o -lstdc++ 2>&1" > /dev/null
MICO_VER=`./micotest` || MICO_VER=2.3.5
sh -c "rm micotest"
sh -c "rm micotest.o"

#do test of MICO_VER
if test MICO_VER != 0; then
AC_DEFINE(MICO_VER)
AC_SUBST(MICO_VER)
fi
#end USE_CORBA test
fi

dnl Checks for typedefs, structures, and compiler characteristics.
AC_AIX
AC_ISC_POSIX
AC_MINIX
fp_C_PROTOTYPES
AC_C_CONST
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM

dnl --- This should be in the stdc checking -----------------
if test "$ac_cv_prog_cc_stdc" = '-Xc'; then
dnl The Pyramids running SMP_DC.OSx on MIPS r3000 chips with
dnl /usr/opt/cc3.11/bin/cc treat -Xc as full ANSI mode - no POSIX or
dnl XOPEN extensions (like popen).
dnl Unfortunately -D_{XOPEN,POSIX}_SOURCE can't provide all that mg
dnl needs. So drop back to -Xa
AC_TRY_COMPILE(
[#include <stdio.h>
], [ FILE *rubbish = popen("yes", "r"); ],,
[CC="`echo $CC | sed 's/-Xc/-Xa/'`"    ac_cv_prog_cc_stdc='-Xa'])
fi
dnl ----------------------


dnl Checks for libraries.
dnl check for -lg:
AC_HAVE_LIBRARY(g)
dnl check for -lm:
#AC_HAVE_LIBRARY(m)
dnl check for -lcrypt:
#AC_HAVE_LIBRARY(crypt)
#if test $ENABLE_ACCENTFOLD = 1; then
#AC_HAVE_LIBRARY(iconv)
#fi

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h limits.h sys/time.h unistd.h crypt.h string.h memory.h sys/procfs.h sys/stat.h)
AC_EGREP_HEADER(fread, stdio.h, AC_DEFINE(HAVE_FREAD_DECL))
AC_EGREP_HEADER(fgetc, stdio.h, AC_DEFINE(HAVE_FGETC_DECL))
AC_EGREP_HEADER(pr_brksize, sys/procfs.h, AC_DEFINE(HAVE_PR_BRKSIZE))

dnl Checks for library functions.
AC_FUNC_ALLOCA
AC_PROG_GCC_TRADITIONAL
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(ftime select strftime strtol getrusage times mallinfo setbuffer getpagesize strerror)
AC_REPLACE_FUNCS(ftruncate strstr strcasecmp)

dnl see if gettext is in libc. (try the textdomain() function).
AC_CHECK_FUNC(textdomain, AC_DEFINE(ENABLE_NLS ,1) )

# *** Custom checking (based on GNU tar configure.in) ***
# ---------------------------------------------------------------------------
AC_MSG_CHECKING(for HP-UX needing gmalloc)
if test "`(uname -s) 2> /dev/null`" = 'HP-UX'; then
  AC_MSG_RESULT(yes)
  AC_LIBOBJ([gmalloc])
  AC_DEFINE(HAVE_VALLOC)
else
  AC_MSG_RESULT(no)
  AC_CHECK_FUNCS(valloc)
fi

# we cannot generate static libraries under Darwin
AC_MSG_CHECKING(for Apple MacOS X/Darwin)
if test "`(uname -s) 2> /dev/null`" = 'Darwin'; then
  AC_MSG_RESULT(yes)
  STATIC=""
else
  AC_MSG_RESULT(no)
  STATIC="-static "
fi
AC_SUBST(STATIC)

fp_WITH_DMALLOC
fp_WITH_REGEX

# ---------------------------------------------------------------------------
if test "$ac_cv_func_alloca" = 'no'; then
dnl    support functions for alloca.c
  AC_LIBOBJ([xmalloc])
  AC_LIBOBJ([error])
fi


# ---------------------------------------------------------------------------

dnl
dnl Switch into C++
dnl
AC_LANG_CPLUSPLUS

dnl
dnl Check if the STL library has any known faults;
dnl In GCC 2.7.2.x series, some STL library headers are missing
dnl a file called "new" which is referred to by other headers
dnl (eg. vector/vector.h); if this applies, then all use of the
dnl STL will cause a compile fail, so we'd better let the user
dnl know now, before things really go wrong!
dnl
success=no
AC_MSG_CHECKING("whether STL library has known faults")

dnl - first shot, try simple good old vector on its own
AC_TRY_COMPILE(
[#include <vector>
], 
[],
success=yes,
)

dnl - try using the .h equivalent
if test $success = "no"; then
AC_TRY_COMPILE(
[#include <vector.h>
], 
[],
success="yes",
)
fi

dnl - now try for the objectspace headers
if test $success = "no"; then
AC_TRY_COMPILE(
[#include <ospace\\std\\vector>
], 
[],
success="yes",
)
fi

if test $success = yes; then
AC_MSG_RESULT("no")
else
AC_MSG_RESULT("yes")
AC_MSG_ERROR("STL Broken - Obtain newer version of GNU C Compiler")
fi

gsdlos=`uname | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
# check for running bash under cygwin
 if test "`echo $gsdlos | sed 's/cygwin//'`" != "$gsdlos" ;
 then
  gsdlos=windows
 fi
if test "x$crossOS" != "x" ; then
  gsdlos=$crossOS
  gsdlarch=""
fi
AC_SUBST(gsdlos)

# Make gsdlarch empty if the OS bit value (32 or 64) is not used in naming 
# directories already or if common-src is compiled up on its own.
# E.g. 32/64 bit won't be used in the SVN version if only bin/linux exists.
if test ! -d "../bin/$gsdlos$gsdlarch" -o ! -f "../setup.bash" ; then
   gsdlarch=""
fi
AC_SUBST(gsdlarch)

# check for endianness
AC_C_BIGENDIAN
# ---------------------------------------------------------------------------
if test "$ac_cv_func_alloca" = 'no'; then
dnl    support functions for alloca.c
  AC_LIBOBJ([xmalloc.o])
  AC_LIBOBJ([error])
fi

# ---------------------------------------------------------------------------


dnl
dnl Locate all children of the modules folder
dnl
moduleDirs=""
MODULEDIRS=""
if test -d modules ; then
  for x in `find modules -mindepth 1 -maxdepth 2`; do
    if test -d "$x"; then
      d="$x/Makefile.in"
      if test -e "$d"; then
  dnl      echo $d
        moduleDirs="$moduleDirs $x/Makefile"
        MODULEDIRS="$MODULEDIRS $x"
      fi
    fi
  done
  echo "Making $moduleDirs in modules directory"
  AC_SUBST(MODULEDIRS)
fi


# ---------------------------------------------------------------------------

AC_CONFIG_SUBDIRS(packages)

commonsrcprefix=`pwd`
ac_configure_args="$ac_configure_args --with-libiconv-prefix=$commonsrcprefix/packages/iconv"
AC_CONFIG_SUBDIRS(indexers)

AC_CONFIG_SUBDIRS(src/getpw)
##
#echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
#echo "GETPW_EXTRA_LDFLAGS: $GETPW_EXTRA_LDFLAGS"
#echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
#GETPW_EXTRA_LDFLAGS=$GETPW_EXTRA_LDFLAGS
#AC_SUBST(GETPW_EXTRA_LDFLAGS)
#AC_CONFIG_SUBDIRS(src/getpw)

#         src/getpw/Makefile \

# the list of folders in the src folder
srclist="cgi-bin/Makefile \
         src/lib/Makefile \
         src/gdbmedit/db2txt/Makefile \
         src/gdbmedit/txt2db/Makefile \
         src/gdbmedit/gdbmget/Makefile \
         src/gdbmedit/gdbmset/Makefile \
         src/gdbmedit/gdbmkeys/Makefile \
         src/gdbmedit/gdbmdel/Makefile \
         src/jdbmedit/Makefile"

AC_OUTPUT(packages/Makefile Makefile $srclist $moduleDirs)


