1 # Extra autoconf macros for the Glasgow fptools
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.
6 dnl *** Is altzone available? ***
8 AC_DEFUN(FPTOOLS_ALTZONE,
9 [AC_CACHE_CHECK([altzone], fptools_cv_altzone,
10 [AC_TRY_LINK([#if TIME_WITH_SYS_TIME
11 # include <sys/time.h>
15 # include <sys/time.h>
21 fptools_cv_altzone=yes, fptools_cv_altzone=no)])
22 if test "$fptools_cv_altzone" = yes; then
23 AC_DEFINE(HAVE_ALTZONE)
28 dnl *** Does libc contain GNU regex? ***
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
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
45 AC_SUBST(HaveGNURegex)
49 dnl ** check for leading underscores in symbol names
51 dnl Test for determining whether symbol names have a leading
54 dnl We assume that they _haven't_ if anything goes wrong.
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.
61 dnl Similarly on OpenBSD, but this test doesn't help. -- dons
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,
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?!?
71 dnl Another hack: cygwin doesn't come with nlist.h , so we hardwire
72 dnl the underscoredness of that "platform"
73 changequote(<<, >>)dnl
76 *openbsd*) # x86 openbsd is ELF from 3.4 >, meaning no leading uscore
78 i386-*2\.[[0-9]] | i386-*3\.[[0-3]] ) fptools_cv_lead_uscore='yes' ;;
79 *) fptools_cv_lead_uscore='no' ;;
81 alpha-dec-osf*) fptools_cv_lead_uscore='no';;
82 *cygwin32) fptools_cv_lead_uscore='yes';;
83 *mingw32) fptools_cv_lead_uscore='yes';;
86 AC_TRY_RUN([#ifdef HAVE_NLIST_H
88 changequote(<<, >>)dnl
90 struct nlist xYzzY1[] = {{"xYzzY1", 0},{0}};
91 struct nlist xYzzY2[] = {{"_xYzzY2", 0},{0}};
99 if(nlist(argv[0], xYzzY1) == 0 && xYzzY1[0].n_value != 0)
101 if(nlist(argv[0], xYzzY2) == 0 && xYzzY2[0].n_value != 0)
106 }], fptools_cv_lead_uscore=yes, fptools_cv_lead_uscore=no, fptools_cv_lead_uscore=NO)
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);;
117 dnl FPTOOLS_PROG_CHECK_VERSION(VERSIONSTR1, TEST, VERSIONSTR2,
118 dnl ACTION-IF-TRUE [, ACTION-IF-FALSE])
120 dnl compare versions field-wise (separator is '.')
121 dnl TEST is one of {-lt,-le,-eq,-ge,-gt}
123 dnl quite shell-independant and SUSv2 compliant code
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... ;)
128 AC_DEFUN(FPTOOLS_PROG_CHECK_VERSION,
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
138 test [$]{h1} [$2] [$]{h2}
140 then ifelse([$4],,[:],[
150 dnl Check for Greencard and version.
152 AC_DEFUN(FPTOOLS_GREENCARD,
154 AC_PATH_PROG(GreencardCmd,greencard)
155 AC_CACHE_CHECK([for version of greencard], fptools_cv_greencard_version,
157 [if test x"$GreencardCmd" != x; then
158 fptools_cv_greencard_version="`$GreencardCmd --version |
159 grep 'version' | sed -e 's/greencard. version \([^ ]*\).*/\1/g'`"
161 fptools_cv_greencard_version=""
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)
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.
176 AC_DEFUN(FPTOOLS_HAPPY,
178 if test -d $srcdir/happy; then
179 SrcTreeHappyCmd=$hardtop/happy/src/happy-inplace
181 if test x"$UseSrcTreeHappy" = xYES; then
182 HappyCmd=$SrcTreeHappyCmd
184 AC_PATH_PROG(HappyCmd,happy,$SrcTreeHappyCmd)
186 AC_CACHE_CHECK([for version of happy], fptools_cv_happy_version,
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'`" ;
194 fptools_cv_happy_version="";
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
202 HappyVersion=$fptools_cv_happy_version;
203 AC_SUBST(HappyVersion)
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.
210 AC_DEFUN(FPTOOLS_HADDOCK,
212 if test -d $srcdir/haddock; then
213 SrcTreeHaddockCmd=$hardtop/haddock/src/haddock-inplace
215 if test x"$UseSrcTreeHaddock" = xYES; then
216 HaddockCmd=$SrcTreeHaddockCmd
218 AC_PATH_PROG(HaddockCmd,haddock,$SrcTreeHaddockCmd)
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.
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.
231 AC_DEFUN(FPTOOLS_ALEX,
233 if test -d $srcdir/alex; then
234 SrcTreeAlexCmd=$hardtop/alex/src/alex-inplace
236 if test x"$UseSrcTreeAlex" = xYES; then
237 AlexCmd=$SrcTreeAlexCmd
239 AC_PATH_PROG(AlexCmd,alex,$SrcTreeAlexCmd)
241 AC_CACHE_CHECK([for version of alex], fptools_cv_alex_version,
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'`" ;
249 fptools_cv_alex_version="";
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
257 AlexVersion=$fptools_cv_alex_version;
258 AC_SUBST(AlexVersion)
262 dnl What's the best way of doing context diffs?
264 dnl (NB: NeXTStep thinks diff'ing a file against itself is "trouble")
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
270 if diff -C 1 conftest1 conftest2 > /dev/null 2>&1 ; then
271 fptools_cv_context_diffs='diff -C 1'
273 if diff -c1 conftest1 conftest2 > /dev/null 2>&1 ; then
274 fptools_cv_context_diffs='diff -c1'
276 echo "Can't figure out how to do context diffs."
277 echo "Neither \`diff -C 1' nor \`diff -c1' works."
281 rm -f conftest1 conftest2
283 ContextDiffCmd=$fptools_cv_context_diffs
284 AC_SUBST(ContextDiffCmd)
288 dnl Check whether ld supports -x
290 AC_DEFUN(FPTOOLS_LD_X,
291 [AC_CACHE_CHECK([whether ld understands -x], fptools_cv_ld_x,
293 echo 'foo() {}' > conftest.c
294 ${CC-cc} -c conftest.c
295 if ${LdCmd} -r -x -o foo.o conftest.o; then
300 rm -rf conftest.c conftest.o foo.o
302 if test "$fptools_cv_ld_x" = yes; then
311 dnl Finding the Right Yacc
313 AC_DEFUN(FPTOOLS_PROG_YACCY,
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
325 echo "I'm assuming the worst...no parser generator at all"
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"
333 ac_cv_prog_yacc=$YACC
338 ac_cv_prog_yacc=$YACC
340 YaccCmd=$ac_cv_prog_yacc
344 dnl *** Checking for ar and its arguments + whether we need ranlib.
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.
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"
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
362 elif $ArCmdRaw clqsZ conftest.a >/dev/null 2>/dev/null; then
365 elif $ArCmdRaw clqs conftest.a >/dev/null 2>/dev/null; then
368 elif $ArCmdRaw cqs conftest.a >/dev/null 2>/dev/null; then
371 elif $ArCmdRaw clq conftest.a >/dev/null 2>/dev/null; then
374 elif $ArCmdRaw cq conftest.a >/dev/null 2>/dev/null; then
377 elif $ArCmdRaw cq conftest.a 2>&1 | grep 'no archive members specified' >/dev/null 2>/dev/null; then
381 echo "I can't figure out how to use your $ArCmd"
385 case $HostPlatform in
387 ArCmd="`cygpath -w ${ArCmdRaw} | sed -e 's@\\\\@/@g' ` ${ArCmdArgs}"
389 *) ArCmd="${ArCmdRaw} ${ArCmdArgs}"
392 test -n "$ArCmd" && test -n "$verbose" && echo " setting ArCmd to $ArCmd"
394 if $ArCmd conftest.a -input /dev/null >/dev/null 2>/dev/null; then
395 ArSupportsInput='-input'
400 test -n "$ArSupportsInput" && test -n "$verbose" && echo " setting ArSupportsInput to $ArSupportsInput"
401 AC_SUBST(ArSupportsInput)
402 if test -z "$NeedRanLib"; then
404 test -n "$verbose" && echo " setting RANLIB to $RANLIB"
412 dnl AC_SHEBANG_PERL - can we she-bang perl?
414 AC_DEFUN(FPTOOLS_SHEBANG_PERL,
415 [AC_CACHE_CHECK([if your perl works in shell scripts], fptools_cv_shebang_perl,
420 (SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
421 if test $? -ne 69; then
422 fptools_cv_shebang_perl=yes
424 fptools_cv_shebang_perl=no
430 dnl Extra testing of the result AC_PROG_CC, testing the gcc version no.
431 dnl *Must* be called after AC_PROG_CC
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
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'
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' `"
444 fptools_cv_have_gcc='yes'
445 FPTOOLS_PROG_CHECK_VERSION($gcc_version_str, -lt, "2.0",
446 fptools_cv_have_gcc='no'
448 echo "your gcc version appears to be ..."
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])
456 HaveGcc=`echo $fptools_cv_have_gcc | sed 'y/yesno/YESNO/'`
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.
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,
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')
473 if test "$fptools_cv_gcc_needs_no_omit_lfptr" = "yes"; then
474 AC_DEFINE(HAVE_GCC_MNO_OMIT_LFPTR)
478 dnl Small feature test for perl version. Assumes PerlCmd
479 dnl contains path to perl binary
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
486 if grep "v5.6" conftest.out >/dev/null 2>&1; then
489 if grep "v5.8" conftest.out >/dev/null 2>&1; then
492 if grep "version 6" conftest.out >/dev/null 2>&1; then
495 echo "Your version of perl probably won't work."
504 dnl Getting at the right version of 'find'
505 dnl (i.e., not the MS util on a Win32 box).
507 AC_DEFUN(FPTOOLS_FIND_FIND,
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.
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)
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
533 AC_DEFUN(FPTOOLS_NOCACHE_CHECK,
534 [AC_MSG_CHECKING([$1])
536 AC_MSG_RESULT([$][$2])
540 dnl FPTOOLS_GHC_VERSION(version)
541 dnl FPTOOLS_GHC_VERSION(major, minor [, patchlevel])
542 dnl FPTOOLS_GHC_VERSION(version, major, minor, patchlevel)
544 dnl Test for version of installed ghc. Uses $GHC.
545 dnl [original version pinched from c2hs]
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'`
554 if test "[$]fptools_version_of_ghc" = ""
556 fptools_version_of_ghc='unknown'
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'`
562 if test "[$]fptools_version_of_ghc[_pl]" = ""
564 fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor]"
565 fptools_version_of_ghc[_pl]="0"
567 fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor].[$]fptools_version_of_ghc[_pl]"
571 [$1]="[$]fptools_version_of_ghc[_all]"
573 [$1]="[$]fptools_version_of_ghc[_major]"
574 [$2]="[$]fptools_version_of_ghc[_minor]"
576 [$1]="[$]fptools_version_of_ghc[_major]"
577 [$2]="[$]fptools_version_of_ghc[_minor]"
578 [$3]="[$]fptools_version_of_ghc[_pl]"
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]"
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)
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
603 AC_MSG_CHECKING(alignment of $1)
604 AC_CACHE_VAL(AC_CV_NAME,
611 #define offsetof(ty,field) ((size_t)((char *)&((ty *)0)->field - (char *)(ty *)0))
616 FILE *f=fopen("conftestval", "w");
618 fprintf(f, "%d", offsetof(struct { char c; $1 ty;},ty));
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
632 dnl ** Map an arithmetic C type to a Haskell type.
633 dnl Based on autconf's AC_CHECK_SIZEOF.
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
643 AC_MSG_CHECKING(Haskell type for $1)
644 AC_CACHE_VAL(AC_CV_NAME,
645 [AC_TRY_RUN([#include <stdio.h>
648 #ifdef HAVE_SYS_TYPES_H
649 # include <sys/types.h>
656 #ifdef HAVE_SYS_STAT_H
657 # include <sys/stat.h>
672 #ifdef HAVE_TERMIOS_H
673 # include <termios.h>
688 #ifdef HAVE_OPENGL_GL_H
689 # include <OpenGL/gl.h>
692 #ifdef HAVE_SYS_RESOURCE_H
693 # include <sys/resource.h>
699 FILE *f=fopen("conftestval", "w");
701 if (((testing)((int)((testing)1.4))) == ((testing)1.4)) {
703 ((testing)(-1) < (testing)0) ? "Int" : "Word",
707 (sizeof(testing) > sizeof(double)) ? "LDouble" :
708 (sizeof(testing) == sizeof(double)) ? "Double" : "Float");
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
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++)
725 dnl If the C compiler supports `long long' types,
726 dnl define `HAVE_LONG_LONG'.
728 AC_DEFUN(FPTOOLS_C_LONG_LONG,
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,
736 AC_TRY_COMPILE(,[long long a;],
737 fptools_cv_have_long_long=yes,
738 fptools_cv_have_long_long=no)
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)
747 dnl ** Obtain the value of a C constant.
748 dnl The value will be `(-1)' if the constant is undefined.
750 dnl This is set up so that the argument can be a shell variable.
752 AC_DEFUN(FPTOOLS_CHECK_CCONST,
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>
761 FILE *f=fopen("conftestval", "w");
763 fprintf(f, "%d\n", $1);
766 eval "$cv_name=`cat conftestval`",
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
775 dnl ** Invoke AC_CHECK_CCONST on each argument (which have to separate with
778 AC_DEFUN(FPTOOLS_CHECK_CCONSTS,
779 [for ac_const_name in $1
781 FPTOOLS_CHECK_CCONST($ac_const_name)dnl
786 dnl *** Can we open files in binary mode? ***
788 AC_DEFUN(FPTOOLS_O_BINARY,
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,
801 fptools_cv_have_o_binary=yes,
802 fptools_cv_have_o_binary=no)
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)
811 dnl *** Helper function **
813 AC_DEFUN(FPTOOLS_IN_SCOPE,
814 [AC_TRY_LINK([extern char* $1;],[return (int)&$2], $3=yes, $3=no)
818 dnl Based on AC_TRY_LINK - run iftrue if links cleanly with no warning
820 dnl FPTOOLS_TRY_LINK_NOWARN(flags,main?,iftrue,iffalse)
822 AC_DEFUN(FPTOOLS_TRY_LINK_NOWARN,
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"
832 int t() { return 0; }
834 if AC_TRY_EVAL(ac_link); then
839 ifelse([$4], , , [else
849 dnl Loosely based on AC_CHECK_LIB in acgeneral.m4 in autoconf distribution
851 dnl FPTOOLS_CHECK_FLAG_NOWARN(NAME, FLAG, CODE, iftrue, iffalse)
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"
861 if eval "test \"`echo '$ac_cv_flag_'$1`\" = yes"; then
871 dnl FPTOOLS_CHECK_LIB_NOWARN(LIBRARY, FUNCTION)
873 AC_DEFUN(FPTOOLS_CHECK_LIB_NOWARN,
874 [FPTOOLS_CHECK_FLAG_NOWARN([function_$2],[],[extern char $2(); $2();],
876 ac_tr_lib=HAVE_LIB`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
878 AC_DEFINE_UNQUOTED($ac_tr_lib)
880 [FPTOOLS_CHECK_FLAG_NOWARN([library_$1],[-l$1],[extern char $2(); $2();],
882 ac_tr_lib=HAVE_LIB`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
884 AC_DEFINE_UNQUOTED($ac_tr_lib)
890 dnl check for prototypes
892 AC_DEFUN([AC_C_PROTOTYPES],
893 [AC_CACHE_CHECK([prototypes], ac_cv_prototypes,
902 ac_cv_prototypes=yes,
903 ac_cv_prototypes=no)])
904 if test "$ac_cv_prototypes" = yes; then
905 AC_DEFINE([HAVE_PROTOTYPES])
909 dnl ** Check which CATALOG file we have to use with DocBook SGML.
911 dnl FPTOOLS_DOCBOOK_CATALOG(VARIABLE, JADE, STYLESHEET, CATALOGS-TO-CHECK-FOR)
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.
918 AC_DEFUN(FPTOOLS_DOCBOOK_CATALOG,
919 [AC_CACHE_CHECK([for DocBook CATALOG], fptools_cv_sgml_catalog,
921 cat > conftest.sgml << EOF
922 <!DOCTYPE Article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
926 <Author><OtherName>Test</OtherName></Author>
927 <Address>Test</Address>
928 <PubDate>Test</PubDate>
930 <Sect1><Title>Test</Title>
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
947 # If the env var SGML_CATALOG_FILES is defined, assume things are cool.
948 fptools_cv_sgml_catalog="yes"
952 if test $fptools_cv_sgml_catalog != "no"; then
953 $1=$fptools_cv_sgml_catalog
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
963 dnl ######################################################################
965 AC_DEFUN(FPTOOLS_SEARCH_LIBS,
967 AC_CACHE_CHECK([for library containing $2], [ac_cv_search_$2],
968 [ac_func_search_save_LIBS="$LIBS"
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"
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"
985 dnl ####################### -*- Mode: M4 -*- ###########################
986 dnl Copyright (C) 98, 1999 Matthew D. Langston <langston@SLAC.Stanford.EDU>
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.
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.
998 dnl You should have received a copy of the GNU General Public License
999 dnl along with this file; if not, write to:
1001 dnl Free Software Foundation, Inc.
1004 dnl Boston, MA 02111-1307, USA.
1005 dnl ####################################################################
1008 dnl @synopsis FPTOOLS_CHECK_LIBM
1010 dnl Search for math library (typically -lm).
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.
1016 dnl @author Matthew D. Langston <langston@SLAC.Stanford.EDU>
1018 # FPTOOLS_CHECK_LIBM - check for math library
1019 AC_DEFUN(FPTOOLS_CHECK_LIBM,
1020 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
1024 # These system don't have libm
1027 AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
1028 AC_CHECK_LIB(m, main, LIBM="$LIBM -lm")
1031 AC_CHECK_LIB(m, main, LIBM="-lm")
1036 dnl ######################################################################
1037 dnl Note: Caching has been completely rewritten, but is still no perfect yet.
1038 dnl ######################################################################
1040 dnl ########################### -*- Mode: M4 -*- #######################
1041 dnl Copyright (C) 98, 1999 Matthew D. Langston <langston@SLAC.Stanford.EDU>
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.
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.
1053 dnl You should have received a copy of the GNU General Public License
1054 dnl along with this file; if not, write to:
1056 dnl Free Software Foundation, Inc.
1059 dnl Boston, MA 02111-1307, USA.
1060 dnl ####################################################################
1062 dnl @synopsis FPTOOLS_HAVE_OPENGL
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'.
1068 dnl The four "standard" OpenGL libraries are searched for: "-lGL",
1069 dnl "-lGLU", "-lGLX" (or "-lMesaGL", "-lMesaGLU" as the case may be) and
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
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.
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.
1092 dnl A complete little toy "Automake `make distcheck'" package of how to
1093 dnl use this macro is available at:
1095 dnl ftp://ftp.slac.stanford.edu/users/langston/autoconf/ac_opengl-0.01.tar.gz
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.
1101 dnl @author Matthew D. Langston <langston@SLAC.Stanford.EDU>
1103 AC_DEFUN(FPTOOLS_HAVE_OPENGL,
1105 AC_REQUIRE([AC_PROG_CC])
1106 AC_REQUIRE([AC_PATH_X])
1107 AC_REQUIRE([AC_PATH_XTRA])
1108 AC_REQUIRE([FPTOOLS_CHECK_LIBM])
1110 dnl Check for Mesa first if we were asked to.
1113 Prefer Mesa over a vendor's native OpenGL library (default=no)
1115 use_Mesa=$enableval,
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"
1123 GL_search_list="GL opengl32 MesaGL"
1124 GLU_search_list="GLU glu32 MesaGLU"
1125 GLX_search_list="GLX MesaGLX"
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"
1139 GL_save_CPPFLAGS="$CPPFLAGS"
1140 CPPFLAGS="$GL_CFLAGS"
1142 GL_save_LIBS="$LIBS"
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)
1149 if test -n "$LIBS"; then
1150 GL_LIBS="$LDFLAGS $LIBS"
1158 FPTOOLS_SEARCH_LIBS([#include <GL/glut.h>], glutMainLoop, glut32 glut, have_glut=yes, have_glut=no)
1160 if test -n "$LIBS"; then
1161 GLUT_LIBS="$LDFLAGS $LIBS"
1164 AC_CACHE_CHECK([OpenGL flags], mdl_cv_gl_cflags, [mdl_cv_gl_cflags="$GL_CFLAGS"])
1165 GL_CFLAGS="$mdl_cv_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"
1170 AC_CACHE_CHECK([GLUT libs], mdl_cv_glut_libs, [mdl_cv_glut_libs="$GLUT_LIBS"])
1171 GLUT_LIBS="$mdl_cv_glut_libs"
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.
1179 LIBS="$GL_save_LIBS"
1180 CPPFLAGS="$GL_save_CPPFLAGS"
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).
1192 AC_DEFUN(AC_PROG_LEX_STRICT,
1193 [AC_CHECK_PROG(LEX, flex, flex)
1196 AC_CHECK_PROG(LEX,lex,lex)
1197 test -z "$LEX" && AC_MSG_ERROR(['lex' or 'flex' is required to compile GHC.])
1202 dnl Check to see whether CC (gcc) supports a particular option.
1204 AC_DEFUN(FPTOOLS_CC_FLAG,
1206 AC_CACHE_CHECK([whether $CC accepts $1], [ac_cv_cc_$2],
1207 [save_CFLAGS="$CFLAGS"
1210 AC_TRY_COMPILE(,[int main(){return(0);}],
1213 CFLAGS="$save_CFLAGS"
1215 if test "$ac_cv_cc_$2"x = "yesx"; then
1223 dnl Check to see whether 'struct msghdr' contains msg_control
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)
1234 AC_SUBST(HAVE_MSGHDR_MSG_CONTROL)dnl
1238 dnl Check to see whether 'struct msghdr' contains msg_accrights
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)
1249 AC_SUBST(HAVE_MSGHDR_MSG_ACCRIGHTS)dnl