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