[project @ 2003-08-18 09:23:09 by dons]
[ghc-hetmet.git] / aclocal.m4
1 dnl $Id: aclocal.m4,v 1.125 2003/08/18 09:23:09 dons Exp $
2 dnl 
3 dnl Extra autoconf macros for the Glasgow fptools
4 dnl
5 dnl To be a good autoconf citizen, names of local macros have
6 dnl prefixed with FPTOOLS_ to ensure we don't clash
7 dnl with any pre-supplied autoconf ones.
8
9 dnl
10 dnl Is timezone around? (in a header file)
11 dnl 
12 AC_DEFUN(FPTOOLS_HAVE_TIMEZONE,
13 [AC_CACHE_CHECK([timezone], fptools_cv_have_timezone,
14 [AC_TRY_COMPILE([#if TIME_WITH_SYS_TIME
15 # include <sys/time.h>
16 # include <time.h>
17 #else
18 # if HAVE_SYS_TIME_H
19 #  include <sys/time.h>
20 # else
21 #  include <time.h>
22 # endif
23 #endif
24 ], [return timezone;], 
25 fptools_cv_have_timezone=yes, fptools_cv_have_timezone=no)])
26 if test "$fptools_cv_have_timezone" = yes; then
27   AC_DEFINE(HAVE_TIMEZONE)
28 fi
29 ])
30
31 dnl
32 dnl Has timezone the type time_t or long (HP-UX 10.20 apparently
33 dnl has `long'..)
34 dnl 
35 AC_DEFUN(FPTOOLS_TYPE_TIMEZONE,
36 [AC_CACHE_CHECK([type of timezone], fptools_cv_type_timezone,
37 [AC_TRY_COMPILE([#if TIME_WITH_SYS_TIME
38 # include <sys/time.h>
39 # include <time.h>
40 #else
41 # if HAVE_SYS_TIME_H
42 #  include <sys/time.h>
43 # else
44 #  include <time.h>
45 # endif
46 #endif
47
48 extern time_t timezone; 
49 ],
50 [int i;], fptools_cv_type_timezone=time_t, fptools_cv_type_timezone=long)])
51 AC_DEFINE_UNQUOTED(TYPE_TIMEZONE, $fptools_cv_type_timezone)
52 ])
53
54 dnl *** Is altzone available? ***
55 dnl 
56 AC_DEFUN(FPTOOLS_ALTZONE,
57 [AC_CACHE_CHECK([altzone], fptools_cv_altzone,
58 [AC_TRY_LINK([#if TIME_WITH_SYS_TIME
59 # include <sys/time.h>
60 # include <time.h>
61 #else
62 # if HAVE_SYS_TIME_H
63 #  include <sys/time.h>
64 # else
65 #  include <time.h>
66 # endif
67 #endif
68 ], [return altzone;], 
69 fptools_cv_altzone=yes, fptools_cv_altzone=no)])
70 if test "$fptools_cv_altzone" = yes; then
71   AC_DEFINE(HAVE_ALTZONE)
72 fi
73 ])
74
75
76 dnl *** Does libc contain GNU regex? ***
77 dnl 
78 AC_DEFUN(FPTOOLS_REGEX_IN_LIBC,
79 [AC_CACHE_CHECK([for GNU regex in libc], fptools_cv_have_regex,
80 [AC_TRY_LINK([#if HAVE_UNISTD_H
81 #include <unistd.h>
82 #endif
83 #include <regex.h>
84 ],[ struct re_pattern_buffer patbuf; 
85     re_compile_pattern("",0,&patbuf);
86     re_search_2 (&patbuf, "", 0, "",0, 0,0,0,0); ],
87 fptools_cv_have_regex=yes, fptools_cv_have_regex=no)])
88 if test "$fptools_cv_have_regex" = yes; then
89         HaveGNURegex=YES
90 else
91         HaveGNURegex=NO
92 fi
93 AC_SUBST(HaveGNURegex)
94 ])
95
96
97 dnl ** check for leading underscores in symbol names
98 dnl 
99 dnl Test for determining whether symbol names have a leading
100 dnl underscore.
101 dnl 
102 dnl We assume that they _haven't_ if anything goes wrong.
103 dnl
104 dnl Some nlist implementations seem to try to be compatible by ignoring
105 dnl a leading underscore sometimes (eg. FreeBSD).  We therefore have
106 dnl to work around this by checking for *no* leading underscore first.
107 dnl Sigh.  --SDM
108 dnl
109 dnl Similarly on OpenBSD, but this test doesn't help. -- dons
110 dnl
111 AC_DEFUN(FPTOOLS_UNDERSCORE,
112 [AC_CHECK_LIB(elf, nlist, LIBS="-lelf $LIBS")dnl
113 AC_CACHE_CHECK([leading underscore in symbol names], fptools_cv_lead_uscore,
114
115 dnl
116 dnl Hack!: nlist() under Digital UNIX insist on there being an _,
117 dnl but symbol table listings shows none. What is going on here?!?
118 dnl
119 dnl Another hack: cygwin doesn't come with nlist.h , so we hardwire
120 dnl the underscoredness of that "platform"
121 changequote(<<, >>)dnl
122 <<
123 case $HostPlatform in
124 *openbsd*) # x86 openbsd is ELF from 3.4 >, meaning no leading uscore
125     case $build in
126         i386-*2\.[[0-9]] | i386-*3\.[[0-3]] ) fptools_cv_lead_uscore='yes' ;;
127         *)      fptools_cv_lead_uscore='no' ;;
128     esac ;;
129 alpha-dec-osf*) fptools_cv_lead_uscore='no';;
130 *cygwin32) fptools_cv_lead_uscore='yes';;
131 *mingw32) fptools_cv_lead_uscore='yes';;
132 *) >>
133 changequote([, ])dnl
134 AC_TRY_RUN([#ifdef HAVE_NLIST_H
135 #include <nlist.h>
136 changequote(<<, >>)dnl
137 <<
138 struct nlist xYzzY1[] = {{"xYzzY1", 0},{0}};
139 struct nlist xYzzY2[] = {{"_xYzzY2", 0},{0}};
140 #endif
141
142 main(argc, argv)
143 int argc;
144 char **argv;
145 {
146 #ifdef HAVE_NLIST_H
147     if(nlist(argv[0], xYzzY1) == 0 && xYzzY1[0].n_value != 0)
148         exit(1);
149     if(nlist(argv[0], xYzzY2) == 0 && xYzzY2[0].n_value != 0)
150         exit(0);>>
151 changequote([, ])dnl
152 #endif
153     exit(1);
154 }], fptools_cv_lead_uscore=yes, fptools_cv_lead_uscore=no, fptools_cv_lead_uscore=NO)
155 ;;
156 esac);
157 LeadingUnderscore=`echo $fptools_cv_lead_uscore | sed 'y/yesno/YESNO/'`
158 AC_SUBST(LeadingUnderscore)
159 case $LeadingUnderscore in
160 YES) AC_DEFINE(LEADING_UNDERSCORE);;
161 esac
162 ])
163
164 dnl
165 dnl FPTOOLS_PROG_CHECK_VERSION(VERSIONSTR1, TEST, VERSIONSTR2,
166 dnl                            ACTION-IF-TRUE [, ACTION-IF-FALSE])
167 dnl
168 dnl compare versions field-wise (separator is '.')
169 dnl TEST is one of {-lt,-le,-eq,-ge,-gt}
170 dnl
171 dnl quite shell-independant and SUSv2 compliant code
172 dnl
173 dnl NOTE: the loop could be unrolled within autoconf, but the
174 dnl       macro code would be a) longer and b) harder to debug... ;)
175 dnl
176 AC_DEFUN(FPTOOLS_PROG_CHECK_VERSION,
177 [if ( IFS=".";
178       a="[$1]";  b="[$3]";
179       while test -n "$a$b"
180       do
181               set -- [$]a;  h1="[$]1";  shift 2>/dev/null;  a="[$]*"
182               set -- [$]b;  h2="[$]1";  shift 2>/dev/null;  b="[$]*"
183               test -n "[$]h1" || h1=0;  test -n "[$]h2" || h2=0
184               test [$]{h1} -eq [$]{h2} || break
185       done
186       test [$]{h1} [$2] [$]{h2}
187     )
188 then ifelse([$4],,[:],[
189   $4])
190 ifelse([$5],,,
191 [else
192   $5])
193 fi
194 ])])dnl
195
196
197 dnl
198 dnl Check for Greencard and version.
199 dnl
200 AC_DEFUN(FPTOOLS_GREENCARD,
201 [
202 AC_PATH_PROG(GreencardCmd,greencard)
203 AC_CACHE_CHECK([for version of greencard], fptools_cv_greencard_version,
204 changequote(, )dnl
205 [if test x"$GreencardCmd" != x; then
206    fptools_cv_greencard_version="`$GreencardCmd --version |
207                           grep 'version' | sed -e 's/greencard. version \([^ ]*\).*/\1/g'`"
208 else
209    fptools_cv_greencard_version=""
210 fi
211 changequote([, ])dnl
212 ])
213 FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_greencard_version],-lt,$1,
214   [AC_MSG_ERROR([greencard version $1 or later is required (found '$fptools_cv_greencard_version')])])dnl
215 GreencardVersion=$fptools_cv_greencard_version
216 AC_SUBST(GreencardVersion)
217 ])
218
219 dnl
220 dnl Check for Happy and version.  If we're building GHC, then we need
221 dnl at least Happy version 1.13.  If there's no installed Happy, we look
222 dnl for a happy source tree and point the build system at that instead.
223 dnl
224 AC_DEFUN(FPTOOLS_HAPPY,
225 [
226 if test -d $srcdir/happy; then
227    SrcTreeHappyCmd=$hardtop/happy/src/happy-inplace
228 fi
229 if test x"$UseSrcTreeHappy" = xYES; then
230   HappyCmd=$SrcTreeHappyCmd
231 else
232   AC_PATH_PROG(HappyCmd,happy,$SrcTreeHappyCmd)
233 fi
234 AC_CACHE_CHECK([for version of happy], fptools_cv_happy_version,
235 changequote(, )dnl
236 [if test x"$HappyCmd" = x"$SrcTreeHappyCmd"; then
237    fptools_cv_happy_version=`grep '^ProjectVersion[     ]*=' $srcdir/happy/mk/version.mk | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`;
238 elif test x"$HappyCmd" != x; then
239    fptools_cv_happy_version="`$HappyCmd -v |
240                           grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'`" ;
241 else
242    fptools_cv_happy_version="";
243 fi;
244 changequote([, ])dnl
245 ])
246 if test -d $srcdir/ghc -a ! -f $srcdir/ghc/compiler/parser/Parser.hs; then
247   FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_happy_version],-lt,[1.13],
248   [AC_MSG_ERROR([Happy version 1.13 or later is required to compile GHC.])])dnl
249 fi
250 HappyVersion=$fptools_cv_happy_version;
251 AC_SUBST(HappyVersion)
252 ])
253
254 dnl
255 dnl Check for Haddock and version.  If there's no installed Haddock, we look
256 dnl for a haddock source tree and point the build system at that instead.
257 dnl
258 AC_DEFUN(FPTOOLS_HADDOCK,
259 [
260 if test -d $srcdir/haddock; then
261    SrcTreeHaddockCmd=$hardtop/haddock/src/haddock-inplace
262 fi
263 if test x"$UseSrcTreeHaddock" = xYES; then
264   HaddockCmd=$SrcTreeHaddockCmd
265 else
266   AC_PATH_PROG(HaddockCmd,haddock,$SrcTreeHaddockCmd)
267 fi
268 dnl Darn, I forgot to make Haddock print out its version number when
269 dnl invoked with -v.  We could try generating some HTML and grepping
270 dnl through that to find the version number, but I think we'll make
271 dnl do without it for now.
272 ])
273
274 dnl
275 dnl Check for Alex and version.  If we're building GHC, then we need
276 dnl at least Alex version 2.0.  If there's no installed Alex, we look
277 dnl for a alex source tree and point the build system at that instead.
278 dnl
279 AC_DEFUN(FPTOOLS_ALEX,
280 [
281 if test -d $srcdir/alex; then
282    SrcTreeAlexCmd=$hardtop/alex/src/alex-inplace
283 fi
284 if test x"$UseSrcTreeAlex" = xYES; then
285   AlexCmd=$SrcTreeAlexCmd
286 else
287   AC_PATH_PROG(AlexCmd,alex,$SrcTreeAlexCmd)
288 fi
289 AC_CACHE_CHECK([for version of alex], fptools_cv_alex_version,
290 changequote(, )dnl
291 [if test x"$AlexCmd" = x"$SrcTreeAlexCmd"; then
292    fptools_cv_alex_version=`grep '^ProjectVersion[      ]*=' $srcdir/alex/mk/version.mk | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`;
293 elif test x"$AlexCmd" != x; then
294    fptools_cv_alex_version="`$AlexCmd -v |
295                           grep 'Alex [Vv]ersion' | sed -e 's/Alex [Vv]ersion \([0-9\.]*\).*/\1/g'`" ;
296 else
297    fptools_cv_alex_version="";
298 fi;
299 changequote([, ])dnl
300 ])
301 dnl if test -d $srcdir/ghc -a ! -f $srcdir/ghc/compiler/parser/Lexer.hs; then
302 dnl   FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_alex_version],-lt,[2.0],
303 dnl   [AC_MSG_ERROR([Alex version 2.0 or later is required to compile GHC.])])dnl
304 dnl fi
305 AlexVersion=$fptools_cv_alex_version;
306 AC_SUBST(AlexVersion)
307 ])
308
309 dnl
310 dnl What's the best way of doing context diffs?
311 dnl
312 dnl (NB: NeXTStep thinks diff'ing a file against itself is "trouble")
313 dnl
314 AC_DEFUN(FPTOOLS_PROG_DIFF,
315 [AC_CACHE_CHECK([for ok way to do context diffs], fptools_cv_context_diffs,
316 [echo foo > conftest1
317 echo foo > conftest2
318 if diff -C 1 conftest1 conftest2 > /dev/null 2>&1 ; then
319     fptools_cv_context_diffs='diff -C 1'
320 else
321     if diff -c1 conftest1 conftest2 > /dev/null 2>&1 ; then
322         fptools_cv_context_diffs='diff -c1'
323     else
324         echo "Can't figure out how to do context diffs."
325         echo "Neither \`diff -C 1' nor \`diff -c1' works."
326         exit 1
327     fi
328 fi
329 rm -f conftest1 conftest2
330 ])
331 ContextDiffCmd=$fptools_cv_context_diffs
332 AC_SUBST(ContextDiffCmd)
333 ])
334
335 dnl
336 dnl Check whether ld supports -x
337 dnl
338 AC_DEFUN(FPTOOLS_LD_X,
339 [AC_CACHE_CHECK([whether ld understands -x], fptools_cv_ld_x,
340 [
341 echo 'foo() {}' > conftest.c
342 ${CC-cc} -c conftest.c
343 if ${LdCmd} -r -x -o foo.o conftest.o; then
344    fptools_cv_ld_x=yes
345 else
346    fptools_cv_ld_x=no
347 fi
348 rm -rf conftest.c conftest.o foo.o
349 ])
350 if test "$fptools_cv_ld_x" = yes; then
351         LdXFlag=-x
352 else
353         LdXFlag=
354 fi
355 AC_SUBST(LdXFlag)
356 ])
357
358 dnl
359 dnl Finding the Right Yacc
360 dnl
361 AC_DEFUN(FPTOOLS_PROG_YACCY,
362 [AC_PROG_YACC
363 if test "$YACC" = "yacc"; then
364    AC_CACHE_CHECK([if it is an OK yacc], ac_cv_prog_yacc,
365    [AC_CHECK_PROG(WhatCmd, what, what, :)
366     $WhatCmd $YACC > conftest.out
367     if egrep 'y1\.c 1\..*SMI' conftest.out >/dev/null 2>&1; then
368         echo "I don't trust your $YaccCmd; it looks like an old Sun yacc"
369         if test -f /usr/lang/yacc; then
370            echo "I'm going to use /usr/lang/yacc instead"
371            ac_cv_prog_yacc=/usr/lang/yacc
372         else
373            echo "I'm assuming the worst...no parser generator at all"
374            ac_cv_prog_yacc=:
375         fi
376     elif egrep 'y1\.c.*Revision: 4\.2\.6\.3.*DEC' conftest.out >/dev/null 2>&1; then
377         echo "I don't trust your $YaccCmd; it looks like a lame DEC yacc"
378         echo "I'm assuming the worst...no parser generator at all"
379         ac_cv_prog_yacc=:
380     else
381         ac_cv_prog_yacc=$YACC
382     fi
383     rm -fr conftest*
384 ])
385 else
386     ac_cv_prog_yacc=$YACC
387 fi
388 YaccCmd=$ac_cv_prog_yacc
389 AC_SUBST(YaccCmd)
390 ])
391
392 dnl *** Checking for ar and its arguments + whether we need ranlib.
393 dnl
394 dnl ArCmd, ArSupportsInput and RANLIB are AC_SUBST'ed
395 dnl On Digital UNIX, we test for the -Z (compress) and
396 dnl -input (take list of files from external file) flags.
397 dnl 
398 AC_DEFUN(FPTOOLS_PROG_AR_AND_RANLIB,
399 [AC_PATH_PROG(ArCmdRaw,ar)
400 if test -z "$ArCmdRaw"; then
401     echo "You don't seem to have ar in your PATH...I have no idea how to make a library"
402     exit 1;
403 fi
404 dnl GNU ar needs special treatment: it appears to have problems with
405 dnl object files with the same name if you use the 's' modifier, but
406 dnl simple 'ar q' works fine, and doesn't need a separate ranlib.
407 if $ArCmdRaw --version | grep 'GNU' >/dev/null 2>/dev/null; then
408     ArCmdArgs='q'
409     NeedRanLib=''
410 elif $ArCmdRaw clqsZ conftest.a >/dev/null 2>/dev/null; then
411     ArCmdArgs="clqsZ"
412     NeedRanLib=''
413 elif $ArCmdRaw clqs conftest.a >/dev/null 2>/dev/null; then
414     ArCmdArgs="clqs"
415     NeedRanLib=''
416 elif $ArCmdRaw cqs conftest.a >/dev/null 2>/dev/null; then
417     ArCmdArgs="cqs"
418     NeedRanLib=''
419 elif $ArCmdRaw clq conftest.a >/dev/null 2>/dev/null; then
420     ArCmdArgs="clq"
421     NeedRanLib='YES'
422 elif $ArCmdRaw cq conftest.a >/dev/null 2>/dev/null; then
423     ArCmdArgs="cq"
424     NeedRanLib='YES'
425 elif $ArCmdRaw cq conftest.a 2>&1 | grep 'no archive members specified' >/dev/null 2>/dev/null; then
426     ArCmdArgs="cq"
427     NeedRanLib='YES'
428 else
429     echo "I can't figure out how to use your $ArCmd"
430     exit 1
431 fi
432 rm -rf conftest*
433 case $HostPlatform in
434  *mingw32) 
435           ArCmd="`cygpath -w ${ArCmdRaw} | sed -e 's@\\\\@/@g' ` ${ArCmdArgs}"
436           ;;
437  *) ArCmd="${ArCmdRaw} ${ArCmdArgs}"
438     ;;
439 esac
440 test -n "$ArCmd" && test -n "$verbose" && echo "        setting ArCmd to $ArCmd"
441 AC_SUBST(ArCmd)
442 if $ArCmd conftest.a -input /dev/null >/dev/null 2>/dev/null; then
443     ArSupportsInput='-input'
444 else
445     ArSupportsInput=''
446 fi
447 rm -rf conftest*
448 test -n "$ArSupportsInput" && test -n "$verbose" && echo "        setting ArSupportsInput to $ArSupportsInput"
449 AC_SUBST(ArSupportsInput)
450 if test -z "$NeedRanLib"; then
451     RANLIB=':'
452     test -n "$verbose" && echo "        setting RANLIB to $RANLIB"
453     AC_SUBST(RANLIB)
454 else
455     AC_PROG_RANLIB
456 fi
457 ])
458
459 dnl
460 dnl AC_SHEBANG_PERL - can we she-bang perl?
461 dnl
462 AC_DEFUN(FPTOOLS_SHEBANG_PERL,
463 [AC_CACHE_CHECK([if your perl works in shell scripts], fptools_cv_shebang_perl,
464 [echo "#!$PerlCmd"'
465 exit $1;
466 ' > conftest
467 chmod u+x conftest
468 (SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
469 if test $? -ne 69; then
470    fptools_cv_shebang_perl=yes
471 else
472    fptools_cv_shebang_perl=no
473 fi
474 rm -f conftest
475 ])])
476
477 dnl
478 dnl Extra testing of the result AC_PROG_CC, testing the gcc version no.
479 dnl *Must* be called after AC_PROG_CC
480 dnl
481 AC_DEFUN(FPTOOLS_HAVE_GCC,
482 [AC_CACHE_CHECK([whether you have an ok gcc], fptools_cv_have_gcc,
483 [if test -z "$GCC"; then
484     echo ''
485     echo "You would be better off with gcc"
486     echo "Perhaps it is already installed, but not in your PATH?"
487     fptools_cv_have_gcc='no'
488 else
489 changequote(, )dnl
490     gcc_version_str="`$CC -v 2>&1 | grep 'version ' | sed -e 's/.*version [^0-9]*\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1\.\2/g' `"
491 changequote([, ])dnl
492     fptools_cv_have_gcc='yes'
493     FPTOOLS_PROG_CHECK_VERSION($gcc_version_str, -lt, "2.0",
494         fptools_cv_have_gcc='no'
495         echo ""
496         echo "your gcc version appears to be ..."
497         $CC --version
498         echo "gcc prior to 2.0 and have never worked with ghc."
499         echo "we recommend 2.95.3, although versions back to 2.7.2 should be ok."
500         AC_MSG_ERROR([gcc 1.X has never been supported])
501     )
502 fi
503 ])
504 HaveGcc=`echo $fptools_cv_have_gcc | sed 'y/yesno/YESNO/'`
505 AC_SUBST(HaveGcc)
506 ])
507
508 dnl
509 dnl Some OSs (Mandrake Linux, in particular) configure GCC with
510 dnl -momit-leaf-frame-pointer on by default.  If this is the case, we
511 dnl need to turn it off for mangling to work.  The test is currently a bit
512 dnl crude, using only the version number of gcc.
513 dnl
514 AC_DEFUN(FPTOOLS_GCC_NEEDS_NO_OMIT_LFPTR,
515 [AC_CACHE_CHECK([whether gcc needs -mno-omit-leaf-frame-pointer], fptools_cv_gcc_needs_no_omit_lfptr,
516 [
517  fptools_cv_gcc_needs_no_omit_lfptr='no'
518  FPTOOLS_PROG_CHECK_VERSION($gcc_version_str, -ge, "3.2",
519      fptools_cv_gcc_needs_no_omit_lfptr='yes')
520 ])
521 if test "$fptools_cv_gcc_needs_no_omit_lfptr" = "yes"; then
522    AC_DEFINE(HAVE_GCC_MNO_OMIT_LFPTR)
523 fi
524 ])
525
526 dnl Small feature test for perl version. Assumes PerlCmd
527 dnl contains path to perl binary
528 dnl
529 AC_DEFUN(FPTOOLS_CHECK_PERL_VERSION,
530 [$PerlCmd -v >conftest.out 2>&1
531 if grep "version 5" conftest.out >/dev/null 2>&1; then
532    :
533 else
534    if grep "v5.6" conftest.out >/dev/null 2>&1; then
535       :
536    else
537       if grep "v5.8" conftest.out >/dev/null 2>&1; then
538          :
539       else
540          if grep "version 6" conftest.out >/dev/null 2>&1; then
541             :
542          else
543             echo "Your version of perl probably won't work."
544          fi  
545       fi
546    fi
547 fi
548 rm -fr conftest*
549 ])
550
551 dnl
552 dnl Getting at the right version of 'find'
553 dnl (i.e., not the MS util on a Win32 box).
554 dnl
555 AC_DEFUN(FPTOOLS_FIND_FIND,
556 [
557 AC_PATH_PROG(Find2Cmd, find)
558 $Find2Cmd --version > conftest.out 2>&1 
559 if grep "FIND: Parameter format" conftest.out >/dev/null 2>&1 ; then
560    # Encountered MS' find utility, which is not what we're after.
561    #
562    # HACK - AC_CHECK_PROG is useful here in that does let you reject
563    # an (absolute) entry in the path (Find2Cmd). It is not so useful
564    # in that it doesn't let you (AFAIU) set VARIABLE equal to the 
565    # absolute path eventually found. So, hack around this by inspecting
566    # what variables hold the abs. path & use them directly.
567    AC_CHECK_PROG(FindCmd,find,`echo $ac_dir/$ac_word`,find,,$Find2Cmd)
568 else
569 FindCmd=$Find2Cmd
570 AC_SUBST(FindCmd)
571 fi
572 ])
573
574 dnl
575 dnl FPTOOLS_NOCACHE_CHECK prints a message, then sets the
576 dnl values of the second argument to the result of running
577 dnl the commands given by the third. It does not cache its
578 dnl result, so it is suitable for checks which should be
579 dnl run every time.
580 dnl
581 AC_DEFUN(FPTOOLS_NOCACHE_CHECK,
582 [AC_MSG_CHECKING([$1])
583  $3
584  AC_MSG_RESULT([$][$2])
585 ])
586
587 dnl
588 dnl FPTOOLS_GHC_VERSION(version)
589 dnl FPTOOLS_GHC_VERSION(major, minor [, patchlevel])
590 dnl FPTOOLS_GHC_VERSION(version, major, minor, patchlevel)
591 dnl
592 dnl Test for version of installed ghc.  Uses $GHC.
593 dnl [original version pinched from c2hs]
594 dnl
595 AC_DEFUN(FPTOOLS_GHC_VERSION,
596 [FPTOOLS_NOCACHE_CHECK([version of ghc], [fptools_version_of_ghc],
597 ["${WithGhc-ghc}" --version > conftestghc 2>&1
598   cat conftestghc >&AC_FD_CC
599 #Useless Use Of cat award...
600   fptools_version_of_ghc=`cat conftestghc | sed -n -e 's/, patchlevel *\([[0-9]]\)/.\1/;s/.* version \([[0-9]][[0-9.]]*\).*/\1/p'`
601   rm -fr conftest*
602   if test "[$]fptools_version_of_ghc" = ""
603   then
604     fptools_version_of_ghc='unknown'
605   fi
606 fptools_version_of_ghc[_major]=`echo [$]fptools_version_of_ghc | sed -e 's/^\([[0-9]]\).*/\1/'`
607 fptools_version_of_ghc[_minor]=`echo [$]fptools_version_of_ghc | sed -e 's/^[[0-9]]\.\([[0-9]]*\).*/\1/'`
608 fptools_version_of_ghc[_pl]=`echo [$]fptools_version_of_ghc | sed -n -e 's/^[[0-9]]\.[[0-9]]*\.\([[0-9]]*\)/\1/p'`
609 #
610 if test "[$]fptools_version_of_ghc[_pl]" = ""
611 then
612   fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor]"
613   fptools_version_of_ghc[_pl]="0"
614 else
615   fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor].[$]fptools_version_of_ghc[_pl]"
616 fi
617 #
618 ifelse($#, [1], [dnl
619 [$1]="[$]fptools_version_of_ghc[_all]"
620 ], $#, [2], [dnl
621 [$1]="[$]fptools_version_of_ghc[_major]"
622 [$2]="[$]fptools_version_of_ghc[_minor]"
623 ], $#, [3], [dnl
624 [$1]="[$]fptools_version_of_ghc[_major]"
625 [$2]="[$]fptools_version_of_ghc[_minor]"
626 [$3]="[$]fptools_version_of_ghc[_pl]"
627 ], $#, [4], [dnl
628 [$1]="[$]fptools_version_of_ghc[_all]"
629 [$2]="[$]fptools_version_of_ghc[_major]"
630 [$3]="[$]fptools_version_of_ghc[_minor]"
631 [$4]="[$]fptools_version_of_ghc[_pl]"
632 ])
633 ])
634 ])dnl
635
636
637 dnl ** figure out the alignment restriction of a type
638 dnl    (required SIZEOF test but AC_CHECK_SIZEOF doesn't call PROVIDE
639 dnl     so we can't call REQUIRE)
640
641 dnl FPTOOLS_CHECK_ALIGNMENT(TYPE)
642 AC_DEFUN(FPTOOLS_CHECK_ALIGNMENT,
643 [changequote(<<, >>)dnl
644 dnl The name to #define.
645 define(<<AC_TYPE_NAME>>, translit(alignment_$1, [a-z *], [A-Z_P]))dnl
646 dnl The cache variable name.
647 define(<<AC_CV_NAME>>, translit(ac_cv_alignment_$1, [ *], [_p]))dnl
648 dnl The name of the corresponding size.
649 define(<<AC_CV_SIZEOF_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
650 changequote([, ])dnl
651 AC_MSG_CHECKING(alignment of $1)
652 AC_CACHE_VAL(AC_CV_NAME,
653 [AC_TRY_RUN([
654 #include <stdio.h>
655 #if HAVE_STDDEF_H
656 #include <stddef.h>
657 #endif
658 #ifndef offsetof
659 #define offsetof(ty,field) ((size_t)((char *)&((ty *)0)->field - (char *)(ty *)0))
660 #endif
661 int
662 main()
663 {
664   FILE *f=fopen("conftestval", "w");
665   if (!f) exit(1);
666   fprintf(f, "%d", offsetof(struct { char c; $1 ty;},ty));
667   exit(0);
668 }],
669 AC_CV_NAME=`cat conftestval`,
670 AC_CV_NAME=$AC_CV_SIZEOF_NAME,
671 AC_CV_NAME=$AC_CV_SIZEOF_NAME)])
672 AC_MSG_RESULT($AC_CV_NAME)
673 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
674 AC_PROVIDE($AC_TYPE_NAME)
675 undefine([AC_TYPE_NAME])dnl
676 undefine([AC_CV_NAME])dnl
677 undefine([AC_CV_SIZEOF_NAME])dnl
678 ])
679
680 dnl ** Map an arithmetic C type to a Haskell type.
681 dnl    Based on autconf's AC_CHECK_SIZEOF.
682
683 dnl FPTOOLS_CHECK_HTYPE(TYPE [, DEFAULT_VALUE, [, VALUE-FOR-CROSS-COMPILATION])
684 AC_DEFUN(FPTOOLS_CHECK_HTYPE,
685 [changequote(<<, >>)dnl
686 dnl The name to #define.
687 define(<<AC_TYPE_NAME>>, translit(htype_$1, [a-z *], [A-Z_P]))dnl
688 dnl The cache variable name.
689 define(<<AC_CV_NAME>>, translit(fptools_cv_htype_$1, [ *], [_p]))dnl
690 changequote([, ])dnl
691 AC_MSG_CHECKING(Haskell type for $1)
692 AC_CACHE_VAL(AC_CV_NAME,
693 [AC_TRY_RUN([#include <stdio.h>
694 #include <stddef.h>
695
696 #ifdef HAVE_SYS_TYPES_H
697 # include <sys/types.h>
698 #endif
699
700 #ifdef HAVE_UNISTD_H
701 # include <unistd.h>
702 #endif
703
704 #ifdef HAVE_SYS_STAT_H
705 # include <sys/stat.h>
706 #endif
707
708 #ifdef HAVE_FCNTL_H
709 # include <fcntl.h>
710 #endif
711
712 #ifdef HAVE_SIGNAL_H
713 # include <signal.h>
714 #endif
715
716 #ifdef HAVE_TIME_H
717 # include <time.h>
718 #endif
719
720 #ifdef HAVE_TERMIOS_H
721 # include <termios.h>
722 #endif
723
724 #ifdef HAVE_STRING_H
725 # include <string.h>
726 #endif
727
728 #ifdef HAVE_CTYPE_H
729 # include <ctype.h>
730 #endif
731
732 #ifdef HAVE_GL_GL_H
733 # include <GL/gl.h>
734 #endif
735
736 #ifdef HAVE_OPENGL_GL_H
737 # include <OpenGL/gl.h>
738 #endif
739
740 #ifdef HAVE_SYS_RESOURCE_H
741 # include <sys/resource.h>
742 #endif
743
744 typedef $1 testing;
745
746 main() {
747   FILE *f=fopen("conftestval", "w");
748   if (!f) exit(1);
749   if (((testing)((int)((testing)1.4))) == ((testing)1.4)) {
750     fprintf(f, "%s%d\n",
751            ((testing)(-1) < (testing)0) ? "Int" : "Word",
752            sizeof(testing)*8);
753   } else {
754     fprintf(f,"%s\n",
755            (sizeof(testing) >  sizeof(double)) ? "LDouble" :
756            (sizeof(testing) == sizeof(double)) ? "Double"  : "Float");
757   }
758   fclose(f);
759   exit(0);
760 }], AC_CV_NAME=`cat conftestval`,
761 ifelse([$2], , AC_CV_NAME=NotReallyAType,      AC_CV_NAME=$2),
762 ifelse([$3], , AC_CV_NAME=NotReallyATypeCross, AC_CV_NAME=$3))]) dnl
763 AC_MSG_RESULT($AC_CV_NAME)
764 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
765 undefine([AC_TYPE_NAME])dnl
766 undefine([AC_CV_NAME])dnl
767 ])
768
769 dnl ** figure out whether C compiler supports 'long long's
770 dnl    (Closely based on Andreas Zeller's macro for testing
771 dnl     for this under C++)
772 dnl
773 dnl    If the C compiler supports `long long' types,
774 dnl    define `HAVE_LONG_LONG'.
775 dnl
776 AC_DEFUN(FPTOOLS_C_LONG_LONG,
777 [
778 AC_REQUIRE([AC_PROG_CC])
779 AC_MSG_CHECKING(whether ${CC} supports long long types)
780 AC_CACHE_VAL(fptools_cv_have_long_long,
781 [
782 AC_LANG_SAVE
783 AC_LANG_C
784 AC_TRY_COMPILE(,[long long a;],
785 fptools_cv_have_long_long=yes,
786 fptools_cv_have_long_long=no)
787 AC_LANG_RESTORE
788 ])
789 AC_MSG_RESULT($fptools_cv_have_long_long)
790 if test "$fptools_cv_have_long_long" = yes; then
791 AC_DEFINE(HAVE_LONG_LONG)
792 fi
793 ])
794
795 dnl ** Obtain the value of a C constant.
796 dnl    The value will be `(-1)' if the constant is undefined.
797 dnl
798 dnl    This is set up so that the argument can be a shell variable.
799 dnl
800 AC_DEFUN(FPTOOLS_CHECK_CCONST,
801 [
802 eval "cv_name=ac_cv_cconst_$1"
803 AC_MSG_CHECKING(value of $1)
804 AC_CACHE_VAL($cv_name,
805 [AC_TRY_RUN([#include <stdio.h>
806 #include <errno.h>
807 main()
808 {
809   FILE *f=fopen("conftestval", "w");
810   if (!f) exit(1);
811   fprintf(f, "%d\n", $1);
812   exit(0);
813 }], 
814 eval "$cv_name=`cat conftestval`",
815 eval "$cv_name=-1",
816 eval "$cv_name=-1")])dnl
817 eval "fptools_check_cconst_result=`echo '$'{$cv_name}`"
818 AC_MSG_RESULT($fptools_check_cconst_result)
819 AC_DEFINE_UNQUOTED(CCONST_$1, $fptools_check_cconst_result)
820 unset fptools_check_cconst_result
821 ])
822
823 dnl ** Invoke AC_CHECK_CCONST on each argument (which have to separate with 
824 dnl    spaces)
825 dnl
826 AC_DEFUN(FPTOOLS_CHECK_CCONSTS,
827 [for ac_const_name in $1
828 do
829 FPTOOLS_CHECK_CCONST($ac_const_name)dnl
830 done
831 ])
832
833
834 dnl *** Can we open files in binary mode? ***
835 dnl 
836 AC_DEFUN(FPTOOLS_O_BINARY,
837 [
838 AC_REQUIRE([AC_PROG_CC])
839 AC_MSG_CHECKING(whether we can open files in binary mode)
840 AC_CACHE_VAL(fptools_cv_have_o_binary,
841 [
842 AC_LANG_SAVE
843 AC_LANG_C
844 AC_TRY_COMPILE(
845 [#ifdef HAVE_FCNTL_H
846 #include <fcntl.h>
847 #endif],
848 [int x = O_BINARY;],
849 fptools_cv_have_o_binary=yes,
850 fptools_cv_have_o_binary=no)
851 AC_LANG_RESTORE
852 ])
853 AC_MSG_RESULT($fptools_cv_have_o_binary)
854 if test "$fptools_cv_have_o_binary" = yes; then
855 AC_DEFINE(HAVE_O_BINARY)
856 fi
857 ])
858
859 dnl *** Helper function **
860 dnl 
861 AC_DEFUN(FPTOOLS_IN_SCOPE,
862 [AC_TRY_LINK([extern char* $1;],[return (int)&$2], $3=yes, $3=no)
863 ])
864
865
866 dnl Based on AC_TRY_LINK - run iftrue if links cleanly with no warning
867
868 dnl FPTOOLS_TRY_LINK_NOWARN(flags,main?,iftrue,iffalse)
869
870 AC_DEFUN(FPTOOLS_TRY_LINK_NOWARN,
871 [
872 ac_save_LIBS="$LIBS"
873 LIBS=[$1];
874 cat > conftest.$ac_ext <<EOF
875 dnl This sometimes fails to find confdefs.h, for some reason.
876 dnl [#]line __oline__ "[$]0"
877 [#]line __oline__ "configure"
878 #include "confdefs.h"
879 [$2]
880 int t() { return 0; }
881 EOF
882 if AC_TRY_EVAL(ac_link); then
883   ifelse([$3], , :, [
884     LIBS="$ac_save_LIBS"
885     rm -rf conftest*
886     $3])
887   ifelse([$4], , , [else
888     LIBS="$ac_save_LIBS"
889     rm -rf conftest*
890     $4
891 ])dnl
892 fi
893 rm -f conftest*
894 ]
895 )
896
897 dnl Loosely based on AC_CHECK_LIB in acgeneral.m4 in autoconf distribution
898
899 dnl FPTOOLS_CHECK_FLAG_NOWARN(NAME, FLAG, CODE, iftrue, iffalse)
900
901 AC_DEFUN(FPTOOLS_CHECK_FLAG_NOWARN,
902 [AC_MSG_CHECKING([for $1])
903  AC_CACHE_VAL(ac_cv_flag_$1,
904    [FPTOOLS_TRY_LINK_NOWARN("$2", [main() { $3; exit(0); } ],
905      eval "ac_cv_flag_$1=yes",
906      eval "ac_cv_flag_$1=no"
907    )]
908  )
909 if eval "test \"`echo '$ac_cv_flag_'$1`\" = yes"; then
910   AC_MSG_RESULT(yes)
911   LIBS="$2 $LIBS"
912   $4
913 else
914   AC_MSG_RESULT(no)
915   $5
916 fi
917 ])
918
919 dnl FPTOOLS_CHECK_LIB_NOWARN(LIBRARY, FUNCTION)
920
921 AC_DEFUN(FPTOOLS_CHECK_LIB_NOWARN,
922 [FPTOOLS_CHECK_FLAG_NOWARN([function_$2],[],[extern char $2(); $2();],
923 [changequote(, )dnl
924   ac_tr_lib=HAVE_LIB`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
925  changequote([, ])dnl
926  AC_DEFINE_UNQUOTED($ac_tr_lib)
927 ],
928 [FPTOOLS_CHECK_FLAG_NOWARN([library_$1],[-l$1],[extern char $2(); $2();],
929 [changequote(, )dnl
930   ac_tr_lib=HAVE_LIB`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
931  changequote([, ])dnl
932  AC_DEFINE_UNQUOTED($ac_tr_lib)
933 ],
934 []
935 )])]
936 )
937
938 dnl check for prototypes
939 dnl
940 AC_DEFUN([AC_C_PROTOTYPES],
941 [AC_CACHE_CHECK([prototypes], ac_cv_prototypes,
942 [AC_TRY_COMPILE([
943 void foo(int);
944 void foo(i)
945 int i; { 
946 return;
947 }
948 ],
949 [int i;], 
950 ac_cv_prototypes=yes,
951 ac_cv_prototypes=no)])
952 if test "$ac_cv_prototypes" = yes; then
953 AC_DEFINE([HAVE_PROTOTYPES])
954 fi
955 ])
956
957 dnl ** Check which CATALOG file we have to use with DocBook SGML.
958 dnl
959 dnl FPTOOLS_DOCBOOK_CATALOG(VARIABLE, JADE, STYLESHEET, CATALOGS-TO-CHECK-FOR)
960 dnl
961 dnl If any of the catalogs given in CATALOGS-TO-CHECK-FOR works on this
962 dnl platform, let VARIABLE refer to this catalog; otherwise, VARIABLE
963 dnl is set to "no".  JADE is the jade executable and STYLESHEET
964 dnl a DocBook style sheet.
965 dnl
966 AC_DEFUN(FPTOOLS_DOCBOOK_CATALOG,
967 [AC_CACHE_CHECK([for DocBook CATALOG], fptools_cv_sgml_catalog,
968 [
969 cat > conftest.sgml << EOF
970 <!DOCTYPE Article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
971 <Article>
972 <ArtHeader>
973 <Title>Test</Title>
974 <Author><OtherName>Test</OtherName></Author>
975 <Address>Test</Address>
976 <PubDate>Test</PubDate>
977 </ArtHeader>
978 <Sect1><Title>Test</Title>
979 <Para>
980 Test.
981 </Para>
982 </Sect1>
983 </Article>
984 EOF
985 fptools_cv_sgml_catalog=no
986 if test -z "$SGML_CATALOG_FILES" ; then
987  for fptools_catalog in $4; do
988    ac_try="$2 -t rtf -d $3#print -c $fptools_catalog conftest.sgml"
989    if AC_TRY_EVAL(ac_try); then
990      fptools_cv_sgml_catalog=[$]fptools_catalog
991      break
992    fi
993  done
994 else
995 # If the env var SGML_CATALOG_FILES is defined, assume things are cool.
996   fptools_cv_sgml_catalog="yes"
997 fi
998 ])
999 rm -rf conftest*
1000 if test $fptools_cv_sgml_catalog != "no"; then
1001   $1=$fptools_cv_sgml_catalog
1002 fi
1003 ])
1004
1005 dnl ######################################################################
1006 dnl FPTOOLS_SEARCH_LIBS(INCLUDES, FUNCTION, SEARCH-LIBS [, ACTION-IF-FOUND
1007 dnl                     [, ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
1008 dnl Search for a library defining FUNC, if it's not already available.
1009 dnl This is almost the same as AC_SEARCH_LIBS, but the INCLUDES can be
1010 dnl specified.
1011 dnl ######################################################################
1012
1013 AC_DEFUN(FPTOOLS_SEARCH_LIBS,
1014 [AC_PREREQ([2.13])
1015 AC_CACHE_CHECK([for library containing $2], [ac_cv_search_$2],
1016 [ac_func_search_save_LIBS="$LIBS"
1017 ac_cv_search_$2="no"
1018 AC_TRY_LINK([$1], [$2()], [ac_cv_search_$2="none required"])
1019 test "$ac_cv_search_$2" = "no" && for i in $3; do
1020 LIBS="-l$i $6 $ac_func_search_save_LIBS"
1021 AC_TRY_LINK([$1], [$2()],
1022 [ac_cv_search_$2="-l$i"
1023 break])
1024 done
1025 LIBS="$ac_func_search_save_LIBS"])
1026 if test "$ac_cv_search_$2" != "no"; then
1027   test "$ac_cv_search_$2" = "none required" || LIBS="$ac_cv_search_$2 $LIBS"
1028   $4
1029 else :
1030   $5
1031 fi])
1032
1033 dnl ####################### -*- Mode: M4 -*- ###########################
1034 dnl Copyright (C) 98, 1999 Matthew D. Langston <langston@SLAC.Stanford.EDU>
1035 dnl
1036 dnl This file is free software; you can redistribute it and/or modify it
1037 dnl under the terms of the GNU General Public License as published by
1038 dnl the Free Software Foundation; either version 2 of the License, or
1039 dnl (at your option) any later version.
1040 dnl
1041 dnl This file is distributed in the hope that it will be useful, but
1042 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
1043 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1044 dnl General Public License for more details.
1045 dnl
1046 dnl You should have received a copy of the GNU General Public License
1047 dnl along with this file; if not, write to:
1048 dnl
1049 dnl   Free Software Foundation, Inc.
1050 dnl   Suite 330
1051 dnl   59 Temple Place
1052 dnl   Boston, MA 02111-1307, USA.
1053 dnl ####################################################################
1054
1055
1056 dnl @synopsis FPTOOLS_CHECK_LIBM
1057 dnl 
1058 dnl Search for math library (typically -lm).
1059 dnl
1060 dnl The variable LIBM (which is not an output variable by default) is
1061 dnl set to a value which is suitable for use in a Makefile (for example,
1062 dnl in make's LOADLIBES macro) provided you AC_SUBST it first.
1063 dnl
1064 dnl @author Matthew D. Langston <langston@SLAC.Stanford.EDU>
1065
1066 # FPTOOLS_CHECK_LIBM - check for math library
1067 AC_DEFUN(FPTOOLS_CHECK_LIBM,
1068 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
1069 LIBM=
1070 case "$host" in
1071 *-*-beos*)
1072   # These system don't have libm
1073   ;;
1074 *-ncr-sysv4.3*)
1075   AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
1076   AC_CHECK_LIB(m, main, LIBM="$LIBM -lm")
1077   ;;
1078 *)
1079   AC_CHECK_LIB(m, main, LIBM="-lm")
1080   ;;
1081 esac
1082 ])
1083
1084 dnl ######################################################################
1085 dnl Note: Caching has been completely rewritten, but is still no perfect yet.
1086 dnl ######################################################################
1087
1088 dnl ########################### -*- Mode: M4 -*- #######################
1089 dnl Copyright (C) 98, 1999 Matthew D. Langston <langston@SLAC.Stanford.EDU>
1090 dnl
1091 dnl This file is free software; you can redistribute it and/or modify it
1092 dnl under the terms of the GNU General Public License as published by
1093 dnl the Free Software Foundation; either version 2 of the License, or
1094 dnl (at your option) any later version.
1095 dnl
1096 dnl This file is distributed in the hope that it will be useful, but
1097 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
1098 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1099 dnl General Public License for more details.
1100 dnl
1101 dnl You should have received a copy of the GNU General Public License
1102 dnl along with this file; if not, write to:
1103 dnl
1104 dnl   Free Software Foundation, Inc.
1105 dnl   Suite 330
1106 dnl   59 Temple Place
1107 dnl   Boston, MA 02111-1307, USA.
1108 dnl ####################################################################
1109
1110 dnl @synopsis FPTOOLS_HAVE_OPENGL
1111 dnl 
1112 dnl Search for OpenGL.  We search first for Mesa (a GPL'ed version of
1113 dnl OpenGL) before a vendor's version of OpenGL if we were specifically
1114 dnl asked to with `--with-Mesa=yes' or `--with-Mesa'.
1115 dnl
1116 dnl The four "standard" OpenGL libraries are searched for: "-lGL",
1117 dnl "-lGLU", "-lGLX" (or "-lMesaGL", "-lMesaGLU" as the case may be) and
1118 dnl "-lglut".
1119 dnl
1120 dnl All of the libraries that are found (since "-lglut" or "-lGLX" might
1121 dnl be missing) are added to the shell output variable "GL_LIBS", along
1122 dnl with any other libraries that are necessary to successfully link an
1123 dnl OpenGL application (e.g. the X11 libraries).  Care has been taken to
1124 dnl make sure that all of the libraries in "GL_LIBS" are listed in the
1125 dnl proper order.
1126 dnl
1127 dnl Additionally, the shell output variable "GL_CFLAGS" is set to any
1128 dnl flags (e.g. "-I" flags) that are necessary to successfully compile
1129 dnl an OpenGL application.
1130 dnl
1131 dnl The following shell variable (which are not output variables) are
1132 dnl also set to either "yes" or "no" (depending on which libraries were
1133 dnl found) to help you determine exactly what was found.
1134 dnl
1135 dnl   have_GL
1136 dnl   have_GLU
1137 dnl   have_GLX
1138 dnl   have_glut
1139 dnl
1140 dnl A complete little toy "Automake `make distcheck'" package of how to
1141 dnl use this macro is available at:
1142 dnl
1143 dnl   ftp://ftp.slac.stanford.edu/users/langston/autoconf/ac_opengl-0.01.tar.gz
1144 dnl
1145 dnl Please note that as the ac_opengl macro and the toy example evolves,
1146 dnl the version number increases, so you may have to adjust the above
1147 dnl URL accordingly.
1148 dnl
1149 dnl @author Matthew D. Langston <langston@SLAC.Stanford.EDU>
1150
1151 AC_DEFUN(FPTOOLS_HAVE_OPENGL,
1152 [
1153   AC_REQUIRE([AC_PROG_CC])
1154   AC_REQUIRE([AC_PATH_X])
1155   AC_REQUIRE([AC_PATH_XTRA])
1156   AC_REQUIRE([FPTOOLS_CHECK_LIBM])
1157
1158 dnl Check for Mesa first if we were asked to.
1159   AC_ARG_ENABLE(Mesa,
1160 [  --enable-mesa
1161         Prefer Mesa over a vendor's native OpenGL library (default=no)
1162 ],
1163                 use_Mesa=$enableval,
1164                 use_Mesa=no)
1165
1166   if test x"$use_Mesa" = xyes; then
1167      GL_search_list="MesaGL  GL  opengl32"
1168     GLU_search_list="MesaGLU GLU glu32"
1169     GLX_search_list="MesaGLX GLX"
1170   else
1171      GL_search_list="GL  opengl32 MesaGL"
1172     GLU_search_list="GLU glu32    MesaGLU"
1173     GLX_search_list="GLX          MesaGLX"
1174   fi      
1175
1176   AC_LANG_SAVE
1177   AC_LANG_C
1178
1179 dnl If we are running under X11 then add in the appropriate libraries.
1180   if test x"$no_x" != xyes; then
1181 dnl Add everything we need to compile and link X programs to GL_CFLAGS
1182 dnl and GL_X_LIBS/GLUT_X_LIBS.
1183     GL_CFLAGS="$CPPFLAGS $X_CFLAGS"
1184     GL_X_LIBS="$X_LIBS $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS $LIBM"
1185     GLUT_X_LIBS="$X_LIBS $X_PRE_LIBS -lXmu -lXt -lXi -lXext -lX11 $X_EXTRA_LIBS $LIBM"
1186   fi
1187   GL_save_CPPFLAGS="$CPPFLAGS"
1188   CPPFLAGS="$GL_CFLAGS"
1189
1190   GL_save_LIBS="$LIBS"
1191   LIBS="$GL_X_LIBS"
1192
1193   FPTOOLS_SEARCH_LIBS([#include <GL/gl.h>],   glEnd,         $GL_search_list,  have_GL=yes,   have_GL=no)
1194   FPTOOLS_SEARCH_LIBS([#include <GL/glu.h>],  gluNewQuadric, $GLU_search_list, have_GLU=yes,  have_GLU=no)
1195   FPTOOLS_SEARCH_LIBS([#include <GL/glx.h>],  glXWaitX,      $GLX_search_list, have_GLX=yes,  have_GLX=no)
1196
1197   if test -n "$LIBS"; then
1198     GL_LIBS="$LDFLAGS $LIBS"
1199   else
1200     GL_LIBS="$LDFLAGS"
1201     GL_CFLAGS=
1202   fi
1203
1204   LIBS="$GLUT_X_LIBS"
1205
1206   FPTOOLS_SEARCH_LIBS([#include <GL/glut.h>], glutMainLoop,  glut32 glut,      have_glut=yes, have_glut=no)
1207
1208   if test -n "$LIBS"; then
1209     GLUT_LIBS="$LDFLAGS $LIBS"
1210   fi
1211
1212   AC_CACHE_CHECK([OpenGL flags], mdl_cv_gl_cflags, [mdl_cv_gl_cflags="$GL_CFLAGS"])
1213   GL_CFLAGS="$mdl_cv_gl_cflags"
1214   AC_SUBST(GL_CFLAGS)
1215   AC_CACHE_CHECK([OpenGL libs],  mdl_cv_gl_libs,   [mdl_cv_gl_libs="$GL_LIBS"])
1216   GL_LIBS="$mdl_cv_gl_libs"
1217   AC_SUBST(GL_LIBS)
1218   AC_CACHE_CHECK([GLUT libs],  mdl_cv_glut_libs,   [mdl_cv_glut_libs="$GLUT_LIBS"])
1219   GLUT_LIBS="$mdl_cv_glut_libs"
1220   AC_SUBST(GLUT_LIBS)
1221
1222 dnl Reset GL_X_LIBS/GLUT_X_LIBS regardless, since they were just temporary variables
1223 dnl and we don't want to be global namespace polluters.
1224   GL_X_LIBS=
1225   GLUT_X_LIBS=
1226
1227   LIBS="$GL_save_LIBS"
1228   CPPFLAGS="$GL_save_CPPFLAGS"
1229
1230   AC_LANG_RESTORE
1231 ])
1232
1233 # LocalWords:  fi
1234
1235 dnl 
1236 dnl acspecific.m4's defn of AC_PROG_LEX is a bit too permissive, as it
1237 dnl defaults to 'lex' if 'flex' isn't found (without checking whether
1238 dnl 'lex' is actually present along the user's PATH).
1239 dnl
1240 AC_DEFUN(AC_PROG_LEX_STRICT,
1241 [AC_CHECK_PROG(LEX, flex, flex)
1242 if test -z "$LEX"
1243 then
1244   AC_CHECK_PROG(LEX,lex,lex)
1245   test -z "$LEX" && AC_MSG_ERROR(['lex' or 'flex' is required to compile GHC.])
1246 fi
1247 ])
1248
1249 dnl
1250 dnl Check to see whether CC (gcc) supports a particular option.
1251 dnl
1252 AC_DEFUN(FPTOOLS_CC_FLAG,
1253 [
1254 AC_CACHE_CHECK([whether $CC accepts $1], [ac_cv_cc_$2],
1255 [save_CFLAGS="$CFLAGS"
1256  CFLAGS="$CFLAGS $1"
1257  AC_LANG_C
1258  AC_TRY_COMPILE(,[int main(){return(0);}],
1259                  [ac_cv_cc_$2=yes],
1260                  [ac_cv_cc_$2=no])
1261  CFLAGS="$save_CFLAGS"
1262 ])
1263 if test "$ac_cv_cc_$2"x = "yesx"; then
1264   $2=$1;
1265 else
1266   $2="";
1267 fi;
1268 ])
1269
1270 dnl
1271 dnl Check to see whether 'struct msghdr' contains msg_control
1272 dnl 
1273 AC_DEFUN(FPTOOLS_MSGHDR_MSG_CONTROL,
1274 [AC_CACHE_CHECK([for msg_control in struct msghdr], fptools_cv_struct_msghdr_msg_control,
1275 [AC_TRY_COMPILE([#include <sys/types.h>
1276 #include <sys/uio.h>
1277 #include <sys/socket.h>], [struct msghdr m; m.msg_control;],
1278 fptools_cv_struct_msghdr_msg_control=yes, fptools_cv_struct_msghdr_msg_control=no)])
1279 if test $fptools_cv_struct_msghdr_msg_control = yes; then
1280   AC_DEFINE(HAVE_MSGHDR_MSG_CONTROL)
1281 fi
1282 AC_SUBST(HAVE_MSGHDR_MSG_CONTROL)dnl
1283 ])
1284
1285 dnl
1286 dnl Check to see whether 'struct msghdr' contains msg_accrights
1287 dnl 
1288 AC_DEFUN(FPTOOLS_MSGHDR_MSG_ACCRIGHTS,
1289 [AC_CACHE_CHECK([for msg_accrights in struct msghdr], fptools_cv_struct_msghdr_msg_accrights,
1290 [AC_TRY_COMPILE([#include <sys/types.h>
1291 #include <sys/uio.h>
1292 #include <sys/socket.h>], [struct msghdr m; m.msg_accrights;],
1293 fptools_cv_struct_msghdr_msg_accrights=yes, fptools_cv_struct_msghdr_msg_accrights=no)])
1294 if test $fptools_cv_struct_msghdr_msg_accrights = yes; then
1295   AC_DEFINE(HAVE_MSGHDR_MSG_ACCRIGHTS)
1296 fi
1297 AC_SUBST(HAVE_MSGHDR_MSG_ACCRIGHTS)dnl
1298 ])
1299