AC_INIT()

AC_CONFIG_AUX_DIR(script)

AC_CANONICAL_HOST
AC_CANONICAL_BUILD

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

AC_PROG_CC
AC_C_INLINE
AC_PROG_INSTALL

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}/kiklib ; then
	KIKLIB_BUILDDIR='${top_builddir}/kiklib'
	SUBDIRS="kiklib"
elif test -d ${top_srcdir-$srcdir}/../kiklib ; then
	KIKLIB_BUILDDIR='${top_builddir}/../kiklib'
	SUBDIRS="../kiklib"
else
	KIKLIB_BUILDDIR=""
	SUBDIRS=""
fi
KIK_CFLAGS="-I${KIKLIB_BUILDDIR}/include"
AC_SUBST(KIK_CFLAGS)

AC_ARG_ENABLE(debug,
	[  --enable-debug          debug @<:@default=disabled@:>@],
	debug=$enable_debug)
if test "$debug" = "yes" ; then
	DEB_CFLAGS="-DDEBUG -DKIK_DEBUG"
fi
AC_SUBST(DEB_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_ENABLE(dl-table,
	[  --disable-dl-table      dynamic loading table @<:@default=enable@:>@],
	dl_table=$enable_dl_table,dl_table="yes")
if test "$dl_table" = "no" ; then
	TABLE_CFLAGS="${TABLE_CFLAGS} -DNO_DYNAMIC_LOAD_TABLE"
else
	DL_LIBS="libmkf_jajp.la libmkf_kokr.la libmkf_zh.la libmkf_8bits.la"
fi
AC_SUBST(TABLE_CFLAGS)
AC_SUBST(DL_LIBS)

#
# --- 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"
	# link mkf_char.lo to libtbl/*.dll to resolve addresses in creating dll.
	MKF_CHAR_LO="../lib/mkf_char.lo"
	if test "x${KIKLIB_BUILDDIR}" != "x" ; then
		KIK_LIBS="${KIKLIB_BUILDDIR}/src/libkik.la"
	else
		KIK_LIBS='-lkik'
	fi
else
	AC_MSG_RESULT(supported)
	NO_UNDEFINED_FLAG=""
	MKF_CHAR_LO=""
	KIK_LIBS=""
fi
AC_SUBST(NO_UNDEFINED_FLAG)
AC_SUBST(MKF_CHAR_LO)
AC_SUBST(KIK_LIBS)


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


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

AC_OUTPUT(Makefile lib/Makefile libtbl/Makefile)
