dnl
dnl Process this file with autoconf to produce a configure script.
dnl
AC_INIT(include/cdk.h)
AC_CONFIG_HEADER(include/cdk_config.h:include/config.hin)

CF_CHECK_CACHE
CF_VERSION_INFO(cdk)

dnl
dnl Checks for programs.
dnl
AC_PROG_CC
AC_PROG_CPP
AC_PROG_GCC_TRADITIONAL
AC_PROG_RANLIB 
AC_PROG_INSTALL

dnl needed for CF_WITH_LIBTOOL
AC_CHECK_TOOL(AR, ar, ar)

AC_PROG_MAKE_SET
CF_MAKEFLAGS
CF_MAKE_TAGS

CF_ANSI_CC_REQD
AC_C_CONST
CF_XOPEN_SOURCE

CF_DISABLE_ECHO
CF_PROG_EXT
CF_LIB_PREFIX

CF_WITH_CURSES_DIR
CF_WITH_WARNINGS
CF_WITH_LIBTOOL
if test "$with_libtool" = "yes" ; then
	OBJEXT="lo"
fi

dnl
dnl Checks for libraries.
dnl

CF_WITH_DBMALLOC
CF_WITH_DMALLOC

dnl
dnl Checks for header files.
dnl
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(\
limits.h \
unistd.h \
)

dnl
dnl Checks for typedefs, structures, and compiler characteristics.
dnl
AC_TYPE_MODE_T
AC_STRUCT_TM
CF_CURSES_CHTYPE
CF_GETOPT_HEADER

dnl
dnl Checks for library functions.
dnl
AC_CHECK_FUNCS(\
getcwd \
mktime \
strdup \
strerror \
)

CF_FUNC_LSTAT
CF_LOCALE([AC_DEFINE(HAVE_SETLOCALE)])

dnl Check for curses libraries last, since XCurses has dependencies which
dnl break the checks for other functions.
use_library=curses
AC_ARG_WITH(ncurses,
	[  --with-ncurses          compile/link with ncurses library],
	[use_library=ncurses],[
AC_ARG_WITH(ncursesw,
	[  --with-ncursesw         compile/line with wide-character ncurses],
	[use_library=ncursesw],[
AC_ARG_WITH(pdcurses,
	[  --with-pdcurses         compile/link with pdcurses X11 library],
	[use_library=pdcurses])])])

LIB_ROOTNAME=cdk
case $use_library in #(vi
ncurses) #(vi
	CF_NCURSES_CPPFLAGS
	CF_NCURSES_LIBS
	;;
ncursesw)
	CF_UTF8_LIB
	CF_NCURSES_CPPFLAGS(ncursesw)
	CF_NCURSES_LIBS(ncursesw)
	LIB_ROOTNAME=cdkw
	;;
pdcurses) #(vi
	CF_PDCURSES_X11
	LIB_ROOTNAME=cdkX
	;;
*)
	CF_CURSES_CPPFLAGS
	CF_NCURSES_VERSION
	CF_CURSES_LIBS
	;;
esac
AC_SUBST(LIB_ROOTNAME)

CF_CURSES_FUNCS(\
	Xinitscr\
	getbegx \
	getbegy \
	getmaxx \
	getmaxy \
	start_color \
	\
)

CF_CURSES_SETBEGYX

dnl
dnl Set pre-processor compile time variables.
dnl
AC_OUTPUT(
	include/cdk_version.h:include/cdk_version.hin
	Makefile
	cli/Makefile
	examples/Makefile
	demos/Makefile,,,sort)
