dnl Process this file with autoconf to produce a configure script.
AC_INIT(xrus.c)
AC_CONFIG_HEADER(config.h)

VERSION=1.4.2
AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
AC_SUBST(VERSION)

if test x$CFLAGS = x
then
   CFLAGS=" "
fi

dnl Checks for programs.
AC_PROG_AWK
AC_PROG_CC
AC_PROG_LN_S

if test x$CC = xgcc
then
   CFLAGS="$CFLAGS -Wall"
fi

dnl Checks for header files.
AC_PATH_XTRA
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_PID_T
AC_CONST

AC_CHECK_LIB(gen,regex) dnl For SCO motif
AC_CHECK_LIB(intl,main)

dnl Checks for library functions.
AC_FUNC_ALLOCA
AC_CHECK_FUNCS(strerror atexit)

dnl Xaw/Motif tests
AC_ARG_WITH(xaw,[  --with-Xaw              compile with Athena widgets])

LIBS="$X_PRE_LIBS $X_LIBS -lXmu -lXt -lX11 $X_EXTRA_LIBS $LIBS"
CFLAGS="$CFLAGS $X_CFLAGS"

# if --with-Xaw was specified, check libXaw first
if test x$with_Xaw = xyes
then
   AC_CHECK_LIB(Xaw,main)
fi

# if we don't use Xaw directly, test for Motif
if test x$ac_cv_lib_Xaw_main != xyes -o x$with_Xaw != xyes
then

dnl Check for Motif
AC_PATH_MOTIF
if test x$no_motif != xyes
then
   AC_DEFINE(HAVE_MOTIF)
   if test x$motif_includes != x && test x$motif_includes != x/usr/include
   then
      CFLAGS="$CFLAGS -I$motif_includes"
   fi
   LIBS="-lXm -lXext $LIBS"
   if test x$motif_libraries != x && test x$motif_libraries != x/usr/lib
   then
      case "$LIBS" in
      *-R*) LIBS="-R$motif_libraries $LIBS";;
      esac
      LIBS="-L$motif_libraries $LIBS"
   fi
fi # !motif

fi # libxaw

# if Motif not found, fall back to Xaw
if test x$no_motif = xyes
then
   if test x$ac_cv_lib_Xaw_main = x -a x$with_Xaw = x
   then
      AC_CHECK_LIB(Xaw,main)
   fi
   if test x$ac_cv_lib_Xaw_main != xyes -o x$with_Xaw = xno
   then
      AC_MSG_WARN(Neither Xaw nor Motif found. Nothing will appear on the screen.)
   fi
fi

if uname -X 2>/dev/null | grep 3.2v5 >/dev/null
then
   # this dirty trick is used to force dynamic
   # compilation with gcc on sco v5
   LIBS="$LIBS /lib/libc.so"
fi

AC_OUTPUT(Makefile)
