dnl Project   : tin - a Usenet reader
dnl Module    : configure.in
dnl Author    : Thomas E. Dickey <dickey@invisible-island.net>
dnl Created   : 1995-08-24
dnl Updated   : 2024-12-15
dnl Notes     :
dnl
dnl Copyright (c) 1995-2024 Thomas E. Dickey <dickey@invisible-island.net>
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl    notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl    notice, this list of conditions and the following disclaimer in the
dnl    documentation and/or other materials provided with the distribution.
dnl 3. The name of the author may not be used to endorse or promote
dnl    products derived from this software without specific prior written
dnl    permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
dnl OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
dnl WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
dnl ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
dnl Process this file with autoconf to produce a configure script.

AC_PREREQ(2.52.20210105)
AC_INIT(include/tin.h)
AC_CONFIG_HEADER(include/autoconf.h:include/autoconf.hin)
AC_PREFIX_DEFAULT(/usr/local)

dnl PACKAGE is required for GNU gettext
PACKAGE=tin
VERSION=2.6.4
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Define this to the package name])
AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Define this to the package version])
AC_SUBST(PACKAGE)
AC_SUBST(VERSION)

EXTRAO_DEP='#'

CF_CHECK_CACHE

CF_PATHSEP
CF_WITH_PATH(install-prefix,
	[  --with-install-prefix   prefixes actual install location],
	DESTDIR,/)
case ".$DESTDIR" in # (vi
./)	DESTDIR=
	;; # (vi
./*/)	;; # (vi
./*)	DESTDIR="$DESTDIR/"
	;;
esac

AC_ARG_PROGRAM

###	Compiler/options that autoconf doesn't get right
case "$host_os" in
	aix*)	#(vi
		if test "$CC" = ""; then
			AC_PATH_PROG(XLC, xlc)
			if test "$ac_cv_path_XLC" != ""; then
				CC="$ac_cv_path_XLC"
			fi
		fi
		;;
	hpux*)	#(vi
		test "$CC" != "cc" && test -z "$CFLAGS" && CFLAGS="-O"
		;;
esac

### Native Language Support
ALL_LINGUAS="da de en_GB es et fr ru sv tr zh_CN zh_TW"

### Checks for programs
save_CFLAGS="$CFLAGS"
CF_PROG_CC
AC_PROG_GCC_TRADITIONAL
AC_PROG_MAKE_SET
AC_PROG_INSTALL
CF_PROG_YACC
AC_CHECK_PROGS(LINT, lint alint lclint tdlint splint, :)
CF_PROG_EXT
CF_LIB_PREFIX(LIB_PREFIX)
AC_PROG_LN_S

CF_BUILD_CC([-I$(INCDIR)],[])

#### initialize $ac_includes_default
AC_CHECK_DECL(exit)

CF_XOPEN_SOURCE
CF_SIGWINCH
CF_PIC_HACK

dnl These are standard among *NIX systems, but not when cross-compiling
AC_CHECK_TOOL(RANLIB, ranlib, ':')
AC_CHECK_TOOL(LD, ld, ld)
CF_PROG_AR
CF_AR_FLAGS

case "$host_cpu:$host_vendor:$host_os" in
	# check for cygwin environment
	# -DSTATIC is needed for pcre
	*:*:*cygwin*)	#(vi
		PCRE_DEFINES="$PCRE_DEFINES -DSTATIC"
		;;
	# SEIUX doesn't have any useful preprocessor symbol
	mips:sei:seiux*)	#(vi
		AC_DEFINE(SEIUX,1,[Define this to 1 for the MIPS/SEIUX system])
		;;
	# ISC Interactive Unix likewise
	i386:pc:isc*)	#(vi
		AC_DEFINE(ISC_UNIX,1,[Define this to 1 for the i386/ISC system])
esac

dnl TODO: also check for heapsort(3) in libbsd? like
dnl AS_IF([test x"ac_cv_func_heapsort" != "xyes"],
dnl  [AC_CHECK_LIB(bsd, heapsort,
dnl   [CF_TRY_PKG_CONFIG([libbsd-overlay], [AC_DEFINE(HAVE_HEAPSORT)])]
dnl   )]
dnl )
AC_MSG_CHECKING(if you would like to use heapsort)
CF_ARG_DISABLE(heapsort,
	[  --disable-heapsort      disable heapsort() as alternative to qsort],
	[cf_use_heapsort=no],
	[cf_use_heapsort=yes])
AC_MSG_RESULT($cf_use_heapsort)
if test "x$cf_use_heapsort" = xyes; then
	AC_CHECK_FUNCS(heapsort)
	if test x"$ac_cv_func_heapsort" = xyes; then
		AC_MSG_CHECKING(if its prototype is compatible with qsort)
		AC_TRY_COMPILE([
$ac_includes_default
extern int my_compare(const void *, const void *);
],[
	char *base = 0;
	heapsort((void *)0, 1, 2, my_compare);
],,[cf_use_heapsort=no]);
		AC_MSG_RESULT($cf_use_heapsort)
	else
		CF_VERBOSE(will use our own heapsort function)
		EXTRAO_DEP=''
		EXTRAOBJS="\$(OBJDIR)/heapsort.o $EXTRAOBJS"
	fi
fi
if test "x$cf_use_heapsort" = xyes; then
	AC_DEFINE(USE_HEAPSORT,1,[Define this to 1 to use the heapsort function])
fi

CF_WITH_PROGRAM(ispell,
[  --with-ispell           (default: from system path)])

CF_WITH_PROGRAM(metamail,
[  --with-metamail         (default: from system path)])

CF_PATH_EDITOR
CF_PATH_MAILER
CF_PATH_MAILBOX
CF_PKG_CONFIG

## PGP Support
AC_MSG_CHECKING(if you want PGP/GPG-Support)
CF_ARG_DISABLE(pgp-gpg,
	[  --disable-pgp-gpg       disable PGP/GPG Support],
	[USE_PGP_GPG=no],
	[USE_PGP_GPG=yes])
AC_MSG_RESULT($enableval)
if test "$USE_PGP_GPG" = "yes" ; then
	CF_WITH_PROGRAM(pgp,
	[  --with-pgp              (default: from system path)])
	# FIXME: check if pgp is pgp2 or pgp6

	CF_WITH_PROGRAM(pgpk,
	[  --with-pgpk             (default: from system path)])
	# FIXME: remove tailing k

	CF_WITH_PROGRAM(gpg,
	[  --with-gpg              (default: from system path)])
fi

## slrnface
CF_WITH_PROGRAM(slrnface,
[  --with-slrnface         (default: from system path)])
if test -n "$ac_cv_path_PATH_SLRNFACE"; then
	EXTRAO_DEP=''
	EXTRAOBJS="\$(OBJDIR)/xface.o $EXTRAOBJS"
fi

## Default shell
AC_ARG_WITH(shell,
	[  --with-shell=PROG       default $SHELL program (default: sh)],
	[cf_cv_default_shell=$withval],
	[cf_cv_default_shell=])
CF_DEFAULT_SHELL($cf_cv_default_shell)

### check for this early, since it'll override several options
AC_MSG_CHECKING(if NNTP-support will be used)
CF_ARG_DISABLE(nntp,
	[  --disable-nntp          disable reading via NNTP],
	[USE_NNTP=no],
	[USE_NNTP=yes])
AC_MSG_RESULT($enableval)

USE_SPOOLDIR=yes
if test "$USE_NNTP" = "yes" ; then
AC_MSG_CHECKING(whether to be NNTP_ONLY)
CF_ARG_ENABLE(nntp-only,
	[  --enable-nntp-only      enable reading via NNTP only],
	[AC_DEFINE(NNTP_ONLY,1,[Define this to 1 to be NNTP-only])
	 USE_SPOOLDIR=no],
	[AC_DEFINE(NNTP_ABLE,1,[Define this to 1 to be NNTP-capable])])
AC_MSG_RESULT($enableval)

AC_MSG_CHECKING(if you want to use zlib for COMPRESS DEFLATE support)
AC_ARG_WITH(zlib,
	[  --with-zlib             use zlib for COMPRESS DEFLATE],
	[use_zlib=$withval],
	[use_zlib=yes])
AC_MSG_RESULT($use_zlib)

if test ".$use_zlib" != ".no" ; then
	CF_WITH_ZLIB($use_zlib)
	test "x$cf_cv_find_linkage_z" = "xyes" && AC_DEFINE(USE_ZLIB,1,[Define to 1 if you want to use zlib for COMPRESS DEFLATE])
fi

fi

###	use option --enable-debug to compile-in test/development code
AC_MSG_CHECKING(if you want to compile-in debug support)
CF_ARG_ENABLE(debug,
	[  --enable-debug          turn on debug support],
	[ENABLE_DEBUG=''
	CFLAGS="-g $CFLAGS"
	LDFLAGS="-g $LDFLAGS"],
	[ENABLE_DEBUG='#'
	test -z "$save_CFLAGS" && CFLAGS="`echo $CFLAGS|sed -e 's/-g //' -e 's/-g$//'`"])
AC_MSG_RESULT($enableval)
AC_SUBST(ENABLE_DEBUG)

###	use option --disable-echo to suppress full display compiling commands
CF_DISABLE_ECHO

### use option --enable-prototypes to turn on optional prototypes
AC_MSG_CHECKING(if you want to compile with fallback prototypes)
CF_ARG_ENABLE(prototypes,
	[  --enable-prototypes     check for optional prototypes],
	[with_decl_check=yes],
	[with_decl_check=no])
AC_MSG_RESULT($enableval)

###	use option --enable-warnings to turn on all gcc warnings
EXTRA_CFLAGS=""
if test -n "$GCC"
then
AC_MSG_CHECKING(if you want to turn on gcc warnings)
CF_ARG_ENABLE(warnings,
	[  --enable-warnings       turn on GCC compiler warnings],
	[with_warnings=yes],
	[with_warnings=no])
AC_MSG_RESULT($with_warnings)
if test "$with_warnings" = "yes"
then
	with_ext_const=yes
	CF_GCC_WARNINGS
fi
fi

## !NNTP_ONLY
if test "$USE_SPOOLDIR" = "yes"; then
	## options for directories
	AC_MSG_CHECKING(for news-library path)
	CF_WITH_PATH(libdir,
		[  --with-libdir=PATH      news-library],
		NEWSLIBDIR,/usr/lib/news)
	AC_MSG_RESULT($NEWSLIBDIR)

	AC_MSG_CHECKING(for news spool-directory path)
	CF_WITH_PATH(spooldir,
		[  --with-spooldir=PATH    news spool-directory],
		SPOOLDIR,/var/spool/news)
	AC_MSG_RESULT($SPOOLDIR)

	AC_MSG_CHECKING(for news overview-directory path)
	CF_WITH_PATH(nov-dir,
		[  --with-nov-dir=PATH     news overview-directory],
		NOVROOTDIR,$SPOOLDIR)
	AC_MSG_RESULT($NOVROOTDIR)

	AC_MSG_CHECKING(for overview filename)
	CF_WITH_VALUE(nov-fname,
		[  --with-nov-fname        specify names of overview files],
		OVERVIEW_FILE,.overview)
	AC_MSG_RESULT($OVERVIEW_FILE)

	INEWSPATH="$NEWSLIBDIR"
else
	NEWSLIBDIR=""
	SPOOLDIR=""
	NOVROOTDIR=""
	INEWSPATH="/usr/lib/news"
fi

## TODO: kick the --with-inews-dir= stuff, the check below should be enough
## (requires some code rework in tin)
AC_MSG_CHECKING(for directory containing \"inews\")
CF_WITH_PATH(inews-dir,
	[  --with-inews-dir=PATH   directory containing "inews"],
	INEWSDIR,$INEWSPATH)
INEWSDIR="`echo $INEWSDIR |sed -e 's,/$,,'`"
AC_MSG_RESULT($INEWSDIR)

AC_PATH_PROG(INEWS,
	inews, --internal,
	$INEWSDIR:/news/bin:/usr/lib/news/bin:$INEWSPATH)
if test "$ac_cv_path_INEWS" != ""; then
	if test "$ac_cv_path_INEWS" = "--internal"; then
		CF_DEFINE_STRING(PATH_INEWS, "$INEWS")
	else
		CF_DEFINE_STRING(PATH_INEWS, "$INEWS -h")
	fi
fi

### Look for network libraries first, since some functions (such as gethostname)
### are used in a lot of places.
AC_CACHE_CHECK(if you want socks library,cf_cv_use_libsocks,[
AC_ARG_WITH(socks,
	[  --with-socks[=path]       link with socks library if available],
	[cf_cv_use_libsocks=$withval],
	[cf_cv_use_libsocks=no])
])

AC_CACHE_CHECK(if you want socks5 library,cf_cv_use_libsocks5,[
AC_ARG_WITH(socks5,
	[  --with-socks5[=path]      link with socks5 library if available],
	[cf_cv_use_libsocks5=$withval],
	[cf_cv_use_libsocks5=no])
])

# socks5 is the newer version of the library.  If both options are selected,
# give a warning and assume socks5 was intended.

if test "x$cf_cv_use_libsocks5" != xno ; then
if test "x$cf_cv_use_libsocks" != xno ; then
	AC_MSG_WARN([assuming --with-socks5 is intended, ignoring --with-socks])
	cf_cv_use_libsocks=no
fi
fi

if test "x$cf_cv_use_libsocks" != xno ; then
	CF_SOCKS($cf_cv_use_libsocks)
else
	CF_NETLIBS
	if test "x$cf_cv_use_libsocks5" != xno ; then
	CF_SOCKS5($cf_cv_use_libsocks5)
	fi
fi

### which locking method should be used for mailbox locking
### first look for all available locking methods
CF_LOCKFILE

AC_MSG_CHECKING(which locking method will be used)
### fcntl() is preferred, if the user just disables fcntl()
### without specifying an alternative lockf() is preferred
CF_ARG_DISABLE(fcntl,
	[  --disable-fcntl         disable fcntl() locking],
		requested_lock="lockf",
		requested_lock="fcntl")
CF_ARG_ENABLE(lockf,
	[  --enable-lockf          enable lockf() locking],
		requested_lock="lockf")
CF_ARG_ENABLE(flock,
	[  --enable-flock          enable flock() locking],
		requested_lock="flock")
### now check the users wishes against available locking methods
if test -n "$cf_cv_lockfile"; then
	for lock in $cf_cv_lockfile; do
		if test "$lock" = "$requested_lock"; then
			used_locking=$lock
			break
		fi
	done
### if none of them matched use the one with the highest priority
	if test "x$used_locking" = "x"; then
		used_locking="`echo $cf_cv_lockfile|sed -e 's/^\([[^ ]]\+\).*/\1/g'`"
	fi
	AC_MSG_RESULT($used_locking)
	CF_UPPER(used_locking,$used_locking)
	AC_DEFINE_UNQUOTED(USE_$used_locking)
else
	AC_MSG_RESULT(none);
	AC_MSG_WARN([[None of fcntl(), lockf(), flock() available]])
fi

AC_MSG_CHECKING(for screen type)
AC_ARG_WITH(screen,
[  --with-screen=xxx       specify screen type, which must be one of:
                          termcap, terminfo, curses, ncurses, ncursesw, or
                          pdcurses (replaces options --enable-curses and
                          --with-ncurses)],
	[cf_with_screen=$withval],
	[cf_with_screen=none])
AC_MSG_RESULT($cf_with_screen)

use_curses=no
use_ncurses=no

CF_WITH_CURSES_DIR($cf_with_screen)

case $cf_with_screen in #(vi
termcap|terminfo) #(we will determine which it really is
	;;
curses) #(vi
	use_curses=yes
	;;
ncurses) #(vi
	use_curses=yes
	use_ncurses=yes
	;;
ncursesw) #(vi
	use_curses=yes
	use_ncurses=yes
	;;
pdcurses) #(vi
	use_curses=yes
	;;
none)
	AC_MSG_CHECKING(if you want to use ncurses library)
	AC_ARG_WITH(ncurses,
		[  --with-ncurses          link with ncurses if available (deprecated)],
		[use_ncurses=$withval],
		[use_ncurses=no])
	AC_MSG_RESULT($use_ncurses)

	AC_MSG_CHECKING(if you want curses rather than termcap interface)
	CF_ARG_ENABLE(curses,
		[  --enable-curses         use curses interface (deprecated)],
		[cf_with_screen=curses;  use_curses=$withval],
		[cf_with_screen=termcap; use_curses=no])
	AC_MSG_RESULT($enableval)
	;;
esac

if test $use_curses != no ; then
	AC_DEFINE(USE_CURSES,1,[Define this to 1 if we will use the curses library])
	case $cf_with_screen in #(vi
	ncurses) #(vi
		CF_NCURSES_CONFIG
		;;
	ncursesw) #(vi
		CF_CHECK_HEADERS(stdlib.h wchar.h wctype.h)
		AM_MULTIBYTE_ABLE
		CF_NCURSES_CONFIG(ncursesw)
		CF_XOPEN_CURSES
		test "$cf_cv_need_xopen_extension" = unknown && AC_ERROR(X/Open curses not found)
		;;
	curses) #(vi
		CF_CURSES_CONFIG
		CF_XOPEN_CURSES
		;;
	esac
fi

## substitute externally-installed PCRE library for our bundled version
AC_MSG_CHECKING(if you want to use installed version of pcre)
AC_ARG_WITH(pcre,
	[  --with-pcre=PATH        use installed pcre versus bundled],
	[PCRE_HOME=$withval],
	[PCRE_HOME=no])
AC_MSG_RESULT($PCRE_HOME)

## Preliminary check for PCRE2
AC_MSG_CHECKING(if you want to use pcre2 in favour of pcre)
AC_ARG_WITH(pcre2-config,
	[  --with-pcre2-config=PATH use pcre2 in favour of pcre],
	[pcre2_config=$withval],
	[pcre2_config=no])
AC_MSG_RESULT($pcre2_config)

if test "$pcre2_config" != no ; then
	if test "$pcre2_config" != yes ; then
		PCRE2_CONFIG=$withval
	else
		CF_ACVERSION_CHECK(2.52,
			[AC_PATH_TOOL(PCRE2_CONFIG,pcre2-config,none)],
			[AC_PATH_PROG(PCRE2_CONFIG,pcre2-config,none)])
	fi

	if test "$PCRE2_CONFIG" != none && "$PCRE2_CONFIG" --version >/dev/null ; then
		PCRE2_LIBS=`$PCRE2_CONFIG --libs8`
		PCRE2_CFLAGS=`$PCRE2_CONFIG --cflags`
		if test -n "$PCRE2_LIBS" ; then
			LIBS="$LIBS $PCRE2_LIBS"
		fi
		if test -n "$PCRE2_CFLAGS" ; then
			CFLAGS="$CFLAGS $PCRE2_CFLAGS"
		fi
		AC_DEFINE(HAVE_LIB_PCRE2,1,[Define to 1 if we can/should compile with the PCRE2 library])
		# TODO: header / link checks?
	else
		AC_MSG_WARN([pcre2-config not found or not working, trying fallback to pcre])
		pcre2_config=no
	fi
fi

PCRE_MAKEFILE=
if test "$pcre2_config" = no ; then

	CF_BUNDLED_PCRE($PCRE_HOME)

	if test "$cf_pcre_home" = "no" ; then
		LINK_SIZE="-DLINK_SIZE=2"
		AC_SUBST(LINK_SIZE)
		UTF8="-DSUPPORT_UTF8"
		UCP="-DSUPPORT_UCP"
		AC_SUBST(UTF8)
		AC_SUBST(UCP)
		PCRE_MAKEFILE="$PCRE_MAKEFILE pcre/Makefile pcre/RunTest"
	fi
else
	PCREDIR_MAKE='#'
fi

## debugging libraries (do this after other libraries)
debug_malloc=none
CF_WITH_DBMALLOC(debug_malloc=DBMALLOC)
CF_WITH_DMALLOC(debug_malloc=DMALLOC)

AC_ARG_WITH(trace,
	[  --with-trace            use debugging/traces for screen output],
	[
	AC_CHECK_FUNC(_tracef,[AC_DEFINE(HAVE__TRACEF,1,[Define this to 1 if we have function _tracef])],[
	AC_CHECK_LIB(${cf_with_screen}_g,_tracef,
		[AC_DEFINE(HAVE__TRACEF)
		 LIBS="`echo "$LIBS" | sed -e s/-l${cf_with_screen}// -e s/-lcurses//`"
		 LIBS="-l${cf_with_screen}_g $LIBS"
		 use_trace=yes
		 AC_DEFINE(USE_TRACE,1,[Define this to 1 if we will use ncurses' trace-functions])
		 EXTRAO_DEP=''
		 EXTRAOBJS="\$(OBJDIR)/trace.o $EXTRAOBJS"],
		 use_trace=no)])],
	[use_trace=no])
#AC_MSG_CHECKING(if you want debugging-trace)
#AC_MSG_RESULT($use_trace)
AC_SUBST(EXTRAOBJS)
AC_SUBST(EXTRAO_DEP)

## options for miscellaneous definitions
AC_MSG_CHECKING(for domain-name)
CF_ARG_WITH(domain-name,
	[  --with-domain-name      sets $DOMAIN_NAME],
	DOMAIN_NAME)
if test "$DOMAIN_NAME" != ""; then
	AC_DEFINE_UNQUOTED(DOMAIN_NAME, "$DOMAIN_NAME",[Define this to the news server's domain-name])
fi
AC_MSG_RESULT($DOMAIN_NAME)

if test "$USE_NNTP" = "yes" ; then
AC_MSG_CHECKING(for NNTP default-server)
CF_ARG_WITH(nntp-default-server,
	[  --with-nntp-default-server
                          (sets NNTP_DEFAULT_SERVER)
                         ],
                          [NNTP_DEFAULT_SERVER], news.$DOMAIN_NAME)

	if test "$NNTP_DEFAULT_SERVER" = "" ; then
	if test "$DOMAIN_NAME" != "" ; then
		test -z "$NNTP_DEFAULT_SERVER" && \
		case "$DOMAIN_NAME" in #(((
	 	/*)
			if test -r "$DOMAIN_NAME" ; then
				NNTP_DEFAULT_SERVER="news.`cat $DOMAIN_NAME`"
			else
				NNTP_DEFAULT_SERVER="news"
			fi
			;;
	 	*)
			NNTP_DEFAULT_SERVER="news.$DOMAIN_NAME"
			;;
	 	esac
	else
		NNTP_DEFAULT_SERVER="news"
	fi
    fi
AC_MSG_RESULT($NNTP_DEFAULT_SERVER)
fi

## These options are interdependent, so we delay defining them til now:
test -n "$NNTP_DEFAULT_SERVER" \
	&& AC_DEFINE_UNQUOTED(NNTP_DEFAULT_SERVER,"$NNTP_DEFAULT_SERVER",[Define this to the default NNTP server])
test ".$INEWSDIR" != ".$NEWSLIBDIR" && AC_DEFINE_UNQUOTED(INEWSDIR,"$INEWSDIR",[Define this to the inews directory path])
AC_DEFINE_UNQUOTED(NEWSLIBDIR,"$NEWSLIBDIR",[Define this to the news library directory path])
AC_DEFINE_UNQUOTED(NOVROOTDIR,"$NOVROOTDIR",[Define this to the news overview directory path])
AC_DEFINE_UNQUOTED(SPOOLDIR,"$SPOOLDIR",[Define this to the spool directory path])

## optional features
AC_MSG_CHECKING(whether to use MH style mail handling for mailgroups)
CF_ARG_ENABLE(mh-mail-handling,
	[  --enable-mh-mail-handling
                          use MH style mail handling for mailgroups],
	[AC_DEFINE(HAVE_MH_MAIL_HANDLING,1,[Define this to 1 to use MH style mail handling for mailgroups])])
AC_MSG_RESULT($enableval)

AC_MSG_CHECKING(whether to use Cancel-Locks)
CF_ARG_ENABLE(cancel-locks,
	[  --enable-cancel-locks   enable creation of Cancel-Locks])
AC_MSG_RESULT($enableval)
USE_CANLOCK=$enableval

if test "$USE_CANLOCK" = yes ; then
	AC_MSG_CHECKING(whether to use installed canlock rather than bundled)
	AC_ARG_WITH(canlock,
		[  --with-canlock=PATH use installed canlock versus bundled],
		[CANLOCK_HOME=$withval],
		[CANLOCK_HOME=$USE_CANLOCK])
	AC_MSG_RESULT($CANLOCK_HOME)
	CF_BUNDLED_CANLOCK($CANLOCK_HOME)
else
	CANDIR_MAKE='#'
fi
AC_SUBST(CANDIR_MAKE)

## gsasl - used for AUTH SASL PLAIN
## we currently check for gsasl_free() (avail since 0.2.19)
## update if we ever use calls from a newer API
gsasl=no
AC_CHECK_HEADER(gsasl.h,
	[AC_CHECK_LIB(gsasl, gsasl_free, gsasl=yes)]
)
if test "$gsasl" = "yes"; then
	CF_ARG_DISABLE(gsasl,
		[  --disable-gsasl         don't use GNU SASL],
		,
		[USE_GSASL=yes
		AC_DEFINE(USE_GSASL, 1, [Define to 1 if you want GNU SASL.])
		LIBS="$LIBS -lgsasl"])
fi


AC_MSG_CHECKING(whether to enable 8-bit keycodes)
CF_ARG_DISABLE(8bit-keys,
	[  --disable-8bit-keys     disable 8-bit keycode support],,
	[AC_DEFINE(HAVE_KEY_PREFIX,1,[Define this to 1 to enable 8-bit keycodes])])
AC_MSG_RESULT($enableval)

AC_MSG_CHECKING(whether to enable ANSI-color)
CF_ARG_DISABLE(color,
	[  --disable-color         disable ANSI-color support])
use_color=$enableval
AC_MSG_RESULT($use_color)

AC_MSG_CHECKING(whether to enable posting-etiquette)
CF_ARG_DISABLE(etiquette,
	[  --disable-etiquette     disable printing of posting-etiquette],
	[AC_DEFINE(NO_ETIQUETTE,1,[Define this to 1 to enable posting-etiquette])])
AC_MSG_RESULT($enableval)

AC_MSG_CHECKING(whether to strictly observe RFC2047 and break long lines)
CF_ARG_DISABLE(break-long-lines,
	[  --disable-break-long-lines
                          don't break long mime-encoded lines],,
	[AC_DEFINE(MIME_BREAK_LONG_LINES,1,[Define this to 1 to strictly observe RFC2047 and break long lines])])
AC_MSG_RESULT($enableval)

AC_MSG_CHECKING(whether to force MM_CHARSET obeyance when decoding mime)
CF_ARG_DISABLE(mime-strict-charset,
	[  --disable-mime-strict-charset
                          force MM_CHARSET obeyance],,
	[AC_DEFINE(MIME_STRICT_CHARSET,1,[Define this to 1 to force MM_CHARSET obeyance when decoding mime])])
AC_MSG_RESULT($enableval)

AC_MSG_CHECKING(for MIME character-set)
CF_WITH_DFTENV(mime-default-charset,
	[  --with-mime-default-charset=CHARSET
                          fallback for $MM_CHARSET],
	MM_CHARSET,US-ASCII)
AC_MSG_RESULT($MM_CHARSET)

AC_MSG_CHECKING(for default ISO/ASCII table)
CF_WITH_DFTENV(iso-to-ascii,
	[  --with-iso-to-ascii     ISO -> ASCII conversion],
	DEFAULT_ISO2ASC,-1)
AC_MSG_RESULT($DEFAULT_ISO2ASC)

AC_MSG_CHECKING(whether to enable locale support)
CF_ARG_DISABLE(locale,
	[  --disable-locale        disable locale support],
	[AC_DEFINE(NO_LOCALE,1,[Define this to 1 to disable locale support])])
AC_MSG_RESULT($enableval)

AC_MSG_CHECKING(whether to enable posting)
CF_ARG_DISABLE(posting,
	[  --disable-posting       disable posting],
	[AC_DEFINE(NO_POSTING,1,[Define this to 1 to disable posting])])
AC_MSG_RESULT($enableval)

AC_MSG_CHECKING(whether to enable shell escape)
CF_ARG_DISABLE(shell-escape,
	[  --disable-shell-escape  disable shell escape],
	[AC_DEFINE(NO_SHELL_ESCAPE,1,[Define this to 1 to disable shell escape])])
AC_MSG_RESULT($enableval)

AC_MSG_CHECKING(whether to have fascist newsadmin)
CF_ARG_ENABLE(fascist-newsadmin,
	[  --enable-fascist-newsadmin
                          have fascist newsadmin],
	[AC_DEFINE(HAVE_FASCIST_NEWSADMIN,1,[Define this to 1 to have fascist newsadmin])])
AC_MSG_RESULT($enableval)

AC_MSG_CHECKING(whether to enable inverse video and highlighting)
CF_ARG_DISABLE(inverse-video,
	[  --disable-inverse-video disable inverse video and highlighting],
	[AC_DEFINE(USE_INVERSE_HACK,1,[Define this to 1 to enable inverse video and highlighting])])
AC_MSG_RESULT($enableval)

AC_MSG_CHECKING(whether to enable piping support)
CF_ARG_DISABLE(piping,
	[  --disable-piping        disable piping support],
	[AC_DEFINE(DONT_HAVE_PIPING,1,[Define this to 1 to enable piping support])])
AC_MSG_RESULT($enableval)

AC_MSG_CHECKING(whether to enable printer support)
CF_ARG_DISABLE(printing,
	[  --disable-printing      disable printer support],
	[AC_DEFINE(DISABLE_PRINTING,1,[Define this to 1 to enable printer support])])
AC_MSG_RESULT($enableval)

### TODO: skip and disable if $ac_cv_sys_long_file_names != yes
AC_MSG_CHECKING(whether to unique tmp-files by appending .pid)
CF_ARG_DISABLE(append-pid,
	[  --disable-append-pid    disable appending .pid to tmp-files],,
	[AC_DEFINE(APPEND_PID,1,[Define this to 1 to unique tmp-files by appending .pid])])
AC_MSG_RESULT($enableval)

AC_MSG_CHECKING(whether to fallback to XHDR XREF if XOVER isn't supported)
CF_ARG_DISABLE(xhdr-xref,
	[  --disable-xhdr-xref     disable XHDR XREF fallback],,
	[AC_DEFINE(XHDR_XREF,1,[Define this to 1 to fallback to XHDR XREF if XOVER isn't supported])])
AC_MSG_RESULT($enableval)

### bypass a bug in old versions of leafnode & NNTPcache
AC_MSG_CHECKING(whether to send a GROUP command before a LISTGROUP)
CF_ARG_ENABLE(broken-listgroup-fix,
	[  --enable-broken-listgroup-fix
                          send extra GROUP command before LISTGROUP],
	[AC_DEFINE(BROKEN_LISTGROUP,1,[Define this to 1 to send a GROUP command before a LISTGROUP])])
AC_MSG_RESULT($enableval)

### on some old systems the WIFEXITED()/WEXITSTATUS() macros do not work
AC_MSG_CHECKING(whether to ignore system()s return value)
CF_ARG_ENABLE(broken-system-fix,
	[  --enable-broken-system-fix
                          ignore system()s return value],
	[AC_DEFINE(IGNORE_SYSTEM_STATUS,1,[Define this to 1 to ignore system()s return value])])
AC_MSG_RESULT($enableval)

### checks for the location of the system-wide default setting file
AC_MSG_CHECKING(for directory containing tin.defaults file)
CF_WITH_PATH(defaults-dir,
	[  --with-defaults-dir=PATH
                          directory containing tin.defaults file
                         ],
                          TIN_DEFAULTS_DIR,/etc/tin)
AC_MSG_RESULT($TIN_DEFAULTS_DIR)
AC_DEFINE_UNQUOTED(TIN_DEFAULTS_DIR,"$TIN_DEFAULTS_DIR",[Define this to the directory containing tin.defaults file])

### check for ipv6 support
AC_MSG_CHECKING([whether to enable IPv6])
CF_ARG_DISABLE(ipv6,
	[  --disable-ipv6          disable IPv6 support (default: enabled)],
	,
	[AC_DEFINE(ENABLE_IPV6,1,[Define this to 1 to enable IPv6])])
AC_MSG_RESULT($enableval)
if test "$enableval" = "yes"; then
	CF_CHECK_IPV6
fi
AC_REPLACE_FUNCS(getaddrinfo getnameinfo)

### should we use 64 bit article numbers if possible?
AC_MSG_CHECKING([whether to enable long article numbers])
CF_ARG_ENABLE(long-article-numbers,
	[  --enable-long-article-numbers
                          enable long article numbers (default: disabled)],
	[AC_DEFINE(ENABLE_LONG_ARTICLE_NUMBERS,1,[Define this to 1 to enable long article numbers])]
)
AC_MSG_RESULT($enableval)

### TLS support
if test "$USE_NNTP" = "yes" ; then
AC_MSG_CHECKING([whether to enable NNTPS support])
AC_ARG_WITH(
	nntps,
	[  --with-nntps=ssl        enable NNTPS, needs LibreSSL, OpenSSL or GnuTLS
	                  possible values: libtls, openssl, gnutls],
	[enable_nntps=$withval],
	[enable_nntps="no"])
AC_MSG_RESULT($enable_nntps)

# TODO: checklib for openssl in non pkg-config case
#       version checking in non pkg-config case for openssl
#       cleanup (duplicate code, messages, formatting, ...)
AS_IF([test "$enable_nntps" != "no"],

	[AS_IF([test "$enable_nntps" = "yes" || test "$enable_nntps" = "libtls"],[
AC_MSG_CHECKING(for LibreSSL)
CF_TRY_PKG_CONFIG([libtls],[
AC_TRY_COMPILE([
#include <tls.h>
],[
#if TLS_API < 20200120
#error "Please use LibreSSL TLS_API >= 20200120"
#endif /* TLS_API < 20200120 */
],[have_libtls=yes],[
have_libtls=no
AC_MSG_RESULT([\tLibreSSL TLS_API too old (< 20200120)])
])],[
AC_CHECK_LIB(tls,tls_config_new,[
AC_CHECK_HEADERS(tls.h,[
AC_TRY_COMPILE([
#include <tls.h>
],[
#if TLS_API < 20200120
#error "Please use LibreSSL TLS_API >= 20200120"
#endif /* TLS_API < 20200120 */
],[
LIBS="$LIBS -ltls"
have_libtls=yes
],[have_libtls=no
AC_MSG_RESULT([\tLibreSSL TLS_API too old (< 20200120)])
])
],[have_libtls=no])
],[
have_libtls=no
AC_MSG_RESULT($have_libtls)
])])])

	AS_IF([test "$enable_nntps" = "yes" && test "$have_libtls" = "no" || test "$enable_nntps" = "openssl"],[
AC_MSG_CHECKING(for OpenSSL)
CF_TRY_PKG_CONFIG([openssl],[
AC_TRY_COMPILE([
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/rand.h>
],[
#if OPENSSL_VERSION_NUMBER < 0x1010100fL
#error "Please use OpenSSL >= 1.1.1"
#endif /* OPENSSL_VERSION_NUMBER < 0x1010100fL */
#if defined(LIBRESSL_VERSION_NUMBER)
#error "Please use real OpenSSL >= 1.1.1"
#endif /* LIBRESSL pretending to be OPENSSL */
],[have_openssl=yes],[
have_openssl=no
AC_MSG_RESULT([\tOpenSSL too old (< 1.1.1)])
])],[
have_openssl=no
AC_MSG_RESULT($have_openssl)
])])

	AS_IF([test "$enable_nntps" = "yes" && test "$have_libtls" = "no" && test "$have_openssl" = "no" || test "$enable_nntps" = "gnutls"],[
AC_MSG_CHECKING(for GnuTLS)
CF_TRY_PKG_CONFIG([gnutls],[
AC_TRY_COMPILE([
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
],[
#if GNUTLS_VERSION_NUMBER < 0x030700
#error "Please use GnuTLS >= 3.7.0"
#endif /* GNUTLS_VERSION_NUMBER < 0x030700 */
],[have_gnutls=yes],[
AC_MSG_RESULT([\tGnuTLS too old (< 3.7.0)])
])],[
AC_CHECK_LIB(gnutls,gnutls_certificate_allocate_credentials,[
AC_CHECK_HEADERS(gnutls/gnutls.h gnutls/x509.h,[
AC_TRY_COMPILE([
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
],[
#if GNUTLS_VERSION_NUMBER < 0x030700
#error "Please use GnuTLS >= 3.7.0"
#endif /* GNUTLS_VERSION_NUMBER < 0x030700 */
],[
LIBS="$LIBS -lgnutls"
have_gnutls=yes
],[have_gnutls=no
AC_MSG_RESULT([\tGnuTLS too old (< 3.7.0)])
])
],[have_gnutls=no])
],[
have_gnutls=no=no
AC_MSG_RESULT($have_gnutls)
])])])

	AS_IF([test "$have_libtls" != "yes" && test "$have_openssl" != "yes" && test "$have_gnutls" != "yes"],
		[AC_MSG_ERROR([You requested NNTPS support but no usable TLS implementation was found])],
		[AC_DEFINE(NNTPS_ABLE,1,[Define to 1 to enable NNTPS support])
		AS_IF([test "$have_libtls" = "yes"],
			[AC_DEFINE(HAVE_LIB_LIBTLS,1,[Define to 1 if we can/should compile with the LibreSSL libtls library])],
			[AS_IF([test "$have_openssl" = "yes"],
				[AC_DEFINE(HAVE_LIB_OPENSSL,1,[Define to 1 if we can/should compile with the OpenSSL libraries])],
				[AC_DEFINE(HAVE_LIB_GNUTLS,1,[Define to 1 if we can/should compile with the GNUTLS library])])])])])

### as the above is already complicated enough, the following will be dealt
### with separately
AS_IF([test "$have_libtls" = "yes"],[
	AC_MSG_CHECKING(for libcrypto)
	CF_TRY_PKG_CONFIG([crypto],[
		AC_TRY_COMPILE([
#include <openssl/ssl.h>
],[
BIO_free(NULL);
],
			[
			have_libcrypto=yes
			AC_DEFINE(HAVE_LIB_CRYPTO,1,[Define to 1 if we can/should compile with the OpenSSL crypto library])
			],
 			[
			have_libcrypto=no
			AC_MSG_RESULT($have_libcrypto)
			]
		)
	],[
		AC_CHECK_LIB(crypto,BIO_free,[
			AC_CHECK_HEADERS(openssl/ssl.h,[
				AC_TRY_COMPILE(
[
#include <openssl/ssl.h>
],[
BIO_free(NULL);
],[
				LIBS="$LIBS -lcrypto"
				have_libcrypto=yes
				AC_CHECK_HEADERS(openssl/asn1.h openssl/bio.h openssl/pem.h openssl/x509.h)
				AC_DEFINE(HAVE_LIB_CRYPTO,1,[Define to 1 if we can/should compile with the OpenSSL crypto library])
				],[
				have_libcrypto=no
				AC_MSG_RESULT($have_libcrypto)
				])
			],[have_libcrypto=no])
		],[
		have_libcrypto=no
		AC_MSG_RESULT($have_libcrypto)
		])
	])
])
fi


# <https://github.com/uriparser/uriparser>
AC_MSG_CHECKING(for liburiparser)
CF_TRY_PKG_CONFIG(
	[liburiparser],
	[AC_DEFINE(HAVE_LIBURIPARSER)],
	[AC_TRY_COMPILE([
#include <uriparser/Uri.h>
	],[
#if URI_VER_MAJOR = 0 && URI_VER_MINOR <= 9 && URI_VER_RELEASE <= 7
#error "Please use liburiparser >= 0.9.8"
#endif /* URI_VER_MAJOR */
	],
	[have_liburiparser=yes],
	[have_liburiparser=no
	AC_MSG_RESULT($have_liburiparser)]
	)]
)

CF_FUNC_CURSES_VERSION

### checks for operator characteristics (should be the last option)
AC_MSG_CHECKING(whether to make a coffee while compiling)
AC_ARG_WITH(coffee,
	[  --with-coffee           coffee support],
	[ case "$withval" in
	yes)
	AC_MSG_RESULT(yes - with milk - please!)
	AC_DEFINE(HAVE_COFFEE,1,[Define this to 1 to make a coffee while compiling])
	;;
	*)
	AC_MSG_RESULT(no)
	;;
	esac],
	AC_MSG_RESULT(no))

### checks for compiler characteristics
CF_MAKEFLAGS
AC_LANG_C
AC_C_CONST
AC_C_INLINE
CF_CPP_EXPANDS
CF_CPP_CONCATS
CF_CHECK_NESTED_PARAMS

###	Checks for header files.
AC_HEADER_STDC
AC_HEADER_DIRENT
AC_HEADER_TIME
AC_HEADER_SYS_WAIT
CF_CHECK_HEADERS(\
	argz.h \
	arpa/inet.h \
	curses.h \
	errno.h \
	fcntl.h \
	getopt.h \
	ioctl.h \
	inttypes.h \
	langinfo.h \
	libc.h \
	limits.h \
	locale.h \
	malloc.h \
	netdb.h \
	netinet/in.h \
	netlib.h \
	nl_types.h \
	nomacros.h \
	paths.h	\
	poll.h \
	prototypes.h \
	pwd.h \
	sgtty.h \
	socket.h \
	stdarg.h \
	stdbool.h \
	stddef.h \
	stdint.h \
	stdlib.h \
	string.h \
	strings.h \
	stropts.h \
	sys/bsdtypes.h \
	sys/errno.h \
	sys/file.h \
	sys/ioctl.h \
	sys/param.h \
	sys/poll.h \
	sys/ptem.h \
	sys/pty.h \
	sys/select.h \
	sys/stat.h \
	sys/stream.h \
	sys/socket.h \
	sys/time.h \
	sys/timeb.h \
	sys/times.h \
	sys/types.h \
	sys/utsname.h \
	term.h \
	termio.h \
	time.h \
	unistd.h \
	wchar.h \
	wctype.h \
)

###	Checks that depend on existence-checks for headers
CF_SIZECHANGE
CF_SYS_SELECT_TIMEVAL
CF_VA_COPY

###	Checks for Datatypes.
AC_CHECK_TYPE(gid_t, int)
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_CHECK_TYPE(ssize_t, int)
AC_CHECK_TYPE(time_t, long)
AC_EGREP_HEADER(in_addr_t, netinet/in.h, ,[
	AC_EGREP_HEADER(in_addr_t, sys/endian.h, ,[
		AC_CHECK_TYPE(in_addr_t, unsigned long)]
	)]
)
AC_TYPE_UID_T

AC_MSG_CHECKING(for tcflag_t defined in termios.h)
AC_EGREP_HEADER(tcflag_t, termios.h, AC_MSG_RESULT(yes),[
	AC_CHECK_TYPE(tcflag_t, unsigned int)
])

dnl test to see if quad_t is defined
AC_MSG_CHECKING(for quad_t)
AC_TRY_COMPILE([
$ac_includes_default
],[quad_t x; x = 0; (void)x],
ac_cv_quad_t=yes, ac_cv_quad_t=no)
AC_MSG_RESULT($ac_cv_quad_t)
if test $ac_cv_quad_t = yes; then
	AC_DEFINE(HAVE_QUAD_T,1,[Define this to 1 if we have type quad_t])
fi

dnl test to see if long long is defined
AC_MSG_CHECKING(for long long)
AC_TRY_COMPILE([
$ac_includes_default
],[long long x; x = 0; (void)x],
ac_cv_long_long=yes, ac_cv_long_long=no)
AC_MSG_RESULT($ac_cv_long_long)
if test $ac_cv_long_long = yes; then
	AC_DEFINE(HAVE_LONG_LONG,1,[Define this to 1 if we have long-long type])
fi

dnl test to see if int_least64_t is defined
AC_MSG_CHECKING(for int_least64_t)
AC_TRY_COMPILE([
$ac_includes_default
],[int_least64_t x; x = 0; (void)x],
ac_cv_int_least64_t=yes, ac_cv_int_least64_t=no)
AC_MSG_RESULT($ac_cv_int_least64_t)
if test $ac_cv_int_least64_t = yes; then
	AC_DEFINE(HAVE_INT_LEAST64_T,1,[Define this to 1 if we have type least64_t])

	AC_MSG_CHECKING(for INT64_C)
	AC_TRY_COMPILE([
$ac_includes_default
],[int_least64_t x; x = INT64_C(0); (void)x],
	ac_cv_int64_c=yes, ac_cv_int64_c=no)
	AC_MSG_RESULT($ac_cv_int64_c)
	if test $ac_cv_int64_c = yes; then
		AC_DEFINE(HAVE_INT64_C,1,[Define this to 1 if we have function INT64_C])
	fi
	AC_MSG_CHECKING(for PRIdLEAST64)
	AC_TRY_COMPILE([
$ac_includes_default
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif /* HAVE_INTTYPES_H */
],[printf("%"PRIdLEAST64, (long int) 0);],
	ac_cv_pridleast64=yes, ac_cv_pridleast64=no)
	AC_MSG_RESULT($ac_cv_pridleast64)
	if test $ac_cv_pridleast64 = yes; then
		AC_DEFINE(HAVE_PRIDLEAST64,1,[Define this to 1 if we have PRIdLEAST64])
	fi
	AC_MSG_CHECKING(for SCNdLEAST64)
	AC_TRY_COMPILE([
$ac_includes_default
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif /* HAVE_INTTYPES_H */
],[printf("%"SCNdLEAST64, (long int) 0);],
	ac_cv_scndleast64=yes, ac_cv_scndleast64=no)
	AC_MSG_RESULT($ac_cv_scndleast64)
	if test $ac_cv_scndleast64 = yes; then
		AC_DEFINE(HAVE_SCNDLEAST64,1,[Define this to 1 if we have SCNdLEAST64])
	fi
fi

dnl test to see if nl_item is defined
AC_MSG_CHECKING(for nl_item)
AC_TRY_COMPILE([
$ac_includes_default
#ifdef HAVE_LANGINFO_H
#include <langinfo.h>
#else
#ifdef HAVE_NL_TYPES_H
#include <nl_types.h>
#endif
#endif
],[nl_item x; x = 0; (void)x],
ac_cv_nl_item=yes, ac_cv_nl_item=no)
AC_MSG_RESULT($ac_cv_nl_item)
if test $ac_cv_nl_item = yes; then
	AC_DEFINE(HAVE_NL_ITEM,1,[Define this to 1 if we have header nl_types.h])
fi

###	Checks for libraries.
# libuu/uudeview
# only define HAVE_LIBUU and HAVE_UUDEVIEW_H if both are found
AC_CHECK_LIB(uu, UUInitialize,
	[AC_CHECK_HEADER(uudeview.h,
		[AC_DEFINE(HAVE_LIBUU,1,[Define this to 1 if we have library uu])
		AC_DEFINE(HAVE_UUDEVIEW_H,1,[Define this to 1 if we have header uudeview.h])
		LIBS="$LIBS -luu"]
	)]
)


# ICU - International Components for Unicode
# TODO: do separate checks for
#  - unorm_normalize() # deprecated since ICU 56
#  - uidna_IDNToUnicode() # deprecated since ICU 56
#  - ubidi_open()
# and for IDNA2008
#  - uidna_openUTS46()
#  - uidna_nameToUnicode()
#  - unorm2_normalize()
# get $CFLAGS/$LDFLAGS from pkg-config icu-uc if possible
cf_try_icuuc="no"
cf_try_icuuc46="no"
AC_CHECK_HEADER(unicode/unorm.h,[
	AC_CHECK_HEADER(unicode/ustring.h, [
		AC_DEFINE(HAVE_UNICODE_UNORM_H,1,[Define this to 1 if we have header unicode/unorm.h])
		AC_DEFINE(HAVE_UNICODE_USTRING_H,1,[Define this to 1 if we have header unicode/ustring.h])
		AC_MSG_CHECKING(for unorm_normalize in libicuuc)
		cf_save_LIBS="$LIBS"
		cf_try_icuuc="no"
		LIBS="$LIBS -licuuc"
		AC_TRY_LINK([$ac_includes_default
			#include <unicode/unorm.h>], [
			int32_t needed;
			const UChar *ustr = NULL;
 			UErrorCode status;
			needed = unorm_normalize(ustr, -1, UNORM_DEFAULT, 0, NULL, 0, &status);
			(void)needed], [
			AC_DEFINE(HAVE_LIBICUUC,1,[Define this to 1 if we have libicuuc])
			cf_try_icuuc="yes"],
			LIBS=$cf_save_LIBS
		)
		AC_MSG_RESULT($cf_try_icuuc)
		cf_save_LIBS="$LIBS"
		AC_CHECK_HEADER(unicode/uidna.h, [
			AC_DEFINE(HAVE_UNICODE_UIDNA_H,1,[Define this to 1 if we have header unicode/uidna.h])
		])
		AC_MSG_CHECKING(for uidna_nameToUnicode in libicuuc)
		AC_TRY_LINK([#include <unicode/uidna.h>
			#include <unicode/unorm.h>], [
			UErrorCode status = U_ZERO_ERROR;
			UIDNAInfo info = UIDNA_INFO_INITIALIZER;
			UIDNA *uts46 = uidna_openUTS46(UNORM_DEFAULT, &status);
			uidna_nameToUnicode(uts46, NULL, 0, NULL, 0, &info, &status);
			uidna_close(uts46);], [
			AC_DEFINE(HAVE_LIBICUUC_46_API,1,[Define this to 1 if we have libicuus 46-API])
			cf_try_icuuc46="yes"],
			LIBS=$cf_save_LIBS
		)
		AC_MSG_RESULT($cf_try_icuuc46)
		AC_CHECK_HEADER(unicode/ubidi.h, [
			AC_DEFINE(HAVE_UNICODE_UBIDI_H,1,[Define this to 1 if we have header unicode/ubidi.h])
		])
	])
])

AC_CHECK_HEADERS(unicode/unorm.h unicode/unorm2.h unicode/ustring.h unicode/ucnv.h unicode/ubidi.h)

# this doesn't work, why?
#AC_CHECK_LIB(icuuc, ucnv_open,
#	[AC_DEFINE(HAVE_UCNV_OPEN, 1, [Define to 1 if you want have ucnv_open])]
#)
#AC_CHECK_LIB(icuuc, ubidi_open,
#	[AC_DEFINE(HAVE_UBIDI_OPEN, 1, [Define to 1 if you have ubidi_open])]
#)
# ok, we go with
if test x"$ac_cv_header_unicode_ucnv_h" = "xyes" ; then
	AC_DEFINE(HAVE_UCNV_OPEN, 1)
fi
if test x"$ac_cv_header_unicode_ubidi_h" = "xyes" ; then
	AC_DEFINE(HAVE_UBIDI_OPEN, 1)
fi


# without icuuc try GNU libunistring for normalization
if test $cf_try_icuuc = no ; then
	AC_CHECK_HEADERS(unistring/version.h)
	AC_CHECK_HEADER(unitypes.h,[
		AC_CHECK_HEADER(uninorm.h,[
			AC_DEFINE(HAVE_UNITYPES_H,1,[Define this to 1 if we have header unitypes.h])
			AC_DEFINE(HAVE_UNINORM_H,1,[Define this to 1 if we have header uninorm.h])
			AC_MSG_CHECKING(for u8_normalize in libunistring)
			cf_save_LIBS="$LIBS"
			cf_try_unistring="no"
			LIBS="$LIBS -lunistring"
			AC_TRY_LINK([#include <unitypes.h>
				#include <uninorm.h>], [
				size_t ol = 0;
				u8_normalize(UNINORM_NFC, (uint8_t *) "x", 2, NULL, &ol);], [
				AC_DEFINE(HAVE_LIBUNISTRING,1,[Define this to 1 if we have library unistring])
				cf_try_unistring="yes"],
				LIBS=$cf_save_LIBS
			)
			AC_MSG_RESULT($cf_try_unistring)
		])
	])
fi

# without icuuc try libidn for Internationalized Domain Names / IDN 2003
# TODO: get $CFLAGS/$LDFLAGS from pkg-config libidn if possible
if test $cf_try_icuuc = no ; then
	AC_CHECK_LIB(idn, stringprep_check_version,
		[AC_CHECK_HEADER(stringprep.h,[
			AC_DEFINE(HAVE_STRINGPREP_H,1,[Define this to 1 if we have header stringprep.h])
			AC_CHECK_HEADER(idna.h, [
				AC_DEFINE(HAVE_IDNA_H,1,[Define this to 1 if we have header idna.h])
				AC_CHECK_LIB(idn, idna_to_unicode_lzlz, [
					AC_DEFINE(HAVE_IDNA_TO_UNICODE_LZLZ,1,[Define this to 1 if we have function idna_to_unicode_lzlz])
					AC_MSG_CHECKING(for IDNA_USE_STD3_ASCII_RULES)
					AC_EGREP_HEADER(IDNA_USE_STD3_ASCII_RULES, idna.h, [
						AC_DEFINE(HAVE_IDNA_USE_STD3_ASCII_RULES,1,[Define this to 1 if we have symbol IDNA_USE_STD3_ASCII_RULES in idna.h])
						AC_MSG_RESULT(yes)],
						AC_MSG_RESULT(no)
					)
				])
				AC_CHECK_LIB(idn, idna_strerror, [
					AC_DEFINE(HAVE_IDNA_STRERROR,1,[Define this to 1 if we have function idna_strerror])
				])
			])
			AC_DEFINE(HAVE_LIBIDN,1,[Define this to 1 if we have library idn])
			LIBS="$LIBS -lidn"]
		)]
	)
fi

# GNU linidn2 // CF_TRY_PKG_CONFIG has no version checking yet
AC_MSG_CHECKING(for libidn2)
CF_TRY_PKG_CONFIG(
	[libidn2],
	[AC_DEFINE(HAVE_LIBIDN2)
	AC_DEFINE(HAVE_IDN2_H)
	have_libidn2=yes],
	[AC_TRY_COMPILE([
#include <idn2.h>
	],[
#if IDN2_VERSION_MAJOR < 2 || (IDN2_VERSION_MAJOR == 2 && IDN2_VERSION_MINOR < 3)
#error "Please use libidn2 >= 2.3.0"
#endif /* IDN2_VERSION_MAJOR < 2 || (IDN2_VERSION_MAJOR == 2 && IDN2_VERSION_MINOR < 3) */
	],
	[have_libidn2=yes
	AC_DEFINE(HAVE_IDN2_H)],
	[have_libidn2=no
	AC_MSG_RESULT($have_libidn2)]
	)]
)

# libidnkit - Internationalized Domain Names / IDN 2008
if test "x$have_libidn2" != "xyes"; then
AC_CHECK_LIB(idnkit, idn_decodename, [
	AC_CHECK_HEADERS(idn/version.h)
	AC_CHECK_HEADER(idn/api.h, [
		AC_MSG_CHECKING(for IDN_DECODE_LOOKUP)
		cf_save_LIBS="$LIBS"
		LIBS="$LIBS -lidnkit"
		AC_TRY_LINK([#include <idn/api.h>
			#include <string.h>], [
			idn_result_t rs;
			char in[255], out[255];
			const char *i = in;
			char *o = out;
			strcpy(in, "xn--brenfe-fta9a2q.de");
			rs = idn_decodename(IDN_DECODE_LOOKUP, i, o, 254);
			idn_result_tostring(rs);], [
			AC_DEFINE(HAVE_LIBIDNKIT,1,[Define this to 1 if we can link with idnkit library])
			AC_DEFINE(HAVE_IDN_API_H,1,[Define this to 1 if we have header idn/api.h])
			AC_DEFINE(HAVE_IDN_DECODENAME,1,[Define this to 1 if we have function idn_decodename])
			AC_MSG_RESULT(yes)
			cf_have_libidnkit="yes"], [
			LIBS=$cf_save_LIBS
			AC_MSG_RESULT(no)
		])
	])
])
fi


# ICU >= 3.6 ucsdet_detect() and co.
# rewrite, CF_TRY_PKG_CONFIG([icu-i18n], ...)
AC_CHECK_HEADERS(unicode/ucsdet.h, [
	AC_MSG_CHECKING(for ucsdet_detect in libicui18n)
	cf_save_LIBS="$LIBS"
	cf_try_icui18n="no"
	LIBS="$LIBS -licui18n"
	AC_TRY_LINK([
$ac_includes_default
#include <unicode/ucsdet.h>], [
		UErrorCode status = 0;
		UCharsetDetector *detector;
		const UCharsetMatch *match;

		detector = ucsdet_open(&status);
		match = ucsdet_detect(detector, &status);
		ucsdet_getName(match, &status);
	], [AC_DEFINE(USE_ICU_UCSDET,1,[Define this to 1 if we have libicui18n])
		cf_try_icui18n="yes"],
		LIBS=$cf_save_LIBS)
	AC_MSG_RESULT($cf_try_icui18n)
	cf_save_LIBS="$LIBS"
])

if test $use_curses != no ; then
	cf_cv_termlib=$cf_with_screen
else
	CF_TERMCAP_LIBS
	# terminfo-based termcap interfaces may be prototyped in <curses.h>,
	# which may/may not be compatible with <termcap.h>
	AC_MSG_CHECKING(if we should include termcap.h)
	cf_save_CFLAGS="$CFLAGS"
	CFLAGS="$CFLAGS -I$srcdir/include"
	AC_TRY_COMPILE([
#define HAVE_TERMCAP_H 1
#include <tcurses.h>],[
#ifdef NCURSES_VERSION
make an error
#endif
],
		[cf_result=yes],
		[cf_result=no])
	AC_MSG_RESULT($cf_result)
	CFLAGS="$cf_save_CFLAGS"
	test $cf_result = yes && AC_DEFINE(HAVE_TERMCAP_H,1,[Define this to 1 if we have non-ncurses header termcap.h])
	CF_TYPE_OUTCHAR
fi

cf_tc_funcs=
cf_tc_externs=
if test ".$cf_cv_termlib" = .terminfo ; then
	AC_DEFINE(USE_TERMINFO,1,[Define this to 1 if we use terminfo functions for screen management])
	cf_tc_funcs="tigetint tigetnum tparam tparm"
	cf_tc_externs="$cf_tc_funcs tgoto tigetstr tputs tigetflag"
elif test ".$cf_cv_termlib" = .termcap ; then
	# BSD 'tputs()' may need 'PC' to be set.
	AC_TRY_LINK([],[extern char PC; PC = 0],
		[AC_DEFINE(HAVE_EXTERN_TCAP_PC,1,[Define this if termcap's extern PC exists])])
	cf_tc_funcs="tgetint tgetnum tparam tparm"
	cf_tc_externs="$cf_tc_funcs tgoto tgetstr tputs tgetent tgetflag"
fi

###	Checks for external-data
CF_ERRNO
CF_STRERROR

###	Checks for library functions.
AC_CHECK_FUNCS(\
	alarm \
	arc4random_uniform \
	atoi \
	atol \
	atoll \
	atoq \
	bcopy \
	chmod \
	execlp \
	explicit_bzero \
	explicit_memset \
	fchmod \
	fcntl \
	fdopen \
	fork \
	ftruncate \
	fsync \
	getcwd \
	gettimeofday \
	getwd \
	inet_aton \
	inet_pton \
	is_xterm \
	isascii \
	lockf \
	lrand48 \
	memcmp \
	memcpy \
	memmove \
	memset \
	mkdir \
	mkfifo \
	mktemp \
	mkstemp \
	nl_langinfo \
	poll \
	putenv \
	random \
	rewinddir \
	resizeterm \
	select \
	setenv \
	setlocale \
	settz \
	setvbuf \
	sigaction \
	snprintf \
	strchr \
	strcasecmp \
	strcasestr \
	strdup \
	strftime \
	strpbrk \
	strrchr \
	strrstr \
	strsep \
	strstr \
	strtol \
	strtoll \
	tzset \
	uname \
	unlink \
	use_default_colors \
	usleep \
	vsnprintf \
	waitpid \
$cf_tc_funcs )

AC_CHECK_FUNC(flock,
	AC_DEFINE(HAVE_FLOCK,1,[Define this to 1 if flock function exists]),[
	AC_CHECK_LIB(bsd, flock,
		AC_DEFINE(HAVE_FLOCK)
		LIBS="$LIBS -lbsd")])

# clock_gettime() / librt
AC_CHECK_FUNC(clock_gettime,
	AC_DEFINE(HAVE_CLOCK_GETTIME,1,[Define this to 1 if clock_gettime function exists]),[
		AC_CHECK_LIB(rt, clock_gettime,
			AC_DEFINE(HAVE_CLOCK_GETTIME)
			LIBS="$LIBS -lrt"
		)
	]
)

AC_MSG_CHECKING([for memset_s])
AC_TRY_RUN([
/* Request C11 Annex K */
#define __STDC_WANT_LIB_EXT1__ 1
$ac_includes_default
#include <string.h>
int main(void)
{
	char buf[10] = { 1 };
	if (memset_s((void*) buf, (size_t) 100, 0, (size_t) 1))
		return(-1);
}],
	[
		AC_MSG_RESULT([yes])
		AC_DEFINE(HAVE_MEMSET_S,1,[Define this to 1 if we have function memset_s])
	],
	[AC_MSG_RESULT([no])],
	[AC_MSG_RESULT([unknown])]
)

AM_MULTIBYTE_ABLE

AC_MSG_CHECKING(if gettimeofday takes two arguments)
AC_TRY_COMPILE([
$ac_includes_default
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif],
[static struct timeval tv;
gettimeofday(&tv, NULL);],
ac_cv_func_gettimeofday_2args=yes, ac_cv_func_gettimeofday_2args=no)
AC_MSG_RESULT($ac_cv_func_gettimeofday_2args)
if test $ac_cv_func_gettimeofday_2args = yes; then
	AC_DEFINE(GETTIMEOFDAY_2ARGS,1,[Define this to 1 if gettimeofday takes two arguments])
fi

CF_POSIX_JC
CF_FUNC_FORK
CF_FUNC_MEMMOVE

AC_MSG_CHECKING(if select expects int * arguments)
AC_EGREP_HEADER([select\(.*, *int *\*,],time.h,
	AC_DEFINE(HAVE_SELECT_INTP,1,[Define this to 1 if select expects int * arguments]) AC_MSG_RESULT(yes),
	AC_MSG_RESULT(no)
)

AC_FUNC_CLOSEDIR_VOID

# autoconf 2.5x assumes setvbuf is not reversed when cross-compiling
if test "$cross_compiling" != yes ; then
	AC_FUNC_SETVBUF_REVERSED
fi

###	Checks for network library functions.
AC_CHECK_FUNCS(\
	gai_strerror \
	getaddrinfo \
	gethostname \
	gethostbyname \
	getpeername \
	getservbyname \
	inet_addr \
	inet_ntoa \
	strncasecmp \
)

CF_TYPE_SIGACTION
CF_TERMIOS
CF_PW_GECOS
CF_TM_GMTOFF

AC_SYS_LONG_FILE_NAMES
CF_FUNC_SYSTEM

# Check if we are trying to use curses+color, but cannot
if test $use_color = yes ; then
	if test $use_curses = no ; then
		AC_DEFINE(HAVE_COLOR,1,[Define this to 1 if curses supports color])
	elif test $cf_with_screen = pdcurses ; then
		AC_DEFINE(HAVE_COLOR)
	else
	 	CF_NCURSES_BROKEN
		CF_COLOR_CURSES
		if test $cf_cv_color_curses = yes ; then
			AC_DEFINE(HAVE_COLOR)
		else
			AC_MSG_WARN(This curses library does not support color)
		fi
	fi
fi

# GCC and Apollo compilers are quite noisy about signal constants (quiet them).
if test -n "$GCC"; then
	check_sig_const=yes
elif test -f /sys/dm/dm ; then
	check_sig_const=yes
elif test -f /sys/dm/spm ; then
	check_sig_const=yes
else
	check_sig_const=no
fi

if test $check_sig_const = yes ; then
	CF_SIG_CONST
fi

CF_COMPTYPE
CF_COREFILE

### test this last, since it uses a partly-built autoconf.h
# Setup includes for test-program to verify declarations
CHECK_DECL_FLAG="-I$srcdir/include"
if test "$PCREDIR_MAKE" != "#" ; then
	CHECK_DECL_FLAG=$CHECK_DECL_FLAG" -I$srcdir/pcre"
fi
if test "$CANDIR_MAKE" != "#" ; then
	CHECK_DECL_FLAG=$CHECK_DECL_FLAG" -I$srcdir/libcanlock/include"
fi
CHECK_DECL_HDRS='
#undef __CPROTO__
#define __CPROTO__
#define HAVE_CONFDEFS_H
#include <tin.h>'
TIN_DECL_HDRS="$CHECK_DECL_HDRS"

dnl These return non-int values, and can be troublesome if not declared
CF_CHECK_DECL(\
	errno \
	getenv \
	getlogin \
	getpwnam \
	popen \
	strchr \
	strcasestr \
	strsep \
)

dnl Check network stuff separately, to limit the effect of inconsistent headers
CHECK_DECL_HDRS="$TIN_DECL_HDRS
#include <tnntp.h>"
CF_CHECK_DECL(\
	gethostbyname \
	getservbyname \
	inet_aton \
	inet_ntoa \
	socket \
)

if test $use_curses = no ; then
CHECK_DECL_HDRS="$TIN_DECL_HDRS
#include <tcurses.h>"
CF_CHECK_DECL(\
	tgetstr \
	tgoto \
)
fi

if test $with_decl_check = yes; then
CHECK_DECL_HDRS="$TIN_DECL_HDRS"
CF_CHECK_DECL(\
	_flsbuf \
	alarm \
	atoi \
	atol \
	atoll \
	atoq \
	bcopy \
	bzero \
	calloc \
	fchmod \
	fclose \
	fdopen \
	fflush \
	fgetc \
	fileno \
	fprintf \
	fputc \
	fputs \
	fread \
	free \
	fseek \
	fwrite \
	getcwd \
	getopt \
	getwd \
	heapsort \
	ioctl \
	isascii \
	kill \
	lrand48 \
	malloc \
	memset \
	mkstemp \
	mktemp \
	pclose \
	perror \
	printf \
	putenv \
	qsort \
	realloc \
	rename \
	rewind \
	select \
	setenv \
	snprintf \
	srand48 \
	sscanf \
	strcasecmp \
	strftime \
	strncasecmp \
	strtol \
	strtoll \
	system \
	time \
	tolower \
	toupper \
	ungetc \
	usleep \
	vsprintf \
	vsnprintf \
	wcswidth \
	wcwidth \
)

if test $use_curses = no ; then
CHECK_DECL_HDRS="$TIN_DECL_HDRS
#include <tcurses.h>"
CF_CHECK_DECL($cf_tc_externs)
fi

CHECK_DECL_HDRS="$TIN_DECL_HDRS
#include <tnntp.h>"
CF_CHECK_DECL(\
	connect \
	gethostname \
)

fi

CF_TIOCGWINSZ

### append special libraries that get in the way of testing
case $debug_malloc in
DBMALLOC)
	AC_DEFINE(USE_DBMALLOC)
	LIBS="$LIBS -ldbmalloc"
	;;
DMALLOC)
	AC_DEFINE(USE_DMALLOC)
	LIBS="$LIBS -ldmalloc"
	;;
esac

### Use gettext
### this also calls AM_LANGINFO_CODESET and AM_ICONV
### so we don't need to do the tests ourselves.
CF_BUNDLED_INTL
LIBS="$LIBS $LIBICONV"

### check for alloca (required for bison)
case "$YACC" in
bison*)
	use_alloca=yes
	;;
esac

if test ".$use_alloca" = .yes ; then
	CF_FUNC_ALLOCA
else
	ALLOCA=""
	AC_SUBST(ALLOCA)
fi

# if struct hostent contains h_addr_list or not (SunOS-3.5)
AC_MSG_CHECKING(for h_addr_list in struct hostent)
AC_TRY_COMPILE([
$ac_includes_default
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
],[
static struct hostent h;
h.h_addr_list[0] = malloc(1);
],ac_cv_hostent_h_addr_list=yes,ac_cv_hostent_h_addr_list=no)
AC_MSG_RESULT($ac_cv_hostent_h_addr_list)
if test $ac_cv_hostent_h_addr_list = yes; then
	AC_DEFINE(HAVE_HOSTENT_H_ADDR_LIST,1,[Define this to 1 if we have h_addr_list in struct hostent])
fi

CF_CHECK_FD_SET

# snprintf() doesn't return length
# wrap into
#	if test "$ac_cv_func_snprintf" == "yes" ; then
#	fi
#?
AC_MSG_CHECKING(for working snprintf())
AC_TRY_RUN([
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
	char skip[5], fmt[9];
	int len;

	strcpy(fmt, "%d.%d.%d");
	strcpy(skip, "Test");
	len = snprintf(NULL, 0, "%s%s", skip, fmt);
	if (len != (int)strlen(fmt) + (int)strlen(skip))
		exit(1);
	exit(0);
}],
	[
		AC_MSG_RESULT(yes)
	],
	[
		AC_DEFINE(SNPRINTF_BROKEN,1,[Define this to 1 if function SNPRINTF is buggy])
		AC_MSG_RESULT(no)
	],
	[
		AC_MSG_RESULT(unknown)
	]
)


# tolower() is known to be broken on 4.2BSD by
# not checking if input is an uppercase letter
# /* #define tolower(c)	((c)-'A'+'a') */
AC_MSG_CHECKING(for working tolower())
AC_TRY_RUN([
#include <ctype.h>
int main(void) {
	unsigned char str;

	for (str = 1; str < 127; str++) {
		if ((char) tolower(str) != ((str >= 'A' && str <= 'Z') ? ((unsigned char) (str - 'A' + 'a')) : str))
			return 1;
	}
	return 0;
}],
	[
		AC_MSG_RESULT(yes)
	],
	[
		AC_DEFINE(TOLOWER_BROKEN,1,[Define this to 1 if function tolower is broken])
		AC_MSG_RESULT(no)
	],
	[
		AC_MSG_RESULT(unknown)
	]
)


# toupper is known to be broken on 4.2BSD by
# not checking if input is a lowercase letter
# /* #define toupper(c)	((c)-'a'+'A') */
AC_MSG_CHECKING(for working toupper())
AC_TRY_RUN([
#include <ctype.h>
int main(void) {
	unsigned char str;

	for (str = 1; str < 127; str++) {
		if ((char) toupper(str) != ((str >= 'a' && str <= 'z') ? ((unsigned char) (str - 'a' + 'A')) : str))
			return 1;
	}
	return 0;
}],
	[
		AC_MSG_RESULT(yes)
	],
	[
		AC_DEFINE(TOUPPER_BROKEN,1,[Define this to 1 if function toupper is broken])
		AC_MSG_RESULT(no)
	],
	[
		AC_MSG_RESULT(unknown)
	]
)


AC_CHECK_HEADER(stdnoreturn.h,[
	AC_MSG_CHECKING(for C11 _Noreturn feature)
	AC_TRY_COMPILE([
$ac_includes_default
#include <stdnoreturn.h>
static _Noreturn void giveup(void) { exit(0);}],[
#if defined(__STDC__) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
	if (feof(stdin)) giveup()
#else
#	error "__STDC_VERSION__ < 201112L"
#endif],
	[cf_cv_c11_noreturn=yes
	AC_MSG_RESULT($cf_cv_c11_noreturn)],
	[cf_cv_c11_noreturn=no
	AC_MSG_RESULT($cf_cv_c11_noreturn)])
],
[cf_cv_c11_noreturn=no]
)
AS_IF([test x"$cf_cv_c11_noreturn" = "xyes" && test x"$ac_cv_header_stdnoreturn_h" = "xyes"],
[
	AC_DEFINE(HAVE_STDNORETURN_H, 1,[Define if <stdnoreturn.h> header is available and working])
	AC_DEFINE_UNQUOTED(STDC_NORETURN,_Noreturn,[Define if C11 _Noreturn keyword is supported])
])

# signal type - all but POSIX is untested
CF_CHECK_HEADERS(signal.h)
AC_MSG_CHECKING([for POSIX signal support])
AC_TRY_COMPILE([
#ifdef HAVE_STDDEF_H
#	include <stddef.h>
#endif /* HAVE_STDDEF_H */
#ifdef HAVE_SIGNAL_H
#	include <signal.h>
#endif /* HAVE_SIGNAL_H */
],[
sigset_t set;

sigfillset(&set);
(void) sigprocmask(SIG_SETMASK, &set, NULL);
],[
have_posix_signal=yes
AC_DEFINE(HAVE_POSIX_SIGNALS,1)
],[
have_posix_signal=no
])
AC_MSG_RESULT($have_posix_signal)

AS_IF([test x"$have_posix_signal" != "xyes"],
[
AC_MSG_CHECKING([for BSD signal support])
AC_TRY_COMPILE([
#ifdef HAVE_SIGNAL_H
#	include <signal.h>
#endif /* HAVE_SIGNAL_H */
],[
sigblock(0);
],[
have_bsd_signal=yes
AC_DEFINE(HAVE_BSD_SIGNALS,1)
],[
have_bsd_signal=no
])
AC_MSG_RESULT($have_bsd_signal)
])

AS_IF([test x"$have_posix_signal" != "xyes" && test x"$have_bsd_signal" != "xyes"],
[
AC_MSG_CHECKING([for SYSV signal support])
AC_TRY_COMPILE([
#ifdef HAVE_SIGNAL_H
#	include <signal.h>
#endif /* HAVE_SIGNAL_H */
],[
sigignore(0);
],[
have_sysv_signal=yes
AC_DEFINE(HAVE_SYSV_SIGNALS,1)
],[
have_sysv_signal=no
])
AC_MSG_RESULT($have_sysv_signal)
])

AS_IF(
[test x"$have_posix_signal" = "xno" && test x"$have_bsd_signal" = "xno" && test x"$have_sysv_signal" = "xno"],
[AC_DEFINE(HAVE_NO_SIGNAL_BLOCKING,1)
AC_MSG_WARN([[not having blockable signals]])])


CF_CHECK_HEADERS(iconv.h)
AC_MSG_CHECKING(for iconv_open() //TRANSLIT extension)
AC_TRY_RUN([
#ifdef HAVE_ICONV_H
#	include <iconv.h>
#endif /* HAVE_ICONV_H */
#ifdef HAVE_STDLIB_H
#	include <stdlib.h>
#endif /* HAVE_STDLIB_H */
int main(void) {
	iconv_t cd;

	if ((cd = iconv_open("US-ASCII//TRANSLIT", "ISO-8859-1")) == (iconv_t) (-1))
		exit(1);
	exit(0);
}],
	[
		AC_DEFINE(HAVE_ICONV_OPEN_TRANSLIT,1,[Define this to 1 if iconv_open() //TRANSLIT extension works])
		AC_MSG_RESULT(yes)
	],
	[
		AC_MSG_RESULT(no)
	],
	[
		AC_MSG_RESULT(unknown)
	]
)


# TLI, Transport Layer Interface; SVR3, SVR4
# TODO check for funcs: t_sync(), t_open(), t_bind(), t_connect(), t_alloc()
#                       t_free(), t_close(), t_error()
#      check for types: t_errno, t_call
#      libs may be covered already by CF_NETLIBS
# XTI, X/Open Transport Interface
#      AC_CHECK_LIB([xnet], [t_open])
CF_CHECK_HEADERS(tiuser.h sys/tiuser.h)


# FIXME / TESTME
# locale is broken on cygwin < 1.7.0
# group/other bits don't work on cygwin < 1.7.0
# locking doesn't work on cygwin < 2.0 as link(2) is detected but doesn't work
case "$host_os" in
	*cygwin*)
		case `uname -r | sed 's,(.*,,'` in
			B*|1.0-6].*)
				# multiple defects
				AC_DEFINE(NO_LOCALE,1,[Define this to 1 if locale does not work])
				AC_DEFINE(NO_LOCKING,1,[Define this to 1 if locking does not work])
				AC_DEFINE(FILE_MODE_BROKEN,1,[Define this to 1 if file-permissions are broken])
				;;
			1.7.*)
				# link does not work
				AC_DEFINE(NO_LOCKING)
				;;
			*)
				AC_CHECK_FUNC(link, AC_DEFINE(HAVE_LINK,1,[Define this to 1 if we have function link]))
				;;
			esac
		;;
	*haiku*)
		# link does not work
		AC_DEFINE(NO_LOCKING)
		;;
	*)
		AC_CHECK_FUNC(link, AC_DEFINE(HAVE_LINK))
esac

if test "$cf_cv_termlib" = pdcurses ; then
	CF_PDCURSES_X11
fi
CF_CURSES_FUNCS(vw_printw get_wch wget_wch)

### sum up warnings
if test "$cf_cv_termlib" = none ; then
	AC_MSG_WARN([no term-lib found, you might run into trouble later.])
fi
if test "$YACC" = "" ; then
	AC_MSG_WARN([no yacc-parser found, you might run into trouble later.])
fi
if test "$RANLIB" = "" ; then
	AC_MSG_WARN([no library archive builder found, you might run into trouble later.])
fi

### Finally, build autoconf.h and the makefiles
CFLAGS="$CFLAGS $EXTRA_CFLAGS"

LINTFLAGS=$LINTFLAGS
AC_SUBST(LINTFLAGS)

CF_DEFINE_STRING(TIN_CC,       "$CC")
CF_DEFINE_STRING(TIN_CFLAGS,   "$CFLAGS")
CF_DEFINE_STRING(TIN_CPP,      "$CPP")
CF_DEFINE_STRING(TIN_CPPFLAGS, "$CPPFLAGS")
CF_DEFINE_STRING(TIN_LD,       "$CC")
CF_DEFINE_STRING(TIN_LDFLAGS,  "$LDFLAGS")
CF_DEFINE_STRING(TIN_LIBS,     "$PCREDIR_LIBS $CANLIBS $LIBS")

AC_OUTPUT($PCRE_MAKEFILE
	$SUB_MAKEFILE
	$CAN_MAKEFILE
	src/Makefile)
