
dnl AC_INIT(mgpp/text/MGQuery.cpp)
dnl http://www.gnu.org/software/hello/manual/autoconf/Initializing-configure.html
AC_INIT()

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 AC_MSG_CHECKING(to see if architecture is 64-bit)
dnl arch_64bit=no
dnl case "$host_cpu" in
dnl x86_64) arch_64bit=yes ;;
dnl esac
if test -z "$ARCH_DEP_FLAGS" ; then
    ARCH_DEP_FLAGS=
fi
AC_SUBST(ARCH_DEP_FLAGS)

dnl
dnl Disable accent folding
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 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 -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 -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
dnl Make sure Javac and Java are available if were are compiling Lucene
dnl
if test "$ENABLE_LUCENE" = "1" ; then
  AC_PROG_JAVAC
  AC_PROG_JAVA
fi

dnl
dnl Specify location of unac - if specified, will be passed to cascading configures
dnl
AC_ARG_WITH(unac, [  --with-unac=dir       Use specified unac directory], UNAC_DIR=$withval)

dnl
dnl Specify location of libiconv - if specified, will be passed to cascading configures
dnl
AC_ARG_WITH(libiconv, [  --with-libiconv-prefix=dir       Use specified libiconv directory], LIBICONV_DIR=$withval)

if test $ENABLE_ACCENTFOLD = 1; then
AC_CONFIG_SUBDIRS(packages/unac)
fi

dnl AC_CONFIG_SUBDIRS(mg mgpp)

if test $ENABLE_MG = 1; then
if test ! -d mg; then
echo "***** Folder mg does not exist, cannot ENABLE_MG.";
exit 1;
fi
AC_CONFIG_SUBDIRS(mg)
fi

if test $ENABLE_MGPP = 1; then
if test ! -d mgpp; then
echo "***** Folder mgpp does not exist, cannot ENABLE_MGPP.";
exit 1;
fi
AC_CONFIG_SUBDIRS(mgpp)
fi

if test $ENABLE_LUCENE = 1; then
if test ! -d lucene-gs; then
echo "***** Folder lucene-gs does not exist, cannot ENABLE_LUCENE.";
exit 1;
fi
fi

srclist="lucene-gs/Makefile"

AC_OUTPUT(Makefile $srclist)
