AC_INIT(src)

CFLAGS="$CFLAGS"
CPPFLAGS="$CPPFLAGS"
CXXFLAGS="$CXXFLAGS"

AC_PREFIX_DEFAULT(/usr/local/irstlm)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(irstlm, 5.70.03)
WEBSITE="http://hlt.fbk.eu/en/irstlm"

AC_CONFIG_MACRO_DIR([m4])

AC_PROG_CXX
AC_PROG_CXXCPP
AC_LANG_CPLUSPLUS

AC_DISABLE_SHARED 
AC_PROG_LIBTOOL
# Shared library are disabled for default
#LT_INIT([disable-shared])

AC_CHECK_TOOL(PDFLATEX,pdflatex,"no")
AC_CHECK_TOOL(BIBTEX,bibtex,"no")

#AC_ARG_ENABLE([trace],
#    AS_HELP_STRING([--enable-trace|--disable-trace], [Enable (default) or Disable trace]))

AC_ARG_ENABLE([debugging],
    AS_HELP_STRING([--enable-debugging|--disable-debugging], [Enable or Disable (default) compilation with debugging "-g -O2" info]))

AC_ARG_ENABLE(profiling,
            [AC_HELP_STRING([--enable-profiling|--disable-profiling], [Enable or Disable (default) profiling info])])

AC_ARG_ENABLE(traincaching,
            [AC_HELP_STRING([--enable-traincaching|--disable-traincaching], [Enable or Disable (default) the usage of caching in training])])

AC_ARG_ENABLE(caching,
            [AC_HELP_STRING([--enable-caching|--disable-caching], [Enable or Disable (default) the usage prob caches to store probs and other info])])

AC_ARG_ENABLE(interpsearch,
            [AC_HELP_STRING([--enable-interpsearch|--disable-interpsearch], [Enable or Disable (default) the use interpolated search to retrieve n-grams])])

AC_ARG_ENABLE(optimization,
            [AC_HELP_STRING([--enable-optimization|--disable-optimization], [Enable or Disable (default) compilation with optimization -O3 flag])])

AC_ARG_WITH(zlib,
            [AC_HELP_STRING([--with-zlib=PATH], [(optional) path to zlib])],
            [with_zlib=$withval],
            [with_zlib=no]
           )

AC_ARG_WITH(traceLevel,
            [AC_HELP_STRING([--with-traceLevel=INT], [(optional) level of tracing; 0 disable tracing, 1 (default) or higher enable increasing tracing])],
            [with_traceLevel=$withval],
            [with_traceLevel=1]
           )


AM_CONDITIONAL([am__fastdepCC], false)
AM_CONDITIONAL([WITH_THREADS],false)

#### Use this if you want that the default is yes
#### if test "x$enable_foo" != 'xno'
#### Use this if you want that the default is no
#### if test "x$enable_foo" = 'xyes'

CPPFLAGS="$CPPFLAGS -DTRACE_LEVEL=${with_traceLevel}" 
AC_MSG_NOTICE([trace Level: ${with_traceLevel}])


#if test "x$enable_trace" = 'xno'
#then
#    AC_MSG_NOTICE([trace disabled, most regression tests will fail])
#    CPPFLAGS="$CPPFLAGS" 
#else
#    AC_MSG_NOTICE([trace enabled (default)])
#    CPPFLAGS="$CPPFLAGS -DTRACE_ENABLE" 
#fi

if test "x$enable_debugging" = 'xyes'
then
    AC_MSG_NOTICE([generation of debugging symbols enabled, compilation with "-g -O2"])
    CPPFLAGS="$CPPFLAGS -g -O2"
else
    AC_MSG_NOTICE([generation of debugging symbols disabled (default), compilation without "-g", only "-O2"])
fi

if test "x$enable_profiling" = 'xyes'
then
    AC_MSG_NOTICE([profiling enabled])
    CPPFLAGS="$CPPFLAGS -pg"
    LDFLAGS="$LDFLAGS -pg"
else
    AC_MSG_NOTICE([profiling disabled (default)])
fi

if test "x$enable_traincaching" = 'xyes'
then
    AC_MSG_NOTICE([train-caching enabled])
    CPPFLAGS="$CPPFLAGS -DMDIADAPTLM_CACHE_ENABLE=1";
    LDFLAGS="$LDFLAGS"
else
    AC_MSG_NOTICE([train-caching disabled (default)])
fi

if test "x$enable_caching" = 'xyes'
then
    AC_MSG_NOTICE([caching enabled])
    CPPFLAGS="$CPPFLAGS -DPS_CACHE_ENABLE=1 -DLMT_CACHE_ENABLE=1";
    LDFLAGS="$LDFLAGS"
else
    AC_MSG_NOTICE([caching disabled (default)])
fi

if test "x$enable_interpsearch" = 'xyes'
then
    AC_MSG_NOTICE([interpolated search enabled])
    CPPFLAGS="$CPPFLAGS -DINTERP_SEARCH=1";
    LDFLAGS="$LDFLAGS"
else
    AC_MSG_NOTICE([interpolated search disabled (default)])
fi

if test "x$enable_optimization" = 'xyes'
then
    AC_MSG_NOTICE([optimization enabled])
    CPPFLAGS="$CPPFLAGS -O3";
    LDFLAGS="$LDFLAGS -O3"
else
    AC_MSG_NOTICE([optimization disabled (default)])
fi

AC_MSG_NOTICE([Building non-threaded irstlm.])

AC_CHECK_HEADERS([getopt.h],
            [AM_CONDITIONAL([WITH_MERT],true)],
            [AC_MSG_WARN([Cannot find getopt.h - disabling new mert])])

if test "x$with_zlib" != 'xno'
then
  CPPFLAGS="$CPPFLAGS -I${with_zlib}/include"
  LDFLAGS="$LDFLAGS -L${with_zlib}/lib"
fi

LIBS="$LIBS -lz"


AC_CONFIG_FILES(Makefile src/Makefile scripts/Makefile)

AC_SUBST(transform,'s/_lm/-lm/')

AC_OUTPUT()

AC_MSG_NOTICE([The software will be installed into $prefix])
