164e6d8e739ff73cc043ea779894e1a0aeb4b9ff
[xscreensaver] / configure.in
1 # configure.in --- xscreensaver, Copyright (c) 1997-2000 Jamie Zawinski.
2 #
3
4 AC_INIT(driver/subprocs.c)
5 AC_CONFIG_HEADER(config.h)
6
7 echo "current directory: `pwd`"
8 echo "command line was: $0 $@"
9
10
11 # After checking to see that --srcdir is correct (which AC_INIT does)
12 # check for some random other files that come later in the tar file,
13 # to make sure everything is here.
14 #
15 for d in driver utils hacks hacks/glx ; do
16   f=$srcdir/$d/Makefile.in
17   if test \! -r $f ; then
18     echo ""
19     echo "ERROR: The package is incomplete: $f does not exist."
20     echo "       This probably means that your download was truncated."
21     echo ""
22     exit 1
23   fi
24 done
25
26
27 ###############################################################################
28 #
29 #       Function to figure out how to run the compiler.
30 #
31 ###############################################################################
32
33 AC_DEFUN(AC_PROG_CC_ANSI,
34  [AC_PROG_CC
35
36   if test -z "$GCC"; then
37     AC_MSG_CHECKING(how to request ANSI compilation)
38     case "$host" in
39       *-hpux* )
40         AC_MSG_RESULT(HPUX: adding -Ae)
41         CC="$CC -Ae"
42       ;;
43       *-aix* )
44         AC_MSG_RESULT(AIX: adding -qlanglvl=ansi -qhalt=e)
45         CC="$CC -qlanglvl=ansi -qhalt=e"
46       ;;
47
48       *-dec-* )
49         AC_MSG_RESULT(DEC: adding -std1)
50         CC="$CC -std1"
51       ;;
52
53       *)
54         AC_MSG_RESULT(no idea)
55       ;;
56     esac
57   fi
58
59   AC_MSG_CHECKING([whether the compiler works on ANSI C])
60   AC_TRY_RUN([ main(int ac, char **av) { return 0; } ],
61      AC_MSG_RESULT(yes),
62      AC_MSG_RESULT(no)
63      AC_MSG_ERROR(Couldn't build even a trivial ANSI C program: check CC.),
64      AC_MSG_ERROR(Couldn't build even a trivial ANSI C program: check CC.))
65
66   if test -n "$GCC"; then
67     AC_MSG_RESULT(Turning on gcc compiler warnings.)
68     CC="$CC -Wall -Wstrict-prototypes -Wnested-externs -Wno-format"
69     AC_MSG_RESULT(Disabling C++ comments in ANSI C code.)
70     CC="$CC -Wp,-lang-c89"
71   else
72     case "$host" in
73       *-irix5* |*-irix6.[0-3]* )
74         AC_MSG_RESULT(Turning on SGI compiler warnings.)
75         CC="$CC -fullwarn -use_readonly_const -rdata_shared -g3"
76       ;;
77 #     *-dec-osf* )
78 #       if test -z "$GCC"; then
79 #         AC_MSG_RESULT(Turning on DEC C compiler warnings.)
80 #         CC="$CC -migrate -w0 -verbose -warnprotos"
81 #       fi
82 #     ;;
83     esac
84   fi
85 ])
86
87
88 ###############################################################################
89 #
90 #       Function to work around the fucked up gcc 2.96 included in Red Hat 7.0
91 #
92 ###############################################################################
93
94 AC_DEFUN(AC_ESCHEW_REDHAT_GCC_LOSSAGE,
95  [if test -n "$GCC"; then
96    AC_MSG_CHECKING(for Red Hat GCC lossage)
97    AC_CACHE_VAL(ac_cv_red_hat_gcc_lossage,
98     [ac_cv_red_hat_gcc_lossage=no
99       AC_EGREP_CPP(lossage,
100      [#include <stdlib.h>
101       #if !defined(__USE_POSIX) || !defined(__USE_SVID) || !defined(__USE_BSD)
102         lossage
103       #endif
104      ], ac_cv_red_hat_gcc_lossage=yes)
105     ])
106
107     ac_red_hat_gcc_lossage=$ac_cv_red_hat_gcc_lossage
108     if test "$ac_cv_red_hat_gcc_lossage" = yes ; then
109       rh_defines="-D_POSIX_SOURCE -D_SVID_SOURCE -D_BSD_SOURCE";
110       CC="$CC $rh_defines"
111       AC_MSG_RESULT(yes: need $rh_defines)
112     else
113       AC_MSG_RESULT(no)
114     fi
115   fi
116 ])
117
118
119 ###############################################################################
120 #
121 #       Function to figure out how to create directory trees.
122 #
123 ###############################################################################
124
125 AC_DEFUN(AC_PROG_INSTALL_DIRS,
126  [AC_CACHE_CHECK([whether \"\${INSTALL} -d\" creates intermediate directories],
127     ac_cv_install_d_creates_dirs,
128     [ac_cv_install_d_creates_dirs=no
129      rm -rf conftestdir
130      if mkdir conftestdir; then
131        cd conftestdir >&-
132        ${INSTALL} -d `pwd`/dir1/dir2 >&- 2>&-
133        if test -d dir1/dir2/. ; then
134          ac_cv_install_d_creates_dirs=yes
135        fi
136        cd .. >&-
137        rm -rf conftestdir
138      fi
139     ])
140
141   if test "$ac_cv_install_d_creates_dirs" = no ; then
142     AC_CACHE_CHECK([whether \"mkdir -p\" creates intermediate directories],
143       ac_cv_mkdir_p_creates_dirs,
144       [ac_cv_mkdir_p_creates_dirs=no
145        rm -rf conftestdir
146        if mkdir conftestdir; then
147          cd conftestdir >&-
148          mkdir -p dir1/dir2 >&- 2>&-
149          if test -d dir1/dir2/. ; then
150            ac_cv_mkdir_p_creates_dirs=yes
151          fi
152          cd .. >&-
153          rm -rf conftestdir
154        fi
155       ])
156   fi
157
158   if test "$ac_cv_install_d_creates_dirs" = yes ; then
159     INSTALL_DIRS='${INSTALL} -d'
160   elif test "$ac_cv_mkdir_p_creates_dirs" = yes ; then
161     INSTALL_DIRS='mkdir -p'
162   else
163     # any other ideas?
164     INSTALL_DIRS='${INSTALL} -d'
165   fi
166 ])
167
168
169 ###############################################################################
170 #
171 #       Function to check whether gettimeofday() exists, and how to call it.
172 #       This may define HAVE_GETTIMEOFDAY and GETTIMEOFDAY_TWO_ARGS.
173 #
174 ###############################################################################
175
176 AC_DEFUN(AC_GETTIMEOFDAY_ARGS,
177  [AC_MSG_CHECKING(how to call gettimeofday)
178   AC_CACHE_VAL(ac_cv_gettimeofday_args,
179    [AC_TRY_COMPILE([#include <stdlib.h>
180                     #include <sys/time.h>],
181                    [struct timeval tv; struct timezone tzp;
182                     gettimeofday(&tv, &tzp);],
183                    [ac_gettimeofday_args=2],
184                    [AC_TRY_COMPILE([#include <stdlib.h>
185                                     #include <sys/time.h>],
186                                    [struct timeval tv; gettimeofday(&tv);],
187                                    [ac_gettimeofday_args=1],
188                                    [ac_gettimeofday_args=0])])
189     ac_cv_gettimeofday_args=$ac_gettimeofday_args])
190   ac_gettimeofday_args=$ac_cv_gettimeofday_args
191   if test "$ac_gettimeofday_args" = 1 ; then
192     AC_DEFINE(HAVE_GETTIMEOFDAY)
193     AC_MSG_RESULT(one argument)
194   elif test "$ac_gettimeofday_args" = 2 ; then
195     AC_DEFINE(HAVE_GETTIMEOFDAY)
196     AC_DEFINE(GETTIMEOFDAY_TWO_ARGS)
197     AC_MSG_RESULT(two arguments)
198   else
199     AC_MSG_RESULT(unknown)
200   fi
201 ])
202
203
204 ###############################################################################
205 #
206 #       Function to find perl5 (defines PERL and PERL_VERSION.)
207 #
208 ###############################################################################
209
210 # M4 sucks!!  perl sucks too!!
211 changequote(X,Y)
212 perl_version_cmd='print $]'
213 changequote([,])
214
215 AC_DEFUN(AC_PROG_PERL,
216  [AC_PATH_PROGS(PERL, [perl5 perl],,)
217   if test -z "$PERL" ; then
218     PERL_VERSION=0
219   else
220     AC_CACHE_CHECK([perl version], ac_cv_perl_version,
221                    [ac_cv_perl_version=`$PERL -e "$perl_version_cmd"`])
222     PERL_VERSION=$ac_cv_perl_version
223   fi
224  ])
225
226
227 ###############################################################################
228 #
229 #       Function to demand "bc".  Losers.
230 #
231 ###############################################################################
232
233 AC_DEFUN(AC_DEMAND_BC,
234  [ac_bc_result=`echo 6+9 | bc 2>/dev/null`
235   AC_MSG_CHECKING([for bc])
236   if test "$ac_bc_result" = "15" ; then
237     AC_MSG_RESULT(yes)
238   else
239     AC_MSG_RESULT(no)
240     echo ''
241     AC_MSG_ERROR([Your system doesn't have \"bc\", which has been a standard
242                   part of Unix since the 1970s.  Come back when your vendor
243                   has grown a clue.])
244   fi
245  ])
246
247 ###############################################################################
248 #
249 #       Functions to check how to do ICMP PING requests.
250 #
251 ###############################################################################
252
253 AC_DEFUN(AC_CHECK_ICMP,
254  [AC_CACHE_CHECK([for struct icmp], ac_cv_have_icmp,
255   [AC_TRY_COMPILE([#include <stdlib.h>
256                    #include <stdio.h>
257                    #include <math.h>
258                    #include <unistd.h>
259                    #include <limits.h>
260                    #include <signal.h>
261                    #include <fcntl.h>
262                    #include <sys/types.h>
263                    #include <sys/time.h>
264                    #include <sys/ipc.h>
265                    #include <sys/shm.h>
266                    #include <sys/socket.h>
267                    #include <netinet/in_systm.h>
268                    #include <netinet/in.h>
269                    #include <netinet/ip.h>
270                    #include <netinet/ip_icmp.h>
271                    #include <netinet/udp.h>
272                    #include <arpa/inet.h>
273                    #include <netdb.h>],
274                   [struct icmp i;
275                    struct sockaddr s;
276                    struct sockaddr_in si;
277                    struct ip ip;
278                    i.icmp_type = ICMP_ECHO;
279                    i.icmp_code = 0;
280                    i.icmp_cksum = 0;
281                    i.icmp_id = 0;
282                    i.icmp_seq = 0;
283                    si.sin_family = AF_INET;
284                    ip.ip_hl = 0;],
285                   [ac_cv_have_icmp=yes],
286                   [ac_cv_have_icmp=no])])
287  if test "$ac_cv_have_icmp" = yes ; then
288    AC_DEFINE(HAVE_ICMP)
289  fi])
290
291 AC_DEFUN(AC_CHECK_ICMPHDR,
292  [AC_CACHE_CHECK([for struct icmphdr], ac_cv_have_icmphdr,
293   [AC_TRY_COMPILE([#include <stdlib.h>
294                    #include <stdio.h>
295                    #include <math.h>
296                    #include <unistd.h>
297                    #include <limits.h>
298                    #include <signal.h>
299                    #include <fcntl.h>
300                    #include <sys/types.h>
301                    #include <sys/time.h>
302                    #include <sys/ipc.h>
303                    #include <sys/shm.h>
304                    #include <sys/socket.h>
305                    #include <netinet/in_systm.h>
306                    #include <netinet/in.h>
307                    #include <netinet/ip.h>
308                    #include <netinet/ip_icmp.h>
309                    #include <netinet/udp.h>
310                    #include <arpa/inet.h>
311                    #include <netdb.h>],
312                   [struct icmphdr i;
313                    struct sockaddr s;
314                    struct sockaddr_in si;
315                    struct ip ip;
316                    i.type = ICMP_ECHO;
317                    i.code = 0;
318                    i.cksum = 0;
319                    i.un.echo.id = 0;
320                    i.un.echo.sequence = 0;
321                    si.sin_family = AF_INET;
322                    ip.ip_hl = 0;],
323                   [ac_cv_have_icmphdr=yes],
324                   [ac_cv_have_icmphdr=no])])
325  if test "$ac_cv_have_icmphdr" = yes ; then
326    AC_DEFINE(HAVE_ICMPHDR)
327  fi])
328
329
330 ###############################################################################
331 #
332 #       Functions to check for various X11 crap.
333 #
334 ###############################################################################
335
336 # Try and find the app-defaults directory.
337 # It sucks that autoconf doesn't do this already...
338 #
339 AC_DEFUN(AC_PATH_X_APP_DEFAULTS_XMKMF,[
340   rm -fr conftestdir
341   if mkdir conftestdir; then
342     cd conftestdir >&-
343     # Make sure to not put "make" in the Imakefile rules, since we grep it out.
344     cat > Imakefile <<'EOF'
345 acfindx:
346         @echo 'ac_x_app_defaults="${XAPPLOADDIR}"'
347 EOF
348     if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then
349       # GNU make sometimes prints "make[1]: Entering...", which'd confuse us.
350       eval `${MAKE-make} acfindx 2>/dev/null | grep -v make`
351     fi
352     cd .. >&-
353     rm -fr conftestdir
354   fi])
355
356 AC_DEFUN(AC_PATH_X_APP_DEFAULTS_DIRECT,[
357   # Look for the directory under a standard set of common directories.
358   # Check X11 before X11Rn because it's often a symlink to the current release.
359   for ac_dir in                                 \
360     /usr/X11/lib/app-defaults                   \
361     /usr/X11R6/lib/app-defaults                 \
362     /usr/X11R6/lib/X11/app-defaults             \
363     /usr/X11R5/lib/app-defaults                 \
364     /usr/X11R5/lib/X11/app-defaults             \
365     /usr/X11R4/lib/app-defaults                 \
366     /usr/X11R4/lib/X11/app-defaults             \
367                                                 \
368     /usr/lib/X11/app-defaults                   \
369     /usr/lib/X11R6/app-defaults                 \
370     /usr/lib/X11R5/app-defaults                 \
371     /usr/lib/X11R4/app-defaults                 \
372                                                 \
373     /usr/local/X11/lib/app-defaults             \
374     /usr/local/X11R6/lib/app-defaults           \
375     /usr/local/X11R5/lib/app-defaults           \
376     /usr/local/X11R4/lib/app-defaults           \
377                                                 \
378     /usr/local/lib/X11/app-defaults             \
379     /usr/local/lib/X11R6/app-defaults           \
380     /usr/local/lib/X11R6/X11/app-defaults       \
381     /usr/local/lib/X11R5/app-defaults           \
382     /usr/local/lib/X11R5/X11/app-defaults       \
383     /usr/local/lib/X11R4/app-defaults           \
384     /usr/local/lib/X11R4/X11/app-defaults       \
385                                                 \
386     /usr/X386/lib/X11/app-defaults              \
387     /usr/x386/lib/X11/app-defaults              \
388     /usr/XFree86/lib/X11/app-defaults           \
389                                                 \
390     /usr/lib/X11/app-defaults                   \
391     /usr/local/lib/X11/app-defaults             \
392     /usr/unsupported/lib/X11/app-defaults       \
393     /usr/athena/lib/X11/app-defaults            \
394     /usr/local/x11r5/lib/X11/app-defaults       \
395     /usr/lpp/Xamples/lib/X11/app-defaults       \
396     /lib/usr/lib/X11/app-defaults               \
397                                                 \
398     /usr/openwin/lib/app-defaults               \
399     /usr/openwin/lib/X11/app-defaults           \
400     /usr/openwin/share/lib/app-defaults         \
401     /usr/openwin/share/lib/X11/app-defaults     \
402                                                 \
403     /X11R6/lib/app-defaults                     \
404     /X11R5/lib/app-defaults                     \
405     /X11R4/lib/app-defaults                     \
406     ; \
407   do
408     if test -d "$ac_dir"; then
409       ac_x_app_defaults=$ac_dir
410       break
411     fi
412   done
413 ])
414
415 AC_DEFUN(AC_PATH_X_APP_DEFAULTS,
416   [AC_REQUIRE_CPP()
417     AC_CACHE_CHECK([for X app-defaults directory], ac_cv_x_app_defaults,
418      [AC_PATH_X_APP_DEFAULTS_XMKMF
419       if test x"$ac_x_app_defaults" = x; then
420         AC_PATH_X_APP_DEFAULTS_DIRECT
421       fi
422       if test x"$ac_x_app_defaults" = x; then
423         ac_cv_x_app_defaults="/usr/lib/X11/app-defaults"
424       else
425         # Record where we found app-defaults for the cache.
426         ac_cv_x_app_defaults="$ac_x_app_defaults"
427       fi])
428     eval ac_x_app_defaults="$ac_cv_x_app_defaults"])
429
430
431 AC_DEFUN(AC_XPOINTER,
432  [AC_CACHE_CHECK([for XPointer], ac_cv_xpointer,
433                  [AC_TRY_X_COMPILE([#include <X11/Xlib.h>],
434                                    [XPointer foo = (XPointer) 0;],
435                                    [ac_cv_xpointer=yes],
436                                    [ac_cv_xpointer=no])])
437   if test "$ac_cv_xpointer" != yes; then
438    AC_DEFINE(XPointer,[char*])
439   fi])
440
441
442 # Random special-cases for X on certain pathological OSes.
443 # You know who you are.
444 #
445 AC_DEFUN(AC_X_RANDOM_PATHS,
446  [case "$host" in
447     *-hpux*)
448
449       # The following arcana was gleaned from conversations with
450       # Eric Schwartz <erics@col.hp.com>:
451       #
452       # On HPUX 10.x, the parts of X that HP considers "standard" live in
453       # /usr/{include,lib}/X11R6/.  The parts that HP doesn't consider
454       # "standard", notably, Xaw and Xmu, live in /usr/contrib/X11R6/.
455       # Yet /usr/contrib/X11R6/ comes preinstalled on all HPUX systems.
456       # Also, there are symlinks from /usr/include/ and /usr/lib/ into
457       # /usr/{include,lib}/X11R6/, so that (if you don't use Xmu at all)
458       # you don't need any -I or -L arguments.
459       #
460       # On HPUX 9.x, /usr/{include,lib}/X11R5/ and /usr/contrib/X11R5/
461       # are the same division as 10.x.  However, there are no symlinks to
462       # the X stuff from /usr/include/ and /usr/lib/, so -I and -L
463       # arguments are always necessary.
464       #
465       # However, X11R6 was available on HPUX 9.x as a patch: if that
466       # patch was installed, then all of X11R6 went in to
467       # /usr/contrib/X11R6/ (there was no /usr/{include,lib}/X11R6/.)
468       #
469       # HPUX 8.x was the same as 9.x, but was X11R4 instead (I don't know
470       # whether R5 was available as a patch; R6 undoubtedly was not.)
471       #
472       # So.  We try and use the highest numbered pair of
473       # /usr/{include,lib}/X11R?/ and /usr/contrib/X11R?/{include,lib}/
474       # that are available.  We do not mix and match different versions
475       # of X.
476       #
477       # Question I still don't know the answer to: (do you?)
478       #
479       #   * On HPUX 9.x, where /usr/include/X11R5/ was standard, and
480       #     /usr/contrib/X11R6/ could be installed as a patch, what was in
481       #     that contrib directory?  Did it contain so-called "standard"
482       #     X11R6, or did it include Xaw and Xmu as well?  If the former,
483       #     where did one find Xaw and Xmu on 9.x R6 systems?  Would this
484       #     be a situation where one had to reach into the R5 headers and
485       #     libs to find Xmu?  That is, must both R6 and R5 directories
486       #     be on the -I and -L lists in that case?
487       #
488       for version in X11R6 X11R5 X11R4 ; do
489         # if either pair of directories exists...
490         if test -d /usr/lib/$version || test -d /usr/contrib/$version/lib
491         then
492            # if contrib exists, use it...
493            if test -d /usr/contrib/$version/lib ; then
494              X_CFLAGS="$X_CFLAGS -I/usr/contrib/$version/include"
495              X_LIBS="$X_LIBS -L/usr/contrib/$version/lib"
496            fi
497            # if the "standard" one exists, use it.
498            if test -d /usr/lib/$version ; then
499              X_CFLAGS="$X_CFLAGS -I/usr/include/$version"
500              X_LIBS="$X_LIBS -L/usr/lib/$version"
501            fi
502            # since at least one of the pair exists, go no farther.
503            break
504         fi
505       done
506
507       # Now find Motif.  Thanks for not making xmkmf find this by
508       # default, you losers.
509       #
510       if test -d /usr/lib/Motif1.2 ; then
511         X_CFLAGS="$X_CFLAGS -I/usr/include/Motif1.2"
512         X_LIBS="$X_LIBS -L/usr/lib/Motif1.2"
513       elif test -d /usr/lib/Motif1.1 ; then
514         X_CFLAGS="$X_CFLAGS -I/usr/include/Motif1.1"
515         X_LIBS="$X_LIBS -L/usr/lib/Motif1.1"
516       fi
517
518       # Now let's check for the pseudo-standard locations for OpenGL and XPM.
519       #
520       if test -d /opt/Mesa/lib ; then
521         X_CFLAGS="-I/opt/Mesa/include $X_CFLAGS"
522         X_LIBS="-L/opt/Mesa/lib $X_LIBS"
523       fi
524
525       if test -d /opt/xpm/lib/X11 ; then
526         X_CFLAGS="-I/opt/xpm/include $X_CFLAGS"
527         X_LIBS="-L/opt/xpm/lib/X11 $X_LIBS"
528       fi
529
530       # On HPUX, default to installing in /opt/xscreensaver/ instead of
531       # in /usr/local/, unless there is already an xscreensaver in
532       # /usr/local/bin/.  This can be overridden with the --prefix arg
533       # to configure.  I'm not sure this is the right thing to do, but
534       # Richard Lloyd says so...
535       #
536       if test \! -x /usr/local/bin/xscreensaver ; then
537         ac_default_prefix=/opt/xscreensaver
538       fi
539
540     ;;
541     *-solaris*)
542
543       # Thanks for not making xmkmf find this by default, pinheads.
544       # And thanks for moving things around again, too.  Is this
545       # really the standard location now?  What happened to the
546       # joke that this kind of thing went in /opt?
547       # cthomp says "answer: CDE (Common Disorganized Environment)"
548       #
549       if test -f /usr/dt/include/Xm/Xm.h ; then
550         X_CFLAGS="$X_CFLAGS -I/usr/dt/include"
551         X_LIBS="$X_LIBS -L/usr/dt/lib -R:/usr/dt/lib"
552
553         # Some versions of Slowlaris Motif require -lgen.  But not all.  Why?
554         AC_CHECK_LIB(gen, regcmp, [X_LIBS="$X_LIBS -lgen"])
555       fi
556     ;;
557   esac])
558
559
560
561 ###############################################################################
562 #
563 #       Some utility functions to make checking for X things easier.
564 #
565 ###############################################################################
566
567 # Like AC_CHECK_HEADER, but it uses the already-computed -I directories.
568 #
569 AC_DEFUN(AC_CHECK_X_HEADER, [
570   ac_save_CPPFLAGS="$CPPFLAGS"
571   if test \! -z "$includedir" ; then 
572     CPPFLAGS="$CPPFLAGS -I$includedir"
573   fi
574   CPPFLAGS="$CPPFLAGS $X_CFLAGS"
575   AC_CHECK_HEADER([$1], [$2])
576   CPPFLAGS="$ac_save_CPPFLAGS"])
577
578 # Like AC_EGREP_HEADER, but it uses the already-computed -I directories.
579 #
580 AC_DEFUN(AC_EGREP_X_HEADER, [
581   ac_save_CPPFLAGS="$CPPFLAGS"
582   if test \! -z "$includedir" ; then 
583     CPPFLAGS="$CPPFLAGS -I$includedir"
584   fi
585   CPPFLAGS="$CPPFLAGS $X_CFLAGS"
586   AC_EGREP_HEADER([$1], [$2], [$3], [$4])
587   CPPFLAGS="$ac_save_CPPFLAGS"])
588
589 # Like AC_TRY_COMPILE, but it uses the already-computed -I directories.
590 #
591 AC_DEFUN(AC_TRY_X_COMPILE, [
592   ac_save_CPPFLAGS="$CPPFLAGS"
593   if test \! -z "$includedir" ; then 
594     CPPFLAGS="$CPPFLAGS -I$includedir"
595   fi
596   CPPFLAGS="$CPPFLAGS $X_CFLAGS"
597   AC_TRY_COMPILE([$1], [$2], [$3], [$4])
598   CPPFLAGS="$ac_save_CPPFLAGS"])
599
600
601 # Like AC_CHECK_LIB, but it uses the already-computed -I and -L directories.
602 # Use this sparingly; it probably doesn't work very well on X programs.
603 #
604 AC_DEFUN(AC_CHECK_X_LIB, [
605   ac_save_CPPFLAGS="$CPPFLAGS"
606   ac_save_LDFLAGS="$LDFLAGS"
607 #  ac_save_LIBS="$LIBS"
608
609   if test \! -z "$includedir" ; then 
610     CPPFLAGS="$CPPFLAGS -I$includedir"
611   fi
612   # note: $X_CFLAGS includes $x_includes
613   CPPFLAGS="$CPPFLAGS $X_CFLAGS"
614
615   if test \! -z "$libdir" ; then
616     LDFLAGS="$LDFLAGS -L$libdir"
617   fi
618   # note: $X_LIBS includes $x_libraries
619   LDFLAGS="$LDFLAGS $X_LIBS $X_EXTRA_LIBS"
620
621   AC_CHECK_LIB([$1], [$2], [$3], [$4], [$5])
622   CPPFLAGS="$ac_save_CPPFLAGS"
623   LDFLAGS="$ac_save_LDFLAGS"
624 #  LIBS="$ac_save_LIBS"
625   ])
626
627 # Like AC_TRY_RUN, but it uses the already-computed -I directories.
628 # (But not the -L directories!)
629 #
630 AC_DEFUN(AC_TRY_X_RUN, [
631   ac_save_CPPFLAGS="$CPPFLAGS"
632   if test \! -z "$includedir" ; then 
633     CPPFLAGS="$CPPFLAGS -I$includedir"
634   fi
635   CPPFLAGS="$CPPFLAGS $X_CFLAGS"
636   AC_TRY_RUN([$1], [$2], [$3], [$4])
637   CPPFLAGS="$ac_save_CPPFLAGS"])
638
639
640
641 # Usage: HANDLE_X_PATH_ARG([variable_name],
642 #                          [--command-line-option],
643 #                          [descriptive string])
644 #
645 # All of the --with options take three forms:
646 #
647 #   --with-foo (or --with-foo=yes)
648 #   --without-foo (or --with-foo=no)
649 #   --with-foo=/DIR
650 #
651 # This function, HANDLE_X_PATH_ARG, deals with the /DIR case.  When it sees
652 # a directory (string beginning with a slash) it checks to see whether
653 # /DIR/include and /DIR/lib exist, and adds them to $X_CFLAGS and $X_LIBS
654 # as appropriate.
655 #
656 AC_DEFUN(HANDLE_X_PATH_ARG, [
657    case "$[$1]" in
658     yes) ;;
659     no)  ;;
660
661     /*)
662      AC_MSG_CHECKING([for [$3] headers])
663      d=$[$1]/include
664      if test -d $d; then
665        X_CFLAGS="-I$d $X_CFLAGS"
666        AC_MSG_RESULT($d)
667      else
668        AC_MSG_RESULT(not found ($d: no such directory))
669      fi
670
671      AC_MSG_CHECKING([for [$3] libs])
672      d=$[$1]/lib
673      if test -d $d; then
674        X_LIBS="-L$d $X_LIBS"
675        AC_MSG_RESULT($d)
676      else
677        AC_MSG_RESULT(not found ($d: no such directory))
678      fi
679
680      # replace the directory string with "yes".
681      [$1]_req="yes"
682      [$1]=$[$1]_req
683      ;;
684
685     *)
686      echo ""
687      echo "error: argument to [$2] must be \"yes\", \"no\", or a directory."
688      echo "       If it is a directory, then \`DIR/include' will be added to"
689      echo "       the -I list, and \`DIR/lib' will be added to the -L list."
690      exit 1
691      ;;
692    esac
693   ])
694
695
696
697 ###############################################################################
698 ###############################################################################
699 #
700 #       End of function definitions.  Now start actually executing stuff.
701 #
702 ###############################################################################
703 ###############################################################################
704
705 # random compiler setup
706 AC_CANONICAL_HOST
707 AC_PROG_CC_ANSI
708 AC_ESCHEW_REDHAT_GCC_LOSSAGE
709 AC_PROG_CPP
710 AC_C_CONST
711 AC_C_INLINE
712 AC_DEMAND_BC
713
714 # stuff for Makefiles
715 AC_PROG_INSTALL
716 AC_PROG_INSTALL_DIRS
717 AC_PROG_MAKE_SET
718
719 # random libc stuff
720 AC_HEADER_STDC
721 AC_CHECK_HEADERS(unistd.h)
722 AC_TYPE_MODE_T
723 AC_TYPE_PID_T
724 AC_TYPE_SIZE_T
725 AC_TYPE_SIGNAL
726 AC_HEADER_TIME
727 AC_HEADER_SYS_WAIT
728 AC_HEADER_DIRENT
729 AC_GETTIMEOFDAY_ARGS
730 AC_CHECK_FUNCS(select fcntl uname nice setpriority getcwd getwd putenv)
731
732 AC_CHECK_FUNCS(sigaction syslog realpath)
733 AC_CHECK_ICMP
734 AC_CHECK_ICMPHDR
735 AC_CHECK_HEADERS(crypt.h sys/select.h)
736 AC_PROG_PERL
737
738 if test -z "$PERL" ; then
739   # don't let it be blank...
740   PERL=/usr/local/bin/perl5
741 fi
742
743 AC_PATH_XTRA
744
745 if test "$have_x" != yes; then
746   AC_MSG_ERROR(Couldn't find X11 headers/libs.  Try \`$0 --help'.)
747 fi
748
749 AC_PATH_X_APP_DEFAULTS
750 AC_X_RANDOM_PATHS
751 AC_XPOINTER
752
753
754
755 ###############################################################################
756 #
757 #       Check for -lXmu (some fucked up vendors don't ship it...)
758 #
759 ###############################################################################
760
761 have_xmu=no
762 AC_CHECK_X_HEADER(X11/Xmu/Error.h, [have_xmu=yes])
763 if test "$have_xmu" = no ; then
764   XMU_SRCS='$(UTILS_SRC)/xmu.c'
765   XMU_OBJS='$(UTILS_BIN)/xmu.o'
766 else
767   XMU_SRCS=''
768   XMU_OBJS=''
769   SAVER_LIBS="-lXmu $SAVER_LIBS"
770   HACK_LIBS="-lXmu $HACK_LIBS"
771   MOTIF_LIBS="-lXmu $MOTIF_LIBS"
772   GTK_LIBS="-lXmu $GTK_LIBS"
773   AC_DEFINE(HAVE_XMU)
774 fi
775
776
777 ###############################################################################
778 #
779 #       Check for the SunOS 4.1.x _get_wmShellWidgetClass bug.
780 #       See comp.windows.x FAQ question 124.  The right fix is to
781 #       get OpenWindows 3.0 patches 100512-02 and 100573-03.
782 #
783 ###############################################################################
784
785 if test "$have_xmu" = yes ; then
786   case "$host" in
787     *-sunos4*)
788     AC_CACHE_CHECK([for the SunOS 4.1.x _get_wmShellWidgetClass bug],
789                    ac_cv_sunos_xmu_bug,
790                    [ac_save_LDFLAGS="$LDFLAGS"
791                     if test \! -z "$x_libraries" ; then
792                       LDFLAGS="$LDFLAGS -L$x_libraries"
793                     fi
794                     # Note: this trick never works!  (Generally.)
795                     # We're only getting away with using AC_TRY_LINK
796                     # with X libraries because we know it's SunOS.
797                     LDFLAGS="$LDFLAGS -lXmu -lXt -lX11 -lXext -lm"
798                     AC_TRY_LINK(,,
799                                 [ac_cv_sunos_xmu_bug=no],
800                                 [ac_cv_sunos_xmu_bug=yes])
801                     LDFLAGS="$ac_save_LDFLAGS"])
802     if test "$ac_cv_sunos_xmu_bug" = yes ; then
803       AC_CACHE_CHECK([whether the compiler understands -static], 
804                      ac_cv_ld_static,
805                      [ac_save_LDFLAGS="$LDFLAGS"
806                       LDFLAGS="$LDFLAGS -static"
807                       AC_TRY_LINK(,,[ac_cv_ld_static=yes],[ac_cv_ld_static=no])
808                     LDFLAGS="$ac_save_LDFLAGS"])
809       if test "$ac_cv_ld_static" = yes ; then
810         LDFLAGS="$LDFLAGS -static"
811       else
812         LDFLAGS="$LDFLAGS -Bstatic"
813       fi
814     fi
815     ;;
816   esac
817 fi
818
819
820 ###############################################################################
821 #
822 #       Handle the --enable-subdir option
823 #
824 ###############################################################################
825
826 AC_ARG_ENABLE(subdir,[
827 Installation options:
828
829   --enable-subdir=DIR     Put the demo programs in a subdirectory of \`bindir',
830                           instead of putting them in bindir itself.  You can
831                           specify the name of the subdirectory.  For example,
832                           \`--exec-prefix=/usr/local --enable-subdir=demos'
833                           would put xscreensaver in /usr/local/bin/, and would
834                           put the demos in /usr/local/bin/demos/.  (If DIR
835                           begins with /, then bindir will not be prepended.)
836
837   --disable-subdir        Just put the demos in \`bindir' (this is the default.)
838 ],
839   [enable_subdir="$enableval"],[enable_subdir=no])
840 if test x"$enable_subdir" = xno; then
841   HACKDIR='${bindir}'
842 elif test x"$enable_subdir" = xyes -o x"$enable_subdir" = x ; then
843   echo "error: must be a subdirectory name: --enable-subdir=$enable_subdir"
844   exit 1
845 else
846   # there must be a better way than this...
847   if test -z "`echo $enable_subdir | sed 's@^/.*@@'`" ; then
848     # absolute path
849     HACKDIR=$enable_subdir
850   else
851     # relative path
852     HACKDIR='${bindir}/'$enable_subdir
853   fi
854 fi
855
856 # canonicalize slashes.
857 HACKDIR=`echo "${HACKDIR}" | sed 's@/$@@;s@//*@/@g'`
858
859
860 ###############################################################################
861 #
862 #       Check for the SGI SCREEN_SAVER server extension.
863 #
864 ###############################################################################
865
866 have_sgi=no
867 with_sgi_req=unspecified
868 AC_ARG_WITH(sgi-ext,
869 [Except where noted, all of the --with options below can also take a
870 directory argument: for example, \`--with-motif=/opt/Motif'.  That would
871 cause /opt/Motif/include/ to be added to the -I list, and /opt/Motif/lib/
872 to be added to the -L list, assuming those directories exist.  
873
874 By default, support for each of these options will be built in, if the
875 relevant library routines exist.  At run time, they will then be used
876 only if the X server being used supports them.  Each --with option has
877 a corresponding --without option, to override building support for them
878 at all.
879
880 Screen blanking and idle-detection options:
881
882   --with-sgi-ext          Include support for the SGI SCREEN_SAVER extension.],
883   [with_sgi="$withval"; with_sgi_req="$withval"],[with_sgi=yes])
884
885 HANDLE_X_PATH_ARG(with_sgi, --with-sgi-ext, SGI SCREEN_SAVER)
886
887 if test "$with_sgi" = yes; then
888   AC_CHECK_X_HEADER(X11/extensions/XScreenSaver.h,
889                     [have_sgi=yes
890                      AC_DEFINE(HAVE_SGI_SAVER_EXTENSION)])
891
892 elif test "$with_sgi" != no; then
893   echo "error: must be yes or no: --with-sgi-ext=$with_sgi"
894   exit 1
895 fi
896
897
898 ###############################################################################
899 #
900 #       Check for the MIT-SCREEN-SAVER server extension.
901 #
902 ###############################################################################
903
904 have_mit=no
905 with_mit_req=unspecified
906 AC_ARG_WITH(mit-ext,
907 [  --with-mit-ext          Include support for the MIT-SCREEN-SAVER extension.],
908   [with_mit="$withval"; with_mit_req="$withval"],[with_mit=yes])
909
910 HANDLE_X_PATH_ARG(with_mit, --with-mit-ext, MIT-SCREEN-SAVER)
911
912 if test "$with_mit" = yes; then
913   AC_CHECK_X_HEADER(X11/extensions/scrnsaver.h, [have_mit=yes])
914
915   # Now check to see if it's really in the library; XF86Free-3.3 ships
916   # scrnsaver.h, but doesn't include the code in libXext.a, the idiots!
917   #
918   if test "$have_mit" = yes; then
919     AC_CHECK_X_LIB(Xext, XScreenSaverRegister, [true], [have_mit=no], -lm)
920
921     if test "$have_mit" = no; then
922       # Fuck!  Looks like XF86Free-3.3 actually puts it in XExExt instead
923       # of in Xext.  Thank you master, may I have another.
924       AC_CHECK_X_LIB(XExExt, XScreenSaverRegister,
925                      [have_mit=yes; SAVER_LIBS="$SAVER_LIBS -lXExExt"],
926                      [true], -lX11 -lXext -lm)
927     fi
928
929     if test "$have_mit" = no; then
930       # Double fuck!  Looks like some versions of XFree86 (whichever version
931       # it is that comes with RedHat Linux 2.0 -- I can't find a version 
932       # number) put this garbage in Xss instead of Xext.  Thank you master,
933       #  may I have another.
934       AC_CHECK_X_LIB(Xss, XScreenSaverRegister,
935                      [have_mit=yes; SAVER_LIBS="$SAVER_LIBS -lXss"],
936                      [true], -lX11 -lXext -lm)
937     fi
938
939   if test "$have_mit" = yes; then
940     AC_DEFINE(HAVE_MIT_SAVER_EXTENSION)
941   fi
942
943   fi
944
945 elif test "$with_mit" != no; then
946   echo "error: must be yes or no: --with-mit-ext=$with_mit"
947   exit 1
948 fi
949
950
951 ###############################################################################
952 #
953 #       Check for the XIDLE server extension.
954 #
955 ###############################################################################
956
957 have_xidle=no
958 with_xidle_req=unspecified
959 AC_ARG_WITH(xidle-ext,
960 [  --with-xidle-ext        Include support for the XIDLE extension.],
961   [with_xidle="$withval"; with_xidle_req="$withval"],[with_xidle=yes])
962
963 HANDLE_X_PATH_ARG(with_xidle, --with-xidle-ext, XIDLE)
964
965 if test "$with_xidle" = yes; then
966   AC_CHECK_X_HEADER(X11/extensions/xidle.h,
967                     [have_xidle=yes
968                      AC_DEFINE(HAVE_XIDLE_EXTENSION)])
969 elif test "$with_xidle" != no; then
970   echo "error: must be yes or no: --with-xidle-ext=$with_xidle"
971   exit 1
972 fi
973
974
975 ###############################################################################
976 #
977 #       Check for the SGI-VIDEO-CONTROL server extension.
978 #
979 ###############################################################################
980
981 have_sgivc=no
982 with_sgivc_req=unspecified
983 AC_ARG_WITH(sgivc-ext,
984 [  --with-sgivc-ext        Include support for the SGI-VIDEO-CONTROL extension.],
985   [with_sgivc="$withval"; with_sgivc_req="$withval"],[with_sgivc=yes])
986
987 HANDLE_X_PATH_ARG(with_sgivc, --with-sgivc-ext, SGI-VIDEO-CONTROL)
988
989 if test "$with_sgivc" = yes; then
990
991   # first check for XSGIvc.h
992   AC_CHECK_X_HEADER(X11/extensions/XSGIvc.h, [have_sgivc=yes])
993
994   # if that succeeded, then check for the -lXsgivc
995   if test "$have_sgivc" = yes; then
996     have_sgivc=no
997     AC_CHECK_X_LIB(Xsgivc, XSGIvcQueryGammaMap,
998                   [have_sgivc=yes; SAVER_LIBS="$SAVER_LIBS -lXsgivc"], [true],
999                   -lXext -lX11)
1000   fi
1001
1002   # if that succeeded, then we've really got it.
1003   if test "$have_sgivc" = yes; then
1004     AC_DEFINE(HAVE_SGI_VC_EXTENSION)
1005   fi
1006
1007 elif test "$with_sgivc" != no; then
1008   echo "error: must be yes or no: --with-sgivc-ext=$with_sgivc"
1009   exit 1
1010 fi
1011
1012
1013 ###############################################################################
1014 #
1015 #       Check for the DPMS server extension.
1016 #
1017 ###############################################################################
1018
1019 have_dpms=no
1020 with_dpms_req=unspecified
1021 AC_ARG_WITH(dpms-ext,
1022 [  --with-dpms-ext         Include support for the DPMS extension.],
1023   [with_dpms="$withval"; with_dpms_req="$withval"],[with_dpms=yes])
1024
1025 HANDLE_X_PATH_ARG(with_dpms, --with-dpms-ext, DPMS)
1026
1027 if test "$with_dpms" = yes; then
1028
1029   # first check for dpms.h
1030   AC_CHECK_X_HEADER(X11/extensions/dpms.h, [have_dpms=yes])
1031
1032   # if that succeeded, then check for the DPMS code in the libraries
1033   if test "$have_dpms" = yes; then
1034
1035     # first look in -lXext (this is where it is with XFree86 4.0)
1036     have_dpms=no
1037     AC_CHECK_X_LIB(Xext, DPMSInfo, [have_dpms=yes], [true], -lXext -lX11)
1038
1039     # if that failed, look in -lXdpms (this is where it was in XFree86 3.x)
1040     if test "$have_dpms" = no; then
1041       AC_CHECK_X_LIB(Xdpms, DPMSInfo,
1042                     [have_dpms=yes; SAVER_LIBS="$SAVER_LIBS -lXdpms"], [true],
1043                     -lXext -lX11)
1044     fi
1045   fi
1046
1047
1048   # if that succeeded, then we've really got it.
1049   if test "$have_dpms" = yes; then
1050     AC_DEFINE(HAVE_DPMS_EXTENSION)
1051   fi
1052
1053 elif test "$with_dpms" != no; then
1054   echo "error: must be yes or no: --with-dpms-ext=$with_dpms"
1055   exit 1
1056 fi
1057
1058
1059 ###############################################################################
1060 #
1061 #       Check for the XF86VMODE server extension.
1062 #
1063 ###############################################################################
1064
1065 have_xf86vmode=no
1066 with_xf86vmode_req=unspecified
1067 AC_ARG_WITH(xf86vmode-ext,
1068 [  --with-xf86vmode-ext    Include support for XFree86 virtual screens.],
1069   [with_xf86vmode="$withval"; with_xf86vmode_req="$withval"],
1070   [with_xf86vmode=yes])
1071
1072 HANDLE_X_PATH_ARG(with_xf86vmode, --with-xf86vmode-ext, xf86vmode)
1073
1074 if test "$with_xf86vmode" = yes; then
1075
1076   # first check for xf86vmode.h
1077   AC_CHECK_X_HEADER(X11/extensions/xf86vmode.h, [have_xf86vmode=yes])
1078
1079   # if that succeeded, then check for the -lXxf86vm
1080   if test "$have_xf86vmode" = yes; then
1081     have_xf86vmode=no
1082     AC_CHECK_X_LIB(Xxf86vm, XF86VidModeGetViewPort,
1083                   [have_xf86vmode=yes; SAVER_LIBS="$SAVER_LIBS -lXxf86vm"],
1084                    [true], -lXext -lX11)
1085   fi
1086
1087   # if that succeeded, then we've really got it.
1088   if test "$have_xf86vmode" = yes; then
1089     AC_DEFINE(HAVE_XF86VMODE)
1090   fi
1091
1092 elif test "$with_xf86vmode" != no; then
1093   echo "error: must be yes or no: --with-xf86vmode-ext=$with_xf86vmode"
1094   exit 1
1095 fi
1096
1097
1098 ###############################################################################
1099 #
1100 #       Check for HP XHPDisableReset and XHPEnableReset.
1101 #
1102 ###############################################################################
1103
1104 AC_EGREP_X_HEADER(XHPDisableReset, X11/XHPlib.h,
1105                   [AC_DEFINE(HAVE_XHPDISABLERESET)
1106                    SAVER_LIBS="-lXhp11 $SAVER_LIBS"])
1107
1108
1109 ###############################################################################
1110 #
1111 #       Check for /proc/interrupts.
1112 #
1113 ###############################################################################
1114
1115 have_proc_interrupts=no
1116 with_proc_interrupts_req=unspecified
1117 AC_ARG_WITH(proc-interrupts,
1118 [  --with-proc-interrupts  Include support for consulting the /proc/interrupts
1119                           file to notice keyboard activity.],
1120   [with_proc_interrupts="$withval"; with_proc_interrupts_req="$withval"],
1121   [with_proc_interrupts=yes])
1122
1123 if test "$with_proc_interrupts" = yes; then
1124
1125    AC_CACHE_CHECK([whether /proc/interrupts contains keyboard data],
1126     ac_cv_have_proc_interrupts,
1127     [ac_cv_have_proc_interrupts=no
1128      if grep keyboard /proc/interrupts >/dev/null 2>&1 ; then
1129        ac_cv_have_proc_interrupts=yes
1130      fi
1131     ])
1132    have_proc_interrupts=$ac_cv_have_proc_interrupts
1133
1134   if test "$have_proc_interrupts" = yes; then
1135     AC_DEFINE(HAVE_PROC_INTERRUPTS)
1136   fi
1137
1138 elif test "$with_proc_interrupts" != no; then
1139   echo "error: must be yes or no: --with-proc-interrupts=$with_proc_interrupts"
1140   exit 1
1141 fi
1142
1143
1144 ###############################################################################
1145 #
1146 #       The --enable-locking option
1147 #
1148 ###############################################################################
1149
1150 AC_ARG_ENABLE(locking,[
1151 Screen locking options:
1152
1153   --enable-locking        Compile in support for locking the display.
1154   --disable-locking       Do not allow locking at all.
1155 ],
1156   [enable_locking="$enableval"],[enable_locking=yes])
1157 if test "$enable_locking" = yes; then
1158   true
1159 elif test "$enable_locking" = no; then
1160   AC_DEFINE(NO_LOCKING)
1161 else
1162   echo "error: must be yes or no: --enable-locking=$enable_locking"
1163   exit 1
1164 fi
1165
1166
1167
1168 ###############################################################################
1169 #
1170 #       The --enable-vt-locking option
1171 #
1172 ###############################################################################
1173
1174 #ac_vt_lockswitch=no
1175 #AC_ARG_ENABLE(vt-locking,[
1176 #  --enable-vt-locking     Compile in support for locking Virtual Terminals.
1177 #                          This is the default if the system supports it, and
1178 #                          if locking support is included (--enable-locking.)
1179 #  --disable-vt-locking    Do not allow locking of VTs, even if locking is
1180 #                          enabled.],
1181 #  [enable_vt_locking="$enableval"],[enable_vt_locking=yes])
1182 #if test "$enable_vt_locking" = yes; then
1183 #
1184 #  AC_CACHE_CHECK([for the VT_LOCKSWITCH ioctl], ac_cv_vt_lockswitch,
1185 #   [AC_TRY_COMPILE([#include <fcntl.h>
1186 #                   #include <sys/ioctl.h>
1187 #                   #include <sys/vt.h>],
1188 #                  [int x = VT_LOCKSWITCH; int y = VT_UNLOCKSWITCH;],
1189 #                  [ac_cv_vt_lockswitch=yes],
1190 #                  [ac_cv_vt_lockswitch=no])])
1191 #  ac_vt_lockswitch=$ac_cv_vt_lockswitch
1192 #
1193 #elif test "$enable_vt_locking" = no; then
1194 #  true
1195 #else
1196 #  echo "error: must be yes or no: --enable-vt-locking=$enable_vt_locking"
1197 #  exit 1
1198 #fi
1199 #
1200 #if test "$ac_vt_lockswitch" = yes; then
1201 #  AC_DEFINE(HAVE_VT_LOCKSWITCH)
1202 #  # the VT_LOCKSWITCH ioctl can only be used when running as root.
1203 #  # #### but it doesn't work yet, so don't worry about that for now.
1204 ##  need_setuid=yes
1205 #fi
1206
1207
1208
1209 ###############################################################################
1210 #
1211 #       Check for PAM.
1212 #
1213 ###############################################################################
1214
1215 case "$host" in
1216   *-solaris*)
1217    # Solaris systems tend to come with PAM misconfigured.
1218    #  Don't build it by default, even if the headers exist.
1219    with_pam_default=no
1220    ;;
1221   *)
1222    # Default to building PAM support on all other systems, if it exists.
1223    with_pam_default=yes
1224   ;;
1225 esac
1226
1227 have_pam=no
1228 with_pam_req=unspecified
1229
1230 AC_ARG_WITH(pam,
1231 [  --with-pam              Include support for PAM (Pluggable Auth Modules.)],
1232   [with_pam="$withval"; with_pam_req="$withval"],[with_pam=$with_pam_default])
1233
1234 HANDLE_X_PATH_ARG(with_pam, --with-pam, PAM)
1235
1236 if test "$enable_locking" = yes -a "$with_pam" = yes; then
1237   AC_CACHE_CHECK([for PAM], ac_cv_pam,
1238                  [AC_TRY_X_COMPILE([#include <security/pam_appl.h>],,
1239                                    [ac_cv_pam=yes],
1240                                    [ac_cv_pam=no])])
1241   if test "$ac_cv_pam" = yes ; then
1242     have_pam=yes
1243     AC_DEFINE(HAVE_PAM)
1244     PASSWD_LIBS="${PASSWD_LIBS} -lpam"
1245
1246     # libpam typically requires dlopen and dlsym.  On FreeBSD,
1247     # those are in libc.  On Linux and Solaris, they're in libdl.
1248     AC_CHECK_LIB(dl, dlopen, [PASSWD_LIBS="${PASSWD_LIBS} -ldl"])
1249
1250     AC_MSG_CHECKING(how to call pam_strerror)
1251     AC_CACHE_VAL(ac_cv_pam_strerror_args,
1252      [AC_TRY_COMPILE([#include <stdio.h>
1253                       #include <stdlib.h>
1254                       #include <security/pam_appl.h>],
1255                      [pam_handle_t *pamh = 0;
1256                       char *s = pam_strerror(pamh, PAM_SUCCESS);],
1257                      [ac_pam_strerror_args=2],
1258                      [AC_TRY_COMPILE([#include <stdio.h>
1259                                       #include <stdlib.h>
1260                                       #include <security/pam_appl.h>],
1261                                      [char *s =
1262                                        pam_strerror(PAM_SUCCESS);],
1263                                      [ac_pam_strerror_args=1],
1264                                      [ac_pam_strerror_args=0])])
1265       ac_cv_pam_strerror_args=$ac_pam_strerror_args])
1266     ac_pam_strerror_args=$ac_cv_pam_strerror_args
1267     if test "$ac_pam_strerror_args" = 1 ; then
1268       AC_MSG_RESULT(one argument)
1269     elif test "$ac_pam_strerror_args" = 2 ; then
1270       AC_DEFINE(PAM_STRERROR_TWO_ARGS)
1271       AC_MSG_RESULT(two arguments)
1272     else
1273       AC_MSG_RESULT(unknown)
1274     fi
1275   fi
1276 fi
1277
1278
1279 ###############################################################################
1280 #
1281 #       Check for Kerberos.
1282 #
1283 ###############################################################################
1284
1285 have_kerberos=no
1286 have_kerberos5=no
1287 with_kerberos_req=unspecified
1288
1289 AC_ARG_WITH(kerberos, 
1290 [  --with-kerberos         Include support for Kerberos authentication.],
1291   [with_kerberos="$withval"; with_kerberos_req="$withval"],[with_kerberos=yes])
1292
1293 HANDLE_X_PATH_ARG(with_kerberos, --with-kerberos, Kerberos)
1294
1295 if test "$enable_locking" = yes -a "$with_kerberos" = yes; then
1296   AC_CACHE_CHECK([for Kerberos 4], ac_cv_kerberos,
1297                  [AC_TRY_X_COMPILE([#include <krb.h>],,
1298                                    [ac_cv_kerberos=yes],
1299                                    [ac_cv_kerberos=no])])
1300   AC_CACHE_CHECK([for Kerberos 5], ac_cv_kerberos5,
1301                  [AC_TRY_X_COMPILE([#include <kerberosIV/krb.h>],,
1302                                    [ac_cv_kerberos5=yes],
1303                                    [ac_cv_kerberos5=no])])
1304
1305   if test "$ac_cv_kerberos" = yes ; then
1306     have_kerberos=yes
1307     AC_DEFINE(HAVE_KERBEROS)
1308   fi
1309
1310   if test "$ac_cv_kerberos5" = yes ; then
1311     have_kerberos=yes
1312     have_kerberos5=yes
1313     AC_DEFINE(HAVE_KERBEROS)
1314     AC_DEFINE(HAVE_KERBEROS5)
1315   fi
1316
1317   if test "$have_kerberos5" = yes ; then
1318     # from Matt Knopp <mhat@infocalypse.netlag.com>
1319     # (who got it from amu@mit.edu)
1320     PASSWD_LIBS="$PASSWD_LIBS -lkrb4 -ldes425 -lkrb5 -lk5crypto -lcrypt -lcom_err"
1321   elif test "$have_kerberos" = yes ; then
1322     # from Tim Showalter <tjs+@andrew.cmu.edu>
1323     PASSWD_LIBS="$PASSWD_LIBS -lkrb -ldes"
1324   fi
1325
1326   if test "$have_kerberos" = yes ; then
1327     AC_CHECK_FUNC(res_search,,
1328       AC_CHECK_LIB(resolv,res_search,PASSWD_LIBS="${PASSWD_LIBS} -lresolv",
1329         AC_MSG_WARN([Can't find DNS resolver libraries needed for Kerberos])
1330       ))
1331   fi
1332 fi
1333
1334
1335 ###############################################################################
1336 #
1337 #       Check for the nine billion variants of shadow passwords...
1338 #
1339 ###############################################################################
1340
1341 need_setuid=no
1342
1343 have_shadow=no
1344 with_shadow_req=unspecified
1345
1346 AC_ARG_WITH(shadow,
1347 [  --with-shadow           Include support for shadow password authentication.],
1348   [with_shadow="$withval"; with_shadow_req="$withval"],[with_shadow=yes])
1349
1350 HANDLE_X_PATH_ARG(with_shadow, --with-shadow, shadow password)
1351
1352 if test "$enable_locking" = no ; then
1353   with_shadow_req=no
1354   with_shadow=no
1355 fi
1356
1357
1358 ###############################################################################
1359 #
1360 #       Check for Sun "adjunct" passwords.
1361 #
1362 ###############################################################################
1363
1364 if test "$with_shadow" = yes ; then
1365   AC_CACHE_CHECK([for Sun-style shadow passwords], ac_cv_sun_adjunct,
1366                  [AC_TRY_X_COMPILE([#include <stdlib.h>
1367                                     #include <unistd.h>
1368                                     #include <sys/types.h>
1369                                     #include <sys/label.h>
1370                                     #include <sys/audit.h>
1371                                     #include <pwdadj.h>],
1372                       [struct passwd_adjunct *p = getpwanam("nobody");
1373                        const char *pw = p->pwa_passwd;],
1374                       [ac_cv_sun_adjunct=yes],
1375                       [ac_cv_sun_adjunct=no])])
1376   if test "$ac_cv_sun_adjunct" = yes; then
1377     have_shadow_adjunct=yes
1378     have_shadow=yes
1379     need_setuid=yes
1380   fi
1381 fi
1382
1383
1384 ###############################################################################
1385 #
1386 #       Check for DEC and SCO so-called "enhanced" security.
1387 #
1388 ###############################################################################
1389
1390 if test "$with_shadow" = yes ; then
1391   AC_CACHE_CHECK([for DEC-style shadow passwords], ac_cv_enhanced_passwd,
1392                  [AC_TRY_X_COMPILE([#include <stdlib.h>
1393                                     #include <unistd.h>
1394                                     #include <sys/types.h>
1395                                     #include <pwd.h>
1396                                     #include <sys/security.h>
1397                                     #include <prot.h>],
1398                       [struct pr_passwd *p;
1399                        const char *pw;
1400                        set_auth_parameters(0, 0);
1401                        check_auth_parameters();
1402                        p = getprpwnam("nobody");
1403                        pw = p->ufld.fd_encrypt;],
1404                       [ac_cv_enhanced_passwd=yes],
1405                       [ac_cv_enhanced_passwd=no])])
1406   if test $ac_cv_enhanced_passwd = yes; then
1407     have_shadow_enhanced=yes
1408     have_shadow=yes
1409     need_setuid=yes
1410
1411     # On SCO, getprpwnam() is in -lprot (which uses nap() from -lx)
1412     # (I'm told it needs -lcurses too, but I don't understand why.)
1413     # But on DEC, it's in -lsecurity.
1414     #
1415     AC_CHECK_LIB(prot, getprpwnam, 
1416                  [PASSWD_LIBS="$PASSWD_LIBS -lprot -lcurses -lx"],
1417                  [AC_CHECK_LIB(security, getprpwnam, 
1418                                [PASSWD_LIBS="$PASSWD_LIBS -lsecurity"])],
1419                  [-lx])
1420   fi
1421 fi
1422
1423 ###############################################################################
1424 #
1425 #       Check for HP's entry in the "Not Invented Here" Sweepstakes.
1426 #
1427 ###############################################################################
1428
1429 if test "$with_shadow" = yes ; then
1430   AC_CACHE_CHECK([for HP-style shadow passwords], ac_cv_hpux_passwd,
1431                  [AC_TRY_X_COMPILE([#include <stdlib.h>
1432                                     #include <unistd.h>
1433                                     #include <sys/types.h>
1434                                     #include <pwd.h>
1435                                     #include <hpsecurity.h>
1436                                     #include <prot.h>],
1437                       [struct s_passwd *p = getspwnam("nobody");
1438                        const char *pw = p->pw_passwd;],
1439                       [ac_cv_hpux_passwd=yes],
1440                       [ac_cv_hpux_passwd=no])])
1441   if test "$ac_cv_hpux_passwd" = yes; then
1442     have_shadow_hpux=yes
1443     have_shadow=yes
1444     need_setuid=yes
1445
1446     # on HPUX, bigcrypt is in -lsec
1447     AC_CHECK_LIB(sec, bigcrypt, [PASSWD_LIBS="$PASSWD_LIBS -lsec"])
1448   fi
1449 fi
1450
1451
1452 ###############################################################################
1453 #
1454 #       Check for FreeBSD-style shadow passwords.
1455 #
1456 #       On FreeBSD, getpwnam() and friends work just like on non-shadow-
1457 #       password systems -- except you only get stuff in the pw_passwd field
1458 #       if the running program is setuid.  So, guess that we've got this
1459 #       lossage to contend with if /etc/master.passwd exists, and default to
1460 #       a setuid installation.
1461 #
1462 ###############################################################################
1463
1464 if test "$with_shadow" = yes ; then
1465   AC_CACHE_CHECK([for FreeBSD-style shadow passwords], ac_cv_master_passwd,
1466                  [if test -f /etc/master.passwd ; then
1467                     ac_cv_master_passwd=yes
1468                   else
1469                     ac_cv_master_passwd=no
1470                   fi])
1471   if test "$ac_cv_master_passwd" = yes; then
1472     need_setuid=yes
1473   fi
1474 fi
1475
1476
1477 ###############################################################################
1478 #
1479 #       Check for traditional (ha!) shadow passwords.
1480 #
1481 ###############################################################################
1482
1483 if test "$with_shadow" = yes ; then
1484   AC_CACHE_CHECK([for generic shadow passwords], ac_cv_shadow,
1485                  [AC_TRY_X_COMPILE([#include <stdlib.h>
1486                                     #include <unistd.h>
1487                                     #include <sys/types.h>
1488                                     #include <pwd.h>
1489                                     #include <shadow.h>],
1490                       [struct spwd *p = getspnam("nobody");
1491                        const char *pw = p->sp_pwdp;],
1492                       [ac_cv_shadow=yes],
1493                       [ac_cv_shadow=no])])
1494   if test "$ac_cv_shadow" = yes; then
1495     have_shadow=yes
1496     need_setuid=yes
1497
1498     # On some systems (UnixWare 2.1), getspnam() is in -lgen instead of -lc.
1499     have_getspnam=no
1500     AC_CHECK_LIB(c, getspnam, [have_getspnam=yes])
1501     if test "$have_getspnam" = no ; then
1502       AC_CHECK_LIB(gen, getspnam,
1503                    [have_getspnam=yes; PASSWD_LIBS="$PASSWD_LIBS -lgen"])
1504     fi
1505   fi
1506 fi
1507
1508
1509 ###############################################################################
1510 #
1511 #       Check for other libraries needed for non-shadow passwords.
1512 #
1513 ###############################################################################
1514
1515 if test "$enable_locking" = yes ; then
1516
1517   # On some systems (UnixWare 2.1), crypt() is in -lcrypt instead of -lc.
1518   have_crypt=no
1519   AC_CHECK_LIB(c, crypt, [have_crypt=yes])
1520   if test "$have_crypt" = no ; then
1521     AC_CHECK_LIB(crypt, crypt,
1522                  [have_crypt=yes; PASSWD_LIBS="$PASSWD_LIBS -lcrypt"])
1523   fi
1524 fi
1525
1526
1527 # Most of the above shadow mechanisms will have set need_setuid to yes,
1528 # if they were found.  But, on some systems, we need setuid even when
1529 # using plain old vanilla passwords.
1530 #
1531 if test "$enable_locking" = yes ; then
1532   case "$host" in
1533     *-hpux* | *-aix* | *-netbsd* | *-freebsd* | *-openbsd* )
1534       need_setuid=yes
1535     ;;
1536   esac
1537 fi
1538
1539
1540 if test "$have_shadow_adjunct" = yes ; then
1541   AC_DEFINE(HAVE_ADJUNCT_PASSWD)
1542 elif test "$have_shadow_enhanced" = yes ; then
1543   AC_DEFINE(HAVE_ENHANCED_PASSWD)
1544 elif test "$have_shadow_hpux" = yes ; then
1545   AC_DEFINE(HAVE_HPUX_PASSWD)
1546 elif test "$have_shadow" = yes ; then
1547   AC_DEFINE(HAVE_SHADOW_PASSWD)
1548 fi
1549
1550
1551 ###############################################################################
1552 #
1553 #       Check for -lXm.
1554 #
1555 ###############################################################################
1556
1557 have_motif=no
1558 with_motif_req=unspecified
1559 AC_ARG_WITH(motif,[
1560 User interface options:
1561
1562   --with-motif            Use the Motif toolkit for the user interface.],
1563   [with_motif="$withval"; with_motif_req="$withval"],[with_motif=yes])
1564
1565 HANDLE_X_PATH_ARG(with_motif, --with-motif, Motif)
1566
1567 if test "$with_motif" != yes -a "$with_motif" != no ; then
1568   echo "error: must be yes or no: --with-motif=$with_motif"
1569   exit 1
1570 fi
1571
1572 if test "$with_motif" = yes; then
1573   have_motif=no
1574   AC_CHECK_X_HEADER(Xm/Xm.h,
1575                     [have_motif=yes
1576                      AC_DEFINE(HAVE_MOTIF)
1577                      MOTIF_LIBS="$MOTIF_LIBS -lXm"])
1578 fi
1579
1580
1581 if test "$have_motif" = yes; then
1582   AC_CHECK_X_HEADER(Xm/ComboBox.h, [AC_DEFINE(HAVE_XMCOMBOBOX)])
1583 fi
1584
1585
1586 ###############################################################################
1587 #
1588 #       Check for -lgtk (and Gnome stuff)
1589 #
1590 ###############################################################################
1591
1592 have_gtk=no
1593 with_gtk_req=unspecified
1594 AC_ARG_WITH(gtk,
1595 [  --with-gtk              Use the Gtk toolkit for the user interface.],
1596   [with_gtk="$withval"; with_gtk_req="$withval"],[with_gtk=yes])
1597
1598 # if --with-gtk=/directory/ was specified, remember that directory so that
1599 # we can also look for the `gtk-config' program in that directory.
1600 case "$with_gtk" in
1601   /*)
1602     gtk_dir="$with_gtk"
1603     ;;
1604   *)
1605     gtk_dir=""
1606     ;;
1607 esac
1608
1609 HANDLE_X_PATH_ARG(with_gtk, --with-gtk, Gtk)
1610
1611 if test "$with_gtk" != yes -a "$with_gtk" != no ; then
1612   echo "error: must be yes or no: --with-gtk=$with_gtk"
1613   exit 1
1614 fi
1615
1616 have_gnome=no
1617 with_gnome_req=unspecified
1618 AC_ARG_WITH(gnome,
1619 [  --with-gnome            Include support for the Gnome Control Center.],
1620   [with_gnome="$withval"; with_gnome_req="$withval"],[with_gnome=yes])
1621
1622 # if --with-gnome=/directory/ was specified, remember that directory so that
1623 # we can also look for the `gnome-config' program in that directory.
1624 case "$with_gnome" in
1625   /*)
1626     gnome_dir="$with_gnome"
1627     ;;
1628   *)
1629     gnome_dir=""
1630     ;;
1631 esac
1632
1633 HANDLE_X_PATH_ARG(with_gnome, --with-gnome, Gnome)
1634
1635 if test "$with_gnome" != yes -a "$with_gnome" != no ; then
1636   echo "error: must be yes or no: --with-gnome=$with_gnome"
1637   exit 1
1638 fi
1639
1640
1641 jurassic_gtk=no
1642 if test "$with_gtk" = yes; then
1643   have_gtk=no
1644   
1645   # if the user specified --with-gtk=/foo/ then look in /foo/bin/
1646   # for glib-config and gtk-config.
1647   #
1648   gtk_path="$PATH"
1649
1650   if test ! -z "$gtk_dir"; then
1651     # canonicalize slashes.
1652     gtk_dir=`echo "${gtk_dir}/bin" | sed 's@//*@/@g'`
1653     gtk_path="$gtk_dir:$gtk_path"
1654   fi
1655
1656   if test ! -z "gnome_dir"; then
1657     # canonicalize slashes.
1658     gnome_dir=`echo "${gnome_dir}/bin" | sed 's@//*@/@g'`
1659     gtk_path="$gnome_dir:$gtk_path"
1660   fi
1661
1662   AC_PATH_PROGS(glib_config,  glib12-config glib-config,,  $gtk_path)
1663   AC_PATH_PROGS(gtk_config,   gtk12-config  gtk-config,,   $gtk_path)
1664
1665   if test "$with_gnome" = yes; then
1666     AC_PATH_PROGS(gnome_config, gnome-config,, $gtk_path)
1667   fi
1668
1669   if test -n "$glib_config" -a  -n "gtk_config" ; then
1670     have_gtk=yes
1671     if test "$with_gnome" = yes -a -n "$gnome_config" ; then
1672       have_gnome=yes
1673     fi
1674   fi
1675
1676   if test "$have_gtk" = yes; then
1677     AC_CACHE_CHECK([Gtk version number], ac_cv_gtk_version_string,
1678                    [ac_cv_gtk_version_string=`$gtk_config --version`])
1679     ac_gtk_version_string=$ac_cv_gtk_version_string
1680     # M4 sucks!!
1681     changequote(X,Y)
1682     maj=`echo $ac_gtk_version_string | sed -n 's/\..*//p'`
1683     min=`echo $ac_gtk_version_string | sed -n 's/[^.]*\.\([^.]*\).*/\1/p'`
1684     changequote([,])
1685     ac_gtk_version=`echo "$maj * 1000 + $min" | bc`
1686     if test -z "$ac_gtk_version"; then
1687       ac_gtk_version=unknown
1688       ac_gtk_version_string=unknown
1689     fi
1690     if test "$ac_gtk_version" = "unknown" || test "$ac_gtk_version" -lt 1002
1691     then
1692       have_gtk=no
1693       have_gnome=no
1694       jurassic_gtk=yes
1695     fi
1696   fi
1697
1698   if test "$have_gtk" = yes; then
1699     AC_CACHE_CHECK([for Gtk includes], ac_cv_gtk_config_cflags,
1700                    [ac_cv_gtk_config_cflags=`$gtk_config --cflags`])
1701     AC_CACHE_CHECK([for Gtk libs], ac_cv_gtk_config_libs,
1702                    [ac_cv_gtk_config_libs=`$gtk_config --libs`])
1703   fi
1704   ac_gtk_config_cflags=$ac_cv_gtk_config_cflags
1705   ac_gtk_config_libs=$ac_cv_gtk_config_libs
1706
1707   # Check for Gnome Capplet support.
1708   #
1709   if test "$have_gnome" = yes -a "$have_gtk" = yes; then
1710     gnome_config_libs="capplet gnomeui"
1711     AC_MSG_CHECKING(for Gnome capplet includes)
1712     AC_CACHE_VAL(ac_cv_gnome_config_cflags,
1713       [if ( $gnome_config --cflags $gnome_config_libs 2>&1 >/dev/null | \
1714             grep Unknown >/dev/null ) ; then
1715          ac_cv_gnome_config_cflags=''
1716        else
1717          ac_cv_gnome_config_cflags=`$gnome_config --cflags $gnome_config_libs`
1718        fi])
1719     ac_gnome_config_cflags=$ac_cv_gnome_config_cflags
1720     if test "$ac_gnome_config_cflags" = "" ; then
1721       have_gnome=no
1722       AC_MSG_RESULT(no)
1723     else
1724       AC_MSG_RESULT($ac_gnome_config_cflags)
1725     fi
1726   fi
1727
1728   if test "$have_gnome" = yes -a "$have_gtk" = yes; then
1729     AC_MSG_CHECKING(for Gnome capplet libs)
1730     AC_CACHE_VAL(ac_cv_gnome_config_libs,
1731       [if ( $gnome_config --libs $gnome_config_libs 2>&1 >/dev/null |
1732             grep Unknown >/dev/null ) ; then
1733          ac_cv_gnome_config_libs=''
1734        else
1735          ac_cv_gnome_config_libs=`$gnome_config --libs $gnome_config_libs`
1736        fi])
1737     ac_gnome_config_libs=$ac_cv_gnome_config_libs
1738     if test "$ac_gnome_config_libs" = "" ; then
1739       have_gnome=no
1740       AC_MSG_RESULT(no)
1741     else
1742       AC_MSG_RESULT($ac_gnome_config_libs)
1743     fi
1744   fi
1745
1746   GNOME_DATADIR=""
1747   if test "$have_gnome" = yes -a "$have_gtk" = yes; then
1748     GNOME_DATADIR=`$gnome_config --datadir`
1749   fi
1750
1751
1752   # If we have Gnome, then override the gtk-config values with 
1753   # the gnome-config values.
1754   #
1755   if test "$have_gnome" = yes -a "$have_gtk" = yes; then
1756     ac_gtk_config_cflags=$ac_gnome_config_cflags
1757     ac_gtk_config_libs=$ac_gnome_config_libs
1758     AC_DEFINE(HAVE_CRAPPLET)
1759   fi
1760
1761
1762   if test "$have_gtk" = yes; then
1763     INCLUDES="$INCLUDES $ac_gtk_config_cflags"
1764     GTK_LIBS="$GTK_LIBS $ac_gtk_config_libs"
1765     AC_DEFINE(HAVE_GTK)
1766   fi
1767
1768 fi
1769
1770
1771 ###############################################################################
1772 #
1773 #       Checking whether Motif is really Lesstif.
1774 #
1775 ###############################################################################
1776
1777 have_lesstif=no
1778 if test "$have_motif" = yes ; then
1779   AC_CACHE_CHECK([whether Motif is really LessTif], 
1780                  ac_cv_have_lesstif,
1781                  [AC_TRY_X_COMPILE([#include <Xm/Xm.h>],
1782                                    [long vers = LesstifVersion;],
1783                                    [ac_cv_have_lesstif=yes],
1784                                    [ac_cv_have_lesstif=no])])
1785   have_lesstif=$ac_cv_have_lesstif
1786 fi
1787
1788
1789 lesstif_version=unknown
1790 lesstif_version_string=unknown
1791
1792 if test "$have_lesstif" = yes ; then
1793   ltv=unknown
1794   echo unknown > conftest-lt
1795   AC_CACHE_CHECK([LessTif version number],
1796                  ac_cv_lesstif_version_string,
1797       [AC_TRY_X_RUN([#include <stdio.h>
1798                      #include <Xm/Xm.h>
1799                      int main() {
1800                        FILE *f = fopen("conftest-lt", "w");
1801                        if (!f) exit(1);
1802                        fprintf(f, "%d %d.%d\n", LesstifVersion,
1803                           LESSTIF_VERSION, LESSTIF_REVISION);
1804                        fclose(f);
1805                        exit(0);
1806                      }],
1807                     [ltv=`cat conftest-lt`
1808                      ac_cv_lesstif_version=`echo $ltv | sed 's/ .*//'`
1809                      ac_cv_lesstif_version_string=`echo $ltv | sed 's/.* //'`],
1810                     [ac_cv_lesstif_version=unknown
1811                      ac_cv_lesstif_version_string=unknown],
1812                     [ac_cv_lesstif_version=unknown
1813                      ac_cv_lesstif_version_string=unknown])])
1814   rm -f conftest-lt
1815   lesstif_version=$ac_cv_lesstif_version
1816   lesstif_version_string=$ac_cv_lesstif_version_string
1817
1818 fi
1819
1820
1821 if test "$have_motif" = yes ; then
1822   mtv=unknown
1823   echo unknown > conftest-mt
1824   AC_CACHE_CHECK([Motif version number],
1825                  ac_cv_motif_version_string,
1826       [AC_TRY_X_RUN([#include <stdio.h>
1827                      #include <Xm/Xm.h>
1828                      int main() {
1829                        FILE *f = fopen("conftest-mt", "w");
1830                        if (!f) exit(1);
1831                        fprintf(f, "%d %d.%d\n", XmVersion,
1832                           XmVERSION, XmREVISION);
1833                        fclose(f);
1834                        exit(0);
1835                      }],
1836                     [mtv=`cat conftest-mt`
1837                      ac_cv_motif_version=`echo $mtv | sed 's/ .*//'`
1838                      ac_cv_motif_version_string=`echo $mtv | sed 's/.* //'`],
1839                     [ac_cv_motif_version=unknown
1840                      ac_cv_motif_version_string=unknown],
1841                     [ac_cv_motif_version=unknown
1842                      ac_cv_motif_version_string=unknown])])
1843   rm -f conftest-mt
1844   motif_version=$ac_cv_motif_version
1845   motif_version_string=$ac_cv_motif_version_string
1846
1847 fi
1848
1849
1850 ###############################################################################
1851 #
1852 #       Checking whether Motif requires -lXpm.
1853 #
1854 #       If this is Motif 2.x, and we have XPM, then link against XPM as well.
1855 #       The deal is, Motif 2.x requires XPM -- but it's a compilation option
1856 #       of the library whether to build the XPM code into libXm, or whether
1857 #       to rely on an external libXm.  So the only way to tell whether XPM is
1858 #       a link-time requirement is to examine libXm.a, which is very
1859 #       difficult to do in an autoconf script.  So... if it's Motif 2.x, we
1860 #       always link against XPM if the XPM lib exists (and this will be a
1861 #       no-op if libXm happens to already have the XPM code in it.)
1862 #
1863 ###############################################################################
1864
1865 motif_requires_xpm=no
1866 if test "$have_motif" = yes ; then
1867    AC_MSG_CHECKING(whether Motif requires XPM)
1868    if test "$motif_version" = "unknown" || test "$motif_version" -ge 2000
1869    then
1870      motif_requires_xpm=yes
1871      AC_MSG_RESULT(maybe)
1872    else
1873      AC_MSG_RESULT(no)
1874    fi
1875 fi
1876
1877
1878 ###############################################################################
1879 #
1880 #       Checking whether Motif requires -lXp.
1881 #
1882 #       Some versions of Motif (2.1.0, at least) require -lXp, the "X Printing
1883 #       Extension".   Why this extension isn't in -lXext with all the others,
1884 #       I have no idea.
1885 #
1886 ###############################################################################
1887
1888 have_xp_ext=no
1889 if test "$have_motif" = yes ; then
1890    have_xp_ext=no
1891    AC_CHECK_X_LIB(Xp, XpQueryExtension,
1892                   [have_xp_ext=yes; MOTIF_LIBS="$MOTIF_LIBS -lXp"],
1893                   [true], -lX11 -lXext -lm)
1894 fi
1895
1896
1897 ###############################################################################
1898 #
1899 #       Checking whether Motif requires -lXintl (for _Xsetlocale.)
1900 #
1901 ###############################################################################
1902
1903 have_xintl=no
1904 if test "$have_motif" = yes ; then
1905   AC_CHECK_X_LIB(Xintl, _Xsetlocale, [have_xintl=yes], [have_xintl=no],
1906                  -lX11 -lXext -lm)
1907   if test "$have_xintl" = yes; then
1908     MOTIF_LIBS="$MOTIF_LIBS -lXintl"
1909   fi
1910 fi
1911
1912
1913 ###############################################################################
1914 #
1915 #       Check for -lGL or -lMesaGL.
1916 #
1917 ###############################################################################
1918
1919 have_gl=no
1920 ac_have_mesa_gl=no
1921 with_gl_req=unspecified
1922 gl_halfassed=no
1923 AC_ARG_WITH(gl,[
1924 Graphics options:
1925
1926   --with-gl               Build those demos which depend on OpenGL.],
1927   [with_gl="$withval"; with_gl_req="$withval"],[with_gl=yes])
1928
1929 HANDLE_X_PATH_ARG(with_gl, --with-gl, GL)
1930
1931 ac_mesagl_version=unknown
1932 ac_mesagl_version_string=unknown
1933
1934 if test "$with_gl" = yes; then
1935   AC_CHECK_X_HEADER(GL/gl.h, have_gl=yes, have_gl=no)
1936   if test "$have_gl" = yes ; then
1937     AC_CHECK_X_HEADER(GL/glx.h, have_gl=yes, have_gl=no)
1938   fi
1939
1940   # If we have the headers, try and figure out which vendor it's from.
1941   #
1942   if test "$have_gl" = yes ; then
1943
1944     # We need to know whether it's MesaGL so that we know which libraries
1945     # to link against.
1946     #
1947     AC_CACHE_CHECK([whether GL is really MesaGL], ac_cv_have_mesa_gl,
1948       [ac_cv_have_mesa_gl=no
1949        AC_EGREP_X_HEADER(Mesa, GL/glx.h, [ac_cv_have_mesa_gl=yes])
1950       ])
1951     ac_have_mesa_gl=$ac_cv_have_mesa_gl
1952  
1953
1954     gl_lib_1=""
1955     GL_LIBS=""
1956
1957
1958     # Some versions of MesaGL are compiled to require -lpthread.
1959     # So if the Mesa headers exist, and -lpthread exists, then always
1960     # link -lpthread after the Mesa libs (be they named -lGL or -lMesaGL.)
1961     #
1962     if test "$ac_have_mesa_gl" = yes; then
1963       AC_CHECK_LIB(pthread, pthread_create, [GL_LIBS="-lpthread"], [],)
1964     fi
1965
1966
1967     # If we have Mesa headers, check to see if we can link against -lMesaGL.
1968     # If we don't have Mesa headers, or we don't have -lMesaGL, try -lGL.
1969     # Else, warn that GL is busted.  (We have the headers, but no libs.)
1970     #
1971
1972     if test "$ac_have_mesa_gl" = yes ; then
1973       AC_CHECK_X_LIB(MesaGL, glXCreateContext, 
1974                      [gl_lib_1="MesaGL"
1975                       GL_LIBS="-lMesaGL -lMesaGLU $GL_LIBS"],
1976                      [], -lMesaGLU $GL_LIBS -lX11 -lXext -lm)
1977     fi
1978
1979     if test "$gl_lib_1" = "" ; then
1980       AC_CHECK_X_LIB(GL, glXCreateContext, 
1981                      [gl_lib_1="GL"
1982                       GL_LIBS="-lGL -lGLU $GL_LIBS"],
1983                      [], -lGLU $GL_LIBS -lX11 -lXext -lm)
1984     fi
1985
1986     if test "$gl_lib_1" = "" ; then
1987       # we have headers, but no libs -- bail.
1988       have_gl=no
1989       ac_have_mesa_gl=no
1990       gl_halfassed=yes
1991     else
1992       # linking works -- we can build the GL hacks.
1993       AC_DEFINE(HAVE_GL)
1994       if test "$ac_have_mesa_gl" = yes ; then
1995         AC_DEFINE(HAVE_MESA_GL)
1996       fi
1997     fi
1998   fi
1999
2000
2001   # Now that we know we have GL headers and libs, do some more GL testing.
2002   #
2003
2004   if test "$have_gl" = yes ; then
2005     # If it's MesaGL, we'd like to issue a warning if the version number
2006     # is less than or equal to 2.6, because that version had a security bug.
2007     #
2008     if test "$ac_have_mesa_gl" = yes; then
2009
2010       AC_CACHE_CHECK([MesaGL version number], ac_cv_mesagl_version_string,
2011         [cat > conftest.$ac_ext <<EOF
2012 #line __oline__ "configure"
2013 #include "confdefs.h"
2014 #include <GL/gl.h>
2015 configure: MESA_MAJOR_VERSION MESA_MINOR_VERSION
2016 EOF
2017
2018          ac_save_CPPFLAGS="$CPPFLAGS"
2019          if test \! -z "$includedir" ; then 
2020            CPPFLAGS="$CPPFLAGS -I$includedir"
2021          fi
2022          CPPFLAGS="$CPPFLAGS $X_CFLAGS"
2023
2024           # M4 sucks!!
2025          changequote(X,Y)
2026          mglv=`(eval "$ac_cpp conftest.$ac_ext") 2>&AC_FD_CC | sed -n \
2027               's/^configure:.*\([0-9][0-9]*\).*\([0-9][0-9]*\).*$/\1.\2/p'`
2028          changequote([,])
2029
2030          rm -f conftest.$ac_ext
2031
2032          CPPFLAGS="$ac_save_CPPFLAGS"
2033
2034          if test "$mglv" = ""; then
2035            ac_mesagl_version=unknown
2036            ac_mesagl_version_string=unknown
2037          else
2038            ac_mesagl_version_string=$mglv
2039            maj=`echo $mglv | sed -n 's/\..*//p'`
2040            min=`echo $mglv | sed -n 's/.*\.//p'`
2041            ac_mesagl_version=`echo "$maj * 1000 + $min" | bc`
2042            if test -z "$ac_mesagl_version"; then
2043              ac_mesagl_version=unknown
2044              ac_mesagl_version_string=unknown
2045            fi
2046          fi
2047          ac_cv_mesagl_version=$ac_mesagl_version
2048          ac_cv_mesagl_version_string=$ac_mesagl_version_string
2049       ])
2050       ac_mesagl_version=$ac_cv_mesagl_version
2051       ac_mesagl_version_string=$ac_cv_mesagl_version_string
2052     fi
2053
2054
2055     # Check for OpenGL 1.1 features.
2056     #
2057     AC_CHECK_X_LIB($gl_lib_1, glBindTexture, [AC_DEFINE(HAVE_GLBINDTEXTURE)],
2058                    [true], $GL_LIBS -lX11 -lXext -lm)
2059   fi
2060
2061 elif test "$with_gl" != no; then
2062   echo "error: must be yes or no: --with-gl=$with_gl"
2063   exit 1
2064 fi
2065
2066
2067 ###############################################################################
2068 #
2069 #       Check for -lgle.
2070 #
2071 ###############################################################################
2072
2073 have_gle=no
2074 with_gle_req=unspecified
2075 gle_halfassed=no
2076 AC_ARG_WITH(gle,
2077 [  --with-gle              Build those demos which depend on GLE
2078                           (the OpenGL "extrusion" library.)],
2079   [with_gle="$withval"; with_gle_req="$withval"],[with_gle=yes])
2080
2081 HANDLE_X_PATH_ARG(with_gle, --with-gle, GLE)
2082
2083 GLE_LIBS=""
2084
2085 if test "$with_gle" = yes; then
2086
2087   AC_CHECK_X_HEADER(GL/gle.h, have_gle3=yes, have_gle3=no)
2088   if test "$have_gle3" = yes ; then
2089     have_gle=yes;
2090   else
2091     AC_CHECK_X_HEADER(GL/gutil.h, have_gle=yes, have_gle=no)
2092     if test "$have_gle" = yes ; then
2093       AC_CHECK_X_HEADER(GL/tube.h, have_gle=yes, have_gle=no)
2094     fi
2095   fi
2096
2097   if test "$have_gle" = yes ; then
2098     have_gle=no
2099     gle_halfassed=yes
2100     AC_CHECK_X_LIB(gle, gleCreateGC, 
2101                    [have_gle=yes; gle_halfassed=no; GLE_LIBS="-lgle"],
2102                    [], $GL_LIBS -lX11 -lXext -lm)
2103   fi
2104   if test "$have_gle" = yes ; then
2105     have_gle=no
2106     gle_halfassed=yes
2107
2108     # sometimes the libmatrix stuff is included in libgle.  look there first.
2109 #
2110 # I don't get it.  For some reason, this test passes on SGI, as if
2111 # uview_direction_d() was in libgle -- but it's not, it's in libmatrix.
2112 # Yet the link is succeeding.  Why???
2113 #
2114 #    AC_CHECK_X_LIB(gle, uview_direction_d, 
2115 #                   [have_gle=yes; gle_halfassed=no],
2116 #                   [], $GL_LIBS -lX11 -lXext -lm)
2117
2118     # As of GLE 3 this is in libgle, and has changed name to uview_direction!
2119     # *sigh*
2120     if test "$have_gle3" = yes ; then
2121       AC_CHECK_X_LIB(gle, uview_direction, 
2122                      [have_gle=yes; gle_halfassed=no],
2123                     [], $GL_LIBS -lX11 -lXext -lm)
2124     fi
2125     # if it wasn't in libgle, then look in libmatrix.
2126     if test "$have_gle" = no ; then
2127       AC_CHECK_X_LIB(matrix, uview_direction_d, 
2128                      [have_gle=yes; gle_halfassed=no;
2129                       GLE_LIBS="$GLE_LIBS -lmatrix"],
2130                     [], $GL_LIBS -lX11 -lXext -lm)
2131     fi
2132   fi
2133
2134   if test "$have_gle" = yes ; then
2135     AC_DEFINE(HAVE_GLE)
2136     if test "$have_gle3" = yes ; then
2137       AC_DEFINE(HAVE_GLE3)
2138     fi
2139   fi
2140
2141 elif test "$with_gle" != no; then
2142   echo "error: must be yes or no: --with-gle=$with_gle"
2143   exit 1
2144
2145 fi
2146
2147
2148
2149 ###############################################################################
2150 #
2151 #       Check for -lXpm.
2152 #
2153 ###############################################################################
2154
2155 have_xpm=no
2156 with_xpm_req=unspecified
2157 AC_ARG_WITH(xpm,
2158 [  --with-xpm              Include support for XPM files in some demos.],
2159   [with_xpm="$withval"; with_xpm_req="$withval"],[with_xpm=yes])
2160
2161 HANDLE_X_PATH_ARG(with_xpm, --with-xpm, XPM)
2162
2163 if test "$with_xpm" = yes; then
2164   AC_CHECK_X_HEADER(X11/xpm.h,
2165                    [have_xpm=yes
2166                     AC_DEFINE(HAVE_XPM)
2167                     XPM_LIBS="-lXpm"])
2168 elif test "$with_xpm" != no; then
2169   echo "error: must be yes or no: --with-xpm=$with_xpm"
2170   exit 1
2171 fi
2172
2173 # See comment near $motif_requires_xpm, above.
2174 # Need to do this here, after both Motif and XPM have been checked for.
2175 #
2176 if test "$have_motif" = yes -a "$have_xpm" = yes ; then
2177   if test "$motif_requires_xpm" = yes ; then
2178     MOTIF_LIBS="$MOTIF_LIBS $XPM_LIBS"
2179   fi
2180 fi
2181
2182
2183 ###############################################################################
2184 #
2185 #       Check for the XSHM server extension.
2186 #
2187 ###############################################################################
2188
2189 have_xshm=no
2190 with_xshm_req=unspecified
2191 AC_ARG_WITH(xshm-ext,
2192 [  --with-xshm-ext         Include support for the XSHM extension.],
2193   [with_xshm="$withval"; with_xshm_req="$withval"],[with_xshm=yes])
2194
2195 HANDLE_X_PATH_ARG(with_xshm, --with-xshm-ext, XSHM)
2196
2197 if test "$with_xshm" = yes; then
2198
2199   # first check for Xshm.h.
2200   AC_CHECK_X_HEADER(X11/extensions/XShm.h, [have_xshm=yes])
2201
2202   # if that succeeded, then check for sys/ipc.h.
2203   if test "$have_xshm" = yes; then
2204     have_xshm=no
2205     AC_CHECK_X_HEADER(sys/ipc.h, [have_xshm=yes])
2206   fi
2207
2208   # if that succeeded, then check for sys/shm.h.
2209   if test "$have_xshm" = yes; then
2210     have_xshm=no
2211     AC_CHECK_X_HEADER(sys/shm.h, [have_xshm=yes])
2212   fi
2213
2214   # AIX is pathological, as usual: apparently it's normal for the Xshm headers
2215   # to exist, but the library code to not exist.  And even better, the library
2216   # code is in its own library: libXextSam.a.  So, if we're on AIX, and that
2217   # lib doesn't exist, give up.  (This lib gets added to X_EXTRA_LIBS, and
2218   # that's not quite right, but close enough.)
2219   #
2220   case "$host" in
2221     *-aix*)
2222       if [ `uname -v` -eq 3 ]; then
2223         have_xshm=no
2224         AC_CHECK_X_LIB(XextSam, XShmQueryExtension,
2225                        [have_xshm=yes; X_EXTRA_LIBS="$X_EXTRA_LIBS -lXextSam"],
2226                        [true], -lX11 -lXext -lm)
2227       fi
2228     ;;
2229   esac
2230
2231   # if that succeeded, then we've really got it.
2232   if test "$have_xshm" = yes; then
2233     AC_DEFINE(HAVE_XSHM_EXTENSION)
2234   fi
2235
2236 elif test "$with_xshm" != no; then
2237   echo "error: must be yes or no: --with-xshm-ext=$with_xshm"
2238   exit 1
2239 fi
2240
2241
2242 ###############################################################################
2243 #
2244 #       Check for the DOUBLE-BUFFER server extension.
2245 #
2246 ###############################################################################
2247
2248 have_xdbe=no
2249 with_xdbe_req=unspecified
2250 AC_ARG_WITH(xdbe-ext,
2251 [  --with-xdbe-ext         Include support for the DOUBLE-BUFFER extension.],
2252   [with_xdbe="$withval"; with_xdbe_req="$withval"],[with_xdbe=yes])
2253
2254 HANDLE_X_PATH_ARG(with_xdbe, --with-xdbe-ext, DOUBLE-BUFFER)
2255
2256 if test "$with_xdbe" = yes; then
2257
2258   AC_CHECK_X_HEADER(X11/extensions/Xdbe.h, [have_xdbe=yes])
2259   if test "$have_xdbe" = yes; then
2260     AC_DEFINE(HAVE_DOUBLE_BUFFER_EXTENSION)    
2261   fi
2262
2263 elif test "$with_xdbe" != no; then
2264   echo "error: must be yes or no: --with-xdbe-ext=$with_xshm"
2265   exit 1
2266 fi
2267
2268
2269 ###############################################################################
2270 #
2271 #       Check for the SGI XReadDisplay server extension.
2272 #
2273 #       Note: this has to be down here, rather than up with the other server
2274 #       extension tests, so that the output of `configure --help' is in the
2275 #       right order.  Arrgh!
2276 #
2277 ###############################################################################
2278
2279 have_readdisplay=no
2280 with_readdisplay_req=unspecified
2281 AC_ARG_WITH(readdisplay,
2282 [  --with-readdisplay      Include support for the XReadDisplay extension.],
2283   [with_readdisplay="$withval"; with_readdisplay_req="$withval"],
2284   [with_readdisplay=yes])
2285
2286 HANDLE_X_PATH_ARG(with_readdisplay, --with-readdisplay, XReadDisplay)
2287
2288 if test "$with_readdisplay" = yes; then
2289   AC_CHECK_X_HEADER(X11/extensions/readdisplay.h,
2290                     AC_DEFINE(HAVE_READ_DISPLAY_EXTENSION))
2291 elif test "$with_readdisplay" != no; then
2292   echo "error: must be yes or no: --with-readdisplay=$with_readdisplay"
2293   exit 1
2294 fi
2295
2296
2297 ###############################################################################
2298 #
2299 #       Check for the SGI Iris Video Library.
2300 #
2301 ###############################################################################
2302
2303 have_sgivideo=no
2304 with_sgivideo_req=unspecified
2305 AC_ARG_WITH(sgivideo,
2306 [  --with-sgivideo         Include support for SGI's Iris Video Library.],
2307   [with_sgivideo="$withval"; with_sgivideo_req="$withval"],
2308   [with_sgivideo=yes])
2309
2310 HANDLE_X_PATH_ARG(with_sgivideo, --with-sgivideo, Iris Video)
2311
2312 if test "$with_sgivideo" = yes; then
2313   AC_CHECK_X_HEADER(dmedia/vl.h, have_sgivideo=yes)
2314   if test "$have_sgivideo" = yes; then
2315     have_sgivideo=no
2316     AC_CHECK_LIB(vl, vlOpenVideo, [have_sgivideo=yes])
2317     if test "$have_sgivideo" = yes; then
2318       SGI_VIDEO_OBJS="$(UTILS_BIN)/sgivideo.o"
2319       SGI_VIDEO_LIBS="-lvl"
2320       AC_DEFINE(HAVE_SGI_VIDEO)
2321     fi
2322   fi
2323 elif test "$with_sgivideo" != no; then
2324   echo "error: must be yes or no: --with-sgivideo=$with_sgivideo"
2325   exit 1
2326 fi
2327
2328
2329 ###############################################################################
2330 #
2331 #       Check for a program to generate random text.
2332 #
2333 #       Zippy is funnier than the idiocy generally spat out by `fortune',
2334 #       so try to find that, by invoking Emacs and asking it where its 
2335 #       libexec directory is ("yow" lives in there.)
2336 #
2337 #       If that doesn't work, see if fortune, zippy, or yow are on $PATH,
2338 #       and if so, use them.
2339 #
2340 #       If that doesn't work, look in /usr/games, and if it's there, use
2341 #       the full pathname.
2342 #
2343 ###############################################################################
2344
2345 with_zippy_req=""
2346 AC_ARG_WITH(zippy,[
2347   --with-zippy=PROGRAM    Some demos are able to run an external program and
2348                           display its text; this names the program to use by
2349                           default (though it can be overridden with X
2350                           resources.)  If you don't specify this, the default
2351                           is to use \"yow\" from the Emacs distribution (if you
2352                           have it) or else to use \"fortune\".
2353 ],
2354   [with_zippy_req="$withval"; with_zippy="$withval"],[with_zippy=yes])
2355
2356 if test "$with_zippy" = no || test "$with_zippy" = yes ; then
2357   with_zippy=""
2358   with_zippy_req=""
2359 fi
2360
2361 if test -n "$with_zippy_req" ; then
2362   ac_cv_zippy_program=""
2363   case "$with_zippy_req" in
2364     /*)
2365       AC_MSG_CHECKING([for $with_zippy_req])
2366       if test -x "$with_zippy_req" ; then
2367         AC_MSG_RESULT(yes)
2368       else
2369         AC_MSG_RESULT(no)
2370         with_zippy=""
2371       fi
2372     ;;
2373     *)
2374       # don't cache
2375       unset ac_cv_path_zip2
2376       AC_PATH_PROG(zip2, $with_zippy_req, [])
2377       if test "$zip2" = ""; then
2378         with_zippy=""
2379       fi
2380     ;;
2381   esac
2382   ac_cv_zippy_program="$with_zippy"
2383
2384 elif test -n "$ac_cv_zippy_program"; then
2385   AC_MSG_RESULT([checking for zippy... (cached) $ac_cv_zippy_program])
2386 fi
2387
2388 if test ! -n "$ac_cv_zippy_program"; then
2389
2390   AC_CHECK_PROGS(emacs_exe, emacs)
2391   AC_CHECK_PROGS(xemacs_exe, xemacs)
2392
2393   ac_cv_zippy_program=""
2394   eargs='-batch -q -nw --eval'
2395
2396   if test -n "$emacs_exe" ; then
2397     AC_MSG_CHECKING([for emacs yow])
2398     #
2399     # get emacs to tell us where the libexec directory is.
2400     #
2401     dir=`$emacs_exe $eargs '(princ (concat exec-directory "\n"))' \
2402          2>/dev/null | tail -1`
2403     dir=`echo "$dir" | sed 's@///*@/@g;s@/$@@'`
2404     #
2405     # try running libexec/yow and see if it exits without error.
2406     #
2407     if test x"$dir" != x -a -x "$dir/yow" ; then
2408       if $dir/yow >&- 2>&- ; then
2409         ac_cv_zippy_program="$dir/yow"
2410         AC_MSG_RESULT($ac_cv_zippy_program)
2411       else
2412         AC_MSG_RESULT(no)
2413       fi
2414     fi
2415   fi
2416
2417   if test -z "$ac_cv_zippy_program" ; then
2418     AC_MSG_CHECKING([for xemacs yow])
2419     if test -n "$xemacs_exe" ; then
2420       #
2421       # get xemacs to tell us where the libexec directory is.
2422       #
2423       dir=`$xemacs_exe $eargs '(princ (concat exec-directory "\n"))' \
2424            2>/dev/null | tail -1`
2425       dir=`echo "$dir" | sed 's@///*@/@g;s@/$@@'`
2426       #
2427       # try running libexec/yow and see if it exits without error.
2428       #
2429       if test x"$dir" != x -a -x "$dir/yow" ; then
2430         if $dir/yow >&- 2>&- ; then
2431           ac_cv_zippy_program="$dir/yow"
2432           AC_MSG_RESULT($ac_cv_zippy_program)
2433         else
2434           #
2435           # in some xemacs installations, the pathname of the yow.lines file
2436           # isn't hardcoded into the yow executable, and must be passed on 
2437           # the command line.  See if it's in libexec/../etc/.
2438
2439           # M4 sucks!!
2440           changequote(X,Y)
2441           dir_up=`echo "$dir" | sed 's@/[^/]*$@@'`
2442           changequote([,])
2443
2444           yowlines="$dir_up/etc/yow.lines"
2445           if $dir/yow -f $yowlines >&- 2>&- ; then
2446             ac_cv_zippy_program="$dir/yow -f $yowlines"
2447             AC_MSG_RESULT($ac_cv_zippy_program)
2448           else
2449             #
2450             # In newer XEmacs releases, yow.lines is in a different place,
2451             # and the easiest way to get it is by calling the new function
2452             # `locate-data-file'.
2453             #
2454             yowlines=`$xemacs_exe $eargs \
2455               '(princ (concat (locate-data-file "yow.lines") "\n"))' \
2456               2>/dev/null | tail -1`
2457             if $dir/yow -f $yowlines >&- 2>&- ; then
2458               ac_cv_zippy_program="$dir/yow -f $yowlines"
2459               AC_MSG_RESULT($ac_cv_zippy_program)
2460             else
2461               AC_MSG_RESULT(no)
2462             fi
2463           fi
2464         fi
2465       fi
2466     fi
2467   fi
2468
2469   # if that didn't work, try for some other programs...
2470   if test -z "$ac_cv_zippy_program" ; then
2471     fortune=''
2472     AC_CHECK_PROGS(fortune, [fortune zippy yow])
2473     # if that didn't work, try for those programs in /usr/games...
2474     if test -z "$fortune" ; then
2475       AC_PATH_PROGS(fortune, [fortune zippy yow], fortune,
2476                     /usr/games:/usr/local/games:$PATH)
2477     fi
2478   fi
2479 fi
2480
2481 if test -z "$ac_cv_zippy_program" ; then
2482   ac_cv_zippy_program=fortune
2483 fi
2484
2485 AC_DEFINE_UNQUOTED(ZIPPY_PROGRAM, "$ac_cv_zippy_program")
2486
2487
2488 ###############################################################################
2489 #
2490 #       Done testing.  Now, set up the various -I and -L variables,
2491 #       and decide which GUI program to build by default.
2492 #
2493 ###############################################################################
2494
2495 DEPEND=makedepend
2496 DEPEND_FLAGS=
2497 DEPEND_DEFINES=
2498
2499
2500 if test \! -z "$includedir" ; then 
2501   INCLUDES="$INCLUDES -I$includedir"
2502 fi
2503
2504 if test \! -z "$libdir" ; then
2505   LDFLAGS="$LDFLAGS -L$libdir"
2506 fi
2507
2508
2509 PREFERRED_DEMO_PROGRAM=xscreensaver-demo-Xm
2510 ALL_DEMO_PROGRAMS=
2511 if test "$have_motif" = yes; then
2512   PREFERRED_DEMO_PROGRAM=xscreensaver-demo-Xm
2513   ALL_DEMO_PROGRAMS="$PREFERRED_DEMO_PROGRAM $ALL_DEMO_PROGRAMS"
2514 fi
2515 if test "$have_gtk" = yes; then
2516   PREFERRED_DEMO_PROGRAM=xscreensaver-demo-Gtk
2517   ALL_DEMO_PROGRAMS="$PREFERRED_DEMO_PROGRAM $ALL_DEMO_PROGRAMS"
2518 fi
2519
2520
2521 if test "$have_kerberos" = yes; then
2522   PASSWD_SRCS="$PASSWD_SRCS \$(KERBEROS_SRCS)"
2523   PASSWD_OBJS="$PASSWD_OBJS \$(KERBEROS_OBJS)"
2524 fi
2525 if test "$have_pam" = yes; then
2526   PASSWD_SRCS="$PASSWD_SRCS \$(PAM_SRCS)"
2527   PASSWD_OBJS="$PASSWD_OBJS \$(PAM_OBJS)"
2528   INSTALL_PAM="install-pam"
2529 fi
2530   PASSWD_SRCS="$PASSWD_SRCS \$(PWENT_SRCS)"
2531   PASSWD_OBJS="$PASSWD_OBJS \$(PWENT_OBJS)"
2532
2533
2534 if test "$enable_locking" = yes; then
2535   LOCK_SRCS='$(LOCK_SRCS_1) $(PASSWD_SRCS)'
2536   LOCK_OBJS='$(LOCK_OBJS_1) $(PASSWD_OBJS)'
2537 else
2538   LOCK_SRCS='$(NOLOCK_SRCS_1)'
2539   LOCK_OBJS='$(NOLOCK_OBJS_1)'
2540 fi
2541
2542 if test "$need_setuid" = yes; then
2543   NEED_SETUID=yes
2544   INSTALL_SETUID='$(INSTALL) $(SUID_FLAGS)'
2545 else
2546   NEED_SETUID=no
2547   INSTALL_SETUID='$(INSTALL_PROGRAM)'
2548 fi
2549
2550 tab='   '
2551 if test "$have_gl" = yes; then
2552   GL_EXES='$(GL_EXES)'
2553   GL_MEN='$(GL_MEN)'
2554   GL_KLUDGE="${tab}  "
2555 else
2556   GL_KLUDGE="-${tab}  "
2557 fi
2558
2559 if test "$have_gle" = yes; then
2560   GLE_EXES='$(GLE_EXES)'
2561   GLE_MEN='$(GLE_MEN)'
2562   GLE_KLUDGE="${tab}   "
2563 else
2564   GLE_KLUDGE="-${tab}   "
2565 fi
2566
2567
2568 ###############################################################################
2569 #
2570 #       Perform substitutions and write Makefiles.
2571 #
2572 ###############################################################################
2573
2574 AC_SUBST(INCLUDES)
2575
2576 AC_SUBST(PREFERRED_DEMO_PROGRAM)
2577 AC_SUBST(ALL_DEMO_PROGRAMS)
2578 AC_SUBST(SAVER_LIBS)
2579 AC_SUBST(MOTIF_LIBS)
2580 AC_SUBST(GTK_LIBS)
2581 AC_SUBST(HACK_LIBS)
2582 AC_SUBST(XPM_LIBS)
2583 AC_SUBST(GL_LIBS)
2584 AC_SUBST(GLE_LIBS)
2585 AC_SUBST(PASSWD_LIBS)
2586 AC_SUBST(INSTALL_SETUID)
2587 AC_SUBST(INSTALL_DIRS)
2588 AC_SUBST(NEED_SETUID)
2589 AC_SUBST(INSTALL_PAM)
2590 AC_SUBST(SGI_VIDEO_OBJS)
2591 AC_SUBST(SGI_VIDEO_LIBS)
2592
2593 AC_SUBST(PASSWD_SRCS)
2594 AC_SUBST(PASSWD_OBJS)
2595 AC_SUBST(XMU_SRCS)
2596 AC_SUBST(XMU_OBJS)
2597 AC_SUBST(SAVER_GL_SRCS)
2598 AC_SUBST(SAVER_GL_OBJS)
2599 AC_SUBST(SAVER_GL_LIBS)
2600 AC_SUBST(LOCK_SRCS)
2601 AC_SUBST(LOCK_OBJS)
2602 AC_SUBST(GL_EXES)
2603 AC_SUBST(GL_MEN)
2604 AC_SUBST(GL_KLUDGE)
2605 AC_SUBST(GLE_EXES)
2606 AC_SUBST(GLE_MEN)
2607 AC_SUBST(GLE_KLUDGE)
2608 AC_SUBST(HACKDIR)
2609 AC_SUBST(GNOME_DATADIR)
2610
2611 APPDEFAULTS=$ac_x_app_defaults
2612 AC_SUBST(APPDEFAULTS)
2613
2614 AC_SUBST(DEPEND)
2615 AC_SUBST(DEPEND_FLAGS)
2616 AC_SUBST(DEPEND_DEFINES)
2617 AC_SUBST(PERL)
2618
2619 AC_OUTPUT(Makefile
2620           utils/Makefile
2621           driver/Makefile
2622           hacks/Makefile
2623           hacks/glx/Makefile
2624           driver/XScreenSaver.ad)
2625
2626 ###############################################################################
2627 #
2628 #       Print some warnings at the end.
2629 #
2630 ###############################################################################
2631
2632 warn_prefix_1="    Warning:"
2633 warn_prefix_2="       Note:"
2634 warn_prefix="$warn_prefix_1"
2635
2636 warning=no
2637 warnsep='    #################################################################'
2638
2639 warnpre() {
2640   if test "$warning" = no ; then
2641     echo '' ; echo "$warnsep" ; echo ''
2642     warning=yes
2643   fi
2644 }
2645
2646 warn() {
2647   warnpre
2648   if test "$warning" = long ; then echo '' ; fi
2649   warning=yes
2650   rest="$@"
2651   echo "$warn_prefix $rest"
2652 }
2653
2654 warnL() {
2655   was=$warning
2656   warnpre
2657   warning=yes
2658   if test "$was" != no ; then echo '' ; fi
2659   rest="$@"
2660   echo "$warn_prefix $rest"
2661 }
2662
2663 warn2() {
2664   rest="$@"
2665   echo "             $rest"
2666   warning=long
2667 }
2668
2669 note() {
2670   warn_prefix="$warn_prefix_2"
2671   warn $@
2672   warn_prefix="$warn_prefix_1"
2673 }
2674
2675 noteL() {
2676   warn_prefix="$warn_prefix_2"
2677   warnL $@
2678   warn_prefix="$warn_prefix_1"
2679 }
2680
2681
2682 if test "$with_sgi_req" = yes -a "$have_sgi" = no ; then
2683   warn 'The SGI saver extension was requested, but was not found.'
2684 fi
2685
2686 if test "$with_mit_req" = yes -a "$have_mit" = no ; then
2687   warn 'The MIT saver extension was requested, but was not found.'
2688 fi
2689
2690 if test "$with_xidle_req" = yes -a "$have_xidle" = no ; then
2691   warn 'The XIdle extension was requested, but was not found.'
2692 fi
2693
2694 if test "$with_xshm_req" = yes -a "$have_xshm" = no ; then
2695   warn 'The XSHM extension was requested, but was not found.'
2696 fi
2697
2698 if test "$with_xdbe_req" = yes -a "$have_xdbe" = no ; then
2699   warn 'The DOUBLE-BUFFER extension was requested, but was not found.'
2700 fi
2701
2702 if test "$with_sgivc_req" = yes -a "$have_sgivc" = no ; then
2703   warn 'The SGI-VIDEO-CONTROL extension was requested, but was not found.'
2704 fi
2705
2706 if test "$with_dpms_req" = yes -a "$have_dpms" = no ; then
2707   warn 'The DPMS extension was requested, but was not found.'
2708 fi
2709
2710 if test "$with_xf86vmode_req" = yes -a "$have_xf86vmode" = no ; then
2711   warn 'The XF86VMODE extension was requested, but was not found.'
2712 fi
2713
2714 if test "$with_proc_interrupts_req" = yes -a "$have_proc_interrupts" = no; then
2715   warn "Checking of /proc/interrupts was requested, but it's bogus."
2716 fi
2717
2718
2719 if test "$have_motif" = no -a "$have_gtk" = no; then
2720   warnL "Neither Motif nor Gtk seem to be available;"
2721   warn2 "the \`xscreensaver-demo' program requires one of these."
2722
2723 elif test "$with_motif_req" = yes -a "$have_motif" = no ; then
2724   warnL "Use of Motif was requested, but it wasn't found;"
2725   warn2 "Gtk will be used instead."
2726
2727 elif test "$jurassic_gtk" = yes ; then
2728
2729   pref_gtk=1.2
2730
2731   v="$ac_gtk_version_string"
2732   if test "$with_gtk_req" = yes -a "$ac_gtk_version" = "unknown" ; then
2733     warnL "Use of Gtk was requested, but its version number is unknown;"
2734   elif test "$with_gtk_req" = yes ; then
2735     warnL "Use of Gtk was requested, but it is version $v;"
2736   else
2737     warnL "Gtk was found on this system, but it is version $v;"
2738   fi
2739
2740   warn2 "Gtk $pref_gtk or newer is required.  Motif will be used instead."
2741
2742 elif test "$with_gtk_req" = yes -a "$have_gtk" = no ; then
2743   warnL "Use of Gtk was requested, but it wasn't found;"
2744   warn2 "Motif will be used instead."
2745
2746 fi
2747
2748
2749 if test "$with_gnome_req" = yes -a "$have_gnome" = no ; then
2750   warn  'Use of the Gnome Control Panel was requested, but the necessary'
2751   warn2 'headers and/or libraries were not found.'
2752 fi
2753
2754
2755 if test "$have_motif" = yes -a "$have_lesstif" = yes ; then
2756
2757   preferred_lesstif=0.86
2758
2759   if test "$lesstif_version" = unknown; then
2760     warnL "Unable to determine the LessTif version number!"
2761     warn2 "Make sure you are using version $preferred_lesstif or newer."
2762     warn2 "See <http://www.lesstif.org/>."
2763
2764   elif test \! $lesstif_version -gt 82; then
2765     warnL "LessTif version $lesstif_version_string is being used."
2766     warn2 "LessTif versions 0.82 and earlier are too buggy to"
2767     warn2 "use with XScreenSaver; it is strongly recommended"
2768     warn2 "that you upgrade to at least version $preferred_lesstif!"
2769     warn2 "See <http://www.lesstif.org/>."
2770   fi
2771 fi
2772
2773
2774
2775 if test "$have_xpm" = no ; then
2776   if test "$with_xpm_req" = yes ; then
2777     warnL 'Use of XPM was requested, but it was not found.'
2778   elif test "$with_xpm_req" = no ; then
2779     noteL 'The XPM library is not being used.'
2780   else
2781     noteL 'The XPM library was not found.'
2782   fi
2783
2784   echo ''
2785   warn2 'Some of the demos will not be as colorful as they'
2786   warn2 'could be.  You might want to consider installing XPM'
2787   warn2 'and re-running configure.  (Remember to delete the'
2788   warn2 'config.cache file first.)  You can find XPM at most'
2789   warn2 'X11 archive sites, such as <http://sunsite.unc.edu/>.'
2790 fi
2791
2792
2793 if test "$have_gl" = yes -a "$ac_have_mesa_gl" = yes ; then
2794   preferred_mesagl=3.0
2795
2796   if test "$ac_mesagl_version" = unknown; then
2797     warnL "Unable to determine the MesaGL version number!"
2798     warn2 "Make sure you are using version $preferred_mesagl or newer."
2799
2800   elif test \! "$ac_mesagl_version" -gt 2006; then
2801     warnL "MesaGL version $ac_mesagl_version_string is being used."
2802     warn2 "MesaGL versions 2.6 and earlier have a security bug."
2803     warn2 "It is strongly recommended that you upgrade to at"
2804     warn2 "least version $preferred_mesagl."
2805   fi
2806 fi
2807
2808 if test "$have_gl" = no ; then
2809   if test "$with_gl_req" = yes ; then
2810     warnL 'Use of GL was requested, but it was not found.'
2811   elif test "$with_gl_req" = no ; then
2812     noteL 'The OpenGL 3D library is not being used.'
2813   else
2814     noteL 'The OpenGL 3D library was not found.'
2815   fi
2816
2817   if test "$gl_halfassed" = yes ; then
2818     echo ''
2819     warn2 'More specifically, we found the headers, but not the'
2820     warn2 'libraries; so either GL is half-installed on this'
2821     warn2 "system, or something else went wrong.  The \`config.log'"
2822     warn2 'file might contain some clues.'
2823   fi
2824
2825   echo ''
2826   warn2 'Those demos which use 3D will not be built or installed.'
2827   warn2 'You might want to consider installing OpenGL and'
2828   warn2 're-running configure.  (Remember to delete the'
2829   warn2 "config.cache file first.)  If your vendor doesn't ship"
2830   warn2 'their own implementation of OpenGL, you can get a free'
2831   warn2 'version at <http://www.mesa3d.org/>.  For general OpenGL'
2832   warn2 'info, see <http://www.opengl.org/>.'
2833
2834 fi
2835
2836
2837 if test "$have_gl" = yes -a "$have_gle" = no ; then
2838   if test "$with_gle_req" = yes ; then
2839     noteL 'Use of the GLE (GL Extrusion) library was requested, but'
2840     warn2 'it was not found (though the OpenGL library was found, and'
2841     warn2 'is being used.)'
2842   elif test "$with_gle_req" = no ; then
2843     noteL 'The OpenGL Library is being used, but the GLE (GL Extrusion)'
2844     warn2 'library is not.'
2845   else
2846     noteL 'The OpenGL Library was found, but the GLE (GL Extrusion)'
2847     warn2 'was not.'
2848   fi
2849
2850   if test "$gle_halfassed" = yes ; then
2851     echo ''
2852     warn2 'More specifically, we found the headers, but not the'
2853     warn2 'libraries; so either GLE is half-installed on this'
2854     warn2 "system, or something else went wrong.  The \`config.log'"
2855     warn2 'file might contain some clues.'
2856   fi
2857
2858   echo ''
2859   warn2 'Some of the OpenGL (3D) demos (those that depend on GLE)'
2860   warn2 'will not be built or installed.  You might want to consider'
2861   warn2 'installing GLE and re-running configure.  (Remember to delete'
2862   warn2 'the config.cache file first.)  You can find the GLE library'
2863   warn2 'at <http://www.linas.org/gle/>.  For general OpenGL info,'
2864   warn2 'see <http://www.opengl.org/>.'
2865
2866 fi
2867
2868
2869 if test "$with_readdisplay_req" = yes -a "$have_readdisplay" = no ; then
2870   warn 'Use of XReadDisplay was requested, but it was not found.'
2871 fi
2872
2873 if test "$with_sgivideo_req" = yes -a "$have_sgivideo" = no ; then
2874   warn 'Use of the Iris Video Library was requested, but it was not found.'
2875 fi
2876
2877 if test -n "$with_zippy_req"; then
2878   if test "$with_zippy_req" != "$ac_cv_zippy_program" ; then
2879     warnL "$with_zippy_req was requested as the Zippy program,"
2880     warn2 "but was not found.  The default will be used instead."
2881   fi
2882 fi
2883
2884 if test "$with_kerberos_req" = yes -a "$have_kerberos" = no ; then
2885   warn 'Use of Kerberos was requested, but it was not found.'
2886 fi
2887
2888 if test "$with_pam_req" = yes -a "$have_pam" = no ; then
2889   warn 'Use of PAM was requested, but it was not found.'
2890 fi
2891
2892 if test "$with_shadow_req" = yes -a "$have_shadow" = no ; then
2893   warn 'Use of shadow passwords was requested, but they were not found.'
2894 fi
2895
2896
2897 # You are in a twisty maze of namespaces and syntaxes, all alike.
2898 # Fuck the skull of Unix.
2899 #
2900 eval bindir=${bindir}
2901 eval bindir=${bindir}
2902 eval bindir=${bindir}
2903 eval bindir=${bindir}
2904 eval bindir=${bindir}
2905 eval bindir=${bindir}
2906 eval HACKDIR=${HACKDIR}
2907 eval HACKDIR=${HACKDIR}
2908 eval HACKDIR=${HACKDIR}
2909 eval HACKDIR=${HACKDIR}
2910 eval HACKDIR=${HACKDIR}
2911 eval HACKDIR=${HACKDIR}
2912
2913 # canonicalize slashes.
2914 bindir=`echo  "${bindir}"  | sed 's@/$@@;s@//*@/@g'`
2915 HACKDIR=`echo "${HACKDIR}" | sed 's@/$@@;s@//*@/@g'`
2916
2917
2918 # Sanity check the subdir
2919 for bad_choice in xscreensaver xscreensaver-demo xscreensaver-command ; do
2920   if test "${HACKDIR}" = "${bindir}/${bad_choice}" ; then
2921     echo ""
2922     AC_MSG_ERROR([\"--enable-subdir=${bindir}/${bad_choice}\" won't work.
2923                    There will be an executable installed with that name, so
2924                    that can't be the name of a directory as well.  Please
2925                    re-configure with a different directory name.])
2926   fi
2927 done
2928
2929
2930 do_dir_warning=no
2931
2932 # Now let's see if there's a previous RPM version already installed.  Blargh!
2933
2934 # M4 sucks!!
2935 changequote(X,Y)
2936 rpmv=`(rpm -qv xscreensaver) 2>&- | \
2937       sed 's/^xscreensaver-\([0-9][0-9]*[.][0-9][0-9]*\)-.*$/\1/'`
2938 changequote([,])
2939
2940 if test \! -z "$rpmv" ; then
2941   rpmbdir=`rpm -ql xscreensaver | sed -n 's@^\(.*\)/xscreensaver-demo$@\1@p'`
2942   rpmhdir=`rpm -ql xscreensaver | sed -n 's@^\(.*\)/attraction$@\1@p'`
2943
2944   warning=no
2945   warnL "There is already an installed RPM of xscreensaver $rpmv"
2946   warn2 "on this system.  You might want to remove it (with"
2947   warn2 '"rpm -ve xscreensaver") before running "make install"'
2948   warn2 "from this directory."
2949   echo ""
2950   warn2 "Alternately, you could build this version of xscreensaver"
2951   warn2 'as an RPM, and then install that.  An "xscreensaver.spec"'
2952   warn2 "file is included.  See the RPM documentation for more info."
2953   echo ""
2954
2955   if test "$rpmbdir" = "$rpmhdir" ; then
2956     warn2 "The RPM version was installed in $rpmbdir."
2957   else
2958     warn2 "The RPM version was installed in $rpmbdir,"
2959     warn2 "with demos in $rpmhdir."
2960   fi
2961
2962   do_dir_warning=yes
2963 fi
2964
2965
2966 # Warn about egregious GNOME bogosity.
2967 #
2968 #if (rpm -qv control-center) >&- 2>&- ; then
2969 #  warning=no
2970 #  warnL "The Gnome Control Center seems to be installed."
2971 #  echo  ""
2972 #  warn2 "Note that simply installing this version of xscreensaver"
2973 #  warn2 "will not cause GNOME to know about the newly-added display"
2974 #  warn2 "modes -- GNOME is just lame that way.  Instead of using the"
2975 #  warn2 "Control Center, try using the \`xscreensaver-demo' command."
2976 #fi
2977
2978
2979 if test "${bindir}" = "${HACKDIR}" ; then
2980   do_dir_warning=yes
2981 fi
2982
2983 if test "$do_dir_warning" = yes; then
2984   echo ""
2985   echo "$warnsep"
2986   echo ""
2987   echo '      When you run "make install", the "xscreensaver",'
2988   echo '      "xscreensaver-demo", and "xscreensaver-command" executables'
2989   echo "      will be installed in ${bindir}."
2990   echo ""
2991   echo "      The various graphics demos (100+ different executables) will"
2992   echo "      also be installed in ${HACKDIR}."
2993   echo ""
2994   echo "      If you would prefer the demos to be installed elsewhere"
2995   echo "      (for example, in a dedicated directory) you should re-run"
2996   echo "      configure with the --enable-subdir=DIR option.  For more"
2997   echo "      information, run $0 --help."
2998   warning=yes
2999 fi
3000
3001 if test "$warning" != no; then
3002   echo '' ; echo "$warnsep" ; echo ''
3003 fi