dnl# -*- sh -*-
dnl# Process this file with autoconf to produce a configure script.
dnl#
AC_INIT(src/feature.h)

DATE="6 January 2002"
LSMDATE=6JAN02
VERSION=1.06
VERNAME=xiterm+thai-${VERSION}
MAINT="Theppitak Karoonboonyanan <thep@linux.thai.net>"

AC_SUBST(DATE)
AC_SUBST(LSMDATE)
AC_SUBST(VERSION)
AC_SUBST(VERNAME)
AC_SUBST(MAINT)

dnl#
dnl# Supply default CFLAGS, if not specified by `CFLAGS=flags ./configure'
dnl#
if test -z "${CFLAGS}"; then
    if test -z "${CCOPTS}"; then
	CCOPTS='-O3 -fno-strength-reduce'
	if test "x$GCC" = xyes; then
	    if test x$system = xLinux; then
		CCOPTS='-O3 -fno-strength-reduce'
	    fi
	fi
    fi
    CFLAGS="$CCOPTS"
fi

dnl# Checks for programs.
dnl AC_MAKE_SET

AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL

AC_PATH_PROG(RM, rm, rm)
AC_PATH_PROG(CP, cp, cp)

dnl# system hacks
AC_AIX
AC_ISC_POSIX

dnl# need a neat way to detect SVR4 or its features
dnl# in src/command.c we use these functions:
dnl# grantpt(), unlockpt(), ptsname(), which are defined in <sys/ptms.h>
dnl# - but are these also defined for other systems?

dnl# hack to find if this is SVR4 -- who knows?
dnl## AC_MSG_CHECKING(for SVR4)
dnl## AC_EGREP_CPP(yes,
dnl## [#if defined (SVR4) || defined (_SVR4) || defined (__svr4__)
dnl##   yes;
dnl## #endif
dnl## ], [AC_MSG_RESULT(yes); AC_DEFINE(PERHAPS_SVR4)], AC_MSG_RESULT(perhaps not?))

AC_C_CONST
AC_C_INLINE
AC_PATH_XTRA
AC_CHECK_LIB(Xpm, XpmReadFileToPixmap,
cat >> confdefs.h <<EOF
#define HAVE_LIBXPM
EOF
X_PRE_LIBS="$X_PRE_LIBS -lXpm", , -lXt -lX11)

dnl# Checks for header files.
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h termios.h \
sys/ioctl.h sys/select.h sys/time.h \
sys/sockio.h sys/byteorder.h \
utmpx.h unistd.h)
AC_HEADER_TIME
dnl# "stdlib.h", "stdarg.h", "string.h", "float.h"
dnl# skip this test, Sun always fails anyhow.
dnl> AC_HEADER_STDC

dnl# Missing typedefs and replacements
AC_TYPE_MODE_T
dnl> AC_CHECK_TYPE(umode_t, int)
dnl> AC_CHECK_TYPE(off_t, long)
AC_TYPE_PID_T
AC_TYPE_UID_T

dnl# Checks for library functions.
AC_TYPE_SIGNAL
dnl> AC_FUNC_VPRINTF
AC_CHECK_FUNCS(atexit unsetenv setutent seteuid)

dnl> AC_CHECK_FUNCS(gettimeofday putenv select socket)

CFLAGS=${CFLAGS--O}
LDFLAGS=${LDFLAGS--O}

CPPFLAGS="$CPPFLAGS"
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(LIBS)

dnl# common parts of the Makefile
MCOMMON=./Make.common
AC_SUBST_FILE(MCOMMON)

AC_CONFIG_HEADER(config.h)
AC_OUTPUT(Make.common Makefile src/Makefile \
doc/Makefile doc/LSM doc/xiterm.1 xiterm+thai.spec)

echo "
Configuration:

  Source code location:       ${srcdir}
  Compiler:	              ${CC}
  Compiler flags:             ${CFLAGS}
  Install path:		      ${prefix}/bin"
dnl#  X11 versions:               ${X_LIBS}
echo ""
