# -*- mode:sh; sh-basic-offset:2; tab-width:2; indent-tabs-mode:t -*-
AC_INIT()

AC_CONFIG_AUX_DIR(script)

AC_CANONICAL_HOST
AC_CANONICAL_BUILD

# for CFLAGS="..." ./configure ...
AC_SUBST(CFLAGS)

AC_PROG_CC
AC_PROG_INSTALL

#detect glibc
AC_TRY_COMPILE([#include <features.h>],
[
#ifdef __GLIBC__
#else
#error
int boil\[-1\];
#endif
], [CFLAGS="$CFLAGS -D_GNU_SOURCE"])

AC_C_INLINE

AC_ARG_ENABLE(debug,
	[  --enable-debug          debug @<:@default=disabled@:>@],
	debug=$enable_debug)
if test "$debug" = "yes" ; then
	DEB_CFLAGS="-DDEBUG -DBL_DEBUG"
fi
AC_SUBST(DEB_CFLAGS)

AC_LIBTOOL_WIN32_DLL
AC_ARG_WITH(libtool,
	[  --with-libtool@<:@=ARG@:>@    libtool path @<:@default=without@:>@],
	libtool=$with_libtool)
if test "${libtool}" != "" ; then
	LIBTOOL=${libtool}
else
	AM_PROG_LIBTOOL
	LIBTOOL='${top_builddir}/libtool'
fi
AC_SUBST(LIBTOOL)

if test -d ${top_srcdir-$srcdir}/baselib ; then
	POBL_BUILDDIR='${top_builddir}/baselib'
	SUBDIRS="baselib"
elif test -d ${top_srcdir-$srcdir}/../baselib ; then
	POBL_BUILDDIR='${top_builddir}/../baselib'
	SUBDIRS="../baselib"
else
	POBL_BUILDDIR=""
	SUBDIRS=""
fi
POBL_CFLAGS="-I${POBL_BUILDDIR}/include"
AC_SUBST(POBL_CFLAGS)

AC_ARG_WITH(map-table,
	[  --without-map-table     mapping table @<:@default=with@:>@],
	map_table=$with_map_table,map_table="yes")
if test "$map_table" = "no" ; then
	TABLE_CFLAGS="${TABLE_CFLAGS} -DREMOVE_MAPPING_TABLE"
fi

AC_ARG_WITH(prop-table,
	[  --without-prop-table    property table @<:@default=with@:>@],
	prop_table=$with_prop_table,prop_table="yes")
if test "$prop_table" = "no" ; then
	TABLE_CFLAGS="${TABLE_CFLAGS} -DREMOVE_PROPERTY_TABLE"
fi

AC_ARG_WITH(iconv,
	[  --with-iconv            use iconv for charset conversion @<:@default=without@:>@],
	iconv=$with_iconv,iconv="no")
if test "$iconv" = "yes" ; then
	TABLE_CFLAGS="${TABLE_CFLAGS} -DUSE_ICONV"
fi

AC_ARG_ENABLE(dl-table,
	[  --disable-dl-table      dynamic loading table @<:@default=enable@:>@],
	dl_table=$enable_dl_table,
	[
		if test "$iconv" = "yes"; then
			dl_table="no"
		else
			dl_table="yes"
		fi
	])
if test "$enable_shared" = "no" ; then
	dl_table="no"
fi
if test "$dl_table" = "no" ; then
	TABLE_CFLAGS="${TABLE_CFLAGS} -DNO_DYNAMIC_LOAD_TABLE"
	MAKE_DIRS="src"
else
	MAKE_DIRS="src module"
fi
AC_SUBST(TABLE_CFLAGS)
AC_SUBST(MAKE_DIRS)

#
# --- check for undefined symbol ---
#
AC_MSG_CHECKING([for undefined symbol])
if test "x$allow_undefined_flag" = "xunsupported" ; then
	AC_MSG_RESULT([not supported])
	NO_UNDEFINED_FLAG="-no-undefined"
else
	AC_MSG_RESULT(supported)
	NO_UNDEFINED_FLAG=""
fi
if test "x${POBL_BUILDDIR}" != "x" ; then
	LPOBL="${POBL_BUILDDIR}/src/libpobl.la"
else
	LPOBL='-lpobl'
fi
AC_SUBST(NO_UNDEFINED_FLAG)
AC_SUBST(LPOBL)


if test "$with_gnu_ld" = "yes" ; then
	DEXPORT="-Wl,--version-script=\$(VPATH)/dexport.map"
fi
AC_SUBST(DEXPORT)

AC_SUBST(mef_top_srcdir_suffix)
AC_SUBST(mef_top_builddir_suffix)

# This should be uncommented if mef and pobl alone are distributed in a package.
#if test "${SUBDIRS}" != "" ; then
#	AC_CONFIG_SUBDIRS(${SUBDIRS})
#fi

AC_OUTPUT(Makefile src/Makefile module/Makefile)
