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