dnl Process this file with autoconf to produce a configure script.
AC_INIT(xdvi.c)

sinclude(../kpathsea/common.ac)

dnl Substitutes for X_CFLAGS, X_LIBS, and X_EXTRA_LIBS.
AC_PATH_XTRA

AC_FUNC_VPRINTF

# We actually only need getwd if we're being compiled with -DSELFILE.
# And we only need isinf and ieeefp.h to work around a Solaris bug in
# -ldps; see psdps.c.
# <sys/bsdtypes.h> is for ISC 4.0, to define fd_set in psgs.c.
AC_CHECK_FUNCS(getwd isinf)
AC_CHECK_HEADERS(ieeefp.h sys/bsdtypes.h)

# Do we have the SIGIO signal (and F_SETOWN and FASYNC)?
AC_MSG_CHECKING(for SIGIO)
AC_CACHE_VAL(kb_cv_sys_sigio,
[AC_TRY_COMPILE([#include <signal.h>
#include <fcntl.h>],
  [int x = SIGIO + F_SETOWN + FASYNC;],
  kb_cv_sys_sigio=yes, kb_cv_sys_sigio=no)])dnl
AC_MSG_RESULT($kb_cv_sys_sigio)
if test $kb_cv_sys_sigio = yes; then
  AC_DEFINE(HAVE_SIGIO)
fi

# Check if the user wants to use GhostScript, DPS or NeWS to
# display PostScript.
AC_ARG_WITH(ps,
changequote(`,')
`  --with-ps={no,yes,gs,dps,news} PostScript interpreter [gs]',
changequote([,])
[case $withval in
  yes|gs) PS_DEF="$PS_DEF -DPS_GS";;
      no) PS_DEF=no;;
     dps) PS_DEF="$PS_DEF -DPS_DPS";;
    news) PS_DEF="$PS_DEF -DPS_NEWS";;
       *)] AC_MSG_WARN(Unknown --with-ps argument \`$withval'; using gs.);;
 esac)
test -z "$PS_DEF" && PS_DEF=-DPS_GS
test "$PS_DEF" = no && PS_DEF=
AC_SUBST(PS_DEF)dnl
dnl
# If we're on Solaris and we want DPS, then add the extra compilation stuff
# to get it.
if echo "$PS_DEF" | grep PS_DPS >/dev/null; then
   if test "`(uname) 2>/dev/null`" = SunOS \
      && uname -r | grep '^5' >/dev/null; then
    AC_MSG_RESULT(adding DPS includes and libraries for Solaris)
    X_CFLAGS="$X_CFLAGS -I/usr/openwin/include/X11"
    # -lsunmath is for isinf.
    X_LIBS="$X_LIBS -R/usr/openwin/lib /usr/openwin/lib/libdps.so -lsunmath"
  else
    # SunOS 4.x is simpler.
    AC_MSG_RESULT(adding DPS includes and libraries for SunOS 4.x)
    X_LIBS="$X_LIBS -ldps"
  fi
elif echo "$PS_DEF" | grep PS_NEWS >/dev/null; then
    AC_MSG_RESULT(adding NeWS libraries)
    X_LIBS="$X_LIBS -lxview -lcps -lolgx -lxvps"
fi

AC_OUTPUT(Makefile)
