dnl $XTermId: configure.in,v 1.49 2020/10/03 12:39:34 tom Exp $
dnl
dnl ---------------------------------------------------------------------------
dnl
dnl Copyright 2006-2019,2020 by Thomas E. Dickey
dnl
dnl                         All Rights Reserved
dnl
dnl Permission to use, copy, modify, and distribute this software and its
dnl documentation for any purpose and without fee is hereby granted,
dnl provided that the above copyright notice appear in all copies and that
dnl both that copyright notice and this permission notice appear in
dnl supporting documentation, and that the name of the above listed
dnl copyright holder(s) not be used in advertising or publicity pertaining
dnl to distribution of the software without specific, written prior
dnl permission.
dnl
dnl THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD
dnl TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dnl AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
dnl LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
dnl WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
dnl ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
dnl OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
dnl
dnl ---------------------------------------------------------------------------

AC_PREREQ(2.52.20200802)
AC_INIT(luit.c)
AC_CONFIG_HEADER(config.h:config_h.in)
CF_CHECK_CACHE

AC_ARG_PROGRAM

CF_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
CF_PROG_LINT
CF_MAKE_TAGS

AC_CONST

AC_PATH_XTRA
CF_XOPEN_SOURCE(600)
CF_SIGWINCH
CF_SVR4
CF_SYSV
AC_TYPE_UID_T
CF_WITHOUT_X

CF_DISABLE_ECHO
CF_ENABLE_WARNINGS(Wwrite-strings Wconversion)

AC_CHECK_HEADERS( \ 
poll.h \
pty.h \
stropts.h \
sys/ioctl.h \
sys/param.h \
sys/poll.h \
sys/select.h \
sys/time.h \
termios.h \
) 

AC_CHECK_FUNCS(\
poll \
putenv \
select \
strdup \
strcasecmp \
)

CF_CHECK_TYPE([nfds_t],[unsigned long],[
#include <sys/types.h>
#ifdef HAVE_SYS_POLL_H
#include <sys/poll.h>
#endif
])

CF_SYS_TIME_SELECT 

# workaround for divergence of xterm/luit in the [CF_FUNC_GRANTPT] macro...
AC_CHECK_FUNCS(grantpt)
disable_openpty=$ac_cv_func_grantpt

CF_FUNC_GRANTPT
CF_FUNC_POLL

AC_MSG_CHECKING(if you want to use fontenc)
CF_ARG_ENABLE(fontenc,
	[  --enable-fontenc        enable/disable use of fontenc],
	[with_fontenc=yes],
	[with_fontenc=maybe])
AC_MSG_RESULT($with_fontenc)

AC_MSG_CHECKING(if you want to use iconv)
CF_ARG_DISABLE(iconv,
	[  --disable-iconv         enable/disable use of iconv],
	[with_iconv=no],
	[with_iconv=maybe])
AC_MSG_RESULT($with_iconv)

case $with_iconv in
yes)
	case $with_fontenc in
	yes)
		with_fontenc=no
		AC_MSG_WARN(overriding deprecated fontenc)
		;;
	maybe|no)
		with_fontenc=no
		AC_MSG_NOTICE(using iconv)
		;;
	esac
	;;
no)
	case $with_fontenc in
	yes)
		;;
	no)
		AC_MSG_ERROR(you must choose between iconv and fontenc)
		;;
	maybe)
		with_fontenc=yes
		AC_MSG_NOTICE(using fontenc)
		;;
	esac
	;;
maybe)
	case $with_fontenc in
	yes)
		with_iconv=no
		AC_MSG_NOTICE(using fontenc)
		;;
	no|maybe)
		with_iconv=yes
		with_fontenc=no
		AC_MSG_NOTICE(using iconv)
		;;
	esac
	;;
esac

CF_WITH_ZLIB
if test "x$ac_cv_func_zError" = xyes
then
	AC_DEFINE(USE_ZLIB,1,[Define to 1 if we can link with zlib])
fi

if test "$with_fontenc" = yes
then
	CF_X_FONTENC
	if test $cf_have_fontenc_libs = yes ; then
		AC_DEFINE(USE_FONTENC,1,[Define to 1 if font-encoding libraries can/should be used])
	else
		AC_MSG_ERROR(cannot link with fontenc)
	fi
fi

AM_LANGINFO_CODESET

# Since iconv is widely available, fallback to using it if fontenc is neither
# requested nor available.
if test "$with_iconv" = yes
then
	AM_ICONV
	AC_DEFINE(USE_ICONV,1,[Define to 1 if iconv-libraries should be used])
	CF_ADD_LIBS($LIBICONV)
	EXTRASRCS="$EXTRASRCS luitconv.c  builtin.c"
	EXTRAOBJS="$EXTRAOBJS luitconv\$o builtin\$o"
fi

CF_WITH_ENCODINGS_DIR
CF_WITH_LOCALE_ALIAS
CF_WITH_MAN2HTML

CF_DISABLE_LEAKS
CF_ENABLE_TRACE

if test "$with_trace" != no
then
	EXTRASRCS="$EXTRASRCS trace.c"
	EXTRAOBJS="$EXTRAOBJS trace\$o"
fi

CF_DISABLE_RPATH_HACK

AC_SUBST(EXTRASRCS)
AC_SUBST(EXTRAOBJS)
AC_OUTPUT(Makefile,,,cat)
CF_MAKE_DOCS(luit,[\$(manext)])
