# configure.in --- xscreensaver, Copyright (c) 1997 Jamie Zawinski.
#

AC_INIT(driver/subprocs.c)

echo "current directory: `pwd`"
echo "command line was: $0 $@"

AC_CONFIG_HEADER(config.h)
AC_CANONICAL_HOST

AC_PROG_CC

if test -z "$GCC"; then
  AC_MSG_CHECKING(how to request ANSI compilation)
  case "$host" in
    *-hpux*)
      AC_MSG_RESULT(HPUX: adding -Ae)
      CC="$CC -Ae"
    ;;
    *-aix*)
      AC_MSG_RESULT(AIX: adding -qlanglvl=ansi -qhalt=e)
      CC="$CC -qlanglvl=ansi -qhalt=e"
    ;;

    *-dec-*)
      AC_MSG_RESULT(DEC: adding -std1)
      CC="$CC -std1"
    ;;

    *)
      AC_MSG_RESULT(no idea)
    ;;
  esac
fi


AC_MSG_CHECKING([whether the compiler works on ANSI C])
AC_TRY_RUN([ main(int ac, char **av) { return 0; } ],
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no)
   AC_MSG_ERROR(Couldn't build even a trivial ANSI C program: check CC.),
   AC_MSG_ERROR(Couldn't build even a trivial ANSI C program: check CC.))

case "$host" in
  *-irix5* |*-irix6.[0-3]* )
    if test -n "$GCC"; then
      AC_MSG_RESULT(Turning on gcc compiler warnings.)
      CC="$CC -Wall -Wstrict-prototypes -Wnested-externs -Wno-format"
    else
      # not gcc
      AC_MSG_RESULT(Turning on SGI compiler warnings.)
      CC="$CC -fullwarn -use_readonly_const -rdata_shared -g3"
    fi
  ;;

    *-linux-*)
      AC_MSG_RESULT(Turning on gcc compiler warnings.)
      CC="$CC -Wall -Wstrict-prototypes -Wnested-externs -Wno-format"
  ;;

#  *-dec-osf*)
#    if test -z "$GCC"; then
#      AC_MSG_RESULT(Turning on DEC C compiler warnings.)
#      CC="$CC -migrate -w0 -verbose -warnprotos"
#    fi
#  ;;

esac


# Try and determine whether ${INSTALL} can create intermediate directories,
# and if not, whether "mkdir -p" works instead.  This sets ${INSTALL_DIRS}.
# (But autoconf should earn its keep and do this for us!)
#
AC_DEFUN(AC_PROG_INSTALL_DIRS,
  [INSTALL_DIRS='${INSTALL} -d'
   AC_MSG_CHECKING(whether \"\${INSTALL} -d\" creates intermediate directories)
   rm -rf conftestdir
   if mkdir conftestdir; then
      cd conftestdir >&-

      ${INSTALL} -d `pwd`/dir1/dir2 >&- 2>&-
      if test -d dir1/dir2 ; then
        AC_MSG_RESULT(yes)
      else
        AC_MSG_RESULT(no)
        AC_MSG_CHECKING(whether \"mkdir -p\" creates intermediate directories)
        rm -rf dir1
        mkdir -p dir1/dir2 >&- 2>&-
        if test -d dir1/dir2/. ; then
	  AC_MSG_RESULT(yes)
	  INSTALL_DIRS='mkdir -p'
        else
	  AC_MSG_RESULT(no)
        fi
      fi
      cd .. >&-
      rm -rf conftestdir
   fi
])


AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_INSTALL_DIRS
AC_PROG_MAKE_SET

AC_C_CONST
AC_C_INLINE

AC_HEADER_STDC
AC_HEADER_TIME
AC_HEADER_SYS_WAIT
AC_HEADER_DIRENT

AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SIGNAL

AC_MSG_CHECKING(how to call gettimeofday)
AC_CACHE_VAL(ac_cv_gettimeofday_args,
 [AC_TRY_COMPILE([#include <stdlib.h>
		  #include <sys/time.h>],
		 [struct timeval tv; struct timezone tzp;
		  gettimeofday(&tv, &tzp);],
		 [ac_gettimeofday_args=2],
		 [AC_TRY_COMPILE([#include <stdlib.h>
				  #include <sys/time.h>],
				 [struct timeval tv; gettimeofday(&tv);],
				 [ac_gettimeofday_args=1],
				 [ac_gettimeofday_args=0])])
  ac_cv_gettimeofday_args=$ac_gettimeofday_args])
ac_gettimeofday_args=$ac_cv_gettimeofday_args
if test "$ac_gettimeofday_args" = 1 ; then
  AC_DEFINE(HAVE_GETTIMEOFDAY)
  AC_MSG_RESULT(one argument)
elif test "$ac_gettimeofday_args" = 2 ; then
  AC_DEFINE(HAVE_GETTIMEOFDAY)
  AC_DEFINE(GETTIMEOFDAY_TWO_ARGS)
  AC_MSG_RESULT(two arguments)
else
  AC_MSG_RESULT(unknown)
fi


AC_CHECK_FUNCS(select fcntl uname nice setpriority getcwd getwd putenv)
AC_CHECK_FUNCS(sigaction syslog)

AC_CHECK_HEADERS(unistd.h crypt.h sys/select.h)

dnl	/usr/local/src/ssh-1.2.17/putenv.c -- AC_REPLACE_FUNCS(putenv)


AC_ARG_ENABLE(subdir,[
Installation options:

  --enable-subdir=DIR     Put the demo programs in a subdirectory of \`bindir',
                          instead of putting them in bindir itself.  You can
                          specify the name of the subdirectory.  For example,
                          --exec-prefix=/usr/local/bin --enable-subdir=demos
                          would put xscreensaver in /usr/local/bin/, and would
                          put the demos in /usr/local/bin/demos/.  (If DIR
                          begins with /, then bindir will not be prepended.)

  --disable-subdir        Just put the demos in \`bindir' (this is the default.)
],
  [enable_subdir="$enableval"],[enable_subdir=no])
if test x"$enable_subdir" = xno; then
  HACKDIR='${bindir}'
elif test x"$enable_subdir" = xyes -o x"$enable_subdir" = x ; then
  echo "error: must be a subdirectory name: --enable-subdir=$enable_subdir"
  exit 1
else
  # there must be a better way than this...
  if test -z "`echo $enable_subdir | sed 's@^/.*@@'`" ; then
    # absolute path
    HACKDIR=$enable_subdir
  else
    # relative path
    HACKDIR='${bindir}/'$enable_subdir
  fi
fi

# canonicalize slashes.
HACKDIR=`echo "${HACKDIR}" | sed 's@/$@@;s@//*@/@g'`


AC_PATH_XTRA

if test "$have_x" != yes; then
  AC_MSG_ERROR(Couldn't find X11 headers/libs.  Try \`$0 --help'.)
fi


# Try and find the app-defaults directory.
# It sucks that autoconf doesn't do this already...
#
AC_DEFUN(AC_PATH_X_APP_DEFAULTS_XMKMF,[
  rm -fr conftestdir
  if mkdir conftestdir; then
    cd conftestdir >&-
    # Make sure to not put "make" in the Imakefile rules, since we grep it out.
    cat > Imakefile <<'EOF'
acfindx:
	@echo 'ac_x_app_defaults="${XAPPLOADDIR}"'
EOF
    if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then
      # GNU make sometimes prints "make[1]: Entering...", which'd confuse us.
      eval `${MAKE-make} acfindx 2>/dev/null | grep -v make`
    fi
    cd .. >&-
    rm -fr conftestdir
  fi])

AC_DEFUN(AC_PATH_X_APP_DEFAULTS_DIRECT,[
  # Look for the directory under a standard set of common directories.
  # Check X11 before X11Rn because it's often a symlink to the current release.
  for ac_dir in					\
    /usr/X11/lib/app-defaults			\
    /usr/X11R6/lib/app-defaults			\
    /usr/X11R6/lib/X11/app-defaults		\
    /usr/X11R5/lib/app-defaults			\
    /usr/X11R5/lib/X11/app-defaults		\
    /usr/X11R4/lib/app-defaults			\
    /usr/X11R4/lib/X11/app-defaults		\
						\
    /usr/lib/X11/app-defaults			\
    /usr/lib/X11R6/app-defaults			\
    /usr/lib/X11R5/app-defaults			\
    /usr/lib/X11R4/app-defaults			\
						\
    /usr/local/X11/lib/app-defaults		\
    /usr/local/X11R6/lib/app-defaults		\
    /usr/local/X11R5/lib/app-defaults		\
    /usr/local/X11R4/lib/app-defaults		\
						\
    /usr/local/lib/X11/app-defaults		\
    /usr/local/lib/X11R6/app-defaults		\
    /usr/local/lib/X11R6/X11/app-defaults	\
    /usr/local/lib/X11R5/app-defaults		\
    /usr/local/lib/X11R5/X11/app-defaults	\
    /usr/local/lib/X11R4/app-defaults		\
    /usr/local/lib/X11R4/X11/app-defaults	\
						\
    /usr/X386/lib/X11/app-defaults		\
    /usr/x386/lib/X11/app-defaults		\
    /usr/XFree86/lib/X11/app-defaults		\
						\
    /usr/lib/X11/app-defaults			\
    /usr/local/lib/X11/app-defaults		\
    /usr/unsupported/lib/X11/app-defaults	\
    /usr/athena/lib/X11/app-defaults		\
    /usr/local/x11r5/lib/X11/app-defaults	\
    /usr/lpp/Xamples/lib/X11/app-defaults	\
    /lib/usr/lib/X11/app-defaults		\
						\
    /usr/openwin/lib/app-defaults		\
    /usr/openwin/lib/X11/app-defaults		\
    /usr/openwin/share/lib/app-defaults		\
    /usr/openwin/share/lib/X11/app-defaults	\
						\
    /X11R6/lib/app-defaults			\
    /X11R5/lib/app-defaults			\
    /X11R4/lib/app-defaults			\
    ; \
  do
    if test -d "$ac_dir"; then
      ac_x_app_defaults=$ac_dir
      break
    fi
  done
])


AC_DEFUN(AC_PATH_X_APP_DEFAULTS,
  [AC_REQUIRE_CPP()
    AC_CACHE_CHECK([for X app-defaults directory], ac_cv_x_app_defaults,
     [AC_PATH_X_APP_DEFAULTS_XMKMF
      if test x"$ac_x_app_defaults" = x; then
        AC_PATH_X_APP_DEFAULTS_DIRECT
      fi
      if test x"$ac_x_app_defaults" = x; then
        ac_cv_x_app_defaults="/usr/lib/X11/app-defaults"
      else
        # Record where we found app-defaults for the cache.
        ac_cv_x_app_defaults="$ac_x_app_defaults"
      fi])
    eval ac_x_app_defaults="$ac_cv_x_app_defaults"])

AC_PATH_X_APP_DEFAULTS

APPDEFAULTS=$ac_x_app_defaults


# Like AC_CHECK_HEADER, but it uses the already-computed -I directories.
#
AC_DEFUN(AC_CHECK_X_HEADER, [
  ac_save_CPPFLAGS="$CPPFLAGS"
  if test \! -z "$includedir" ; then 
    CPPFLAGS="$CPPFLAGS -I$includedir"
  fi
  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
  AC_CHECK_HEADER([$1], [$2])
  CPPFLAGS="$ac_save_CPPFLAGS"])

# Like AC_EGREP_HEADER, but it uses the already-computed -I directories.
#
AC_DEFUN(AC_EGREP_X_HEADER, [
  ac_save_CPPFLAGS="$CPPFLAGS"
  if test \! -z "$includedir" ; then 
    CPPFLAGS="$CPPFLAGS -I$includedir"
  fi
  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
  AC_EGREP_HEADER([$1], [$2], [$3], [$4])
  CPPFLAGS="$ac_save_CPPFLAGS"])

# Like AC_TRY_COMPILE, but it uses the already-computed -I directories.
#
AC_DEFUN(AC_TRY_X_COMPILE, [
  ac_save_CPPFLAGS="$CPPFLAGS"
  if test \! -z "$includedir" ; then 
    CPPFLAGS="$CPPFLAGS -I$includedir"
  fi
  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
  AC_TRY_COMPILE([$1], [$2], [$3], [$4])
  CPPFLAGS="$ac_save_CPPFLAGS"])


# Like AC_CHECK_LIB, but it uses the already-computed -I and -L directories.
# Use this sparingly; it probably doesn't work very well on X programs.
#
AC_DEFUN(AC_CHECK_X_LIB, [
  ac_save_CPPFLAGS="$CPPFLAGS"
  ac_save_LDFLAGS="$LDFLAGS"

  if test \! -z "$includedir" ; then 
    CPPFLAGS="$CPPFLAGS -I$includedir"
  fi
  # note: $X_CFLAGS includes $x_includes
  CPPFLAGS="$CPPFLAGS $X_CFLAGS"

  if test \! -z "$libdir" ; then
    LDFLAGS="$LDFLAGS -L$libdir"
  fi
  # note: $X_LIBS includes $x_libraries
  LDFLAGS="$LDFLAGS $X_LIBS"

  AC_CHECK_LIB([$1], [$2], [$3], [$4], [$5])
  CPPFLAGS="$ac_save_CPPFLAGS"
  LDFLAGS="$ac_save_LDFLAGS"])

# Like AC_TRY_RUN, but it uses the already-computed -I directories.
# (But not the -L directories!)
#
AC_DEFUN(AC_TRY_X_RUN, [
  ac_save_CPPFLAGS="$CPPFLAGS"
  if test \! -z "$includedir" ; then 
    CPPFLAGS="$CPPFLAGS -I$includedir"
  fi
  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
  AC_TRY_RUN([$1], [$2], [$3], [$4])
  CPPFLAGS="$ac_save_CPPFLAGS"])



# Usage: HANDLE_X_PATH_ARG([variable_name],
#			   [--command-line-option],
#			   [descriptive string])
#
# All of the --with options take three forms:
#
#   --with-foo (or --with-foo=yes)
#   --without-foo (or --with-foo=no)
#   --with-foo=/DIR
#
# This function, HANDLE_X_PATH_ARG, deals with the /DIR case.  When it sees
# a directory (string beginning with a slash) it checks to see whether
# /DIR/include and /DIR/lib exist, and adds them to $X_CFLAGS and $X_LIBS
# as appropriate.
#
AC_DEFUN(HANDLE_X_PATH_ARG, [
   case "$[$1]" in
    yes) ;;
    no)  ;;

    /*)
     AC_MSG_CHECKING([for [$3] headers])
     d=$[$1]/include
     if test -d $d; then
       X_CFLAGS="-I$d $X_CFLAGS"
       AC_MSG_RESULT($d)
     else
       AC_MSG_RESULT(not found ($d: no such directory))
     fi

     AC_MSG_CHECKING([for [$3] libs])
     d=$[$1]/lib
     if test -d $d; then
       X_LIBS="-L$d $X_LIBS"
       AC_MSG_RESULT($d)
     else
       AC_MSG_RESULT(not found ($d: no such directory))
     fi

     # replace the directory string with "yes".
     [$1]_req="yes"
     [$1]=$[$1]_req
     ;;

    *)
     echo ""
     echo "error: argument to [$2] must be \"yes\", \"no\", or a directory."
     echo "       If it is a directory, then \`DIR/include' will be added to"
     echo "       the -I list, and \`DIR/lib' will be added to the -L list."
     exit 1
     ;;
   esac

   # why is this necessary?
   # if we don't do this, then "./configure --with-motif=/usr/local/lesstif"
   # behaves as if "--with-zippy=/usr/local/lesstif" was also present!
   withval=
  ])



# check for the HP XHPDisableReset server extension headers.
#
AC_EGREP_X_HEADER(XHPDisableReset, X11/XHPlib.h,
		  [AC_DEFINE(HAVE_XHPDISABLERESET)
		   SAVER_LIBS="-lXhp11 $SAVER_LIBS"])


# Check for the availability of the XPointer typedef, and define it otherwise.
#
AC_CACHE_CHECK([for XPointer], ac_cv_xpointer,
		[AC_TRY_X_COMPILE([#include <X11/Xlib.h>],
				  [XPointer foo = (XPointer) 0;],
				  [ac_cv_xpointer=yes],
				  [ac_cv_xpointer=no])])
if test "$ac_cv_xpointer" != yes; then
  AC_DEFINE(XPointer,[char*])
fi


# Random special-cases for certain pathological OSes.  You know who you are.
#
case "$host" in
  *-hpux*)

    # The following arcana was gleaned from conversations with
    # Eric Schwartz <erics@col.hp.com>:
    #
    # On HPUX 10.x, the parts of X that HP considers "standard" live in
    # /usr/{include,lib}/X11R6/.  The parts that HP doesn't consider
    # "standard", notably, Xaw and Xmu, live in /usr/contrib/X11R6/.
    # Also, there are symlinks from /usr/include/ and /usr/lib/ into
    # /usr/{include,lib}/X11R6/, so that (if you don't use Xmu at all)
    # you don't need any -I or -L arguments.
    #
    # On HPUX 9.x, /usr/{include,lib}/X11R5/ and /usr/contrib/X11R5/
    # are the same division as 10.x.  However, there are no symlinks to
    # the X stuff from /usr/include/ and /usr/lib/, so -I and -L
    # arguments are always necessary.
    #
    # However, X11R6 was available on HPUX 9.x as a patch: if that
    # patch was installed, then all of X11R6 went in to
    # /usr/contrib/X11R6/ (there was no /usr/{include,lib}/X11R6/.)
    #
    # HPUX 8.x was the same as 9.x, but was X11R4 instead (I don't know
    # whether R5 was available as a patch; R6 undoubtedly was not.)
    #
    # So.  We try and use the highest numbered pair of
    # /usr/{include,lib}/X11R?/ and /usr/contrib/X11R?/{include,lib}/
    # that are available.  We do not mix and match different versions
    # of X.
    #
    # Questions I still don't know the answers to: (do you?)
    #
    #   * Does HPUX 10.x come with /usr/contrib/X11R6/ standard?  
    #     Or does that need to be installed separately?
    #
    #   * On HPUX 9.x, where /usr/include/X11R5/ was standard, and
    #     /usr/contrib/X11R6/ could be installed as a patch, what was in
    #     that contrib directory?  Did it contain so-called "standard"
    #     X11R6, or did it include Xaw and Xmu as well?  If the former,
    #     where did one find Xaw and Xmu on 9.x R6 systems?  Would this
    #     be a situation where one had to reach into the R5 headers and
    #     libs to find Xmu?  That is, must both R6 and R5 directories
    #     be on the -I and -L lists in that case?
    #
    for version in X11R6 X11R5 X11R4 ; do
      # if either pair of directories exists...
      if test -d /usr/lib/$version || test -d /usr/contrib/$version/lib ; then
         # if contrib exists, use it...
         if test -d /usr/contrib/$version/lib ; then
           X_CFLAGS="$X_CFLAGS -I/usr/contrib/$version/include"
           X_LIBS="$X_LIBS -L/usr/contrib/$version/lib"
         fi
         # if the "standard" one exists, use it.
         if test -d /usr/lib/$version ; then
           X_CFLAGS="$X_CFLAGS -I/usr/include/$version"
           X_LIBS="$X_LIBS -L/usr/lib/$version"
         fi
         # since at least one of the pair exists, go no farther.
         break
      fi
    done

    # Now find Motif.  Thanks for not making xmkmf find this by
    # default, you losers.
    #
    if test -d /usr/lib/Motif1.2 ; then
      X_CFLAGS="$X_CFLAGS -I/usr/include/Motif1.2"
      X_LIBS="$X_LIBS -L/usr/lib/Motif1.2"
    elif test -d /usr/lib/Motif1.1 ; then
      X_CFLAGS="$X_CFLAGS -I/usr/include/Motif1.1"
      X_LIBS="$X_LIBS -L/usr/lib/Motif1.1"
    fi

    # Now let's check for the pseudo-standard locations for OpenGL and XPM.
    #
    if test -d /opt/Mesa/lib ; then
      X_CFLAGS="-I/opt/Mesa/include $X_CFLAGS"
      X_LIBS="-L/opt/Mesa/lib $X_LIBS"
    fi

    if test -d /opt/xpm/lib/X11 ; then
      X_CFLAGS="-I/opt/xpm/include $X_CFLAGS"
      X_LIBS="-L/opt/xpm/lib/X11 $X_LIBS"
    fi

    # On HPUX, default to installing in /opt/xscreensaver/ instead of
    # in /usr/local/, unless there is already an xscreensaver in
    # /usr/local/bin/.  This can be overridden with the --prefix arg
    # to configure.  I'm not sure this is the right thing to do, but
    # Richard Lloyd says so...
    #
    if test \! -x /usr/local/bin/xscreensaver ; then
      ac_default_prefix=/opt/xscreensaver
    fi

  ;;
  *-solaris*)

    # Thanks for not making xmkmf find this by default, pinheads.
    # And thanks for moving things around again, too.  Is this
    # really the standard location now?  What happened to the
    # joke that this kind of thing went in /opt?
    # cthomp says "answer: CDE (Common Disorganized Environment)"
    #
    if test -f /usr/dt/include/Xm/Xm.h ; then
      X_CFLAGS="$X_CFLAGS -I/usr/dt/include"
      X_LIBS="$X_LIBS -L/usr/dt/lib -R:/usr/dt/lib"

      # Some versions of Slowlaris Motif require -lgen.  But not all.  Why?
      AC_CHECK_LIB(gen, regcmp, [X_LIBS="$X_LIBS -lgen"])
    fi
  ;;
esac



# Check for Xmu (some fucked up vendors don't ship it...)
#
have_xmu=no
AC_CHECK_X_HEADER(X11/Xmu/Error.h, [have_xmu=yes])
if test "$have_xmu" = no ; then
  XMU_SRCS='$(UTILS_SRC)/xmu.c'
  XMU_OBJS='$(UTILS_BIN)/xmu.o'
else
  XMU_SRCS=''
  XMU_OBJS=''
  SAVER_LIBS="-lXmu $SAVER_LIBS"
  HACK_LIBS="-lXmu $HACK_LIBS"
  TOOLKIT_LIBS="-lXmu $TOOLKIT_LIBS"
  AC_DEFINE(HAVE_XMU)
fi


# See comp.windows.x FAQ question 124 about _get_wmShellWidgetClass on 4.1.x.
# The right fix is to get OpenWindows 3.0 patches 100512-02 and 100573-03.
#
if test "$have_xmu" = yes ; then
  case "$host" in
    *-sunos4*)
    AC_CACHE_CHECK([for the SunOS 4.1.x _get_wmShellWidgetClass bug],
		   ac_cv_sunos_xmu_bug,
		   [ac_save_LDFLAGS="$LDFLAGS"
		    if test \! -z "$x_libraries" ; then
		      LDFLAGS="$LDFLAGS -L$x_libraries"
		    fi
		    # Note: this trick never works!  (Generally.)
		    # We're only getting away with using AC_TRY_LINK
		    # with X libraries because we know it's SunOS.
		    LDFLAGS="$LDFLAGS -lXmu -lXt -lX11 -lXext -lm"
		    AC_TRY_LINK(,,
				[ac_cv_sunos_xmu_bug=no],
				[ac_cv_sunos_xmu_bug=yes])
		    LDFLAGS="$ac_save_LDFLAGS"])
    if test "$ac_cv_sunos_xmu_bug" = yes ; then
      AC_CACHE_CHECK([whether the compiler understands -static], 
		     ac_cv_ld_static,
		     [ac_save_LDFLAGS="$LDFLAGS"
		      LDFLAGS="$LDFLAGS -static"
		      AC_TRY_LINK(,,[ac_cv_ld_static=yes],[ac_cv_ld_static=no])
		    LDFLAGS="$ac_save_LDFLAGS"])
      if test "$ac_cv_ld_static" = yes ; then
        LDFLAGS="$LDFLAGS -static"
      else
	LDFLAGS="$LDFLAGS -Bstatic"
      fi
    fi
    ;;
  esac
fi


# Check for the SGI SCREEN_SAVER server extension header.
#
have_sgi=no
with_sgi_req=unspecified
AC_ARG_WITH(sgi-ext,
[Except where noted, all of the --with options below can also take a
directory argument: for example, --with-motif=/opt/Motif.  That would
cause /opt/Motif/include/ to be added to the -I list, and /opt/Motif/lib/
to be added to the -L list, assuming those directories exist.

X Server Extension options:

  --with-sgi-ext          Include support for the SGI SCREEN_SAVER
                          server extension, if possible (this is the default).
  --without-sgi-ext       Do not compile in support for this extension.],
  [with_sgi="$withval"; with_sgi_req="$withval"],[with_sgi=yes])

HANDLE_X_PATH_ARG(with_sgi, --with-sgi-ext, SGI SCREEN_SAVER)

if test "$with_sgi" = yes; then
  AC_CHECK_X_HEADER(X11/extensions/XScreenSaver.h,
		    [have_sgi=yes
		     AC_DEFINE(HAVE_SGI_SAVER_EXTENSION)])

elif test "$with_sgi" != no; then
  echo "error: must be yes or no: --with-sgi-ext=$with_sgi"
  exit 1
fi

# Check for the MIT-SCREEN-SAVER server extension header,
# unless the SGI extension has already been found.
#
have_mit=no
with_mit_req=unspecified
AC_ARG_WITH(mit-ext,
[  --with-mit-ext          Include support for the MIT-SCREEN-SAVER
                          server extension, if possible (this is the default).
  --without-mit-ext       Do not compile in support for this extension.],
  [with_mit="$withval"; with_mit_req="$withval"],[with_mit=yes])

HANDLE_X_PATH_ARG(with_mit, --with-mit-ext, MIT-SCREEN-SAVER)

if test "$have_sgi" != yes; then
  if test "$with_mit" = yes; then
    AC_CHECK_X_HEADER(X11/extensions/scrnsaver.h, [have_mit=yes])

    # Now check to see if it's really in the library; XF86Free-3.3 ships
    # scrnsaver.h, but doesn't include the code in libXext.a, the idiots!
    #
    if test "$have_mit" = yes; then
      AC_CHECK_X_LIB(Xext, XScreenSaverRegister, [], [have_mit=no], -lm)

      if test "$have_mit" = no; then
	# Fuck!  Looks like XF86Free-3.3 actually puts it in XExExt instead
	# of in Xext.  Thank you master, may I have another.
        AC_CHECK_X_LIB(XExExt, XScreenSaverRegister,
		       [have_mit=yes; SAVER_LIBS="$SAVER_LIBS -lXExExt"],
		       [], -lX11 -lXext -lm)
      fi

      if test "$have_mit" = no; then
	# Double fuck!  Looks like some versions of XFree86 (whichever version
	# it is that comes with RedHat Linux 2.0 -- I can't find a version 
	# number) put this garbage in Xss instead of Xext.  Thank you master,
	#  may I have another.
        AC_CHECK_X_LIB(Xss, XScreenSaverRegister,
		       [have_mit=yes; SAVER_LIBS="$SAVER_LIBS -lXss"],
		       [], -lX11 -lXext -lm)
      fi

    if test "$have_mit" = yes; then
      AC_DEFINE(HAVE_MIT_SAVER_EXTENSION)
    fi

    fi

  elif test "$with_mit" != no; then
    echo "error: must be yes or no: --with-mit-ext=$with_mit"
    exit 1
  fi
fi


# Check for the XIDLE server extension header.
#
have_xidle=no
with_xidle_req=unspecified
AC_ARG_WITH(xidle-ext,
[  --with-xidle-ext        Include support for the XIDLE server extension,
                          if possible (this is the default).
  --without-xidle-ext     Do not compile in support for this extension.],
  [with_xidle="$withval"; with_xidle_req="$withval"],[with_xidle=yes])

HANDLE_X_PATH_ARG(with_xidle, --with-xidle-ext, XIDLE)

if test "$with_xidle" = yes; then
  AC_CHECK_X_HEADER(X11/extensions/xidle.h,
		    [have_xidle=yes
		     AC_DEFINE(HAVE_XIDLE_EXTENSION)])
elif test "$with_xidle" != no; then
  echo "error: must be yes or no: --with-xidle-ext=$with_xidle"
  exit 1
fi


# Check for the XSHM server extension header.
#
have_xshm=no
with_xshm_req=unspecified
AC_ARG_WITH(xshm-ext,
[  --with-xshm-ext         Include support for the XSHM (Shared Memory) server
                          extension, if possible (this is the default).
  --without-xshm-ext      Do not compile in support for this extension.],
  [with_xshm="$withval"; with_xshm_req="$withval"],[with_xshm=yes])

HANDLE_X_PATH_ARG(with_xshm, --with-xshm-ext, XSHM)

if test "$with_xshm" = yes; then

  # first check for Xshm.h.
  AC_CHECK_X_HEADER(X11/extensions/XShm.h, [have_xshm=yes])

  # if that succeeded, then check for sys/ipc.h.
  if test "$have_xshm" = yes; then
    have_xshm=no
    AC_CHECK_X_HEADER(sys/ipc.h, [have_xshm=yes])
  fi

  # if that succeeded, then check for sys/shm.h.
  if test "$have_xshm" = yes; then
    have_xshm=no
    AC_CHECK_X_HEADER(sys/shm.h, [have_xshm=yes])
  fi

  # AIX is pathological, as usual: apparently it's normal for the Xshm headers
  # to exist, but the library code to not exist.  And even better, the library
  # code is in its own library: libXextSam.a.  So, if we're on AIX, and that
  # lib doesn't exist, give up.
  #
  case "$host" in
    *-aix*)
      have_xshm=no
      AC_CHECK_X_LIB(XextSam, XShmQueryExtension,
		     [have_xshm=yes; SAVER_LIBS="$SAVER_LIBS -lXextSam"],
		       [], -lX11 -lXext -lm)
    ;;
  esac

  # if that succeeded, then we've really got it.
  if test "$have_xshm" = yes; then
    AC_DEFINE(HAVE_XSHM_EXTENSION)
  fi

elif test "$with_xshm" != no; then
  echo "error: must be yes or no: --with-xshm-ext=$with_xshm"
  exit 1
fi


# Check for the SGI-VIDEO-CONTROL server extension header.
#
have_sgivc=no
with_sgivc_req=unspecified
AC_ARG_WITH(sgivc-ext,
[  --with-sgivc-ext        Include support for the SGI-VIDEO-CONTROL server
                          extension, if possible (this is the default).
  --without-sgivc-ext     Do not compile in support for this extension.],
  [with_sgivc="$withval"; with_sgivc_req="$withval"],[with_sgivc=yes])

HANDLE_X_PATH_ARG(with_sgivc, --with-sgivc-ext, SGI-VIDEO-CONTROL)

if test "$with_sgivc" = yes; then

  # first check for XSGIvc.h
  AC_CHECK_X_HEADER(X11/extensions/XSGIvc.h, [have_sgivc=yes])

  # if that succeeded, then check for the -lXsgivc
  if test "$have_sgivc" = yes; then
    have_sgivc=no
    AC_CHECK_X_LIB(Xsgivc, XSGIvcQueryGammaMap,
		  [have_sgivc=yes; SAVER_LIBS="$SAVER_LIBS -lXsgivc"], [],
		  -lXext -lX11)
  fi

  # if that succeeded, then we've really got it.
  if test "$have_sgivc" = yes; then
    AC_DEFINE(HAVE_SGI_VC_EXTENSION)
  fi

elif test "$with_sgivc" != no; then
  echo "error: must be yes or no: --with-sgivc-ext=$with_sgivc"
  exit 1
fi


# Check for the DPMS server extension header.
#
have_dpms=no
with_dpms_req=unspecified
AC_ARG_WITH(dpms-ext,
[  --with-dpms-ext         Include support for the DPMS server extension,
                          if possible (this is the default).
  --without-dpms-ext      Do not compile in support for this extension.],
  [with_dpms="$withval"; with_dpms_req="$withval"],[with_dpms=yes])

HANDLE_X_PATH_ARG(with_dpms, --with-dpms-ext, DPMS)

if test "$with_dpms" = yes; then

  # first check for dpms.h
  AC_CHECK_X_HEADER(X11/extensions/dpms.h, [have_dpms=yes])

  # if that succeeded, then check for the -lXdpms
  if test "$have_dpms" = yes; then
    have_dpms=no
    AC_CHECK_X_LIB(Xdpms, DPMSInfo,
		  [have_dpms=yes; SAVER_LIBS="$SAVER_LIBS -lXdpms"], [],
		  -lXext -lX11)
  fi

  # if that succeeded, then we've really got it.
  if test "$have_dpms" = yes; then
    AC_DEFINE(HAVE_DPMS_EXTENSION)
  fi

elif test "$with_dpms" != no; then
  echo "error: must be yes or no: --with-dpms-ext=$with_dpms"
  exit 1
fi


# Check for /proc/interrupts
#
have_proc_interrupts=no
with_proc_interrupts_req=unspecified
AC_ARG_WITH(proc-interrupts,
[  --with-proc-interrupts  Include support for consulting the /proc/interrupts
                          file to notice keyboard activity, if possible.
  --without-proc-interrupts   Do not compile in support for this method.],
  [with_proc_interrupts="$withval"; with_proc_interrupts_req="$withval"],
  [with_proc_interrupts=yes])

if test "$with_proc_interrupts" = yes; then

   AC_MSG_CHECKING(whether /proc/interrupts contains keyboard data)
   AC_CACHE_VAL(ac_cv_have_proc_interrupts,
    [ac_cv_have_proc_interrupts=no
     if grep keyboard /proc/interrupts >/dev/null 2>&1 ; then
       ac_cv_have_proc_interrupts=yes
     fi
    ])
   have_proc_interrupts=$ac_cv_have_proc_interrupts

  AC_MSG_RESULT($have_proc_interrupts)

  if test "$have_proc_interrupts" = yes; then
    AC_DEFINE(HAVE_PROC_INTERRUPTS)
  fi

elif test "$with_proc_interrupts" != no; then
  echo "error: must be yes or no: --with-proc-interrupts=$with_proc_interrupts"
  exit 1
fi



# Check for Motif and Athena --with and --without arguments.
#
have_motif=no
have_athena=no
have_athena3d=no
with_motif_req=unspecified
with_athena_req=unspecified

AC_ARG_WITH(motif,[
X Client Toolkit options:

  --with-motif            Use the Motif toolkit for the user interface, if
                          possible (this is the default).
  --without-motif         Do not use Motif.],
  [with_motif="$withval"; with_motif_req="$withval"],[with_motif=no])

HANDLE_X_PATH_ARG(with_motif, --with-motif, Motif)

AC_ARG_WITH(athena,
[  --with-athena           Use the Athena toolkit for the user interface, if
                          possible (this is the default if Motif isn't used.)
  --without-athena        Do not use Athena.],
  [with_athena="$withval"; with_athena_req="$withval"],[with_athena=no])

HANDLE_X_PATH_ARG(with_athena, --with-athena, Athena)

if test "$with_motif" != yes -a "$with_motif" != no ; then
  echo "error: must be yes or no: --with-motif=$with_motif"
  exit 1
fi

if test "$with_athena" != yes -a "$with_athena" != no ; then
  echo "error: must be yes or no: --with-athena=$with_athena"
  exit 1
fi


# Saying --without-motif is the same as saying --with-athena.
if test "$with_motif_req" = no ; then
  with_athena_req=yes
  with_athena=yes
fi

# Saying --without-athena is the same as saying --with-motif.
if test "$with_athena_req" = no ; then
  with_motif_req=yes
  with_motif=yes
fi

# Check for Motif and Athena headers.

check_motif() {
  AC_CHECK_X_HEADER(Xm/Xm.h,
		    [have_motif=yes
		     AC_DEFINE(HAVE_MOTIF)
		     TOOLKIT_LIBS="-lXm $TOOLKIT_LIBS"])
}

check_athena() {
  have_athena=no
  have_athena3d=no
  AC_CHECK_X_HEADER(X11/Xaw/Dialog.h, [have_athena=yes])
  if test "$have_athena" = yes; then
    AC_CHECK_X_LIB(Xaw3d, Xaw3dComputeTopShadowRGB,
		   [have_athena=yes; have_athena3d=yes], [],
		   -lXt -lXmu -lXext -lX11)
  fi

  if test "$have_athena3d" = yes; then
    TOOLKIT_LIBS="-lXaw3d $TOOLKIT_LIBS"
  elif test "$have_athena" = yes; then
    TOOLKIT_LIBS="-lXaw $TOOLKIT_LIBS"
  fi
}


# If they asked for both motif and athena, check motif then athena.
# If they asked for only motif, check motif then athena.
# If they asked for only athena, check athena then motif.
# If they asked for neither, check motif then athena.

proselytize_motif=yes
if test "$with_motif" = yes; then
  # asked for both, or for motif only
  check_motif
  if test "$have_motif" = yes; then
    with_athena=no
    with_athena_req=no
  else
    check_athena
  fi

elif test "$with_athena" = yes; then
  # asked for athena only
  check_athena
  if test "$have_athena" = yes; then
    with_motif=no
    proselytize_motif=no
  else
    check_motif
  fi

else
  # asked for neither
  check_motif
  if test "$have_motif" = yes; then
    with_athena=no
  else
    check_athena
  fi

fi

if test "$have_motif" = yes; then
  proselytize_motif=no
fi

# If we have Athena, check whether it's a version that includes
# XawViewportSetCoordinates in Viewport.h (R3 (or R4?) don't.)
if test "$have_athena" = yes ; then
  AC_CACHE_CHECK([for XawViewportSetCoordinates in Viewport.h], 
		 ac_cv_have_XawViewportSetCoordinates,
		 [ac_cv_have_XawViewportSetCoordinates=no
		  AC_EGREP_X_HEADER(XawViewportSetCoordinates, 
				    X11/Xaw/Viewport.h,
				    ac_cv_have_XawViewportSetCoordinates=yes)])
  if test "$ac_cv_have_XawViewportSetCoordinates" = yes ; then
    AC_DEFINE(HAVE_XawViewportSetCoordinates)
  fi
fi


# If we have Motif, check whether it's really LessTif.
#
have_lesstif=no
if test "$have_motif" = yes ; then
  AC_CACHE_CHECK([whether Motif is really LessTif], 
		 ac_cv_have_lesstif,
		 [AC_TRY_X_COMPILE([#include <Xm/Xm.h>],
				   [long vers = LesstifVersion;],
				   [ac_cv_have_lesstif=yes],
				   [ac_cv_have_lesstif=no])])
  have_lesstif=$ac_cv_have_lesstif
fi

# don't cache these
unset ac_cv_lesstif_version
unset ac_cv_lesstif_version_string

lesstif_version=unknown
lesstif_version_string=unknown

if test "$have_lesstif" = yes ; then
  ltv=unknown
  echo unknown > conftest-lt
  AC_CACHE_CHECK([LessTif version number],
		 ac_cv_lesstif_version_string,
      [AC_TRY_X_RUN([#include <stdio.h>
		     #include <Xm/Xm.h>
		     int main() {
		       FILE *f = fopen("conftest-lt", "w");
		       if (!f) exit(1);
		       fprintf(f, "%d %d.%d\n", LesstifVersion,
		     	  LESSTIF_VERSION, LESSTIF_REVISION);
		       fclose(f);
		       exit(0);
		     }],
		    [ltv=`cat conftest-lt`
		     ac_cv_lesstif_version=`echo $ltv | sed 's/ .*//'`
		     ac_cv_lesstif_version_string=`echo $ltv | sed 's/.* //'`],
		    [ac_cv_lesstif_version=unknown
		     ac_cv_lesstif_version_string=unknown],
		    [ac_cv_lesstif_version=unknown
		     ac_cv_lesstif_version_string=unknown])])
  rm -f conftest-lt
  lesstif_version=$ac_cv_lesstif_version
  lesstif_version_string=$ac_cv_lesstif_version_string

fi


if test "$have_motif" = yes ; then
  mtv=unknown
  echo unknown > conftest-mt
  AC_CACHE_CHECK([Motif version number],
		 ac_cv_motif_version_string,
      [AC_TRY_X_RUN([#include <stdio.h>
		     #include <Xm/Xm.h>
		     int main() {
		       FILE *f = fopen("conftest-mt", "w");
		       if (!f) exit(1);
		       fprintf(f, "%d %d.%d\n", XmVersion,
		     	  XmVERSION, XmREVISION);
		       fclose(f);
		       exit(0);
		     }],
		    [mtv=`cat conftest-mt`
		     ac_cv_motif_version=`echo $mtv | sed 's/ .*//'`
		     ac_cv_motif_version_string=`echo $mtv | sed 's/.* //'`],
		    [ac_cv_motif_version=unknown
		     ac_cv_motif_version_string=unknown],
		    [ac_cv_motif_version=unknown
		     ac_cv_motif_version_string=unknown])])
  rm -f conftest-mt
  motif_version=$ac_cv_motif_version
  motif_version_string=$ac_cv_motif_version_string

fi


# If this is Motif 2.x, and we have XPM, then link against XPM as well.
# The deal is, Motif 2.x requires XPM -- but it's a compilation option of
# the library whether to build the XPM code into libXm, or whether to rely
# on an external libXm.  So the only way to tell whether XPM is a link-time
# requirement is to examine libXm.a, which is very difficult to do in an
# autoconf script.  So... if it's Motif 2.x, we always link against XPM if
# the XPM lib exists (and this will be a no-op if libXm happens to already
# have the XPM code in it.)
#
motif_requires_xpm=no
if test "$have_motif" = yes ; then
   AC_MSG_CHECKING(whether Motif requires XPM)
   if test "$motif_version" -ge 2000; then
     motif_requires_xpm=yes
     AC_MSG_RESULT(maybe)
   else
     AC_MSG_RESULT(no)
   fi
fi



# Some versions of Motif (2.1.0, at least) require -lXp, the "X Printing
# Extension".   Why this extension isn't in -lXext with all the others,
# I have no idea.
#
have_xp_ext=no
if test "$have_motif" = yes ; then
   have_xp_ext=no
   AC_CHECK_X_LIB(Xp, XpQueryExtension,
		  [have_xp_ext=yes; TOOLKIT_LIBS="$TOOLKIT_LIBS -lXp"],
		  [], -lX11 -lXext -lm)
fi


# Check for _Xsetlocale in -lXintl, since at least some recent versions
# of Motif (on Linux) need it.
#
have_xintl=no
if test "$have_motif" = yes ; then
  AC_CHECK_X_LIB(Xintl, _Xsetlocale, [have_xintl=yes], [have_xintl=no],
                 -lX11 -lXext -lm)
  if test "$have_xintl" = yes; then
    TOOLKIT_LIBS="$TOOLKIT_LIBS -lXintl"
  fi
fi


# check for XPM header.
#
have_xpm=no
with_xpm_req=unspecified
AC_ARG_WITH(xpm,[
Graphics Demo options:

  --with-xpm              Include support for XPM files in some demos,
                          if possible (this is the default).
  --without-xpm           Do not compile in support for XPM files.],
  [with_xpm="$withval"; with_xpm_req="$withval"],[with_xpm=yes])

HANDLE_X_PATH_ARG(with_xpm, --with-xpm, XPM)

if test "$with_xpm" = yes; then
  AC_CHECK_X_HEADER(X11/xpm.h,
	           [have_xpm=yes
		    AC_DEFINE(HAVE_XPM)
		    XPM_LIBS="-lXpm"])
elif test "$with_xpm" != no; then
  echo "error: must be yes or no: --with-xpm=$with_xpm"
  exit 1
fi

# See comment near $motif_requires_xpm, above.
# Need to do this here, after both Motif and XPM have been checked for.
#
if test "$have_motif" = yes -a "$have_xpm" = yes ; then
  if test "$motif_requires_xpm" = yes ; then
    TOOLKIT_LIBS="$TOOLKIT_LIBS $XPM_LIBS"
  fi
fi


# check for the GL header
#
have_gl=no
ac_have_mesa_gl=no
with_gl_req=unspecified
AC_ARG_WITH(gl,
[  --with-gl               Build those demos which depend on OpenGL,
                          if possible (this is the default).
  --without-gl            Do not build the OpenGL demos.],
  [with_gl="$withval"; with_gl_req="$withval"],[with_gl=yes])

HANDLE_X_PATH_ARG(with_gl, --with-gl, GL)

ac_mesagl_version=unknown
ac_mesagl_version_string=unknown

if test "$with_gl" = yes; then
  AC_CHECK_X_HEADER(GL/gl.h, have_gl=yes, have_gl=no)
  if test "$have_gl" = yes ; then
    AC_CHECK_X_HEADER(GL/glx.h, have_gl=yes, have_gl=no)
  fi

  # If we have the headers, try and figure out which vendor it's from.
  #
  if test "$have_gl" = yes ; then

    AC_DEFINE(HAVE_GL)

    # We need to know whether it's MesaGL so that we know which libraries
    # to link against.
    #
    AC_MSG_CHECKING(whether GL is really MesaGL)
    AC_CACHE_VAL(ac_cv_have_mesa_gl,
      [ac_cv_have_mesa_gl=no
       AC_EGREP_X_HEADER(Mesa, GL/glx.h, [ac_cv_have_mesa_gl=yes])
      ])
    ac_have_mesa_gl=$ac_cv_have_mesa_gl
    AC_MSG_RESULT($ac_have_mesa_gl)

    if test "$ac_have_mesa_gl" = no ; then
      gl_lib_1="GL"
      GL_LIBS="-lGL -lGLU"
    else
      AC_DEFINE(HAVE_MESA_GL)
      gl_lib_1="MesaGL"
      GL_LIBS="-lMesaGL -lMesaGLU"
    fi


    # If it's MesaGL, we'd like to issue a warning if the version number
    # is less than or equal to 2.6, because that version had a security bug.
    #
    if test "$ac_have_mesa_gl" = yes; then

      # don't cache these.
      unset ac_cv_mesagl_version
      unset ac_cv_mesagl_version_string

      AC_MSG_CHECKING(MesaGL version number)
      AC_CACHE_VAL(ac_cv_mesagl_version_string,
	[cat > conftest.$ac_ext <<EOF
#line __oline__ "configure"
#include "confdefs.h"
#include <GL/gl.h>
configure: MESA_MAJOR_VERSION MESA_MINOR_VERSION
EOF

	 ac_save_CPPFLAGS="$CPPFLAGS"
	 if test \! -z "$includedir" ; then 
	   CPPFLAGS="$CPPFLAGS -I$includedir"
	 fi
	 CPPFLAGS="$CPPFLAGS $X_CFLAGS"

	  # M4 sucks!!
	 changequote(X,Y)
	 mglv=`(eval "$ac_cpp conftest.$ac_ext") 2>&AC_FD_CC | sed -n \
	      's/^configure:.*\([0-9][0-9]*\).*\([0-9][0-9]*\).*$/\1.\2/p'`
	 changequote([,])

         rm -f conftest.$ac_ext

	 CPPFLAGS="$ac_save_CPPFLAGS"

	 if test "$mglv" = ""; then
           ac_mesagl_version=unknown
           ac_mesagl_version_string=unknown
         else
           ac_mesagl_version_string=$mglv
           maj=`echo $mglv | sed -n 's/\..*//p'`
           min=`echo $mglv | sed -n 's/.*\.//p'`
           ac_mesagl_version=`echo "$maj * 1000 + $min" | bc`
           if test -z "$ac_mesagl_version"; then
	     ac_mesagl_version=unknown
             ac_mesagl_version_string=unknown
	   fi
         fi
         ac_cv_mesagl_version=$ac_mesagl_version
         ac_cv_mesagl_version_string=$ac_mesagl_version_string
      ])
      ac_mesagl_version=$ac_cv_mesagl_version
      ac_mesagl_version_string=$ac_cv_mesagl_version_string
      AC_MSG_RESULT($ac_cv_mesagl_version_string)
    fi


    # If it's MesaGL, check to see if it requires -lpthread.
    #
    have_pthread=no
    mesa_requires_pthread=no
    if test "$ac_have_mesa_gl" = yes; then

      AC_CHECK_LIB(pthread, pthread_create, [have_pthread=yes], [],)
      if test "$have_pthread" = yes; then
        AC_CHECK_X_LIB($gl_lib_1, gl_get_thread_context,
                       [mesa_requires_pthread=yes], [],
		       $GL_LIBS -lpthread -lX11 -lXext -lm)
      fi

      if test "$mesa_requires_pthread" = yes; then
        GL_LIBS="$GL_LIBS -lpthread"
      fi
    fi

    # Check for OpenGL 1.1 features.
    #
    AC_CHECK_X_LIB($gl_lib_1, glBindTexture, [AC_DEFINE(HAVE_GLBINDTEXTURE)],
		   [], $GL_LIBS -lX11 -lXext -lm)

  fi

elif test "$with_gl" != no; then
  echo "error: must be yes or no: --with-gl=$with_gl"
  exit 1
fi


# check for SGI XReadDisplay server extension header.
#
have_readdisplay=no
with_readdisplay_req=unspecified
AC_ARG_WITH(readdisplay,
[  --with-readdisplay      Include support for the XReadDisplay server
                          extension if possible (this is the default).
  --without-readdisplay   Do not compile in support for this extension.],
  [with_readdisplay="$withval"; with_readdisplay_req="$withval"],
  [with_readdisplay=yes])

HANDLE_X_PATH_ARG(with_readdisplay, --with-readdisplay, XReadDisplay)

if test "$with_readdisplay" = yes; then
  AC_CHECK_X_HEADER(X11/extensions/readdisplay.h,
	            AC_DEFINE(HAVE_READ_DISPLAY_EXTENSION))
elif test "$with_readdisplay" != no; then
  echo "error: must be yes or no: --with-readdisplay=$with_readdisplay"
  exit 1
fi


# check for SGI's Iris Video Library header.
#
have_sgivideo=no
with_sgivideo_req=unspecified
AC_ARG_WITH(sgivideo,
[  --with-sgivideo         Include support for SGI's Iris Video Library
                          if possible (this is the default).
  --without-sgivideo       Do not compile in support for this library.],
  [with_sgivideo="$withval"; with_sgivideo_req="$withval"],
  [with_sgivideo=yes])

HANDLE_X_PATH_ARG(with_sgivideo, --with-sgivideo, Iris Video)

if test "$with_sgivideo" = yes; then
  AC_CHECK_X_HEADER(dmedia/vl.h, have_sgivideo=yes)
  if test "$have_sgivideo" = yes; then
    have_sgivideo=no
    AC_CHECK_LIB(vl, vlOpenVideo, have_sgivideo=yes)
    if test "$have_sgivideo" = yes; then
      SGI_VIDEO_OBJS="$(UTILS_BIN)/sgivideo.o"
      SGI_VIDEO_LIBS="-lvl"
      AC_DEFINE(HAVE_SGI_VIDEO)
    fi
  fi
elif test "$with_sgivideo" != no; then
  echo "error: must be yes or no: --with-sgivideo=$with_sgivideo"
  exit 1
fi



# Try to find a program to generate random text.
#
# Zippy is funnier than the idiocy generally spat out by `fortune',
# so try to find that, by invoking Emacs and asking it where its 
# libexec directory is ("yow" lives in there.)
#
# If that doesn't work, see if fortune, zippy, or yow are on $PATH,
# and if so, use them.
#
# If that doesn't work, look in /usr/games, and if it's there, use
# the full pathname.
#
with_zippy_req=""
AC_ARG_WITH(zippy,
[  --with-zippy=PROGRAM    Some demos are able to run an external program and
                          display its text; this names the program to use by
                          default (though it can be overridden with X
                          resources.)  If you don't specify this, the default
                          is to use \"yow\" from the Emacs distribution (if you
                          have it) or else to use \"fortune\".],
  [ with_zippy_req="$withval"; with_zippy="$withval" ],
  [ with_zippy_req="$withval"; with_zippy="$withval" ])

if test "$with_zippy" = no || test "$with_zippy" = yes ; then
  with_zippy=""
  with_zippy_req=""
fi

if test -n "$with_zippy_req" ; then
  ac_cv_zippy_program=""
  case "$with_zippy_req" in
    /*)
      AC_MSG_CHECKING([for $with_zippy_req])
      if test -x "$with_zippy_req" ; then
        AC_MSG_RESULT(yes)
      else
        AC_MSG_RESULT(no)
        with_zippy=""
      fi
    ;;
    *)
      # don't cache
      unset ac_cv_path_zip2
      AC_PATH_PROG(zip2, $with_zippy_req, [])
      if test "$zip2" = ""; then
        with_zippy=""
      fi
    ;;
  esac
  ac_cv_zippy_program="$with_zippy"

elif test -n "$ac_cv_zippy_program"; then
  AC_MSG_RESULT([checking for zippy... (cached) $ac_cv_zippy_program])
fi

if test ! -n "$ac_cv_zippy_program"; then

  AC_CHECK_PROGS(emacs_exe, emacs)
  AC_CHECK_PROGS(xemacs_exe, xemacs)

  ac_cv_zippy_program=""
  eargs='-batch -q -nw --eval'

  if test -n "$emacs_exe" ; then
    AC_MSG_CHECKING([for emacs yow])
    #
    # get emacs to tell us where the libexec directory is.
    #
    dir=`$emacs_exe $eargs '(princ (concat exec-directory "\n"))' \
	 2>/dev/null | tail -1`
    dir=`echo "$dir" | sed 's@///*@/@g;s@/$@@'`
    #
    # try running libexec/yow and see if it exits without error.
    #
    if test x"$dir" != x -a -x "$dir/yow" ; then
      if $dir/yow >&- 2>&- ; then
	ac_cv_zippy_program="$dir/yow"
	AC_MSG_RESULT($ac_cv_zippy_program)
      else
	AC_MSG_RESULT(no)
      fi
    fi
  fi

  if test -z "$ac_cv_zippy_program" ; then
    AC_MSG_CHECKING([for xemacs yow])
    if test -n "$xemacs_exe" ; then
      #
      # get xemacs to tell us where the libexec directory is.
      #
      dir=`$xemacs_exe $eargs '(princ (concat exec-directory "\n"))' \
	   2>/dev/null | tail -1`
      dir=`echo "$dir" | sed 's@///*@/@g;s@/$@@'`
      #
      # try running libexec/yow and see if it exits without error.
      #
      if test x"$dir" != x -a -x "$dir/yow" ; then
        if $dir/yow >&- 2>&- ; then
	  ac_cv_zippy_program="$dir/yow"
	  AC_MSG_RESULT($ac_cv_zippy_program)
	else
	  #
	  # in some xemacs installations, the pathname of the yow.lines file
	  # isn't hardcoded into the yow executable, and must be passed on 
	  # the command line.  See if it's in libexec/../etc/.

	  # M4 sucks!!
	  changequote(X,Y)
	  dir_up=`echo "$dir" | sed 's@/[^/]*$@@'`
	  changequote([,])

          yow="yow -f $dir_up/etc/yow.lines"
	  if $dir/$yow >&- 2>&- ; then
	    ac_cv_zippy_program="$dir/$yow"
	    AC_MSG_RESULT($ac_cv_zippy_program)
	  else
	    AC_MSG_RESULT(no)
	  fi
        fi
      fi
    fi
  fi

  # if that didn't work, try for some other programs...
  if test -z "$ac_cv_zippy_program" ; then
    fortune=''
    AC_CHECK_PROGS(fortune, [fortune zippy yow])
    # if that didn't work, try for those programs in /usr/games...
    if test -z "$fortune" ; then
      AC_PATH_PROGS(fortune, [fortune zippy yow], fortune,
		    /usr/games:/usr/local/games)
    fi
  fi
fi

if test -z "$ac_cv_zippy_program" ; then
  ac_cv_zippy_program=fortune
fi

AC_DEFINE_UNQUOTED(ZIPPY_PROGRAM, "$ac_cv_zippy_program")




# Allow locking to be disabled at compile-time.
#
have_kerberos=no
with_kerberos_req=unspecified
have_shadow=no
with_shadow_req=unspecified
have_pam=no
with_pam_req=unspecified
need_setuid=no

AC_ARG_ENABLE(locking,[
Screen Locking options:

  --enable-locking        Compile in support for locking the display
                          (this is the default.)
  --disable-locking       Do not allow locking at all.],
  [enable_locking="$enableval"],[enable_locking=yes])
if test "$enable_locking" = yes; then
  true
elif test "$enable_locking" = no; then
  AC_DEFINE(NO_LOCKING)
else
  echo "error: must be yes or no: --enable-locking=$enable_locking"
  exit 1
fi



# Check to see if we can lock Virtual-Terminal switching, but allow that 
# to be disabled at compile-time.
#
ac_vt_lockswitch=no
AC_ARG_ENABLE(vt-locking,[
  --enable-vt-locking     Compile in support for locking Virtual Terminals.
                          This is the default if the system supports it, and
                          if locking support is included (--enable-locking.)
  --disable-vt-locking    Do not allow locking of VTs, even if locking is
                          enabled.],
  [enable_vt_locking="$enableval"],[enable_vt_locking=yes])
if test "$enable_vt_locking" = yes; then

  AC_MSG_CHECKING(for the VT_LOCKSWITCH ioctl)
  AC_CACHE_VAL(ac_cv_vt_lockswitch,
   [AC_TRY_COMPILE([#include <fcntl.h>
		    #include <sys/ioctl.h>
		    #include <sys/vt.h>],
		   [int x = VT_LOCKSWITCH; int y = VT_UNLOCKSWITCH;],
		   [ac_cv_vt_lockswitch=yes],
		   [ac_cv_vt_lockswitch=no])])
  ac_vt_lockswitch=$ac_cv_vt_lockswitch
  AC_MSG_RESULT($ac_vt_lockswitch)

elif test "$enable_vt_locking" = no; then
  true
else
  echo "error: must be yes or no: --enable-vt-locking=$enable_vt_locking"
  exit 1
fi

if test "$ac_vt_lockswitch" = yes; then
  AC_DEFINE(HAVE_VT_LOCKSWITCH)
  # the VT_LOCKSWITCH ioctl can only be used when running as root.
  # #### but it doesn't work yet, so don't worry about that for now.
#  need_setuid=yes
fi



if test "$enable_locking" = yes; then

  # Check for Kerberos.
  #
  AC_ARG_WITH(kerberos, [
  --with-kerberos         Include support for Kerberos authentication,
                          if possible (this is the default.)
  --without-kerberos      Do not compile in support for Kerberos.],
  [with_kerberos="$withval"; with_kerberos_req="$withval"],[with_kerberos=yes])

  HANDLE_X_PATH_ARG(with_kerberos, --with-kerberos, Kerberos)

  if test "$with_kerberos" = yes; then
    AC_CACHE_CHECK([for Kerberos], ac_cv_kerberos,
		   [AC_TRY_X_COMPILE([#include <krb.h>],,
				     [ac_cv_kerberos=yes],
				     [ac_cv_kerberos=no])])
    if test "$ac_cv_kerberos" = yes ; then
      have_kerberos=yes

      krb_libs=""
      AC_CHECK_FUNC(gethostbyname, :,
		    AC_CHECK_LIB(nsl, gethostbyname,
				 krb_libs="-lnsl $krb_libs", :, $krb_libs))
      AC_CHECK_FUNC(socket, :,
		    AC_CHECK_LIB(socket, socket,
				 krb_libs="-lsocket $krb_libs", :, $krb_libs))
      AC_CHECK_X_LIB(krb4, krb_mk_req, found_libkrb4=yes, found_libkrb4=no,
		     -ldes425 -lkrb5 -lcrypto -lcom_err $krb_libs)
      if test "$found_libkrb4" = yes ; then
	PASSWD_LIBS="$PASSWD_LIBS -lkrb4 -ldes425 -lkrb5 -lcrypto -lcom_err"
        PASSWD_LIBS="$PASSWD_LIBS $krb_libs"
      else
        AC_CHECK_X_LIB(des, des_cbc_encrypt, krb_libs="-ldes $krb_libs", :,
		       $krb_libs)
        AC_CHECK_X_LIB(krb, krb_mk_req,
		       krb_libs="-lkrb $krb_libs"; found_libkrb=yes,
		       found_libkrb=no,
		       $krb_libs)
        if test "$ac_cv_lib_krb_krb_mk_req" = yes ; then
          PASSWD_LIBS="$PASSWD_LIBS $krb_libs"
        else
	  have_kerberos=no
	fi
      fi

      if test "$have_kerberos" = yes ; then
	AC_DEFINE(HAVE_KERBEROS)
	PASSWD_LIBS="$PASSWD_LIBS $krb_libs"
      fi

      AC_CHECK_FUNC(res_search,,
        AC_CHECK_LIB(resolv,res_search,PASSWD_LIBS="${PASSWD_LIBS} -lresolv",
          AC_MSG_WARN([Can't find DNS resolver libraries needed for Kerberos])
	))

    fi
  elif test "$with_kerberos" != no; then
    echo "error: must be yes or no: --with-kerberos=$with_kerberos"
    exit 1
  fi
  
  # Check for PAM.
  AC_ARG_WITH(pam,
[  --with-pam              Include support for PAM (Pluggable Authentication
                          Modules) if possible (this is the default.)
  --without-pam           Do not compile in support for PAM.],
  [with_pam="$withval"; with_pam_req="$withval"],[with_pam=no])
#### Leave PAM off by default for now, since it's buggy on Solaris
#### (and probably Linux, but it's so hard to tell...)

  HANDLE_X_PATH_ARG(with_pam, --with-pam, PAM)

  if test "$with_pam" = yes; then
    AC_CACHE_CHECK([for PAM], ac_cv_pam,
		   [AC_TRY_X_COMPILE([#include <security/pam_appl.h>],,
				     [ac_cv_pam=yes],
				     [ac_cv_pam=no])])
    if test "$ac_cv_pam" = yes ; then
	  have_pam=yes
	  AC_DEFINE(HAVE_PAM)
	  PASSWD_LIBS="${PASSWD_LIBS} -lpam -ldl"
    fi
  elif test "$with_pam" != no; then
  	echo "error: must be yes or no: --with-pam=$with_pam"
	exit 1
  fi

  # Next, check for the nine billion variants of shadow passwords...

  pwent_cruft_done=no
  AC_ARG_WITH(shadow,
[  --with-shadow           Include support for shadow password authentication,
                          if possible (this is the default, if no Kerberos or
                          PAM.)
  --without-shadow        Do not compile in support for shadow passwords.
],
  [with_shadow="$withval"; with_shadow_req="$withval"],[with_shadow=yes])

  HANDLE_X_PATH_ARG(with_shadow, --with-shadow, shadow password)

  if test "$with_shadow" = no; then
    pwent_cruft_done=yes
  elif test "$with_shadow" != yes; then
    echo "error: must be yes or no: --with-shadow=$with_shadow"
    exit 1
  fi


  # Sun's "adjunct" passwords.
  #
  if test "$pwent_cruft_done" = no ; then
    AC_CACHE_CHECK([for Sun-style shadow passwords], ac_cv_sun_adjunct,
		   [AC_TRY_X_COMPILE([#include <stdlib.h>
				      #include <unistd.h>
				      #include <sys/types.h>
				      #include <sys/label.h>
				      #include <sys/audit.h>
				      #include <pwdadj.h>],
			[struct passwd_adjunct *p = getpwanam("nobody");
			 const char *pw = p->pwa_passwd;],
			[ac_cv_sun_adjunct=yes],
			[ac_cv_sun_adjunct=no])])
    if test "$ac_cv_sun_adjunct" = yes; then
      have_shadow=yes
      need_setuid=yes
      pwent_cruft_done=yes
      AC_DEFINE(HAVE_ADJUNCT_PASSWD)
    fi
  fi

  # DEC and SCO so-called "enhanced" security.
  #
  if test "$pwent_cruft_done" = no ; then
    AC_CACHE_CHECK([for DEC-style shadow passwords], ac_cv_enhanced_passwd,
		   [AC_TRY_X_COMPILE([#include <stdlib.h>
				      #include <unistd.h>
				      #include <sys/types.h>
				      #include <pwd.h>
				      #include <sys/security.h>
				      #include <prot.h>],
			[struct pr_passwd *p;
			 const char *pw;
			 set_auth_parameters(0, 0);
			 check_auth_parameters();
			 p = getprpwnam("nobody");
			 pw = p->ufld.fd_encrypt;],
			[ac_cv_enhanced_passwd=yes],
			[ac_cv_enhanced_passwd=no])])
    if test $ac_cv_enhanced_passwd = yes; then
      have_shadow=yes
      need_setuid=yes
      pwent_cruft_done=yes
      AC_DEFINE(HAVE_ENHANCED_PASSWD)

      # On SCO, getprpwnam() is in -lprot (which uses nap() from -lx)
      # (I'm told it needs -lcurses too, but I don't understand why.)
      AC_CHECK_LIB(prot, getprpwnam, 
		   [PASSWD_LIBS="$PASSWD_LIBS -lprot -lcurses -lx"],
		   [# On DEC, getprpwnam() is in -lsecurity
		    AC_CHECK_LIB(security, getprpwnam, 
				 [PASSWD_LIBS="$PASSWD_LIBS -lsecurity"])],
		   [-lx])
    fi
  fi

  # HP's entry in the "Not Invented Here" Sweepstakes.
  #
  if test "$pwent_cruft_done" = no ; then
    AC_CACHE_CHECK([for HP-style shadow passwords], ac_cv_hpux_passwd,
		   [AC_TRY_X_COMPILE([#include <stdlib.h>
				      #include <unistd.h>
				      #include <sys/types.h>
				      #include <pwd.h>
				      #include <hpsecurity.h>
				      #include <prot.h>],
			[struct s_passwd *p = getspwnam("nobody");
			 const char *pw = p->pw_passwd;],
			[ac_cv_hpux_passwd=yes],
			[ac_cv_hpux_passwd=no])])
    if test "$ac_cv_hpux_passwd" = yes; then
      have_shadow=yes
      need_setuid=yes
      pwent_cruft_done=yes
      AC_DEFINE(HAVE_HPUX_PASSWD)

      # on HPUX, bigcrypt is in -lsec
      AC_CHECK_LIB(sec, bigcrypt, [PASSWD_LIBS="$PASSWD_LIBS -lsec"])
    fi
  fi

  # Traditional (ha!) shadow passwords.
  #
  if test "$pwent_cruft_done" = no ; then
    AC_CACHE_CHECK([for generic shadow passwords], ac_cv_shadow,
		   [AC_TRY_X_COMPILE([#include <stdlib.h>
				      #include <unistd.h>
				      #include <sys/types.h>
				      #include <pwd.h>
				      #include <shadow.h>],
			[struct spwd *p = getspnam("nobody");
			 const char *pw = p->sp_pwdp;],
			[ac_cv_shadow=yes],
			[ac_cv_shadow=no])])
    if test "$ac_cv_shadow" = yes; then
      have_shadow=yes
      need_setuid=yes
      pwent_cruft_done=yes
      AC_DEFINE(HAVE_SHADOW_PASSWD)

      # On some systems (UnixWare 2.1), getspnam() is in -lgen instead of -lc.
      have_getspnam=no
      AC_CHECK_LIB(c, getspnam, [have_getspnam=yes])
      if test "$have_getspnam" = no ; then
        AC_CHECK_LIB(gen, getspnam,
		     [have_getspnam=yes; PASSWD_LIBS="$PASSWD_LIBS -lgen"])
      fi
    fi
  fi

  # On FreeBSD, getpwnam() and friends work just like on non-shadow-password
  # systems -- except you only get stuff in the pw_passwd field if the running
  # program is setuid.  So, guess that we've got this lossage to contend with
  # if /etc/master.passwd exists, and default to a setuid installation.
  #
  if test "$pwent_cruft_done" = no ; then
    AC_CACHE_CHECK([for FreeBSD-style shadow passwords], ac_cv_master_passwd,
		   [if test -f /etc/master.passwd ; then
		      ac_cv_master_passwd=yes
		    else
		      ac_cv_master_passwd=no
		    fi])
    if test "$ac_cv_master_passwd" = yes; then
      need_setuid=yes
      pwent_cruft_done=yes
    fi
  fi

  # On some systems (UnixWare 2.1), crypt() is in -lcrypt instead of -lc.
  have_crypt=no
  AC_CHECK_LIB(c, crypt, [have_crypt=yes])
  if test "$have_crypt" = no ; then
    AC_CHECK_LIB(crypt, crypt,
                 [have_crypt=yes; PASSWD_LIBS="$PASSWD_LIBS -lcrypt"])
  fi


  # Most of the above shadow mechanisms will have set need_setuid to yes,
  # if they were found.  But, on some systems, we need setuid even when
  # using plain old vanilla passwords.
  #
  if test "$need_setuid" = no ; then
    case "$host" in
      *-hpux* | *-aix* | *-netbsd* | *-freebsd* | *-openbsd* )
        need_setuid=yes
      ;;
    esac
  fi

fi


if test \! -z "$includedir" ; then 
  INCLUDES="-I$includedir"
fi

if test \! -z "$libdir" ; then
  LDFLAGS="$LDFLAGS -L$libdir"
fi


##### should have options to override the DEPEND crap, I guess...
DEPEND=makedepend
DEPEND_FLAGS=
DEPEND_DEFINES=


# Done testing things -- now substitute in some stuff for the Makefiles.
#
if test "$have_motif" = yes; then
  AC_DEFINE(HAVE_MOTIF)
  TOOLKIT_SRCS='$(MOTIF_SRCS)'
  TOOLKIT_OBJS='$(MOTIF_OBJS)'
elif test "$have_athena" = yes; then
  AC_DEFINE(HAVE_ATHENA)
  TOOLKIT_SRCS='$(ATHENA_SRCS)'
  TOOLKIT_OBJS='$(ATHENA_OBJS)'
else
  TOOLKIT_SRCS=''
  TOOLKIT_OBJS=''
fi

if test "$have_kerberos" = yes; then
  PASSWD_SRCS="$PASSWD_SRCS \$(KERBEROS_SRCS)"
  PASSWD_OBJS="$PASSWD_OBJS \$(KERBEROS_OBJS)"
fi
if test "$have_pam" = yes; then
  PASSWD_SRCS="$PASSWD_SRCS \$(PAM_SRCS)"
  PASSWD_OBJS="$PASSWD_OBJS \$(PAM_OBJS)"
  INSTALL_PAM="install-pam"
fi
  PASSWD_SRCS="$PASSWD_SRCS \$(PWENT_SRCS)"
  PASSWD_OBJS="$PASSWD_OBJS \$(PWENT_OBJS)"


if test "$enable_locking" = yes; then
  LOCK_SRCS='$(LOCK_SRCS_1) $(PASSWD_SRCS)'
  LOCK_OBJS='$(LOCK_OBJS_1) $(PASSWD_OBJS)'
else
  LOCK_SRCS=''
  LOCK_OBJS=''
fi

if test "$need_setuid" = yes; then
  NEED_SETUID=yes
  INSTALL_SETUID='$(INSTALL) $(SUID_FLAGS)'
else
  NEED_SETUID=no
  INSTALL_SETUID='$(INSTALL_PROGRAM)'
fi

tab='	'
if test "$have_gl" = yes; then
  GL_EXES='$(GL_EXES)'
  GL_KLUDGE=${tab}
else
  GL_KLUDGE='  -'${tab}
fi

AC_SUBST(INCLUDES)

AC_SUBST(SAVER_LIBS)
AC_SUBST(TOOLKIT_LIBS)
AC_SUBST(HACK_LIBS)
AC_SUBST(XPM_LIBS)
AC_SUBST(GL_LIBS)
AC_SUBST(PASSWD_LIBS)
AC_SUBST(INSTALL_SETUID)
AC_SUBST(INSTALL_DIRS)
AC_SUBST(NEED_SETUID)
AC_SUBST(INSTALL_PAM)
AC_SUBST(SGI_VIDEO_OBJS)
AC_SUBST(SGI_VIDEO_LIBS)

AC_SUBST(TOOLKIT_SRCS)
AC_SUBST(TOOLKIT_OBJS)
AC_SUBST(PASSWD_SRCS)
AC_SUBST(PASSWD_OBJS)
AC_SUBST(XMU_SRCS)
AC_SUBST(XMU_OBJS)
AC_SUBST(LOCK_SRCS)
AC_SUBST(LOCK_OBJS)
AC_SUBST(GL_EXES)
AC_SUBST(GL_KLUDGE)
AC_SUBST(HACKDIR)
AC_SUBST(APPDEFAULTS)

AC_SUBST(DEPEND)
AC_SUBST(DEPEND_FLAGS)
AC_SUBST(DEPEND_DEFINES)

# Print some warnings before emitting the Makefiles.
#
warn_prefix_1="    Warning:"
warn_prefix_2="       Note:"
warn_prefix="$warn_prefix_1"

warning=no
warnsep='    #################################################################'

warnpre() {
  if test "$warning" = no ; then
    echo '' ; echo "$warnsep" ; echo ''
    warning=yes
  fi
}

warn() {
  warnpre
  if test "$warning" = long ; then echo '' ; fi
  warning=yes
  echo "$warn_prefix $@"
}

warnL() {
  was=$warning
  warnpre
  warning=yes
  if test "$was" != no ; then echo '' ; fi
  echo "$warn_prefix $@"
}

warn2() {
  echo "             $@"
  warning=long
}

note() {
  warn_prefix="$warn_prefix_2"
  warn $@
  warn_prefix="$warn_prefix_1"
}

noteL() {
  warn_prefix="$warn_prefix_2"
  warnL $@
  warn_prefix="$warn_prefix_1"
}


if test "$with_sgi_req" = yes -a "$have_sgi" = no ; then
  warn 'The SGI saver extension was requested, but was not found.'
fi

if test "$with_mit_req" = yes -a "$have_mit" = no ; then
  warn 'The MIT saver extension was requested, but was not found.'
fi

if test "$with_xidle_req" = yes -a "$have_xidle" = no ; then
  warn 'The XIdle extension was requested, but was not found.'
fi

if test "$with_xshm_req" = yes -a "$have_xshm" = no ; then
  warn 'The XSHM extension was requested, but was not found.'
fi

if test "$with_sgivc_req" = yes -a "$have_sgivc" = no ; then
  warn 'The SGI-VIDEO-CONTROL extension was requested, but was not found.'
fi

if test "$with_dpms_req" = yes -a "$have_dpms" = no ; then
  warn 'The DPMS extension was requested, but was not found.'
fi

if test "$have_motif" = no -a "$have_athena" = no ; then
  warnL "Neither Motif nor Athena widgets seem to be available;"
  warn2 "the \`xscreensaver-demo' program requires one or the"
  warn2 "other."
  proselytize_motif=no

elif test "$with_motif_req" = yes -a "$have_motif" = no ; then
  warnL "Use of Motif was requested, but it wasn't found;"
  warn2 "Athena will be used instead."

elif test "$with_athena_req" = yes -a "$have_athena" = no ; then
  warnL "Use of Athena was requested, but it wasn't found;"
  warn2 "Motif will be used instead."
fi

if test "$have_motif" = yes -a "$have_lesstif" = yes ; then

  preferred_lesstif=0.86

  if test "$lesstif_version" = unknown; then
    warnL "Unable to determine the LessTif version number!"
    warn2 "Make sure you are using version $preferred_lesstif or newer."
    warn2 "See <http://www.lesstif.org/>."

  elif test \! $lesstif_version -gt 82; then
    warnL "LessTif version $lesstif_version_string is being used."
    warn2 "LessTif versions 0.82 and earlier are too buggy to"
    warn2 "use with XScreenSaver; it is strongly recommended"
    warn2 "that you upgrade to at least version $preferred_lesstif!"
    warn2 "See <http://www.lesstif.org/>."
  fi
fi

if test "$proselytize_motif" = yes ; then
    warnL "Athena widgets are being used instead of Motif."
    warn2 "The \`xscreensaver-demo' program looks much better"
    warn2 "with Motif.  Wouldn't you rather be using Motif?"
    warn2 "It is shipped by every commercial Unix vendor;"
    warn2 "and there is a free implementation available as"
    warn2 "well: see <http://www.lesstif.org/>."
fi


if test "$have_gl" = yes -a "$ac_have_mesa_gl" = yes ; then
  preferred_mesagl=3.0

  if test "$ac_mesagl_version" = unknown; then
    warnL "Unable to determine the MesaGL version number!"
    warn2 "Make sure you are using version $preferred_mesagl or newer."

  elif test \! "$ac_mesagl_version" -gt 2006; then
    warnL "MesaGL version $ac_mesagl_version_string is being used."
    warn2 "MesaGL versions 2.6 and earlier have a security bug."
    warn2 "It is strongly recommended that you upgrade to at"
    warn2 "least version $preferred_mesagl."
  fi
fi


if test "$have_xpm" = no ; then
  if test "$with_xpm_req" = yes ; then
    warnL 'Use of XPM was requested, but it was not found.'
  elif test "$with_xpm_req" = no ; then
    noteL 'The XPM library is not being used.'
  else
    noteL 'The XPM library was not found.'
  fi

  echo ''
  warn2 'Some of the demos will not be as colorful as they'
  warn2 'could be.  You might want to consider installing XPM'
  warn2 'and re-running configure.  (Remember to delete the'
  warn2 'config.cache file first.)  You can find XPM at most'
  warn2 'X11 archive sites, such as <http://sunsite.unc.edu/>.'
fi

if test "$have_gl" = no ; then
  if test "$with_gl_req" = yes ; then
    warnL 'Use of GL was requested, but it was not found.'
  elif test "$with_gl_req" = no ; then
    noteL 'The OpenGL 3D library is not being used.'
  else
    noteL 'The OpenGL 3D library was not found.'
  fi

  echo ''
  warn2 'Those demos which use 3D will not be built or installed.'
  warn2 'You might want to consider installing OpenGL and'
  warn2 're-running configure.  (Remember to delete the'
  warn2 "config.cache file first.)  If your vendor doesn't ship"
  warn2 'their own implementation of OpenGL, you can get a free'
  warn2 'version at <http://www.mesa3d.org/>.  For general OpenGL'
  warn2 'info, see <http://www.opengl.org/>.'

fi

if test "$with_readdisplay_req" = yes -a "$have_readdisplay" = no ; then
  warn 'Use of XReadDisplay was requested, but it was not found.'
fi

if test "$with_sgivideo_req" = yes -a "$have_sgivideo" = no ; then
  warn 'Use of the Iris Video Library was requested, but it was not found.'
fi

if test "$with_kerberos_req" = yes -a "$have_kerberos" = no ; then
  warn 'Use of Kerberos was requested, but it was not found.'
fi

if test "$with_pam_req" = yes -a "$have_pam" = no ; then
  warn 'Use of PAM was requested, but it was not found.'
fi

if test "$with_shadow_req" = yes -a "$have_shadow" = no ; then
  warn 'Use of shadow passwords was requested, but they were not found.'
fi

if test -n "$with_zippy_req"; then
  if test "$with_zippy_req" != "$ac_cv_zippy_program" ; then
    warnL "$with_zippy_req was requested as the Zippy program,"
    warn2 "but was not found.  The default will be used instead."
  fi
fi

if test "$warning" != no; then
  echo '' ; echo "$warnsep" ; echo ''
fi


AC_OUTPUT(Makefile
	  utils/Makefile
	  driver/Makefile
	  hacks/Makefile
	  hacks/glx/Makefile
	  driver/XScreenSaver.ad)

# You are in a twisty maze of namespaces and syntaxes, all alike.
# Fuck the skull of Unix.
#
eval bindir=${bindir}
eval bindir=${bindir}
eval bindir=${bindir}
eval bindir=${bindir}
eval bindir=${bindir}
eval bindir=${bindir}
eval HACKDIR=${HACKDIR}
eval HACKDIR=${HACKDIR}
eval HACKDIR=${HACKDIR}
eval HACKDIR=${HACKDIR}
eval HACKDIR=${HACKDIR}
eval HACKDIR=${HACKDIR}

# canonicalize slashes.
bindir=`echo  "${bindir}"  | sed 's@/$@@;s@//*@/@g'`
HACKDIR=`echo "${HACKDIR}" | sed 's@/$@@;s@//*@/@g'`

if test "${bindir}" = "${HACKDIR}" ; then
  echo ""
  echo "$warnsep"
  echo ""
  echo '      When you run "make install", the "xscreensaver",'
  echo '      "xscreensaver-demo", and "xscreensaver-command" executables'
  echo "      will be installed in ${bindir}."
  echo ""
  echo "      The various graphics demos (80+ different executables) will"
  echo "      also be installed in ${HACKDIR}."
  echo ""
  echo "      If you would prefer the demos to be installed elsewhere"
  echo "      (for example, in a dedicated directory) you should re-run"
  echo "      configure with the --enable-subdir=DIR option.  For more"
  echo "      information, run $0 --help."
  echo ""
  echo "$warnsep"
  echo ""
fi
