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

AC_CONFIG_HEADER(common/c_config.h)
AC_CONFIG_AUX_DIR(script)

AC_CANONICAL_HOST
AC_CANONICAL_BUILD

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

if test -d ${top_srcdir-$srcdir}/encodefilter -a -d ${top_srcdir-$srcdir}/baselib ; then
	CONFIG_SUBDIR_LIBS="internal"

	if test "$CONFIG_SUBDIR_LIBS" = "external"; then
		SUBDIRS="baselib encodefilter"
	fi

	MEF_CFLAGS='-I${top_builddir}/encodefilter/include'
	POBL_CFLAGS='-I${top_builddir}/baselib/include'

	LMEF='${top_builddir}/encodefilter/src/libmef.la'
	LPOBL='${top_builddir}/baselib/src/libpobl.la'
elif test -d ${top_srcdir-$srcdir}/../../encodefilter -a -d ${top_srcdir-$srcdir}/../../baselib ; then
	# --with-gui=xlib,fb => cd fb ; --with-gui=fb
	MEF_CFLAGS='-I${top_builddir}/../../encodefilter/include'
	POBL_CFLAGS='-I${top_builddir}/../../baselib/include'

	LMEF='${top_builddir}/../../encodefilter/src/libmef.la'
	LPOBL='${top_builddir}/../../baselib/src/libpobl.la'
else
	LMEF="-lmef"
	LPOBL="-lpobl"
fi

AC_SUBST(LMEF)
AC_SUBST(MEF_CFLAGS)
AC_SUBST(LPOBL)
AC_SUBST(POBL_CFLAGS)

AC_CHECK_TOOL(PKG_CONFIG, pkg-config)

AC_ARG_WITH(ios-sdk,
	[  --with-ios-sdk@<:@=ARG@:>@    iOS SDK (e.g. iphoneos4.3 iphonesimulator4.3) ],
	ios_sdk=$with_ios_sdk)
if test "$ios_sdk" != ""; then
	AC_CHECK_PROG(XCRUN, xcrun, xcrun)
	if test "$XCRUN" != ""; then
		if test "$SDKROOT" = ""; then
			SDKROOT=`$XCRUN --sdk $ios_sdk --show-sdk-path`
		fi

		if test "$CC" = ""; then
			# Do 'export' for baselib/configure and encodefilter/configure.
			export CC="`$XCRUN --sdk $ios_sdk -f cc` -isysroot $SDKROOT"

			simver=`echo $ios_sdk|sed -n 's/^iphonesimulator\(@<:@0-9.@:>@*\)$/\1/p'`
			if test "$simver" != ""; then
				case "$simver" in
				@<:@0-4@:>@.*)
					# -D__IPHONE_OS_VERSION_MIN_REQUIRED=40300 or something like that
					# should be defined as the value of CFLAGS environmental variable
					# before ./configure.
					;;
				*)
					CC="$CC -mios-simulator-version-min=$simver"
					;;
				esac
			fi
		fi

		AC_ARG_WITH(ios-arch,
			[  --with-ios-arch@<:@=ARG@:>@   iOS architectures (e.g. arm7v x86_64,i686) ],
			ios_arch=$with_ios_arch)
		if test "$ios_arch" != ""; then
			ios_arch=`echo ${ios_arch} | sed 's/,/ /g'`
			for arch in $ios_arch; do
				CC="$CC -arch $arch"
			done
		fi

		if test "$CPP" = ""; then
			export CPP="$CC -E"
		fi
		if test "$RANLIB" = ""; then
			export RANLIB=`$XCRUN --sdk $ios_sdk -f ranlib`
		fi
		if test "$LIBTOOL" = ""; then
			export LIBTOOL=`$XCRUN --sdk $ios_sdk -f libtool`
		fi
		if test "$AR" = ""; then
			export AR=`$XCRUN --sdk $ios_sdk -f ar`
		fi
	fi
	XCRUN=
fi

AC_PROG_CC
# mlimgloader (gdiplus.cpp) and SCIM
AC_PROG_CXX
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_LIBTOOL_DLOPEN
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)

AC_CHECK_LIB(socket,connect,SOCK_LIBS=-lsocket)
AC_SUBST(SOCK_LIBS)

AC_PATH_XTRA
if test "$have_x" = "yes"; then
	X_CFLAGS_AUX="-DHAVE_XLIB"
	X_LIBS="$X_LIBS -lX11"
	AC_SUBST(X_CFLAGS_AUX)
fi

MLTERM_FB="mlterm-fb"

AC_ARG_WITH(gui,
	[  --with-gui@<:@=ARG@:>@        gui library (xlib|win32|fb|quartz|console|wayland|sdl2|beos)],
	gui=$with_gui)
if test `echo $gui | grep ,`; then
	gui_list=`echo $gui | sed 's/,/ /g'`
	is_first=t
	mkdir -p ${top_srcdir-$srcdir}/gui
	for g in $gui_list; do
		if test $is_first; then
			gui=$g
			is_first=
		else
			SUBDIRS="${SUBDIRS} gui/$g"
			MAKE_DIRS2="${MAKE_DIRS2} gui/$g"
			if test -d ${top_srcdir-$srcdir}/gui/$g ; then
				echo ""
				echo "** WARNING **"
				echo "${top_srcdir-$srcdir}/gui/$g exists, so copy no files for $g."
				echo "If there are files which should be copied, copy them manually."
				echo ""
			else
				mkdir -p ${top_srcdir-$srcdir}/gui/$g
				# clone source tree to build both mlterm, mlterm-wl, mlterm-fb, mlterm-con and mlterm-sdl2.
				for file in ChangeLog Makefile.in common configure etc gtk inputmethod java \
					main man vtemu script scrollbar uitoolkit doc libvterm; do
					cp -R ${top_srcdir-$srcdir}/$file ${top_srcdir-$srcdir}/gui/$g/
				done
				mkdir -p ${top_srcdir-$srcdir}/gui/$g/contrib
				cp -R ${top_srcdir-$srcdir}/contrib/scrollbar ${top_srcdir-$srcdir}/gui/$g/contrib/
				cp -R ${top_srcdir-$srcdir}/contrib/icon ${top_srcdir-$srcdir}/gui/$g/contrib/
			fi
		fi
	done
elif test "$gui" = "subdir"; then
	gui=`basename $PWD`

	if test "$gui" = "wscons"; then
		MLTERM_FB="mlterm-wscons"
	elif test "$gui" = "x68kgrf"; then
		MLTERM_FB="mlterm-x68kgrf"
	elif test "$gui" = "scpc98"; then
		MLTERM_FB="mlterm-scpc98"
	fi
fi
AC_SUBST(MLTERM_FB)

if test "$gui" = "wscons"; then
	gui="fb"
	fbtype="wscons"
elif test "$gui" = "x68kgrf"; then
	gui="fb"
	fbtype="x68kgrf"
elif test "$gui" = "scpc98"; then
	gui="fb"
	fbtype="pc98"
fi

if test "$gui" = "fb" ; then
	MAKE_DIRS2="doc/kbd ${MAKE_DIRS2}"
	OUTPUT_FILES="doc/kbd/Makefile ${OUTPUT_FILES}"
fi

ml_cv_is_posix="yes"

case "${host_os}" in
mingw*)
	CYGPATHW=echo
	WIN32TAG=_win32
	if test ! -f "/lib/libmsys-1.0.dll.a" ; then
		case "${lt_cv_path_LD}" in
		*-msys*)
			;;
		*)
			ml_cv_is_posix="no"
			;;
		esac
	fi
	if test "$gui" != "sdl2" -a "$gui" != "win32" ; then
		echo "$gui is not supported in ${host_os}. Use win32."
		gui="win32"
	fi
	;;

msys*)
	# msys2
	AC_CHECK_PROG(CYGPATHW,cygpath,cygpath -w,echo)
	WIN32TAG=_win32

	# $have_x is defined in AC_PATH_XTRA.
	if test "$have_x" = "yes" ; then
		if test "$gui" = "" ; then
			gui="xlib"
		elif test "$gui" != "xlib" -a "$gui" != "win32" -a "$gui" != "console" -a "$gui" != "sdl2"; then
			echo "$gui is not supported in ${host_os}. Use win32."
			gui="win32"
		fi
	else
		if test "$gui" != "win32" -a "$gui" != "console" -a "$gui" != "sdl2"; then
			echo "$gui is not supported in ${host_os}. Use win32."
			gui="win32"
		fi
	fi
	;;

cygwin*)
	AC_CHECK_PROG(CYGPATHW,cygpath,cygpath -w,echo)
	WIN32TAG=_win32
	case "${CC} ${CFLAGS}" in
	*mno-cygwin* | *-mingw*)
		ml_cv_is_posix="no"
		;;
	*)
		;;
	esac

	# $have_x is defined in AC_PATH_XTRA.
	if test "$have_x" = "yes" ; then
		if test "$gui" = "" ; then
			gui="xlib"
		elif test "$gui" != "xlib" -a "$gui" != "win32" -a "$gui" != "console" -a "$gui" != "sdl2"; then
			echo "$gui is not supported in ${host_os}. Use win32."
			gui="win32"
		fi
	else
		if test "$gui" != "win32" -a "$gui" != "console" -a "$gui" != "sdl2"; then
			echo "$gui is not supported in ${host_os}. Use win32."
			gui="win32"
		fi
	fi
	;;

*)
	CYGPATHW=echo
	if test "$gui" != "xlib" -a "$gui" != "fb" -a "$gui" != "console" -a "$gui" != "quartz" -a "$gui" != "wayland" -a "$gui" != "sdl2" -a "$gui" != "beos"; then
		if test "$gui" != "" ; then
			echo "$gui is not supported in ${host_os}. xlib is used instead."
		fi
		gui="xlib"
	fi
	# $have_x is defined in AC_PATH_XTRA.
	if test "$gui" = "xlib" -a "$have_x" != "yes" ; then
		echo ""
		echo "** ERROR **"
		echo "Could not find xlib."
		echo ""
		exit 1
	fi
	;;
esac

# for java/Makefile.in
AC_SUBST(WIN32TAG)
AC_SUBST(CYGPATHW)

if test "$ml_cv_is_posix" = "yes" -o "$debug" = "yes" ; then
	SUBSYSTEM="-Wl,--subsystem,console"
fi
AC_SUBST(SUBSYSTEM)

if test "$with_gnu_ld" = "yes" ; then
	DEXPORT="-Wl,--version-script=\$(VPATH)/dexport.map"
elif test "`$LD --version 2>&1 | $GREP Solaris`" != "" ; then
	# This option is for SunOS 5.x (Solaris) or later.
	DEXPORT="-Wl,-M -Wl,\$(VPATH)/dexport-sun.map -Wl,-z -Wl,nodefs"
fi
AC_SUBST(DEXPORT)

AC_ARG_WITH(gtk,
	[  --with-gtk@<:@=ARG@:>@        gtk+ version (2.0|3.0|4.0) @<:@default=3.0@:>@],
	gtk_version=$with_gtk)
if test "$gtk_version" = "no" ; then
	have_gtk=no
else
	if test "$gtk_version" = "4.0" ; then
		PKG_CHECK_MODULES(GTK, gtk4, have_gtk=yes, have_gtk=no)
	else
		if test "$gtk_version" = "" ; then
			gtk_version=3.0
		fi
		PKG_CHECK_MODULES(GTK, gtk+-$gtk_version, have_gtk=yes, have_gtk=no)
	fi

	if test "$have_gtk" != "yes"; then
		if test "$gtk_version" = "3.0"; then
			gtk_version=2.0
		else
			gtk_version=3.0
		fi
		PKG_CHECK_MODULES(GTK, gtk+-$gtk_version, have_gtk=yes, have_gtk=no)
	fi
fi

if test "$ml_cv_is_posix" = "no"; then
	GTK_LIBS="$GTK_LIBS -limagehlp"
fi

AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)

PKG_CHECK_MODULES(GDK_PIXBUF, gdk-pixbuf-2.0, have_gdk_pixbuf2=yes, have_gdk_pixbuf2=no)
# try to link libgio-2.0 explicitly. (SF topic #6234829)
PKG_CHECK_EXISTS(gdk-pixbuf-2.0 >= 2.14, [ PKG_CHECK_MODULES(GIO, gio-2.0) ])
GDK_PIXBUF_CFLAGS="$GDK_PIXBUF_CFLAGS $GIO_CFLAGS"
GDK_PIXBUF_LIBS="$GDK_PIXBUF_LIBS $GIO_LIBS"

AC_CHECK_PROG(have_gdk_pixbuf1,gdk-pixbuf-config,yes)

if test "$gui" = "xlib" ; then
	AC_ARG_WITH(imagelib,
		[  --with-imagelib@<:@=ARG@:>@   image library (gdk-pixbuf) @<:@default=no@:>@],
		imagelib=$with_imagelib)
else
	# Don't link an external image library on win32gdi or framebuffer.
	with_imagelib=""
fi

case ${imagelib} in
imlib)
	AC_CHECK_PROG(imlib_config,imlib-config,yes,no)
	if test "x$imlib_config" = "xno" ; then
		echo ""
		echo "** ERROR **"
		echo "Could not find imlib-config."
		echo ""
		exit 1
	fi
	echo ""
	echo "** WARNING **"
	echo " imlib is no longer supported."
	echo ""
	IMAGELIB_CFLAGS="`imlib-config --cflags` -DBUILTIN_IMAGELIB"
	IMAGELIB_LIBS="`imlib-config --libs`"
	;;
imlib2)
	AC_CHECK_PROG(imlib2_config,imlib2-config,yes,no)
	if test "x$imlib2_config" = "xno" ; then
		echo ""
		echo "** ERROR **"
		echo "Could not find imlib2-config."
		echo ""
		exit 1
	fi
	echo ""
	echo "** WARNING **"
	echo " imlib2 is no longer supported."
	echo ""
	IMAGELIB_CFLAGS="`imlib2-config --cflags` -DBUILTIN_IMAGELIB"
	IMAGELIB_LIBS="`imlib2-config --libs`"
	;;
gdk-pixbuf)
	if test "$have_gdk_pixbuf2" = "yes" ; then
		gdk_pixbuf_version=2
	elif test "$have_gdk_pixbuf1" = "yes" ; then
		gdk_pixbuf_version=1
	else
		echo ""
		echo "** ERROR **"
		echo "Could not find gdk-pixbuf"
		echo ""
		exit 1
	fi
	;;
gdk-pixbuf2)
	if test "$have_gdk_pixbuf2" = "yes" ; then
		gdk_pixbuf_version=2
	else
		echo ""
		echo "** ERROR **"
		echo "Could not find gdk-pixbuf2"
		echo ""
		exit 1
	fi
	;;
gdk-pixbuf1)
	if test "$have_gdk_pixbuf1" = "yes" ; then
		gdk_pixbuf_version=1
	else
		echo ""
		echo "** ERROR **"
		echo "Could not find gdk-pixbuf1"
		echo ""
		exit 1
	fi
	;;
*)
	if test "${imagelib}" != "" ; then
		echo ""
		echo "** ERROR **"
		echo "${imagelib} library is NOT supported."
		echo ""
		exit 1
	fi
	;;
esac

PKG_CHECK_MODULES(FT, freetype2, have_ft=yes, have_ft=no)
if test "$have_ft" = "no" ; then
	PKG_CHECK_MODULES(FT, freetype, have_ft=yes, have_ft=no)
fi
# -DUSE_FREETYPE can be added to FT_CFLAGS later.
FT_CFLAGS_ORIGINAL=$FT_CFLAGS

if test "$gdk_pixbuf_version" != "" ; then
	if test "$gdk_pixbuf_version" = "1" ; then
		# Override GDK_PIXBUF_XXX variables.
		GDK_PIXBUF_CFLAGS="`gdk-pixbuf-config --cflags`"
		GDK_PIXBUF_LIBS="`gdk-pixbuf-config --libs`"
		echo ""
		echo "** WARNING **"
		echo " gdk-pixbuf1 is no longer supported."
		echo ""
	fi

	IMAGELIB_CFLAGS="${GDK_PIXBUF_CFLAGS} -DBUILTIN_IMAGELIB"
	IMAGELIB_LIBS="${GDK_PIXBUF_LIBS}"

	if test "$have_ft" = "yes"; then
		IMAGELIB_CFLAGS="$IMAGELIB_CFLAGS -DUSE_FREETYPE_EMOJI $FT_CFLAGS_ORIGINAL"
		IMAGELIB_LIBS="$IMAGELIB_LIBS $FT_LIBS"
	fi
elif test "$have_gdk_pixbuf2" != "yes" -a "$have_gdk_pixbuf1" = "yes" ; then
	GDK_PIXBUF_CFLAGS="`gdk-pixbuf-config --cflags`"
	GDK_PIXBUF_LIBS="`gdk-pixbuf-config --libs`"
fi

# Used by mlimgloader.
AC_SUBST(GDK_PIXBUF_CFLAGS)
AC_SUBST(GDK_PIXBUF_LIBS)

AC_SUBST(IMAGELIB_CFLAGS)
AC_SUBST(IMAGELIB_LIBS)

# XXX For pow in libm.so which is used in ui_imagelib.c
# /lib/* ... e.g.) /lib/i386-linux-gnu in ubuntu.
for ml_cv_lib_path in /lib /usr/lib /lib/* `echo $LIBRARY_PATH | tr ":" " "` ; do
	libm_files=`ls $ml_cv_lib_path/libm\\.so* $ml_cv_lib_path/libm\\.sl* 2> /dev/null`
	for libm_file in $libm_files ; do
		if test -n "`$NM -D $libm_file | $GREP pow`" ; then
			ml_cv_libm_dir=`dirname $libm_file`
			break
		fi
	done
	if test "$ml_cv_libm_dir" != ""; then
		break
	fi
done
if test -z "$IMAGELIB_LIBS" ; then
	if test -n "$ml_cv_libm_dir" ; then
		MATH_CFLAGS="-DDLOPEN_LIBM -DLIBMDIR=\\\"$ml_cv_libm_dir\\\""
	else
		AC_CHECK_LIB(m, pow, MATH_LIBS=-lm)
	fi
else
	AC_CHECK_LIB(m, pow, MATH_LIBS=-lm)
fi
AC_SUBST(MATH_LIBS)
AC_SUBST(MATH_CFLAGS)


AC_ARG_ENABLE(image,
	[  --disable-image         show image @<:@default=enabled@:>@],
	image=$enable_image, image="yes")
if test "$image" != "yes" ; then
	# If sixel.h is not found on gui=console, set IMAGE_CFLAGS="-DNO_IMAGE" forcibly below.
	IMAGE_CFLAGS="-DNO_IMAGE"
fi
AC_SUBST(IMAGE_CFLAGS)


if test "$gui" = "win32" ; then
	GUI="win32"
	GUI_CFLAGS="-DUSE_WIN32GUI"
	X_CFLAGS=""
elif test "$gui" = "xlib" ; then
	GUI="xlib"
	# Li18nux Xlib-I18N defines X_HAVE_UTF8_STRING but has no Xutf8LookupString.
	ldflags="$LDFLAGS" cflags="$CFLAGS"
	LDFLAGS="$LDFLAGS $X_PRE_LIBS $X_LIBS $X_EXTRA_LIBS" CFLAGS="$X_CFLAGS $CFLAGS"
	AC_CHECK_LIB(X11,Xutf8LookupString,XUTF8_CFLAGS="-DHAVE_XUTF8_LOOKUP_STRING")
	LDFLAGS="$ldflags" CFLAGS="$cflags"
	AC_SUBST(XUTF8_CFLAGS)
elif test "$gui" = "quartz" ; then
	GUI="quartz"
	GUI_CFLAGS="-DUSE_QUARTZ"
	if test "$ios_sdk" != ""; then
		GUI_CFLAGS="$GUI_CFLAGS -DCOCOA_TOUCH"
		COCOAOBJ=cocoatouch.o
		COCOA_LIBS="-framework Foundation -framework UIKit -framework CoreGraphics"
	else
		COCOAOBJ=cocoa.o
		COCOA_LIBS="-framework Foundation -framework Cocoa"
	fi
	AC_SUBST(COCOAOBJ)
	AC_SUBST(COCOA_LIBS)
	# for mlimgloader
	X_CFLAGS_AUX="$X_CFLAGS $X_CFLAGS_AUX"
	X_CFLAGS=""
	VT_NORM_OBJ="vt_normalize.o"
	VT_NORM_CFLAGS="-DUSE_NORMALIZE"
	AC_SUBST(VT_NORM_OBJ)
	AC_SUBST(VT_NORM_CFLAGS)
elif test "$gui" = "console" ; then
	GUI="console"
	GUI_CFLAGS="-DUSE_CONSOLE"
	AC_CHECK_HEADER(sixel.h, SIXEL_CFLAGS="-DUSE_LIBSIXEL")
	if test "$SIXEL_CFLAGS" = "-DUSE_LIBSIXEL" ; then
		SIXEL_LIBS="-lsixel"
	else
		IMAGE_CFLAGS="-DNO_IMAGE"
		IMAGELIB_CFLAGS=""
		IMAGELIB_LIBS=""
	fi
	AC_SUBST(SIXEL_CFLAGS)
	AC_SUBST(SIXEL_LIBS)
elif test "$gui" = "beos" ; then
	GUI="beos"
	GUI_CFLAGS="-DUSE_BEOS"
elif test "$gui" = "wayland" ; then
	PKG_CHECK_MODULES(WAYLAND, [wayland-client wayland-cursor xkbcommon])
	GUI="wayland"
	GUI_CFLAGS="-DUSE_WAYLAND"
	AC_SUBST(WAYLAND_CFLAGS)
	AC_SUBST(WAYLAND_LIBS)
elif test "$gui" = "sdl2" ; then
	PKG_CHECK_MODULES(SDL2, sdl2, have_sdl2=yes, have_sdl2=no)
	if test "$have_sdl2" != "yes" ; then
		AC_CHECK_PROG(sdl2_config, sdl2-config, yes)
		if test "$sdl2_config" = "yes"; then
			SDL2_CFLAGS="`sdl2-config --cflags`"
			SDL2_LIBS="`sdl2-config --libs`"
		else
			echo "sdl2 is not available."
			exit 1
		fi
	fi
	if test "$ml_cv_is_posix" != "yes"; then
		SDL2GUI="win32"
		AC_SUBST(SDL2GUI)
	fi
	GUI="sdl2"
	GUI_CFLAGS="-DUSE_SDL2"
	AC_SUBST(SDL2_CFLAGS)
	AC_SUBST(SDL2_LIBS)
else
	GUI="fb"
	if test "$fbtype" = ""; then
		if test "`sysctl machdep.ispc98`" = "machdep.ispc98: 1"; then
			fbtype="pc98"
		else
			# for NetBSD/x68k
			# <machine/vuid_event.h> is also checked not to enable USE_GRF on NetBSD/macppc.
			AC_CHECK_HEADER(machine/grfioctl.h,
				AC_CHECK_HEADER(machine/vuid_event.h,
					[
					fbtype="x68kgrf"
					GUI_CFLAGS="-DHAVE_GRFIOCTL_H"
					]))
		fi
	fi

	if test "$fbtype" = "x68kgrf"; then
		GUI_CFLAGS="${GUI_CFLAGS} -DUSE_GRF"
	elif test "$fbtype" = "pc98"; then
		GUI_CFLAGS="${GUI_CFLAGS} -DPC98"
	fi

	GUI_CFLAGS="${GUI_CFLAGS} -DUSE_FRAMEBUFFER"
fi
AC_SUBST(GUI)
AC_SUBST(GUI_CFLAGS)

AC_CHECK_HEADER(regex.h,
[
	REGEX_CFLAGS="-DHAVE_REGEX"
	AC_CHECK_LIB(regex,regcomp,REGEX_LIBS=-lregex)
])
AC_SUBST(REGEX_CFLAGS)
AC_SUBST(REGEX_LIBS)


AC_ARG_ENABLE(compact-truecolor,
	[  --disable-compact-truecolor true color support by reusing 240 palettes @<:@default=enabled@:>@],
	compact_truecolor=$enable_compact_truecolor, compact_truecolor="yes")
if test "$compact_truecolor" = "yes" ; then
	TRUECOLOR_CFLAGS="-DUSE_COMPACT_TRUECOLOR"
else
	TRUECOLOR_TAG="x"
fi
AC_SUBST(TRUECOLOR_CFLAGS)
AC_SUBST(TRUECOLOR_TAG)

AC_ARG_ENABLE(dl-ctl,
	[  --disable-dl-ctl        dynamic loading ctl library @<:@default=enable@:>@],
	dl_ctl=$enable_dl_ctl, dl_ctl="yes")
if test "$enable_shared" = "no" ; then
	dl_ctl="no"
fi

if test "$dl_ctl" = "yes" ; then
	LMLTERM_CORE=libmlterm${TRUECOLOR_TAG}_core.la
	CTL_LOADER_OBJ=vt_ctl_loader.o
else
	LMLTERM_CORE=libmlterm${TRUECOLOR_TAG}_core.a
	CTL_CFLAGS="-DNO_DYNAMIC_LOAD_CTL"
	CTL_LIBS_FOR_VTE="../vtemu/libctl/*.lo"
fi
AC_SUBST(LMLTERM_CORE)
AC_SUBST(CTL_LOADER_OBJ)

AC_ARG_ENABLE(fribidi,
	[  --disable-fribidi       bidi @<:@default=enabled@:>@],
	fribidi=$enable_fribidi, fribidi="yes")
if test "$fribidi" = "yes" ; then
	PKG_CHECK_MODULES(FRIBIDI, fribidi, have_fribidi=yes, have_fribidi=no)
	if test "$have_fribidi" != "yes" ; then
		AC_CHECK_PROG(fribidi_config,fribidi-config,yes,fribidi="no")
		if test "$fribidi_config" = "yes" ; then
			FRIBIDI_CFLAGS="`fribidi-config --cflags`"
			FRIBIDI_LIBS="`fribidi-config --libs`"
			have_fribidi="yes"
		fi
	fi
else
	have_fribidi="no"
fi
if test "$have_fribidi" = "yes" ; then
	if test "$dl_ctl" = "yes" ; then
		CTL_LIBS="libctl${TRUECOLOR_TAG}_bidi.la ${CTL_LIBS}"
	else
		CTL_CFLAGS="-DUSE_FRIBIDI ${CTL_CFLAGS}"
		CTL_LIBS="libctl${TRUECOLOR_TAG}_bidi.a ${CTL_LIBS}"
		CTL_LIBS_FOR_PROG="../vtemu/libctl/libctl${TRUECOLOR_TAG}_bidi.a ${FRIBIDI_LIBS} ${CTL_LIBS_FOR_PROG}"
		CTL_LIBS_FOR_VTE="${FRIBIDI_LIBS} ${CTL_LIBS_FOR_VTE}"
	fi
fi

AC_SUBST(FRIBIDI_CFLAGS)
AC_SUBST(FRIBIDI_LIBS)
AC_SUBST(CTL_CFLAGS)
AC_SUBST(CTL_LIBS_FOR_VTE)

AC_ARG_WITH(pthread,
	[  --without-pthread       do not use pthread @<:@default=with@:>@])

AC_ARG_ENABLE(dl-type,
	[  --disable-dl-type       dynamic loading type engine library @<:@default=enable@:>@],
	dl_type=$enable_dl_type, dl_type="yes")
if test "$enable_shared" = "no" ; then
	dl_type="no"
fi

if test "$dl_type" = "yes" ; then
	TYPE_LOADER_OBJ=ui_type_loader.o
	if test "$gui" != "xlib" ; then
		TYPE_CFLAGS="-DNO_DYNAMIC_LOAD_TYPE"
	fi
else
	TYPE_CFLAGS="-DNO_DYNAMIC_LOAD_TYPE"
	TYPE_LIBS_FOR_VTE="../uitoolkit/libtype/*.lo"
fi
AC_SUBST(TYPE_LOADER_OBJ)

if test "$gui" != "win32" -a "$gui" != "quartz"; then
	PKG_CHECK_MODULES(FONTCONFIG, fontconfig, have_fc=yes, have_fc=no)
	if test "$have_fc" = "yes"; then
		FONTCONFIG_CFLAGS="$FONTCONFIG_CFLAGS -DUSE_FONTCONFIG"
		AC_SUBST(FONTCONFIG_CFLAGS)
		AC_SUBST(FONTCONFIG_LIBS)
	fi
fi

AC_ARG_ENABLE(anti_alias,
	[  --disable-anti-alias    same as --with-type-engines=xcore on xlib @<:@default=enabled@:>@
                          do not use truetype fonts on framebuffer @<:@default=enabled@:>@ ],
	anti_alias=$enable_anti_alias, anti_alias="auto")

if test "$anti_alias" != "no"; then
	if test "$gui" = "fb" -o "$gui" = "wayland" -o "$gui" = "sdl2"; then
		if test "$have_ft" = "yes" ; then
			FT_CFLAGS="$FT_CFLAGS -DUSE_FREETYPE "

			AC_ARG_ENABLE(fontconfig,
				[  --disable-fontconfig    use fontconfig with freetype on framebuffer or wayland @<:@default=enabled@:>@ ],
	  		fontconfig=$enable_fontconfig, fontconfig="yes")

			if test "$fontconfig" != "no" -a "$have_fc" = "yes"; then
				FT_CFLAGS="$FT_CFLAGS $FONTCONFIG_CFLAGS"
				FT_LIBS="$FT_LIBS $FONTCONFIG_LIBS"
			else
				fontconfig="no"
  		fi

			AC_SUBST(FT_CFLAGS)
			AC_SUBST(FT_LIBS)
		fi
	fi
fi

AC_ARG_WITH(type_engines,
	[  --with-type-engines@<:@=ARG@:>@ type engines (xcore, xft, cairo) @<:@default=xcore,xft,cairo@:>@],
	type_engines=$with_type_engines)

if test "$gui" != "xlib" ; then
	type_engines="xcore"
elif test "$type_engines" = "" ; then
	if test "$anti_alias" = "no" ; then
		type_engines="xcore"
	else
		type_engines="xcore,xft,cairo"
	fi
fi

type_engines=`echo ${type_engines} | sed 's/,/ /g'`
for type_engine in ${type_engines} ; do
case ${type_engine} in
xft)
	PKG_CHECK_MODULES(XFT, xft, have_xft=yes, have_xft=no)
	if test "$have_xft" != "yes" ; then
		AC_CHECK_PROG(xft_config,xft-config,yes)
		if test "$xft_config" = "yes" ; then
			XFT_CFLAGS="`xft-config --cflags`"
			XFT_LIBS="`xft-config --libs`"
			have_xft=yes
		else
			AC_CHECK_LIB(Xft,XftDrawCreate,
				[
				have_xft=yes
				# -lfontconfig is necessary because ui_font_ft.c refers FcXXX
				# functions directly.
				# -lfreetype is necessary because ui_window_xft.c refers FT_XXX
				# functions directly.
				XFT_LIBS="-lXft -lfontconfig -lfreetype"
				])
		fi
	elif test "$gui" = "xlib" ; then
		# In some platforms (e.g. ubuntu 14.04) dependency_libs="" in libXft.la.
		# So if --disable-shared is specified or allow_undefined_flags = unsupported,
		# compiling fails.
		XFT_LIBS="$XFT_LIBS -lfontconfig -lfreetype"
	fi

	if test "$have_xft" = "yes" ; then
		if test "$dl_type" = "yes" ; then
			TYPE_LIBS="libtype_xft.la ${TYPE_LIBS}"
		else
			NODL_OBJ="ui_window_xft.o ${NODL_OBJ}"
			TYPE_LIBS_FOR_VTE="${XFT_LIBS} ${TYPE_LIBS_FOR_VTE}"
		fi
		TYPE_CFLAGS="-DUSE_TYPE_XFT ${TYPE_CFLAGS}"
		type_engines_result="$type_engines_result xft"
	fi
	;;
cairo)
	PKG_CHECK_MODULES(CAIRO, cairo, have_cairo=yes, have_cairo=no)
	if test "$have_cairo" != "yes" ; then
		AC_CHECK_LIB(cairo,cairo_create,
			[
			have_cairo=yes
			# -lfontconfig is necessary because ui_font_ft.c refers FcXXX
			# functions directly.
			# -lfreetype is necessary because ui_window_cairo.c refers FT_XXX
			# functions directly.
			CAIRO_LIBS="-lcairo -lfontconfig -lfreetype"
			])
	elif test "$gui" = "xlib" ; then
		# In some platforms (e.g. ubuntu 14.04) dependency_libs="" in libcairo.la.
		# So if --disable-shared is specified or allow_undefined_flags = unsupported,
		# compiling fails.
		CAIRO_LIBS="$CAIRO_LIBS -lfontconfig -lfreetype"
	fi

	if test "$have_cairo" = "yes" ; then
		if test "$dl_type" = "yes" ; then
			TYPE_LIBS="libtype_cairo.la ${TYPE_LIBS}"
			if test "$with_pthread" != "no" ; then
				# NetBSD doesn't allow shared libraries to link
				# libpthread without linking it to executables.
				case "${host_os}" in
				netbsd*)
					PTHREAD_LIB="-lpthread"
					;;
				esac
			fi
		else
			NODL_OBJ="ui_window_cairo.o ${NODL_OBJ}"
			TYPE_LIBS_FOR_VTE="${CAIRO_LIBS} ${TYPE_LIBS_FOR_VTE}"
		fi
		TYPE_CFLAGS="-DUSE_TYPE_CAIRO ${TYPE_CFLAGS}"
		type_engines_result="$type_engines_result cairo"
	fi
	;;
xcore)
	TYPE_CFLAGS="-DUSE_TYPE_XCORE ${TYPE_CFLAGS}"
	type_engines_result="$type_engines_result xcore"
	;;
*)
	echo "${type_engine} is unknown type engine."
	;;
esac
done

AC_ARG_ENABLE(otl,
	[  --disable-otl           Open Type layout with the use of harfbuzz or libotf @<:@default=enabled@:>@],
	otl=$enable_otl,
	otl="yes")
if test "$otl" != "yes" ; then
	echo "Open Type layout is disabled"
elif test "$gui" = "xlib" -a "$dl_type" = "no" -a "$type_engines_result" = " xcore"; then
	echo "libotf/libharfbuzz is not available."
elif test "$gui" = "fb" -a "$have_ft" != "yes" ; then
	echo "libotf/libharfbuzz is not available."
elif test "$gui" = "wayland" -a "$have_ft" != "yes" ; then
	echo "libotf/libharfbuzz is not available."
elif test "$gui" = "sdl2" -a "$have_ft" != "yes" ; then
	echo "libotf/libharfbuzz is not available."
elif test "$gui" = "console" ; then
	echo "libotf/libharfbuzz is not available."
else
	PKG_CHECK_MODULES(HB, harfbuzz, have_hb=yes, have_hb=no)
	if test "$have_hb" = "yes" ; then
		if test "$gui" = "quartz" ; then
			CFLAGS_orig=$CFLAGS
			CPPFLAGS_orig=$CPPFLAGS
			CFLAGS="$CFLAGS $HB_CFLAGS"
			CPPFLAGS="$CPPFLAGS $HB_CFLAGS"
			AC_CHECK_HEADER(hb-coretext.h, have_hb_coretext_h=yes, have_hb_coretext_h=no)
			CFLAGS=$CFLAGS_orig
			CPPFLAGS=$CPPFLAGS_orig
			if test "$have_hb_coretext_h" != "yes" ; then
				echo ""
				echo "** ERROR **"
				echo "harfbuzz/hb-coretext.h is not found."
				echo "Install harfbuzz with --with-coretext=yes in advance."
				echo ""
				have_hb=no
			fi
		elif test "$have_ft" = "yes" ; then
			CFLAGS_orig=$CFLAGS
			CPPFLAGS_orig=$CPPFLAGS
			CFLAGS="$CFLAGS $HB_CFLAGS $FT_CFLAGS_ORIGINAL"
			CPPFLAGS="$CPPFLAGS $HB_CFLAGS $FT_CFLAGS_ORIGINAL"
			AC_CHECK_HEADER(hb-ft.h, have_hb_ft_h=yes, have_hb_ft_h=no)
			CFLAGS=$CFLAGS_orig
			CPPFLAGS=$CPPFLAGS_orig
			if test "$have_hb_ft_h" != "yes" ; then
				echo ""
				echo "** ERROR **"
				echo "harfbuzz/hb-ft.h is not found."
				echo "Install harfbuzz with --with-freetype=yes in advance."
				echo ""
				have_hb=no
			fi
		fi
	fi

	if test "$have_hb" = "yes"; then
		OT_LAYOUT_CFLAGS="$HB_CFLAGS -DUSE_HARFBUZZ -DUSE_OT_LAYOUT"
		OT_LAYOUT_LIBS="$HB_LIBS"
		OT_LAYOUT_OBJ=hb.o
		if test "$gui" = "win32"; then
			OT_LAYOUT_LIBS="$OT_LAYOUT_LIBS -lfreetype"
		elif test "$gui" != "quartz" -a "$have_ft" = "yes"; then
			OT_LAYOUT_CFLAGS="$OT_LAYOUT_CFLAGS $FT_CFLAGS_ORIGINAL"
		fi
	elif test "$gui" = "win32" ; then
		OT_LAYOUT_CFLAGS="-DUSE_OT_LAYOUT -DUSE_UNISCRIBE"
		OT_LAYOUT_OBJ=uniscribe.o
		OT_LAYOUT_LIBS="-lusp10"
	else
		AC_CHECK_PROG(libotf_config,libotf-config,yes)
		if test "$libotf_config" = "yes" ; then
			OT_LAYOUT_CFLAGS="`libotf-config --cflags` -DUSE_OT_LAYOUT"
			OT_LAYOUT_LIBS="`libotf-config --libs`"
			OT_LAYOUT_OBJ=otf.o
		fi
	fi

	if test "$OT_LAYOUT_OBJ" != "" -a "$enable_shared" = "no" ; then
		OT_LAYOUT_CFLAGS="$OT_LAYOUT_CFLAGS -DNO_DYNAMIC_LOAD_OTL"
		OT_LAYOUT_LIBS_FOR_PROG="$OT_LAYOUT_LIBS"
	fi

  if test "$OT_LAYOUT_OBJ" != "" -a "$LMLTERM_CORE" = "libmlterm${TRUECOLOR_TAG}_core.la" ; then
		 LMLTERM_CORE="libmlterm${TRUECOLOR_TAG}_coreotl.la"
	fi
fi
AC_SUBST(OT_LAYOUT_LIBS)
AC_SUBST(OT_LAYOUT_LIBS_FOR_PROG)
AC_SUBST(OT_LAYOUT_CFLAGS)
AC_SUBST(OT_LAYOUT_OBJ)

if test "$OT_LAYOUT_OBJ" != "" ; then
	MAKE_DIRS2="uitoolkit/libotl ${MAKE_DIRS2}"
	OUTPUT_FILES="uitoolkit/libotl/Makefile ${OUTPUT_FILES}"
fi

if test "${NODL_OBJ}" != "" ; then
	TYPE_LIBS=libtype.a
	TYPE_LIBS_FOR_PROG="../uitoolkit/libtype/libtype.a ${CAIRO_LIBS} ${XFT_LIBS} ${OT_LAYOUT_LIBS}"
fi

if test "${TYPE_CFLAGS}" = "" ; then
	echo "No type engine is specified."
	exit  1
fi

AC_SUBST(XFT_CFLAGS)
AC_SUBST(XFT_LIBS)
AC_SUBST(CAIRO_LIBS)
AC_SUBST(CAIRO_LIBS)
AC_SUBST(TYPE_CFLAGS)
AC_SUBST(TYPE_LIBS)
AC_SUBST(TYPE_LIBS_FOR_PROG)
AC_SUBST(TYPE_LIBS_FOR_VTE)
AC_SUBST(NODL_OBJ)
AC_SUBST(PROG)

AC_ARG_ENABLE(ssh2,
	[  --disable-ssh2          libssh2 @<:@default=enabled@:>@],
	ssh2=$enable_ssh2, ssh2="yes")
if test "$ssh2" = "yes" ; then
	PKG_CHECK_MODULES(SSH2, libssh2,
		[
		SSH2_CFLAGS="$SSH2_CFLAGS -DUSE_LIBSSH2"
		if test "x$allow_undefined_flag" = "xunsupported" ; then
			# vt_pty_ssh.c uses CRYPTO_xxx functions.
			SSH2_LIBS="-lcrypto $SSH2_LIBS"
		fi
		], ssh2="no")
fi

if test "$enable_shared" != "no" ; then
	AC_ARG_WITH(mosh,
		[  --with-mosh@<:@=ARG@:>@       The directory where mosh is built])

	if test -d "$with_mosh"; then
		PKG_CHECK_MODULES(PROTOBUF, protobuf, MOSH_DIR=$with_mosh, with_mosh="")

		if test "$MOSH_DIR" != ""; then
			if test -f $MOSH_DIR/src/crypto/ocb.cc; then
				# mosh-1.3.2 or before.
				MOSH_OCB_OBJ="ocb.o"
				# XXX (See terminaldisplayinit.cc)
				PROTOBUF_CFLAGS="$PROTOBUF_CFLAGS -DMOSH_VERSION=10302"
			else
				# mosh-1.4.0 or later.
				MOSH_OCB_OBJ="ocb_internal.o"
			fi
		fi
	fi
fi

if test "$ml_cv_is_posix" = "no" ; then
	if test "$ssh2" = "yes" ; then
		VT_PTY_OBJ="vt_pty_ssh.o vt_pty_mosh.o"

		if test -d "$with_mosh"; then
			MAKE_DIRS2="${MAKE_DIRS2} vtemu/libptyssh vtemu/libptymosh"
			OUTPUT_FILES="${OUTPUT_FILES} vtemu/libptyssh/Makefile vtemu/libptymosh/Makefile"
			SSH2_LIBS_FOR_PROG="-lwsock32"
			# XXX Hack for wcwidth()
			PROTOBUF_LIBS="$PROTOBUF_LIBS \${top_builddir}/encodefilter/src/libmef.la"
		else
			# Not dlopen
			SSH2_CFLAGS="$SSH2_CFLAGS -DNO_DYNAMIC_LOAD_SSH"
			SSH2_LIBS_FOR_PROG="$SSH2_LIBS -lwsock32 -lws2_32"
			SSH2_LIBS=
		fi
		SSH2_LIBS_FOR_VTE=$SSH2_LIBS_FOR_PROG
	fi

	AC_CHECK_FUNC(CreatePseudoConsole,
		[
		PTY_CFLAGS="-DUSE_CONPTY"
		win32pty="conpty pipe"
		],
		[win32pty=pipe])
	AC_SUBST(PTY_CFLAGS)

	VT_PTY_OBJ="$VT_PTY_OBJ vt_pty_win32.o"
else
	VT_PTY_OBJ="vt_pty_unix.o"

	if test "$ssh2" = "yes" ; then
		if test "$with_pthread" != "no" ; then
			AC_CHECK_HEADER(pthread.h,
				[
				SSH2_CFLAGS="$SSH2_CFLAGS -DHAVE_PTHREAD"
				SSH2_LIBS="$SSH2_LIBS -lpthread"
				])
			# NetBSD doesn't allow shared libraries to link libpthread
			# without linking it to executables.
			case "${host_os}" in
			netbsd*)
				PTHREAD_LIB="-lpthread"
				;;
			esac
		fi

		VT_PTY_OBJ="vt_pty_ssh.o vt_pty_mosh.o ${VT_PTY_OBJ}"

		if test "$enable_shared" = "no" ; then
			SSH2_CFLAGS="$SSH2_CFLAGS -DNO_DYNAMIC_LOAD_SSH"
			SSH2_LIBS_FOR_PROG="$SSH2_LIBS"
			SSH2_LIBS=
		else
			# dlopen libptyssh
			MAKE_DIRS2="vtemu/libptyssh ${MAKE_DIRS2}"
			OUTPUT_FILES="vtemu/libptyssh/Makefile ${OUTPUT_FILES}"

			if test -d "$with_mosh"; then
				MAKE_DIRS2="${MAKE_DIRS2} vtemu/libptymosh"
				OUTPUT_FILES="${OUTPUT_FILES} vtemu/libptymosh/Makefile"
			fi
		fi

		if test "$ios_sdk" != ""; then
			# system() is disabled on ios.
			SSH2_CFLAGS="$SSH2_CFLAGS -DNO_XAUTH"
		fi
	fi
fi
AC_SUBST(SSH2_LIBS)
AC_SUBST(SSH2_LIBS_FOR_PROG)
AC_SUBST(SSH2_LIBS_FOR_VTE)
AC_SUBST(SSH2_CFLAGS)
AC_SUBST(VT_PTY_OBJ)
AC_SUBST(MOSH_DIR)
AC_SUBST(MOSH_OCB_OBJ)
AC_SUBST(PROTOBUF_CFLAGS)
AC_SUBST(PROTOBUF_LIBS)

if test "${have_gtk}" = "yes" ; then
	if test "${gtk_version}" = "3.0" ; then
		PKG_CHECK_MODULES(VTE, vte-2.91, have_vte=yes, have_vte=no)
		if test "$have_vte" = "yes" ; then
			VTE_ABI=2.91
		else
			PKG_CHECK_MODULES(VTE, vte-2.90, have_vte=yes, have_vte=no)
			if test "$have_vte" = "yes"; then
				VTE_ABI=2.90
			fi
		fi
	elif test "${gtk_version}" = "4.0" ; then
		PKG_CHECK_MODULES(VTE, vte-2.91-gtk4, have_vte=yes, have_vte=no)
		if test "$have_vte" = "yes" ; then
			VTE_ABI=2.91-gtk4
		else
			# Even if vte-2.91-gtk4 is not found, create gtk/Makefile.in for 'make gtk3'.
			PKG_CHECK_MODULES(VTE, vte-2.91, have_vte=yes, have_vte=no)
			if test "$have_vte" = "yes"; then
				VTE_ABI=2.91
			fi
		fi
	else
		PKG_CHECK_MODULES(VTE, vte, have_vte=yes, have_vte=no)
	fi
	if test "$have_vte" = "yes" ; then
		OUTPUT_FILES="gtk/Makefile ${OUTPUT_FILES}"
		AC_SUBST(VTE_ABI)
	fi
else
	have_vte=no
fi

if test "$image" = "yes"; then
	tools="mlclient,mlconfig,mlcc,mlterm-menu,mlimgloader,registobmp,mlfc"
else
	tools="mlclient,mlconfig,mlcc,mlterm-menu,mlfc"
fi
AC_ARG_WITH(tools,
	[  --with-tools@<:@=ARG@:>@      external tools @<:@default=mlclient,mlconfig,mlcc,mlterm-menu,mlimgloader,registobmp,mlfc@:>@]
                          (mlimgloader is automatically added unless --disable-image or --with-imagelib is specified),
	[
	# if given --without-tools
	if test "${with_tools}" = "no" ; then
		tools=""
	else
		if test "${with_tools}" != "yes" ; then
			tools=${with_tools}
		fi
		if test -z "$IMAGELIB_CFLAGS" -a "`echo ${tools}|$GREP mlimgloader`" = "" -a "$image" = "yes"; then
			# If --with-imagelib option is not specified, mlimgloader is always built.
			tools=${tools},mlimgloader
		fi
	fi
	])
tools=`echo ${tools} | sed 's/,/ /g'`

AC_ARG_ENABLE(use-tools,
	[  --disable-use-tools     do not build and use external tools @<:@default=enabled@:>@])
if test "$enable_use_tools" = "no" ; then
	TOOLS_CFLAGS="-DNO_TOOLS"
	tools=
fi
AC_SUBST(TOOLS_CFLAGS)

AM_INIT_AUTOMAKE(mlterm,3.9.5)

if test "$gui_list" != ""; then
	# Enable all tools by default
	gui_for_tool="xlib"
else
	gui_for_tool=$gui
fi

for tool in ${tools} ; do
case ${tool} in
mlconfig)
	if test "$gui_for_tool" != "fb" -a "$gui_for_tool" != "console" ; then
		if test "${have_gtk}" = "yes" ; then
			AM_GLIB_GNU_GETTEXT
			MAKE_DIRS2="tool/mlconfig ${MAKE_DIRS2}"
			OUTPUT_FILES="tool/mlconfig/Makefile ${OUTPUT_FILES}"
			if test "${MSGFMT}" != "no"; then
				OUTPUT_FILES="tool/mlconfig/po/Makefile.in ${OUTPUT_FILES}"
			fi
			tools_result="$tools_result $tool"
			if test "$gtk_version" = "2.0"; then
				# for gtkxlfdsel.c
				X_LIBS_FOR_MLCONFIG=$X_LIBS
			fi
			AC_SUBST(X_LIBS_FOR_MLCONFIG)
		else
			echo ""
			echo "** WARNING  **"
			echo " couldn't compile mlconfig since headers/libraries of GTK+ are missing."
			echo ""
		fi
	fi
	;;
mlterm-menu)
	# gtk4 is not supported.
	if test "${have_gtk}" = "yes" -a "${gtk_version}" != "4.0" -a "$gui_for_tool" != "fb" -a "$gui_for_tool" != "console" ; then
		MAKE_DIRS2="contrib/tool/mlterm-menu ${MAKE_DIRS2}"
		OUTPUT_FILES="contrib/tool/mlterm-menu/Makefile ${OUTPUT_FILES}"
		tools_result="$tools_result $tool"
	else
		echo ""
		echo "** WARNING  **"
		echo " couldn't compile mlterm-menu since headers/libraries of GTK+-2 are missing."
		echo ""
	fi
	;;
mlclient)
	if test "$ml_cv_is_posix" = "yes" -a "$gui_for_tool" != "console" ; then
		MAKE_DIRS2="tool/mlclient ${MAKE_DIRS2}"
		OUTPUT_FILES="tool/mlclient/Makefile ${OUTPUT_FILES}"
		tools_result="$tools_result $tool"
	fi
	;;
w3mmlconfig)
	AC_PATH_PROG(PERL,perl,$PATH)
	if test "x$PERL" = x ; then
		echo ""
		echo "** WARNING  **"
		echo " couldn't find perl in PATH environment variable."
		echo ""
		PERL="/usr/local/bin/perl" # should be "/usr/bin/env perl"?
	fi
	MAKE_DIRS2="tool/w3mmlconfig ${MAKE_DIRS2}"
	OUTPUT_FILES="tool/w3mmlconfig/Makefile tool/w3mmlconfig/mlconfig.cgi tool/w3mmlconfig/w3mmlconfig ${OUTPUT_FILES}"
	tools_result="$tools_result $tool"
	;;
mlcc)
	if test "$ml_cv_is_posix" = "yes" ; then
		MAKE_DIRS2="contrib/tool/mlcc ${MAKE_DIRS2}"
		OUTPUT_FILES="contrib/tool/mlcc/Makefile ${OUTPUT_FILES}"
		tools_result="$tools_result $tool"
	fi
	;;
mlmenu)
	if test "$gui_for_tool" = "xlib" ; then
		MAKE_DIRS2="tool/mlmenu ${MAKE_DIRS2}"
		OUTPUT_FILES="tool/mlmenu/Makefile ${OUTPUT_FILES}"
		tools_result="$tools_result $tool"
	fi
	;;
mlterm-zoom)
	if test "$gui_for_tool" = "xlib" ; then
		MAKE_DIRS2="contrib/tool/mlterm-zoom ${MAKE_DIRS2}"
		OUTPUT_FILES="contrib/tool/mlterm-zoom/Makefile ${OUTPUT_FILES}"
		tools_result="$tools_result $tool"
	fi
	;;
mlimgloader)
	if test "$gui_for_tool" != "quartz" ; then
		OUTPUT_FILES="tool/mlimgloader/Makefile ${OUTPUT_FILES}"
		MAKE_DIRS2="tool/mlimgloader ${MAKE_DIRS2}"
		tools_result="$tools_result $tool"

		AC_TRY_COMPILE([
			#include  <windows.h>
			#include  <gdiplus.h>],,
			have_gdiplus=yes,have_gdiplus=no)
		if test "$have_gdiplus" = "yes" ; then
			MLIMGLOADER_LIB=gdiplus
		elif test "$have_gdk_pixbuf2" = "yes" -o "$have_gdk_pixbuf1" = "yes" ; then
			MLIMGLOADER_LIB=gdk-pixbuf
		else
			PKG_CHECK_MODULES(LIBPNG, libpng, MLIMGLOADER_LIB=libpng, MLIMGLOADER_LIB=none)
			AC_SUBST(LIBPNG_CFLAGS)
			AC_SUBST(LIBPNG_LIBS)
		fi
		AC_SUBST(MLIMGLOADER_LIB)

		if test "$have_ft" = "yes"; then
			EMOJI_CFLAGS="-DUSE_FREETYPE_EMOJI $FT_CFLAGS_ORIGINAL"
			EMOJI_LIBS="$FT_LIBS"
			AC_SUBST(EMOJI_CFLAGS)
			AC_SUBST(EMOJI_LIBS)
		fi
	fi
	;;
registobmp)
	if test "$have_sdl2" = "yes"; then
		SDL_CFLAGS=$SDL2_CFLAGS
		SDL_LIBS=$SDL2_LIBS
	else
		PKG_CHECK_MODULES(SDL, sdl2, have_sdl2=yes, have_sdl2=no)
		if test "$have_sdl2" != "yes" ; then
			PKG_CHECK_MODULES(SDL, sdl, have_sdl=yes, have_sdl=no)
		fi
	fi

	if test "$have_sdl2" = "yes"; then
		PKG_CHECK_MODULES(SDLTTF, SDL2_ttf, have_sdlttf=yes, have_sdlttf=no)
	elif test "$have_sdl" = "yes"; then
		PKG_CHECK_MODULES(SDLTTF, SDL_ttf, have_sdlttf=yes, have_sdlttf=no)
	else
		continue
	fi

	if test "$have_sdlttf" = "yes"; then
		SDLTTF_CFLAGS="$SDLTTF_CFLAGS -DUSE_SDLTTF"
	fi

	SDL_CFLAGS="$SDL_CFLAGS $SDLTTF_CFLAGS"
	SDL_LIBS="$SDL_LIBS $SDLTTF_LIBS"
	AC_SUBST(SDL_CFLAGS)
	AC_SUBST(SDL_LIBS)

	OUTPUT_FILES="tool/registobmp/Makefile ${OUTPUT_FILES}"
	MAKE_DIRS2="tool/registobmp ${MAKE_DIRS2}"
	tools_result="$tools_result $tool"
	;;
mlfc)
	if test "$gui_for_tool" != "win32" -a "$gui_for_tool" != "quartz" ; then
		if test "$have_fc" = "yes" ; then
			OUTPUT_FILES="tool/mlfc/Makefile ${OUTPUT_FILES}"
			MAKE_DIRS2="tool/mlfc ${MAKE_DIRS2}"
			tools_result="$tools_result $tool"
		fi
	fi
	;;
*)
	echo "${tool} is unknown tool."
	;;
esac
done

if test "$gui" = "win32"; then
	OUTPUT_FILES="tool/servman/Makefile ${OUTPUT_FILES}"
  MAKE_DIRS2="tool/servman ${MAKE_DIRS2}"
	tools_result="$tools_result servman"
fi

#
# --- libltdl ---
#
AC_ARG_WITH(libltdl,
	[  --with-libltdl@<:@=PREFIX@:>@ load modules with libltdl @<:@default=without@:>@],,
	[with_libltdl=no])
# We don't check here wheter libltdl is installed. (See pobl/src/configure.in)

#
# --- Xdnd ---
#
AC_ARG_ENABLE(dnd,
	[  --disable-dnd           dnd @<:@default=enabled@:>@],
	dnd=$enable_dnd, dnd="yes")
if test "$dnd" = "no" ; then
	DND_CFLAGS="-DDISABLE_XDND"
fi
AC_SUBST(DND_CFLAGS)


DL_LIBS_IM=""

#
# --- kbd ---
#
AC_ARG_ENABLE(kbd,
	[  --disable-kbd           input method for Arabic and Indic @<:@default=enabled@:>@],
	kbd=$enable_kbd)
if test "$enable_shared" = "no" ; then
	kbd="no"
fi

if test "$kbd" != "no" ; then
	MAKE_DIRS2="inputmethod/kbd ${MAKE_DIRS2}"
	OUTPUT_FILES="inputmethod/kbd/Makefile ${OUTPUT_FILES}"
	if test "x$with_libltdl" != "xno" ; then
		DL_LIBS_IM="-dlopen \$(top_builddir)/inputmethod/kbd/libim-kbd.la ${DL_LIBS_IM}"
	fi
	input_methods_result="$input_methods_result kbd"
fi

#
# --- uim ---
#
AC_ARG_ENABLE(uim,
	[  --disable-uim           uim @<:@default=enabled@:>@],
	uim=$enable_uim)
if test "$enable_shared" = "no" -o "$gui" = "quartz" ; then
	uim="no"
fi

if test "x$uim" != xno ; then
	PKG_CHECK_MODULES(UIM, uim >= 1.0.0, have_uim=yes, have_uim=no)
	if test "x$have_uim" = xyes ; then
		MAKE_DIRS2="inputmethod/uim ${MAKE_DIRS2}"
		OUTPUT_FILES="inputmethod/uim/Makefile ${OUTPUT_FILES}"
		if test "x$with_libltdl" != xno ; then
			DL_LIBS_IM="-dlopen \$(top_builddir)/inputmethod/uim/libim-uim.la ${DL_LIBS_IM}"
		fi
		input_methods_result="$input_methods_result uim"
	fi
fi
AC_SUBST(UIM_CFLAGS)
AC_SUBST(UIM_LIBS)

#
# --- IIIMF ---
#
AC_ARG_ENABLE(iiimf,
	[  --disable-iiimf         IIIMF (Experimental) @<:@default=enabled@:>@],
	iiimf=$enable_iiimf)
if test "x$iiimf" != xno ; then
	PKG_CHECK_MODULES(IIIMCF, iiimf-lib-client, have_iiimcf=yes, have_iiimcf=no)
	if test "x$have_iiimcf" = xyes ; then
		found_iiimcf=yes
	elif test -d /usr/lib/im/lib ; then
		LIBS="$LIBS -L/usr/lib/im/lib"
		AC_CHECK_LIB(iiimcf, iiimcf_create_context,
			[
			found_iiimcf=yes
			IIIMCF_CFLAGS="-I/usr/lib/im/include"
			IIIMCF_LIBS="-L/usr/lib/im/lib -liiimcf"
			])
	else
		AC_CHECK_LIB(iiimcf, iiimcf_create_context,
			[
			found_iiimcf=yes
			IIIMCF_CFLAGS="-I/usr/include/iiim"
			IIIMCF_LIBS="-liiimcf"
			])
	fi

	if test "x$found_iiimcf" = xyes ; then
		IM_CFLAGS="$IM_CFLAGS -DUSE_IIIMF"
		MAKE_DIRS2="inputmethod/iiimf ${MAKE_DIRS2}"
		OUTPUT_FILES="inputmethod/iiimf/Makefile ${OUTPUT_FILES}"
		if test "x$with_libltdl" != xno ; then
			echo ""
			echo "** ERROR **"
			echo " IIIMF plugin couldn't be used with libltdl."
			echo ""
			exit 1
		else
			input_methods_result="$input_methods_result IIIMF"
		fi
		AC_CHECK_LIB(iiimcf, iiimcf_create_hotkey_notify_event,
			[
			IIIMCF_CFLAGS="$IIIMCF_CFLAGS -DHAVE_HOTKEY_NOTFY_EVENT"
			])
		AC_CHECK_LIB(iiimcf, iiimcf_create_aux_getvalues_event,
			[
			IIIMCF_CFLAGS="$IIIMCF_CFLAGS -DHAVE_AUX_GETVALUES_EVENT"
			])
	fi
fi
AC_SUBST(IIIMCF_CFLAGS)
AC_SUBST(IIIMCF_LIBS)

#
# --- m17n library ---
#
AC_ARG_ENABLE(m17nlib,
	[  --disable-m17nlib       m17n library @<:@default=enabled@:>@],
	m17nlib=$enable_m17nlib)
if test "$enable_shared" = "no" -o "$gui" = "quartz" ; then
	m17nlib="no"
fi

if test "x$m17nlib" != xno ; then
	AC_CHECK_PROG(m17n_config, m17n-config, yes, no)
	if test "$m17n_config" = "yes"; then
		M17NLIB_LIBS=`m17n-config --libs`
		M18NLIB_CFLAGS=`m17n-config --cflags`
		m17nlib=yes
	else
	  PKG_CHECK_MODULES(M17NLIB, m17n-shell, m17nlib=yes, m17nlib=no)
	fi

  if test "$m17nlib" = "yes"; then
		m17n_saved_libs="$LIBS"
		LIBS="$LIBS $M17NLIB_LIBS"
		AC_CHECK_LIB(m17n, minput_open_im,
			[
			MAKE_DIRS2="inputmethod/m17nlib ${MAKE_DIRS2}"
			OUTPUT_FILES="inputmethod/m17nlib/Makefile ${OUTPUT_FILES}"
			if test "x$with_libltdl" != xno ; then
				DL_LIBS_IM="-dlopen \$(top_builddir)/inputmethod/m17nlib/libim-m17nlib.la ${DL_LIBS_IM}"
			fi
			input_methods_result="$input_methods_result m17nlib"
			])
		LIBS="$m17n_saved_libs"
	fi
fi
AC_SUBST(M17NLIB_CFLAGS)
AC_SUBST(M17NLIB_LIBS)

#
# --- IBUS ---
#
AC_ARG_ENABLE(ibus,
	[  --disable-ibus          IBUS @<:@default=enabled@:>@],
	ibus=$enable_ibus)
if test "$enable_shared" = "no" -o "$gui" = "quartz" ; then
	ibus="no"
fi

if test "x$ibus" != "xno" ; then
	PKG_CHECK_MODULES(IBUS, ibus-1.0 >= 1.3.0, has_ibus=yes, has_ibus=no)
	if test "x$has_ibus" = xyes ; then
		MAKE_DIRS2="inputmethod/ibus ${MAKE_DIRS2}"
		OUTPUT_FILES="inputmethod/ibus/Makefile ${OUTPUT_FILES}"
		if test "x$with_libltdl" != xno ; then
			DL_LIBS_IM="-dlopen \$(top_builddir)/inputmethod/ibus/libim-ibus.la ${DL_LIBS_IM}"
		fi
		if test "$with_pthread" != "no" ; then
			# NetBSD doesn't allow shared libraries to link libpthread
			# without linking it to executables.
			case "${host_os}" in
			netbsd*)
				PTHREAD_LIB="-lpthread"
				;;
			esac
		fi
		input_methods_result="$input_methods_result iBus"
	fi
fi
AC_SUBST(IBUS_CFLAGS)
AC_SUBST(IBUS_LIBS)

#
# --- FCITX ---
#
AC_ARG_ENABLE(fcitx,
	[  --disable-fcitx         FCITX @<:@default=enabled@:>@],
	fcitx=$enable_fcitx)
if test "$enable_shared" = "no" -o "$gui" = "quartz" ; then
	fcitx="no"
fi

if test "x$fcitx" != "xno" ; then
	PKG_CHECK_MODULES(FCITX, Fcitx5GClient, has_fcitx=yes, has_fcitx=no)
	if test "x$has_fcitx" = xyes ; then
		PKG_CHECK_MODULES(FCITXUTILS, Fcitx5Utils, has_fcitx=yes, has_fcitx=no)
	fi

	fcitx_result="fcitx"
	if test "x$has_fcitx" = xno ; then
		PKG_CHECK_MODULES(FCITX, fcitx-gclient, has_fcitx=yes, has_fcitx=no)
	else
		FCITX_CFLAGS="$FCITX_CFLAGS $FCITXUTILS_CFLAGS -DUSE_FCITX5"
		# 'pkg-config Fcitx5GClient --libs' doesn't output -lFcitx5GClient
		# (fcitx5-gtk-5.0.6 on archlinux)
		# fcitx5-gtk-5.0.7 fixed it.
		if test "`echo $FCITX_LIBS|grep lFcitx5GClient`" = ""; then
			FCITX_LIBS="$FCITX_LIBS -lFcitx5GClient"
		fi
		fcitx_result="fcitx5"
	fi

	if test "x$has_fcitx" = xyes ; then
		MAKE_DIRS2="inputmethod/fcitx ${MAKE_DIRS2}"
		OUTPUT_FILES="inputmethod/fcitx/Makefile ${OUTPUT_FILES}"
		if test "x$with_libltdl" != xno ; then
			DL_LIBS_IM="-dlopen \$(top_builddir)/inputmethod/fcitx/libim-fcitx.la ${DL_LIBS_IM}"
		fi
		if test "$with_pthread" != "no" ; then
			# NetBSD doesn't allow shared libraries to link libpthread
			# without linking it to executables.
			case "${host_os}" in
			netbsd*)
				PTHREAD_LIB="-lpthread"
				;;
			esac
		fi
		input_methods_result="$input_methods_result $fcitx_result"
	fi
fi
AC_SUBST(FCITX_CFLAGS)
AC_SUBST(FCITX_LIBS)

#
# --- SCIM ---
#
AC_ARG_ENABLE(scim,
	[  --disable-scim          SCIM @<:@default=enabled@:>@],
	scim=$enable_scim)
if test "$enable_shared" = "no" -o "$gui" = "quartz" ; then
	scim="no"
fi

if test "x$scim" != "xno" -a "$gui" != "fb" -a "$gui" != "console" ; then
	PKG_CHECK_MODULES(SCIM, scim >= 1.4.0, has_scim=yes , has_scim=no)
	if test "x$has_scim" = xyes ; then
		MAKE_DIRS2="inputmethod/scim ${MAKE_DIRS2}"
		OUTPUT_FILES="inputmethod/scim/Makefile ${OUTPUT_FILES}"
		if test "x$with_libltdl" != xno ; then
			DL_LIBS_IM="-dlopen \$(top_builddir)/inputmethod/scim/libim-scim.la ${DL_LIBS_IM}"
		fi
		input_methods_result="$input_methods_result SCIM"
	fi
fi
AC_SUBST(SCIM_CFLAGS)
AC_SUBST(SCIM_LIBS)


#
# --- CANNA ---
#
AC_ARG_ENABLE(canna,
	[  --disable-canna         CANNA @<:@default=enabled@:>@],
	canna=$enable_canna)
if test "$enable_shared" = "no" -o "$ml_cv_is_posix" = "no" ; then
	canna="no"
fi

if test "x$canna" != "xno" ; then
	AC_CHECK_HEADER(canna/jrkanji.h, has_canna=yes, has_canna=no)
	if test "x$has_canna" = xyes ; then
		CANNA_LIBS="-lcanna"
		MAKE_DIRS2="inputmethod/canna ${MAKE_DIRS2}"
		OUTPUT_FILES="inputmethod/canna/Makefile ${OUTPUT_FILES}"
		if test "x$with_libltdl" != xno ; then
			DL_LIBS_IM="-dlopen \$(top_builddir)/inputmethod/canna/libim-canna.la ${DL_LIBS_IM}"
		fi
		input_methods_result="$input_methods_result canna"
	fi
fi
AC_SUBST(CANNA_CFLAGS)
AC_SUBST(CANNA_LIBS)


#
# --- WNN ---
#
AC_ARG_ENABLE(wnn,
	[  --disable-wnn           WNN @<:@default=enabled@:>@],
	wnn=$enable_wnn)
if test "$enable_shared" = "no" -o "$ml_cv_is_posix" = "no" ; then
	wnn="no"
fi

if test "x$wnn" != "xno" ; then
	AC_CHECK_HEADER(wnn/jllib.h, has_wnn=yes, has_wnn=no)
	if test "x$has_wnn" = xyes ; then
		WNN_LIBS="-ljd"
		if test -d /usr/pkg/share/wnn ; then
			WNN_CFLAGS="-DWNNLIBDIR=\\\"/usr/pkg/share\\\""
		elif test -d /usr/local/share/wnn ; then
			WNN_CFLAGS="-DWNNLIBDIR=\\\"/usr/local/share\\\""
		elif test -d /usr/local/lib/wnn ; then
			WNN_CFLAGS="-DWNNLIBDIR=\\\"/usr/local/lib\\\""
		elif test -d /usr/share/wnn ; then
			WNN_CFLAGS="-DWNNLIBDIR=\\\"/usr/share\\\""
		else
			WNN_CFLAGS="-DWNNLIBDIR=\\\"/usr/lib\\\""
		fi
		MAKE_DIRS2="inputmethod/wnn ${MAKE_DIRS2}"
		OUTPUT_FILES="inputmethod/wnn/Makefile ${OUTPUT_FILES}"
		if test "x$with_libltdl" != xno ; then
			DL_LIBS_IM="-dlopen \$(top_builddir)/inputmethod/wnn/libim-wnn.la ${DL_LIBS_IM}"
		fi
		input_methods_result="$input_methods_result wnn"
	fi
fi
AC_SUBST(WNN_CFLAGS)
AC_SUBST(WNN_LIBS)


#
# --- SKK ---
#
AC_ARG_ENABLE(skk,
	[  --disable-skk           SKK @<:@default=enabled@:>@],
	skk=$enable_skk)
if test "$enable_shared" != "no" -a "$skk" != "no"; then
	MAKE_DIRS2="inputmethod/skk ${MAKE_DIRS2}"
	OUTPUT_FILES="inputmethod/skk/Makefile ${OUTPUT_FILES}"
	if test "x$with_libltdl" != xno ; then
		DL_LIBS_IM="-dlopen \$(top_builddir)/inputmethod/skk/libim-skk.la ${DL_LIBS_IM}"
	fi
	if test "$ml_cv_is_posix" = "no" ; then
		SKK_LIBS="-lwsock32 -lws2_32"
	fi
	input_methods_result="$input_methods_result skk"
fi
AC_SUBST(SKK_LIBS)


if test "x$input_methods_result" != x ; then
	IM_CFLAGS="-DUSE_IM_PLUGIN"
fi
AC_SUBST(IM_CFLAGS)
AC_SUBST(DL_LIBS_IM)


#
# --- scrollbar plugins ---
#

DL_LIBS_SB=""
SB_CFLAGS=""

scrollbars="sample,extra,pixmap_engine"

AC_ARG_WITH(scrollbars,
	[  --with-scrollbars@<:@=ARG@:>@ scrollbar plugins (sample, extra, pixmap_engine) @<:@default=sample,extra,pixmap_engine@:>@],
	[
	# If given --without-scrollbars or --with-scrollbars with no args.
	if test "${with_scrollbars}" = "no" ; then
		scrollbars=""
	elif test "${with_scrollbars}" != "yes" ; then
		scrollbars=${with_scrollbars}
	fi
	])

if test "$enable_shared" != "no" ; then
	scrollbars=`echo ${scrollbars} | sed 's/,/ /g'`
else
	scrollbars=
fi

for scrollbar in ${scrollbars} ; do
case ${scrollbar} in
sample)
	if test "$gui" = "xlib" -o "$gui" = "win32"; then
		MAKE_DIRS2="scrollbar/sample ${MAKE_DIRS2}"
		OUTPUT_FILES="scrollbar/sample/Makefile ${OUTPUT_FILES}"
		if test "x$with_libltdl" != "xno" ; then
			DL_LIBS_SB="-dlopen \$(top_builddir)/scrollbar/sample/libsample.la ${DL_LIBS_SB}"
		fi
		scrollbars_result="$scrollbars_result $scrollbar"
	fi
	;;
extra)
	if test "$gui" = "xlib" ; then
		MAKE_DIRS2="contrib/scrollbar/extra ${MAKE_DIRS2}"
		OUTPUT_FILES="contrib/scrollbar/extra/Makefile ${OUTPUT_FILES}"
		if test "x$with_libltdl" != "xno" ; then
			for name in athena next motif mozmodern ; do
				DL_LIBS_SB="-dlopen \$(top_builddir)/contrib/scrollbar/extra/lib$name.la ${DL_LIBS_SB}"
			done
		fi
		scrollbars_result="$scrollbars_result $scrollbar"
	fi
	;;
pixmap_engine)
	if test "x$allow_undefined_flag" = "xunsupported" ; then
		echo ""
		echo "** ERROR **"
		echo "pixmap_engine has undefined symbols. $host_os does NOT allow it."
		echo ""
	elif test "$gui" = "xlib" -a "$image" != "no"; then
		if test "$have_gdk_pixbuf1" = "yes" -o "$have_gdk_pixbuf2" = "yes" ; then
			MAKE_DIRS2="contrib/scrollbar/pixmap_engine ${MAKE_DIRS2}"
			OUTPUT_FILES="contrib/scrollbar/pixmap_engine/Makefile contrib/scrollbar/pixmap_engine/sample3/Makefile ${OUTPUT_FILES}"
			if test "x$with_libltdl" != "xno" ; then
				DL_LIBS_SB="-dlopen \$(top_builddir)/contrib/scrollbar/pixmap_engine/libpixmap_engine.la ${DL_LIBS_SB}"
			fi
			SB_CFLAGS="-DSUPPORT_PIXMAP_ENGINE"
			scrollbars_result="$scrollbars_result $scrollbar"
		else
			echo ""
			echo "** ERROR **"
			echo "To use pixmap_engine for scrollbar, you need gdk-pixbuf library."
			echo ""
		fi
	fi
	;;
*)
	echo "${scrollbar} is unknown scrollbar."
	;;
esac
done # for scrollbar in ${scrollbars}

AC_SUBST(SB_CFLAGS)
AC_SUBST(DL_LIBS_SB)


#
# --- module related stuffs ---
#

# 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
AC_SUBST(NO_UNDEFINED_FLAG)

if test "x$with_libltdl" != "xno" ; then
	DL_SELF="-dlopen self"
fi
AC_SUBST(DL_SELF)


AC_ARG_ENABLE(vt52,
	[  --enable-vt52           enable VT52 emulation @<:@default=disabled@:>@],
	vt52=$enable_vt52,
	vt52="no")
if test "$vt52" = "yes" ; then
	VT52_CFLAGS="-DUSE_VT52"
fi
AC_SUBST(VT52_CFLAGS)

AC_ARG_ENABLE(optimize_redrawing,
	[  --enable-optimize-redrawing optimize redrawing a line @<:@default=disabled@:>@],
	optimize_redrawing=$enable_optimize_redrawing,
	optimize_redrawing="no")
if test "$optimize_redrawing" = "yes" ; then
	CFLAGS="$CFLAGS -DOPTIMIZE_REDRAWING"
fi

# XXX(maybe not portable)
if test "${USE_NLS}" = "yes" ; then
	AC_CHECK_LIB(intl,gettext,
		[
		INTL_LIBS="-lintl"
		])
fi
AC_SUBST(INTL_LIBS)

# Because pic object files are fat, non-pic ones are linked unless --disable-static
# option is specified.
if test "$enable_static" = "no" ; then
	MAIN_OBJ_SUFFIX=":.o=.lo"
fi
AC_SUBST(MAIN_OBJ_SUFFIX)

CHANGE_DATE=`head -n 1 ${top_srcdir-$srcdir}/ChangeLog | sed -n 's/^\(@<:@0-9@:>@*-@<:@0-9@:>@*-@<:@0-9@:>@*\).*$/\1/p'`
AC_SUBST(CHANGE_DATE)
OUTPUT_FILES="main/version.h ${OUTPUT_FILES}"

if test "${SUBDIRS}" != "" ; then
  # for baselib and encodefilter
	ac_configure_args="${ac_configure_args} --without-funcs-mlterm-unuse"

  # for gui
	ac_configure_args=`echo ${ac_configure_args} | sed 's/--with-gui=@<:@A-Za-z0-9,@:>@*/--with-gui=subdir/g'`
	if test "$dl_ctl" != "no"; then
		ac_configure_args="${ac_configure_args} --disable-ind --disable-fribidi"
	fi
	ac_configure_args="${ac_configure_args} --without-tools"

	AC_CONFIG_SUBDIRS(${SUBDIRS})
fi

MAKE_DIRS2="vtemu vtemu/libctl uitoolkit/libtype uitoolkit main man etc ${MAKE_DIRS2}"
OUTPUT_FILES="Makefile vtemu/Makefile vtemu/libctl/Makefile uitoolkit/libtype/Makefile uitoolkit/Makefile main/Makefile man/Makefile etc/Makefile java/Makefile libvterm/Makefile ${OUTPUT_FILES}"

AC_ARG_ENABLE(ind,
	[  --disable-ind           libind @<:@default=enabled@:>@],
	ind=$enable_ind,
	ind="yes")
if test "$gui" = "quartz" -o "$gui" = "console"; then
	IND_CFLAGS="-DNOT_CONVERT_TO_ISCII"
	ind="no"
fi

if test "$ind" = "yes" ; then
	IND_CFLAGS='-I${top_builddir}/libind'
	IND_LIBS='${top_builddir}/libind/libind.a'
	MAKE_DIRS2="libind ${MAKE_DIRS2}"
	OUTPUT_FILES="libind/Makefile ${OUTPUT_FILES}"
	if test "$dl_ctl" = "yes" ; then
		CTL_LIBS="libctl${TRUECOLOR_TAG}_iscii.la ${CTL_LIBS}"
	else
		CTL_CFLAGS="-DUSE_IND ${CTL_CFLAGS}"
		CTL_LIBS="libctl${TRUECOLOR_TAG}_iscii.a ${CTL_LIBS}"
		CTL_LIBS_FOR_PROG="../vtemu/libctl/libctl${TRUECOLOR_TAG}_iscii.a ${CTL_LIBS_FOR_PROG}"
	fi
fi
AC_SUBST(IND_LIBS)
AC_SUBST(IND_CFLAGS)
AC_SUBST(CTL_LIBS)
AC_SUBST(CTL_LIBS_FOR_PROG)

AC_ARG_ENABLE(brlapi,
	[  --enable-brlapi         libbrlapi @<:@default=disabled@:>@],
	brlapi=$enable_brlapi, brlapi="no")
if test "$brlapi" = "yes" ; then
	BRLAPI_CFLAGS='-DUSE_BRLAPI'
	BRLAPI_LIBS='-lbrlapi'

	if test "$host_os" != "haiku"; then
		INSTALL_OPT="-m 4755 -o root"
	fi
fi
AC_SUBST(BRLAPI_LIBS)
AC_SUBST(BRLAPI_CFLAGS)

AC_ARG_ENABLE(daemon,
	[  --disable-daemon        daemon mode @<:@default=enabled@:>@],
	daemon=$enable_daemon, daemon="yes")
if test "$daemon" = "no" ; then
	DAEMON_CFLAGS="-DNO_DAEMON"
fi
AC_SUBST(DAEMON_CFLAGS)

AC_ARG_ENABLE(split,
	[  --disable-split         split screen @<:@default=enabled@:>@],
	split=$enable_split, split="yes")
if test "$split" = "no" ; then
	SPLIT_CFLAGS="-DNO_SPLIT"
fi
AC_SUBST(SPLIT_CFLAGS)

AC_ARG_ENABLE(zmodem,
	[  --disable-zmodem        zmodem @<:@default=enabled@:>@],
	zmodem=$enable_zmodem, zmodem="yes")
if test "$zmodem" = "no" ; then
	TRANSFER_CFLAGS="-DNO_ZMODEM"
else
	TRANSFER_LIBS="libzmodem.la"
fi
AC_SUBST(TRANSFER_CFLAGS)
AC_SUBST(TRANSFER_LIBS)

AC_SUBST(PTHREAD_LIB)

AC_SUBST(MAKE_DIRS2)

if test "${MAKE_DIRS2}" != "" ; then
	mkdir -p ${MAKE_DIRS2}
fi


if test "$CONFIG_SUBDIR_LIBS" = "internal"; then
#
# ====> check for encodefilter <===
#
mef_top_srcdir_suffix="/encodefilter"
mef_top_builddir_suffix="/.."
AC_SUBST(mef_top_srcdir_suffix)
AC_SUBST(mef_top_builddir_suffix)

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"
	OUTPUT_FILES="${OUTPUT_FILES} encodefilter/Makefile encodefilter/src/Makefile"
else
	MAKE_DIRS="src module"
	OUTPUT_FILES="${OUTPUT_FILES} encodefilter/Makefile encodefilter/src/Makefile encodefilter/module/Makefile"
fi
AC_SUBST(TABLE_CFLAGS)
AC_SUBST(MAKE_DIRS)

if test "${MAKE_DIRS}" != "" ; then
	(cd encodefilter; mkdir -p ${MAKE_DIRS})
fi

#
# ====> check for baselib <===
#

pobl_top_srcdir_suffix="/baselib"
pobl_top_builddir_suffix="/.."
AC_SUBST(pobl_top_srcdir_suffix)
AC_SUBST(pobl_top_builddir_suffix)

AC_CONFIG_HEADER(baselib/src/bl_config.h)

#
# --- Checks for header files ---
#
# NOTE: if --with-libtool is specified, stdc header isn't detected.
AC_HEADER_STDC
AC_CHECK_HEADERS(langinfo.h stropts.h sys/stropts.h stdint.h windows.h errno.h stdint.h)

#
# --- Checks for library functions ---
#
AC_CHECK_FUNCS(strsep fgetln basename isastream seteuid setegid geteuid getegid setsid snprintf usleep setenv unsetenv flock getuid getgid getpwuid recvmsg setpgid socketpair killpg gettimeofday)
AC_FUNC_ALLOCA

AC_C_CONST
AC_C_BIGENDIAN
AC_SYS_LARGEFILE

# for OpenServer 6.0.0
AC_CHECK_HEADER(sys/bitypes.h,
[
ac_includes_default="\
$ac_includes_default
#include <sys/bitypes.h>"
HAVE_SYS_BITYPES_H=1
AC_DEFINE(HAVE_SYS_BITYPES_H)
])

AC_CHECK_TYPE(u_char,unsigned char)
AC_CHECK_TYPE(u_short,unsigned short)
AC_CHECK_TYPE(u_int,unsigned int)
AC_CHECK_TYPE(u_long,unsigned long)
AC_CHECK_TYPE(u_int8_t,unsigned char)
AC_CHECK_TYPE(u_int16_t,unsigned short)
AC_CHECK_TYPE(u_int32_t,unsigned int)
AC_CHECK_TYPE(u_int64_t,unsigned long)
AC_CHECK_TYPE(int8_t,char)
AC_CHECK_TYPE(int16_t,short)
AC_CHECK_TYPE(int32_t,int)
AC_CHECK_TYPE(int64_t,long)
AC_CHECK_TYPE(ssize_t,int)

AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_UID_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T

AC_C_TYPEOF

#
# --- Platform dependent stuff ---
#
bl_cv_cygwin=no
bl_cv_mingw=no
bl_cv_win32=no
case "${host_os}" in
cygwin*)
	bl_cv_cygwin=yes
	case "${CC} ${CFLAGS}" in
	*mno-cygwin* | *-mingw*)
		bl_cv_win32=yes
		AC_DEFINE(USE_WIN32API,,"USE_WIN32API")
		;;
	*)
		;;
	esac
	;;
mingw*)
	bl_cv_mingw=yes
	if test ! -f "/lib/libmsys-1.0.dll.a" ; then
		case "${lt_cv_path_LD}" in
		*-msys*)
			;;
		*)
			bl_cv_win32=yes
			AC_DEFINE(USE_WIN32API,,"USE_WIN32API")
			;;
		esac
	fi
	;;
*)
	;;
esac

#
# --- socklen_t ---
#
# NOTE: #define _BSDTYPES_DEFINED is necessary because AC_TRY_COMPILE defines
#       u_char, u_short and so on before #include <ws2tcpip.h> .
#
AC_CACHE_CHECK(for socklen_t, bl_cv_socklen_ident,
[AC_TRY_COMPILE(
[
#include  <stddef.h>
#include  <sys/types.h>
#include  <sys/socket.h>
],
[
socklen_t  len ;
], bl_cv_socklen_ident=yes,
[AC_TRY_COMPILE(
[
#define  _BSDTYPES_DEFINED
#include  <ws2tcpip.h>
],
[
socklen_t  len ;
], bl_cv_socklen_ident=yes, bl_cv_socklen_ident=no)])])
if test "${bl_cv_socklen_ident}" = "no" ; then
	AC_DEFINE(socklen_t, unsigned int, "socklen_t")
fi

#
# --- Check if concatenation of string literals with __FUNCTION__ is supported. ---
#
AC_CACHE_CHECK(for __FUNCTION__, bl_cv_func_ident,[
AC_TRY_COMPILE(,
[
char * p = "[" __FUNCTION__ "]" ;
] , bl_cv_func_ident=yes,bl_cv_func_ident=no)])
if test "${bl_cv_func_ident}" = "yes" ; then
	AC_DEFINE(CONCATABLE_FUNCTION,,"CONCATABLE_FUNCTION")
fi


#
# --- Check for libxpg4 (for FreeBSD) ---
#
AC_CHECK_FUNCS(setlocale)
if test "x$ac_cv_func_setlocale" = xno ; then
	AC_CHECK_LIB(xpg4, setlocale, XPG4_LIBS=-lxpg4)
	AC_SUBST(XPG4_LIBS)
fi

#
# --- Checks for dynamic linking loader ---
#
DL_LOADER=none
DL_LIBS=
DL_CFLAGS=
# lt_dlopenext in libltdl
AC_ARG_WITH(libltdl,
	[  --with-libltdl@<:@=PREFIX@:>@ load modules with libltdl @<:@default=without@:>@],,
	[with_libltdl=no])
if test "x$with_libltdl" != "xno" ; then
	if test "x$with_libltdl" != "xyes"; then
		DL_CFLAGS="-I$with_libltdl/include"
		bl_libltdl_libdir="-L$with_libltdl/lib"
	fi
	bl_ldflags_save="$LDFLAGS"
	LDFLAGS="$LDFLAGS $bl_libltdl_libdir"
	AC_CHECK_LIB(ltdl, lt_dlopenext,
			[
			DL_LOADER=ltdl
			DL_LIBS="$bl_libltdl_libdir -lltdl"
			],[
			echo ""
			echo "Could not find libltdl"
			echo ""
			exit 1])
	LDFLAGS="$bl_ldflags_save"
fi
# lt_cv_dlopen is set by AC_LIBTOOL_DLOPEN
if test "$DL_LOADER" = none ; then
	case "${lt_cv_dlopen}" in
	# LoadLibrary  (Windows)
	LoadLibrary)
		DL_LOADER=win32
		;;
	# shl_load (HP-UX)
	shl_load)
		DL_LOADER=dld
		;;
	# dlopen (UNIX98)
	dlopen)
		DL_LOADER=dl
		;;
	# What is dld_link? Does anybody know?
	dld_link)
		DL_LOADER=none
		;;
	*)
		DL_LOADER=none
		;;
	esac
	DL_LIBS="${DL_LIBS} ${lt_cv_dlopen_libs}"
	if test "$DL_LOADER" = none ; then
		# NSLinkModule (darwin)
		AC_CHECK_FUNC(NSLinkModule,
			[
			DL_LOADER=dyld
			DL_LIBS=
			], [])
	fi

	# cygwin hack
	# (AC_LIBTOOL_DLOPEN tell lt_cv_dlopen == dlopen but use bl_dlcfn_win32.c.)
	# On msys2, use dlopen because bl_dlfcn_win32 doesn't work correctly.
	if test "$bl_cv_cygwin" = "yes"; then
		DL_LOADER=win32
	fi
fi
AC_SUBST(DL_LOADER)
AC_SUBST(DL_LIBS)
AC_SUBST(DL_CFLAGS)

if test "$DL_LOADER" = none ; then
	AC_DEFINE(DLFCN_NONE,,"DLFCN_NONE")
fi

#
# --- pty check ---
#
AC_MSG_CHECKING(for pty/tty type)
if test "$bl_cv_win32" = "yes" ; then
	bl_cv_pty=none
elif test "$bl_cv_mingw" = "yes" ; then
	bl_cv_pty=streams
elif test "$host" = "$build" ; then
	AC_CHECK_FUNC(posix_openpt,
		[
			AC_DEFINE(HAVE_POSIX_OPENPT,,"HAVE_POSIX_OPENPT")
			bl_cv_pty=streams
			],
		[bl_cv_pty=bsd])
	if test "$bl_cv_pty" = "bsd" ; then
		AC_RUN_IFELSE(
			[AC_LANG_PROGRAM([#include <sys/stat.h>
					#include <fcntl.h>],
					[return open( "/dev/ptmx", O_RDWR | O_NOCTTY, 0) == -1;])],
			[bl_cv_pty=streams])
	fi
else
  # cross compiling
	AC_CHECK_FUNC(posix_openpt,
		[
			AC_DEFINE(HAVE_POSIX_OPENPT,,"HAVE_POSIX_OPENPT")
			bl_cv_pty=streams
			],
		[bl_cv_pty=bsd])
fi
AC_ARG_ENABLE(pty_helper,
	[  --enable-pty-helper     use pty helper @<:@default=disabled@:>@],
	pty_helper=$enable_pty_helper)
if test "$pty_helper" = yes ; then
	if test "$bl_cv_pty" = streams ; then
		bl_cv_pty=helper
	else
		echo ""
		echo "** WARNING **"
		echo " pty helper is not supported in bsd-style pty system."
		echo ""
	fi
fi
AC_MSG_RESULT($bl_cv_pty)
PTY_NAME="${bl_cv_pty}"
AC_SUBST(PTY_NAME)


#
# --- checks for utmp ---
#

AC_ARG_WITH(utmp,
	[  --with-utmp@<:@=ARG@:>@       utmp (utempter,sysv,login,bsd,none)],
	utmp_type=$with_utmp)

UTMP_NAME=
UTMP_LIBS=
if test "$bl_cv_pty" = helper -o "$bl_cv_mingw" = yes -o "$bl_cv_cygwin" = yes -o "$host_os" = "msys" -o "$host_os" = "haiku"; then
	UTMP_NAME=none
	UTMP_LIBS=
fi

#  libutempter
if test  "$utmp_type" = "" -o "$utmp_type" = "utempter"; then
	if test -z "$UTMP_NAME"; then
		AC_CHECK_LIB(utempter, utempter_add_record,
			[
				UTMP_NAME=utmper
				UTMP_LIBS="-lutempter"
				UTMP_CFLAGS="-DUTEMPTER_NEW_API"
			], [])
	fi
	if test -z "$UTMP_NAME"; then
		# FreeBSD
		AC_CHECK_LIB(ulog, utempter_add_record,
			[
				UTMP_NAME=utmper
				UTMP_LIBS="-lulog"
				UTMP_CFLAGS="-DUTEMPTER_NEW_API"
			], [])
	fi
	if test -z "$UTMP_NAME" ; then
		AC_CHECK_LIB(utempter, addToUtmp,
			[
				UTMP_NAME=utmper
				UTMP_LIBS="-lutempter -lutil"
			])
	fi
fi

#  setutxent()  (SysV)
if test  "$utmp_type" = "" -o "$utmp_type" = "sysv"; then
	if test -z "$UTMP_NAME"; then
		AC_CHECK_FUNC(setutxent,
			[
				UTMP_NAME=sysv
				UTMP_LIBS=
				UTMP_CFLAGS=-DUSE_UTMPX
			], [])
	fi

	#  setutent()  (SysV)
	if test -z "$UTMP_NAME"; then
		AC_CHECK_FUNC(setutent,
			[
				UTMP_NAME=sysv
				UTMP_LIBS=
			], [])
	fi
fi

#  libutil
if test  "$utmp_type" = "" -o "$utmp_type" = "login"; then
	if test -z "$UTMP_NAME" ; then
		AC_CHECK_LIB(util, logout,
			[
				UTMP_NAME=login
				UTMP_LIBS=-lutil
			], [])
	fi
fi

#  other (BSD)
if test  "$utmp_type" = "" -o "$utmp_type" = "bsd"; then
	if test -z "$UTMP_NAME" ; then
		UTMP_NAME=bsd
		UTMP_LIBS=
	fi
fi

if test -z "$UTMP_NAME" ; then
	UTMP_NAME=none
	UTMP_LIBS=
fi

if test "$UTMP_NAME" != "none"; then
	# for vtemu/vt_pty_unix.c
	UTMP_CFLAGS="$UTMP_CFLAGS -DUSE_UTMP"
fi

AC_SUBST(UTMP_NAME)
AC_SUBST(UTMP_LIBS)
AC_SUBST(UTMP_CFLAGS)

AC_DEFINE(REMOVE_FUNCS_MLTERM_UNUSE,,"REMOVE_FUNCS_MLTERM_UNUSE")

#
# --- check for malloc ---
#
if test "$host" = "$build"; then
	AC_TRY_RUN(
	[
	#include <stdlib.h>
	#include <stddef.h>
	int main() {
		return calloc(8, ((1 << (sizeof(size_t) * 8 - 1)) + 1)) ? 1 : 0;
	}
	],
	AC_DEFINE(CALLOC_CHECK_OVERFLOW))
fi

OUTPUT_FILES="${OUTPUT_FILES} baselib/Makefile baselib/src/Makefile"

else # CONFIG_SUBDIR_LIBS

# ./configure at subdirs finished.

if test -d baselib; then
	utmp_none_obj=`grep bl_utmp_none.o baselib/src/Makefile`
elif test -d ../../baselib; then
	utmp_none_obj=`grep bl_utmp_none.o ../../baselib/src/Makefile`
fi

if test "$utmp_none_obj" = ""; then
	UTMP_CFLAGS="-DUSE_UTMP"
else
	# for following "$UTMP_NAME" != "none"
	UTMP_NAME="none"
fi

fi # CONFIG_SUBDIR_LIBS


AC_OUTPUT(${OUTPUT_FILES})

AC_ARG_ENABLE(utmp-suid,
	[  --enable-utmp-suid      install mlterm with SUID or SGID for utmp @<:@default=disabled@:>@],
	utmp_suid=$enable_utmp_suid)

if test "$INSTALL_OPT" = ""; then
	# SUID is not set to mlterm on MacOSX/Quartz.
	if test "$utmp_suid" = "yes" -a "$UTMP_NAME" != "none" -a "$gui" != "quartz"; then
		has_utmp=`grep utmp /etc/group 2>/dev/null`
		if test "$has_utmp" ; then
			INSTALL_OPT="-m 2755 -g utmp"
		else
			INSTALL_OPT="-m 4755 -o root"
		fi
	else
		INSTALL_OPT="-m 755"
	fi

	if test "$gui" = "fb" ; then
		INSTALL_OPT="-m 4755 -o root"
	fi
fi

cat main/Makefile | sed "s/@INSTALL_OPT@/$INSTALL_OPT/" | sed "s/@UTMP_CFLAGS@/$UTMP_CFLAGS/" > main/Makefile.new
mv main/Makefile.new main/Makefile
cat vtemu/Makefile | sed "s/@UTMP_CFLAGS@/$UTMP_CFLAGS/" > vtemu/Makefile.new
mv vtemu/Makefile.new vtemu/Makefile

# Remove 'as_fn_exit 0'
sed '$d' ${CONFIG_STATUS} > ${CONFIG_STATUS}.new
mv ${CONFIG_STATUS}.new ${CONFIG_STATUS}
chmod 755 ${CONFIG_STATUS}

cat >>$CONFIG_STATUS <<EOF
cat main/Makefile | sed "s/@INSTALL_OPT@/$INSTALL_OPT/" | sed "s/@UTMP_CFLAGS@/$UTMP_CFLAGS/" > main/Makefile.new
mv main/Makefile.new main/Makefile
cat vtemu/Makefile | sed "s/@UTMP_CFLAGS@/$UTMP_CFLAGS/" > vtemu/Makefile.new
mv vtemu/Makefile.new vtemu/Makefile

as_fn_exit 0
EOF

# configuration result

echo
echo
echo "Mlterm was configured as follows"
echo
echo "Installation path prefix          : $prefix"
dnl echo "Character mapping table           : "
dnl echo "Character property table          : "
echo "Build shared libraries            : $enable_shared"
echo "Build static libraries            : $enable_static"
dnl echo "Optimization for redrawing a line : $optimize_redrawing"
if test "$fbtype" = ""; then
	echo "GUI toolkit                       : $gui"
else
	echo "GUI toolkit                       : $gui ($fbtype)"
fi
echo "BiDi rendering (Fribidi)          : $have_fribidi"
echo "Indic rendering                   : $ind"
if test "$OT_LAYOUT_OBJ" = "hb.o"; then
	echo "OpenType Layout                   : yes (harfbuzz)"
elif test "$OT_LAYOUT_OBJ" = "otf.o"; then
	echo "OpenType Layout                   : yes (libotf)"
elif test "$OT_LAYOUT_OBJ" = "uniscribe.o"; then
	echo "OpenType Layout                   : yes (uniscribe)"
else
	echo "OpenType Layout                   : no"
fi
echo "External tools                    :$tools_result"
echo "Image processing                  : $image"
echo "Built-in image library            : $with_imagelib"
echo "utmp support                      : $UTMP_NAME"
if test "$gui" = "fb" -o "$gui" = "wayland" -o "$gui" = "sdl2"; then
	if test "$have_ft" = "yes"; then
	  if test "$fontconfig" = "yes"; then
				echo "Supported font formats            : pcf ttf(+fontconfig)"
		else
				echo "Supported font formats            : pcf ttf"
		fi
	else
		echo "Supported font formats            : pcf"
	fi
elif test "$gui" = "xlib"; then
	echo "Type engines                      :$type_engines_result"
fi
echo "DnD                               : $dnd"
if test "$gui" = "xlib"; then
echo "Input Methods                     : XIM$input_methods_result"
else
echo "Input Methods                     :$input_methods_result"
fi
echo "Scrollbars                        : simple${scrollbars_result}"
echo "libssh2                           : $ssh2"
if test "$ml_cv_is_posix" = "no"; then
	echo "pty type                          : $win32pty"
fi
echo "mosh directory                    : $MOSH_DIR"
if test "$have_gtk" = "yes"; then
	echo "GTK+                              : yes ($gtk_version)"
else
	echo "GTK+                              : no"
fi
if test "$VTE_ABI" = ""; then
	vte_version=""
else
	vte_version=" (${VTE_ABI})"
fi
echo "libvte                            : $have_vte$vte_version"
echo "brlapi                            : $brlapi"
echo "VT52                              : $vt52"
echo "Permission of mlterm binary       : $INSTALL_OPT"
echo "Compact true color                : $compact_truecolor"
echo

# This should be called at the end of configure.
# If --with-gui=quartz,console is specified, copy uitoolkit/* to gui/console/uitoolkit
# before removing following files.
if test "$gui" = "quartz" ; then
	# ui_event_source.c, ui_sb_view_factory.c, ui_scrollbar.c and ui_simple_sb_view.c
	# exist in uitoolkit/ and uitoolkit/quartz/.
	# Those in uitoolkit/ must be removed to build those in uitoolkit/quartz/.
	(cd uitoolkit/quartz/ && \
	 for file in `ls *.c` ; do if test -f ../$file ; then mv ../$file ../xlib/ ; fi ; done)
fi
