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