dnl
dnl Process this file with autoconf to produce a configure script
dnl

AC_PREREQ(2.13)
AC_INIT(Makefile.in)

AC_CONFIG_AUX_DIR(build)
AC_CONFIG_HEADER(lib/apr_iconv_private.h)
AC_PREFIX_DEFAULT(/usr/local/apache2)

sinclude(build/apr-iconv.m4)
sinclude(build/apr_common.m4)
sinclude(build/find_apr.m4)

dnl This is required by autoconf!
AC_PROG_AWK
AC_PROG_INSTALL

dnl compute the top directory of the build
# Absolute source/build directory
api_srcdir=`(cd $srcdir && pwd)`
api_builddir=`pwd`
AC_SUBST(api_srcdir)
AC_SUBST(api_builddir)

if test "$api_builddir" != "$api_srcdir"; then
  USE_VPATH=1
fi

dnl Default prefix path if none was specified
test "x$prefix" = xNONE && prefix=$ac_default_prefix

dnl check for APR
API_FIND_APR

dnl copy apr's rules.mk into our build directory.
if test ! -d $api_builddir/build ; then
  mkdir $api_builddir/build
fi
cp $APR_BUILD_DIR/apr_rules.mk $api_builddir/build/rules.mk

dnl
dnl set up the compilation flags and stuff
dnl
API_INCLUDES="-I$api_builddir/lib -I$api_builddir/include"
if test -n "$USE_VPATH"; then
  API_INCLUDES="$API_INCLUDES -I$api_srcdir/lib -I$api_srcdir/include"
fi

AC_SUBST(API_INCLUDES)

AC_SUBST(APR_SO_EXT)

dnl Adds in config *.h file
AC_DEFINE_UNQUOTED(ICONV_DEFAULT_PATH,"$prefix/lib/iconv",
	[ Directory where the *.so tables are stored ] )
iconv_libdir=$prefix/lib/iconv
AC_SUBST(iconv_libdir)

dnl
dnl BSD/OS (BSDi) needs to use a different include syntax in the Makefiles
dnl
case "$host_alias" in
*bsdi*)
    INCLUDE_RULES=".include \"$api_builddir/build/rules.mk\""
    ;;
*)
    INCLUDE_RULES="include $api_builddir/build/rules.mk"
    ;;
esac
AC_SUBST(INCLUDE_RULES)

dnl supportes MinGW
case "$host_alias" in
*mingw*)
    API_CPPFLAGS="-DAPI_DECLARE_EXPORT"
    ;;
esac
AC_SUBST(API_CPPFLAGS)

dnl Absolute source/build directory
abs_srcdir=`(cd $srcdir && pwd)`

dnl get our version information
get_version="$abs_srcdir/build/get-version.sh"
version_hdr="$abs_srcdir/include/api_version.h"
API_MAJOR_VERSION="`$get_version major $version_hdr API`"
API_LIBNAME="apriconv-${API_MAJOR_VERSION}"
AC_SUBST(API_LIBNAME)
API_INCPATH="apr-${API_MAJOR_VERSION}"
AC_SUBST(API_INCPATH)
LT_VERSION="-version-info `$get_version libtool $version_hdr API`"
AC_SUBST(LT_VERSION)

dnl
dnl everthing is done. 
AC_OUTPUT([
	Makefile
	ccs/Makefile
	ces/Makefile
	lib/Makefile
	util/Makefile
	])
