1 dnl Extra autoconf macros for the Glasgow fptools
3 dnl To be a good autoconf citizen, names of local macros have
4 dnl prefixed with FPTOOLS_ to ensure we don't clash
5 dnl with any pre-supplied autoconf ones.
7 dnl *** Is altzone available? ***
9 AC_DEFUN(FPTOOLS_ALTZONE,
10 [AC_CACHE_CHECK([altzone], fptools_cv_altzone,
11 [AC_TRY_LINK([#if TIME_WITH_SYS_TIME
12 # include <sys/time.h>
16 # include <sys/time.h>
22 fptools_cv_altzone=yes, fptools_cv_altzone=no)])
23 if test "$fptools_cv_altzone" = yes; then
24 AC_DEFINE(HAVE_ALTZONE)
29 dnl *** Does libc contain GNU regex? ***
31 AC_DEFUN(FPTOOLS_REGEX_IN_LIBC,
32 [AC_CACHE_CHECK([for GNU regex in libc], fptools_cv_have_regex,
33 [AC_TRY_LINK([#if HAVE_UNISTD_H
37 ],[ struct re_pattern_buffer patbuf;
38 re_compile_pattern("",0,&patbuf);
39 re_search_2 (&patbuf, "", 0, "",0, 0,0,0,0); ],
40 fptools_cv_have_regex=yes, fptools_cv_have_regex=no)])
41 if test "$fptools_cv_have_regex" = yes; then
46 AC_SUBST(HaveGNURegex)
50 dnl ** check for leading underscores in symbol names
52 dnl Test for determining whether symbol names have a leading
55 dnl We assume that they _haven't_ if anything goes wrong.
57 dnl Some nlist implementations seem to try to be compatible by ignoring
58 dnl a leading underscore sometimes (eg. FreeBSD). We therefore have
59 dnl to work around this by checking for *no* leading underscore first.
62 dnl Similarly on OpenBSD, but this test doesn't help. -- dons
64 AC_DEFUN(FPTOOLS_UNDERSCORE,
65 [AC_CHECK_LIB(elf, nlist, LIBS="-lelf $LIBS")dnl
66 AC_CACHE_CHECK([leading underscore in symbol names], fptools_cv_lead_uscore,
69 dnl Hack!: nlist() under Digital UNIX insist on there being an _,
70 dnl but symbol table listings shows none. What is going on here?!?
72 dnl Another hack: cygwin doesn't come with nlist.h , so we hardwire
73 dnl the underscoredness of that "platform"
74 changequote(<<, >>)dnl
77 *openbsd*) # x86 openbsd is ELF from 3.4 >, meaning no leading uscore
79 i386-*2\.[[0-9]] | i386-*3\.[[0-3]] ) fptools_cv_lead_uscore='yes' ;;
80 *) fptools_cv_lead_uscore='no' ;;
82 alpha-dec-osf*) fptools_cv_lead_uscore='no';;
83 *cygwin32) fptools_cv_lead_uscore='yes';;
84 *mingw32) fptools_cv_lead_uscore='yes';;
87 AC_TRY_RUN([#ifdef HAVE_NLIST_H
89 changequote(<<, >>)dnl
91 struct nlist xYzzY1[] = {{"xYzzY1", 0},{0}};
92 struct nlist xYzzY2[] = {{"_xYzzY2", 0},{0}};
100 if(nlist(argv[0], xYzzY1) == 0 && xYzzY1[0].n_value != 0)
102 if(nlist(argv[0], xYzzY2) == 0 && xYzzY2[0].n_value != 0)
107 }], fptools_cv_lead_uscore=yes, fptools_cv_lead_uscore=no, fptools_cv_lead_uscore=NO)
110 LeadingUnderscore=`echo $fptools_cv_lead_uscore | sed 'y/yesno/YESNO/'`
111 AC_SUBST(LeadingUnderscore)
112 case $LeadingUnderscore in
113 YES) AC_DEFINE(LEADING_UNDERSCORE);;
118 dnl FPTOOLS_PROG_CHECK_VERSION(VERSIONSTR1, TEST, VERSIONSTR2,
119 dnl ACTION-IF-TRUE [, ACTION-IF-FALSE])
121 dnl compare versions field-wise (separator is '.')
122 dnl TEST is one of {-lt,-le,-eq,-ge,-gt}
124 dnl quite shell-independant and SUSv2 compliant code
126 dnl NOTE: the loop could be unrolled within autoconf, but the
127 dnl macro code would be a) longer and b) harder to debug... ;)
129 AC_DEFUN(FPTOOLS_PROG_CHECK_VERSION,
134 set -- [$]a; h1="[$]1"; shift 2>/dev/null; a="[$]*"
135 set -- [$]b; h2="[$]1"; shift 2>/dev/null; b="[$]*"
136 test -n "[$]h1" || h1=0; test -n "[$]h2" || h2=0
137 test [$]{h1} -eq [$]{h2} || break
139 test [$]{h1} [$2] [$]{h2}
141 then ifelse([$4],,[:],[
151 dnl Check for Greencard and version.
153 AC_DEFUN(FPTOOLS_GREENCARD,
155 AC_PATH_PROG(GreencardCmd,greencard)
156 AC_CACHE_CHECK([for version of greencard], fptools_cv_greencard_version,
158 [if test x"$GreencardCmd" != x; then
159 fptools_cv_greencard_version="`$GreencardCmd --version |
160 grep 'version' | sed -e 's/greencard. version \([^ ]*\).*/\1/g'`"
162 fptools_cv_greencard_version=""
166 FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_greencard_version],-lt,$1,
167 [AC_MSG_ERROR([greencard version $1 or later is required (found '$fptools_cv_greencard_version')])])dnl
168 GreencardVersion=$fptools_cv_greencard_version
169 AC_SUBST(GreencardVersion)
173 dnl Check for Happy and version. If we're building GHC, then we need
174 dnl at least Happy version 1.13. If there's no installed Happy, we look
175 dnl for a happy source tree and point the build system at that instead.
177 AC_DEFUN(FPTOOLS_HAPPY,
179 if test -d $srcdir/happy; then
180 SrcTreeHappyCmd=$hardtop/happy/src/happy-inplace
182 if test x"$UseSrcTreeHappy" = xYES; then
183 HappyCmd=$SrcTreeHappyCmd
185 AC_PATH_PROG(HappyCmd,happy,$SrcTreeHappyCmd)
187 AC_CACHE_CHECK([for version of happy], fptools_cv_happy_version,
189 [if test x"$HappyCmd" = x"$SrcTreeHappyCmd"; then
190 fptools_cv_happy_version=`grep '^ProjectVersion[ ]*=' $srcdir/happy/mk/version.mk | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`;
191 elif test x"$HappyCmd" != x; then
192 fptools_cv_happy_version="`$HappyCmd -v |
193 grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'`" ;
195 fptools_cv_happy_version="";
199 if test -d $srcdir/ghc -a ! -f $srcdir/ghc/compiler/parser/Parser.hs; then
200 FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_happy_version],-lt,[1.13],
201 [AC_MSG_ERROR([Happy version 1.13 or later is required to compile GHC.])])dnl
203 HappyVersion=$fptools_cv_happy_version;
204 AC_SUBST(HappyVersion)
208 dnl Check for Haddock and version. If there's no installed Haddock, we look
209 dnl for a haddock source tree and point the build system at that instead.
211 AC_DEFUN(FPTOOLS_HADDOCK,
213 if test -d $srcdir/haddock; then
214 SrcTreeHaddockCmd=$hardtop/haddock/src/haddock-inplace
216 if test x"$UseSrcTreeHaddock" = xYES; then
217 HaddockCmd=$SrcTreeHaddockCmd
219 AC_PATH_PROG(HaddockCmd,haddock,$SrcTreeHaddockCmd)
221 dnl Darn, I forgot to make Haddock print out its version number when
222 dnl invoked with -v. We could try generating some HTML and grepping
223 dnl through that to find the version number, but I think we'll make
224 dnl do without it for now.
228 dnl Check for Alex and version. If we're building GHC, then we need
229 dnl at least Alex version 2.0. If there's no installed Alex, we look
230 dnl for a alex source tree and point the build system at that instead.
232 AC_DEFUN(FPTOOLS_ALEX,
234 if test -d $srcdir/alex; then
235 SrcTreeAlexCmd=$hardtop/alex/src/alex-inplace
237 if test x"$UseSrcTreeAlex" = xYES; then
238 AlexCmd=$SrcTreeAlexCmd
240 AC_PATH_PROG(AlexCmd,alex,$SrcTreeAlexCmd)
242 AC_CACHE_CHECK([for version of alex], fptools_cv_alex_version,
244 [if test x"$AlexCmd" = x"$SrcTreeAlexCmd"; then
245 fptools_cv_alex_version=`grep '^ProjectVersion[ ]*=' $srcdir/alex/mk/version.mk | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`;
246 elif test x"$AlexCmd" != x; then
247 fptools_cv_alex_version="`$AlexCmd -v |
248 grep 'Alex [Vv]ersion' | sed -e 's/Alex [Vv]ersion \([0-9\.]*\).*/\1/g'`" ;
250 fptools_cv_alex_version="";
254 dnl if test -d $srcdir/ghc -a ! -f $srcdir/ghc/compiler/parser/Lexer.hs; then
255 dnl FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_alex_version],-lt,[2.0],
256 dnl [AC_MSG_ERROR([Alex version 2.0 or later is required to compile GHC.])])dnl
258 AlexVersion=$fptools_cv_alex_version;
259 AC_SUBST(AlexVersion)
263 dnl What's the best way of doing context diffs?
265 dnl (NB: NeXTStep thinks diff'ing a file against itself is "trouble")
267 AC_DEFUN(FPTOOLS_PROG_DIFF,
268 [AC_CACHE_CHECK([for ok way to do context diffs], fptools_cv_context_diffs,
269 [echo foo > conftest1
271 if diff -C 1 conftest1 conftest2 > /dev/null 2>&1 ; then
272 fptools_cv_context_diffs='diff -C 1'
274 if diff -c1 conftest1 conftest2 > /dev/null 2>&1 ; then
275 fptools_cv_context_diffs='diff -c1'
277 echo "Can't figure out how to do context diffs."
278 echo "Neither \`diff -C 1' nor \`diff -c1' works."
282 rm -f conftest1 conftest2
284 ContextDiffCmd=$fptools_cv_context_diffs
285 AC_SUBST(ContextDiffCmd)
289 dnl Check whether ld supports -x
291 AC_DEFUN(FPTOOLS_LD_X,
292 [AC_CACHE_CHECK([whether ld understands -x], fptools_cv_ld_x,
294 echo 'foo() {}' > conftest.c
295 ${CC-cc} -c conftest.c
296 if ${LdCmd} -r -x -o foo.o conftest.o; then
301 rm -rf conftest.c conftest.o foo.o
303 if test "$fptools_cv_ld_x" = yes; then
312 dnl Finding the Right Yacc
314 AC_DEFUN(FPTOOLS_PROG_YACCY,
316 if test "$YACC" = "yacc"; then
317 AC_CACHE_CHECK([if it is an OK yacc], ac_cv_prog_yacc,
318 [AC_CHECK_PROG(WhatCmd, what, what, :)
319 $WhatCmd $YACC > conftest.out
320 if egrep 'y1\.c 1\..*SMI' conftest.out >/dev/null 2>&1; then
321 echo "I don't trust your $YaccCmd; it looks like an old Sun yacc"
322 if test -f /usr/lang/yacc; then
323 echo "I'm going to use /usr/lang/yacc instead"
324 ac_cv_prog_yacc=/usr/lang/yacc
326 echo "I'm assuming the worst...no parser generator at all"
329 elif egrep 'y1\.c.*Revision: 4\.2\.6\.3.*DEC' conftest.out >/dev/null 2>&1; then
330 echo "I don't trust your $YaccCmd; it looks like a lame DEC yacc"
331 echo "I'm assuming the worst...no parser generator at all"
334 ac_cv_prog_yacc=$YACC
339 ac_cv_prog_yacc=$YACC
341 YaccCmd=$ac_cv_prog_yacc
345 dnl *** Checking for ar and its arguments + whether we need ranlib.
347 dnl ArCmd, ArSupportsInput and RANLIB are AC_SUBST'ed
348 dnl On Digital UNIX, we test for the -Z (compress) and
349 dnl -input (take list of files from external file) flags.
351 AC_DEFUN(FPTOOLS_PROG_AR_AND_RANLIB,
352 [AC_PATH_PROG(ArCmdRaw,ar)
353 if test -z "$ArCmdRaw"; then
354 echo "You don't seem to have ar in your PATH...I have no idea how to make a library"
357 dnl GNU ar needs special treatment: it appears to have problems with
358 dnl object files with the same name if you use the 's' modifier, but
359 dnl simple 'ar q' works fine, and doesn't need a separate ranlib.
360 if $ArCmdRaw --version | grep 'GNU' >/dev/null 2>/dev/null; then
363 elif $ArCmdRaw clqsZ conftest.a >/dev/null 2>/dev/null; then
366 elif $ArCmdRaw clqs conftest.a >/dev/null 2>/dev/null; then
369 elif $ArCmdRaw cqs conftest.a >/dev/null 2>/dev/null; then
372 elif $ArCmdRaw clq conftest.a >/dev/null 2>/dev/null; then
375 elif $ArCmdRaw cq conftest.a >/dev/null 2>/dev/null; then
378 elif $ArCmdRaw cq conftest.a 2>&1 | grep 'no archive members specified' >/dev/null 2>/dev/null; then
382 echo "I can't figure out how to use your $ArCmd"
386 case $HostPlatform in
388 ArCmd="`cygpath -w ${ArCmdRaw} | sed -e 's@\\\\@/@g' ` ${ArCmdArgs}"
390 *) ArCmd="${ArCmdRaw} ${ArCmdArgs}"
393 test -n "$ArCmd" && test -n "$verbose" && echo " setting ArCmd to $ArCmd"
395 if $ArCmd conftest.a -input /dev/null >/dev/null 2>/dev/null; then
396 ArSupportsInput='-input'
401 test -n "$ArSupportsInput" && test -n "$verbose" && echo " setting ArSupportsInput to $ArSupportsInput"
402 AC_SUBST(ArSupportsInput)
403 if test -z "$NeedRanLib"; then
405 test -n "$verbose" && echo " setting RANLIB to $RANLIB"
413 dnl AC_SHEBANG_PERL - can we she-bang perl?
415 AC_DEFUN(FPTOOLS_SHEBANG_PERL,
416 [AC_CACHE_CHECK([if your perl works in shell scripts], fptools_cv_shebang_perl,
421 (SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
422 if test $? -ne 69; then
423 fptools_cv_shebang_perl=yes
425 fptools_cv_shebang_perl=no
431 dnl Extra testing of the result AC_PROG_CC, testing the gcc version no.
432 dnl *Must* be called after AC_PROG_CC
434 AC_DEFUN(FPTOOLS_HAVE_GCC,
435 [AC_CACHE_CHECK([whether you have an ok gcc], fptools_cv_have_gcc,
436 [if test -z "$GCC"; then
438 echo "You would be better off with gcc"
439 echo "Perhaps it is already installed, but not in your PATH?"
440 fptools_cv_have_gcc='no'
443 gcc_version_str="`$CC -v 2>&1 | grep 'version ' | sed -e 's/.*version [^0-9]*\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1\.\2/g' `"
445 fptools_cv_have_gcc='yes'
446 FPTOOLS_PROG_CHECK_VERSION($gcc_version_str, -lt, "2.0",
447 fptools_cv_have_gcc='no'
449 echo "your gcc version appears to be ..."
451 echo "gcc prior to 2.0 and have never worked with ghc."
452 echo "we recommend 2.95.3, although versions back to 2.7.2 should be ok."
453 AC_MSG_ERROR([gcc 1.X has never been supported])
457 HaveGcc=`echo $fptools_cv_have_gcc | sed 'y/yesno/YESNO/'`
462 dnl Some OSs (Mandrake Linux, in particular) configure GCC with
463 dnl -momit-leaf-frame-pointer on by default. If this is the case, we
464 dnl need to turn it off for mangling to work. The test is currently a bit
465 dnl crude, using only the version number of gcc.
467 AC_DEFUN(FPTOOLS_GCC_NEEDS_NO_OMIT_LFPTR,
468 [AC_CACHE_CHECK([whether gcc needs -mno-omit-leaf-frame-pointer], fptools_cv_gcc_needs_no_omit_lfptr,
470 fptools_cv_gcc_needs_no_omit_lfptr='no'
471 FPTOOLS_PROG_CHECK_VERSION($gcc_version_str, -ge, "3.2",
472 fptools_cv_gcc_needs_no_omit_lfptr='yes')
474 if test "$fptools_cv_gcc_needs_no_omit_lfptr" = "yes"; then
475 AC_DEFINE(HAVE_GCC_MNO_OMIT_LFPTR)
479 dnl Small feature test for perl version. Assumes PerlCmd
480 dnl contains path to perl binary
482 AC_DEFUN(FPTOOLS_CHECK_PERL_VERSION,
483 [$PerlCmd -v >conftest.out 2>&1
484 if grep "version 5" conftest.out >/dev/null 2>&1; then
487 if grep "v5.6" conftest.out >/dev/null 2>&1; then
490 if grep "v5.8" conftest.out >/dev/null 2>&1; then
493 if grep "version 6" conftest.out >/dev/null 2>&1; then
496 echo "Your version of perl probably won't work."
505 dnl Getting at the right version of 'find'
506 dnl (i.e., not the MS util on a Win32 box).
508 AC_DEFUN(FPTOOLS_FIND_FIND,
510 AC_PATH_PROG(Find2Cmd, find)
511 $Find2Cmd --version > conftest.out 2>&1
512 if grep "FIND: Parameter format" conftest.out >/dev/null 2>&1 ; then
513 # Encountered MS' find utility, which is not what we're after.
515 # HACK - AC_CHECK_PROG is useful here in that does let you reject
516 # an (absolute) entry in the path (Find2Cmd). It is not so useful
517 # in that it doesn't let you (AFAIU) set VARIABLE equal to the
518 # absolute path eventually found. So, hack around this by inspecting
519 # what variables hold the abs. path & use them directly.
520 AC_CHECK_PROG(FindCmd,find,`echo $ac_dir/$ac_word`,find,,$Find2Cmd)
528 dnl FPTOOLS_NOCACHE_CHECK prints a message, then sets the
529 dnl values of the second argument to the result of running
530 dnl the commands given by the third. It does not cache its
531 dnl result, so it is suitable for checks which should be
534 AC_DEFUN(FPTOOLS_NOCACHE_CHECK,
535 [AC_MSG_CHECKING([$1])
537 AC_MSG_RESULT([$][$2])
541 dnl FPTOOLS_GHC_VERSION(version)
542 dnl FPTOOLS_GHC_VERSION(major, minor [, patchlevel])
543 dnl FPTOOLS_GHC_VERSION(version, major, minor, patchlevel)
545 dnl Test for version of installed ghc. Uses $GHC.
546 dnl [original version pinched from c2hs]
548 AC_DEFUN(FPTOOLS_GHC_VERSION,
549 [FPTOOLS_NOCACHE_CHECK([version of ghc], [fptools_version_of_ghc],
550 ["${WithGhc-ghc}" --version > conftestghc 2>&1
551 cat conftestghc >&AC_FD_CC
552 #Useless Use Of cat award...
553 fptools_version_of_ghc=`cat conftestghc | sed -n -e 's/, patchlevel *\([[0-9]]\)/.\1/;s/.* version \([[0-9]][[0-9.]]*\).*/\1/p'`
555 if test "[$]fptools_version_of_ghc" = ""
557 fptools_version_of_ghc='unknown'
559 fptools_version_of_ghc[_major]=`echo [$]fptools_version_of_ghc | sed -e 's/^\([[0-9]]\).*/\1/'`
560 fptools_version_of_ghc[_minor]=`echo [$]fptools_version_of_ghc | sed -e 's/^[[0-9]]\.\([[0-9]]*\).*/\1/'`
561 fptools_version_of_ghc[_pl]=`echo [$]fptools_version_of_ghc | sed -n -e 's/^[[0-9]]\.[[0-9]]*\.\([[0-9]]*\)/\1/p'`
563 if test "[$]fptools_version_of_ghc[_pl]" = ""
565 fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor]"
566 fptools_version_of_ghc[_pl]="0"
568 fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor].[$]fptools_version_of_ghc[_pl]"
572 [$1]="[$]fptools_version_of_ghc[_all]"
574 [$1]="[$]fptools_version_of_ghc[_major]"
575 [$2]="[$]fptools_version_of_ghc[_minor]"
577 [$1]="[$]fptools_version_of_ghc[_major]"
578 [$2]="[$]fptools_version_of_ghc[_minor]"
579 [$3]="[$]fptools_version_of_ghc[_pl]"
581 [$1]="[$]fptools_version_of_ghc[_all]"
582 [$2]="[$]fptools_version_of_ghc[_major]"
583 [$3]="[$]fptools_version_of_ghc[_minor]"
584 [$4]="[$]fptools_version_of_ghc[_pl]"
590 dnl ** figure out the alignment restriction of a type
591 dnl (required SIZEOF test but AC_CHECK_SIZEOF doesn't call PROVIDE
592 dnl so we can't call REQUIRE)
594 dnl FPTOOLS_CHECK_ALIGNMENT(TYPE)
595 AC_DEFUN(FPTOOLS_CHECK_ALIGNMENT,
596 [changequote(<<, >>)dnl
597 dnl The name to #define.
598 define(<<AC_TYPE_NAME>>, translit(alignment_$1, [a-z *], [A-Z_P]))dnl
599 dnl The cache variable name.
600 define(<<AC_CV_NAME>>, translit(ac_cv_alignment_$1, [ *], [_p]))dnl
601 dnl The name of the corresponding size.
602 define(<<AC_CV_SIZEOF_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
604 AC_MSG_CHECKING(alignment of $1)
605 AC_CACHE_VAL(AC_CV_NAME,
612 #define offsetof(ty,field) ((size_t)((char *)&((ty *)0)->field - (char *)(ty *)0))
617 FILE *f=fopen("conftestval", "w");
619 fprintf(f, "%d", offsetof(struct { char c; $1 ty;},ty));
622 AC_CV_NAME=`cat conftestval`,
623 AC_CV_NAME=$AC_CV_SIZEOF_NAME,
624 AC_CV_NAME=$AC_CV_SIZEOF_NAME)])
625 AC_MSG_RESULT($AC_CV_NAME)
626 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
627 AC_PROVIDE($AC_TYPE_NAME)
628 undefine([AC_TYPE_NAME])dnl
629 undefine([AC_CV_NAME])dnl
630 undefine([AC_CV_SIZEOF_NAME])dnl
633 dnl ** Map an arithmetic C type to a Haskell type.
634 dnl Based on autconf's AC_CHECK_SIZEOF.
636 dnl FPTOOLS_CHECK_HTYPE(TYPE [, DEFAULT_VALUE, [, VALUE-FOR-CROSS-COMPILATION])
637 AC_DEFUN(FPTOOLS_CHECK_HTYPE,
638 [changequote(<<, >>)dnl
639 dnl The name to #define.
640 define(<<AC_TYPE_NAME>>, translit(htype_$1, [a-z *], [A-Z_P]))dnl
641 dnl The cache variable name.
642 define(<<AC_CV_NAME>>, translit(fptools_cv_htype_$1, [ *], [_p]))dnl
644 AC_MSG_CHECKING(Haskell type for $1)
645 AC_CACHE_VAL(AC_CV_NAME,
646 [AC_TRY_RUN([#include <stdio.h>
649 #ifdef HAVE_SYS_TYPES_H
650 # include <sys/types.h>
657 #ifdef HAVE_SYS_STAT_H
658 # include <sys/stat.h>
673 #ifdef HAVE_TERMIOS_H
674 # include <termios.h>
689 #ifdef HAVE_OPENGL_GL_H
690 # include <OpenGL/gl.h>
693 #ifdef HAVE_SYS_RESOURCE_H
694 # include <sys/resource.h>
700 FILE *f=fopen("conftestval", "w");
702 if (((testing)((int)((testing)1.4))) == ((testing)1.4)) {
704 ((testing)(-1) < (testing)0) ? "Int" : "Word",
708 (sizeof(testing) > sizeof(double)) ? "LDouble" :
709 (sizeof(testing) == sizeof(double)) ? "Double" : "Float");
713 }], AC_CV_NAME=`cat conftestval`,
714 ifelse([$2], , AC_CV_NAME=NotReallyAType, AC_CV_NAME=$2),
715 ifelse([$3], , AC_CV_NAME=NotReallyATypeCross, AC_CV_NAME=$3))]) dnl
716 AC_MSG_RESULT($AC_CV_NAME)
717 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
718 undefine([AC_TYPE_NAME])dnl
719 undefine([AC_CV_NAME])dnl
722 dnl ** figure out whether C compiler supports 'long long's
723 dnl (Closely based on Andreas Zeller's macro for testing
724 dnl for this under C++)
726 dnl If the C compiler supports `long long' types,
727 dnl define `HAVE_LONG_LONG'.
729 AC_DEFUN(FPTOOLS_C_LONG_LONG,
731 AC_REQUIRE([AC_PROG_CC])
732 AC_MSG_CHECKING(whether ${CC} supports long long types)
733 AC_CACHE_VAL(fptools_cv_have_long_long,
737 AC_TRY_COMPILE(,[long long a;],
738 fptools_cv_have_long_long=yes,
739 fptools_cv_have_long_long=no)
742 AC_MSG_RESULT($fptools_cv_have_long_long)
743 if test "$fptools_cv_have_long_long" = yes; then
744 AC_DEFINE(HAVE_LONG_LONG)
748 dnl ** Obtain the value of a C constant.
749 dnl The value will be `(-1)' if the constant is undefined.
751 dnl This is set up so that the argument can be a shell variable.
753 AC_DEFUN(FPTOOLS_CHECK_CCONST,
755 eval "cv_name=ac_cv_cconst_$1"
756 AC_MSG_CHECKING(value of $1)
757 AC_CACHE_VAL($cv_name,
758 [AC_TRY_RUN([#include <stdio.h>
762 FILE *f=fopen("conftestval", "w");
764 fprintf(f, "%d\n", $1);
767 eval "$cv_name=`cat conftestval`",
769 eval "$cv_name=-1")])dnl
770 eval "fptools_check_cconst_result=`echo '$'{$cv_name}`"
771 AC_MSG_RESULT($fptools_check_cconst_result)
772 AC_DEFINE_UNQUOTED(CCONST_$1, $fptools_check_cconst_result)
773 unset fptools_check_cconst_result
776 dnl ** Invoke AC_CHECK_CCONST on each argument (which have to separate with
779 AC_DEFUN(FPTOOLS_CHECK_CCONSTS,
780 [for ac_const_name in $1
782 FPTOOLS_CHECK_CCONST($ac_const_name)dnl
787 dnl *** Can we open files in binary mode? ***
789 AC_DEFUN(FPTOOLS_O_BINARY,
791 AC_REQUIRE([AC_PROG_CC])
792 AC_MSG_CHECKING(whether we can open files in binary mode)
793 AC_CACHE_VAL(fptools_cv_have_o_binary,
802 fptools_cv_have_o_binary=yes,
803 fptools_cv_have_o_binary=no)
806 AC_MSG_RESULT($fptools_cv_have_o_binary)
807 if test "$fptools_cv_have_o_binary" = yes; then
808 AC_DEFINE(HAVE_O_BINARY)
812 dnl *** Helper function **
814 AC_DEFUN(FPTOOLS_IN_SCOPE,
815 [AC_TRY_LINK([extern char* $1;],[return (int)&$2], $3=yes, $3=no)
819 dnl Based on AC_TRY_LINK - run iftrue if links cleanly with no warning
821 dnl FPTOOLS_TRY_LINK_NOWARN(flags,main?,iftrue,iffalse)
823 AC_DEFUN(FPTOOLS_TRY_LINK_NOWARN,
827 cat > conftest.$ac_ext <<EOF
828 dnl This sometimes fails to find confdefs.h, for some reason.
829 dnl [#]line __oline__ "[$]0"
830 [#]line __oline__ "configure"
831 #include "confdefs.h"
833 int t() { return 0; }
835 if AC_TRY_EVAL(ac_link); then
840 ifelse([$4], , , [else
850 dnl Loosely based on AC_CHECK_LIB in acgeneral.m4 in autoconf distribution
852 dnl FPTOOLS_CHECK_FLAG_NOWARN(NAME, FLAG, CODE, iftrue, iffalse)
854 AC_DEFUN(FPTOOLS_CHECK_FLAG_NOWARN,
855 [AC_MSG_CHECKING([for $1])
856 AC_CACHE_VAL(ac_cv_flag_$1,
857 [FPTOOLS_TRY_LINK_NOWARN("$2", [main() { $3; exit(0); } ],
858 eval "ac_cv_flag_$1=yes",
859 eval "ac_cv_flag_$1=no"
862 if eval "test \"`echo '$ac_cv_flag_'$1`\" = yes"; then
872 dnl FPTOOLS_CHECK_LIB_NOWARN(LIBRARY, FUNCTION)
874 AC_DEFUN(FPTOOLS_CHECK_LIB_NOWARN,
875 [FPTOOLS_CHECK_FLAG_NOWARN([function_$2],[],[extern char $2(); $2();],
877 ac_tr_lib=HAVE_LIB`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
879 AC_DEFINE_UNQUOTED($ac_tr_lib)
881 [FPTOOLS_CHECK_FLAG_NOWARN([library_$1],[-l$1],[extern char $2(); $2();],
883 ac_tr_lib=HAVE_LIB`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
885 AC_DEFINE_UNQUOTED($ac_tr_lib)
891 dnl check for prototypes
893 AC_DEFUN([AC_C_PROTOTYPES],
894 [AC_CACHE_CHECK([prototypes], ac_cv_prototypes,
903 ac_cv_prototypes=yes,
904 ac_cv_prototypes=no)])
905 if test "$ac_cv_prototypes" = yes; then
906 AC_DEFINE([HAVE_PROTOTYPES])
910 dnl ** Check which CATALOG file we have to use with DocBook SGML.
912 dnl FPTOOLS_DOCBOOK_CATALOG(VARIABLE, JADE, STYLESHEET, CATALOGS-TO-CHECK-FOR)
914 dnl If any of the catalogs given in CATALOGS-TO-CHECK-FOR works on this
915 dnl platform, let VARIABLE refer to this catalog; otherwise, VARIABLE
916 dnl is set to "no". JADE is the jade executable and STYLESHEET
917 dnl a DocBook style sheet.
919 AC_DEFUN(FPTOOLS_DOCBOOK_CATALOG,
920 [AC_CACHE_CHECK([for DocBook CATALOG], fptools_cv_sgml_catalog,
922 cat > conftest.sgml << EOF
923 <!DOCTYPE Article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
927 <Author><OtherName>Test</OtherName></Author>
928 <Address>Test</Address>
929 <PubDate>Test</PubDate>
931 <Sect1><Title>Test</Title>
938 fptools_cv_sgml_catalog=no
939 if test -z "$SGML_CATALOG_FILES" ; then
940 for fptools_catalog in $4; do
941 ac_try="$2 -t rtf -d $3#print -c $fptools_catalog conftest.sgml"
942 if AC_TRY_EVAL(ac_try); then
943 fptools_cv_sgml_catalog=[$]fptools_catalog
948 # If the env var SGML_CATALOG_FILES is defined, assume things are cool.
949 fptools_cv_sgml_catalog="yes"
953 if test $fptools_cv_sgml_catalog != "no"; then
954 $1=$fptools_cv_sgml_catalog
958 dnl ######################################################################
959 dnl FPTOOLS_SEARCH_LIBS(INCLUDES, FUNCTION, SEARCH-LIBS [, ACTION-IF-FOUND
960 dnl [, ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
961 dnl Search for a library defining FUNC, if it's not already available.
962 dnl This is almost the same as AC_SEARCH_LIBS, but the INCLUDES can be
964 dnl ######################################################################
966 AC_DEFUN(FPTOOLS_SEARCH_LIBS,
968 AC_CACHE_CHECK([for library containing $2], [ac_cv_search_$2],
969 [ac_func_search_save_LIBS="$LIBS"
971 AC_TRY_LINK([$1], [$2()], [ac_cv_search_$2="none required"])
972 test "$ac_cv_search_$2" = "no" && for i in $3; do
973 LIBS="-l$i $6 $ac_func_search_save_LIBS"
974 AC_TRY_LINK([$1], [$2()],
975 [ac_cv_search_$2="-l$i"
978 LIBS="$ac_func_search_save_LIBS"])
979 if test "$ac_cv_search_$2" != "no"; then
980 test "$ac_cv_search_$2" = "none required" || LIBS="$ac_cv_search_$2 $LIBS"
986 dnl ####################### -*- Mode: M4 -*- ###########################
987 dnl Copyright (C) 98, 1999 Matthew D. Langston <langston@SLAC.Stanford.EDU>
989 dnl This file is free software; you can redistribute it and/or modify it
990 dnl under the terms of the GNU General Public License as published by
991 dnl the Free Software Foundation; either version 2 of the License, or
992 dnl (at your option) any later version.
994 dnl This file is distributed in the hope that it will be useful, but
995 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
996 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
997 dnl General Public License for more details.
999 dnl You should have received a copy of the GNU General Public License
1000 dnl along with this file; if not, write to:
1002 dnl Free Software Foundation, Inc.
1005 dnl Boston, MA 02111-1307, USA.
1006 dnl ####################################################################
1009 dnl @synopsis FPTOOLS_CHECK_LIBM
1011 dnl Search for math library (typically -lm).
1013 dnl The variable LIBM (which is not an output variable by default) is
1014 dnl set to a value which is suitable for use in a Makefile (for example,
1015 dnl in make's LOADLIBES macro) provided you AC_SUBST it first.
1017 dnl @author Matthew D. Langston <langston@SLAC.Stanford.EDU>
1019 # FPTOOLS_CHECK_LIBM - check for math library
1020 AC_DEFUN(FPTOOLS_CHECK_LIBM,
1021 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
1025 # These system don't have libm
1028 AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
1029 AC_CHECK_LIB(m, main, LIBM="$LIBM -lm")
1032 AC_CHECK_LIB(m, main, LIBM="-lm")
1037 dnl ######################################################################
1038 dnl Note: Caching has been completely rewritten, but is still no perfect yet.
1039 dnl ######################################################################
1041 dnl ########################### -*- Mode: M4 -*- #######################
1042 dnl Copyright (C) 98, 1999 Matthew D. Langston <langston@SLAC.Stanford.EDU>
1044 dnl This file is free software; you can redistribute it and/or modify it
1045 dnl under the terms of the GNU General Public License as published by
1046 dnl the Free Software Foundation; either version 2 of the License, or
1047 dnl (at your option) any later version.
1049 dnl This file is distributed in the hope that it will be useful, but
1050 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
1051 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1052 dnl General Public License for more details.
1054 dnl You should have received a copy of the GNU General Public License
1055 dnl along with this file; if not, write to:
1057 dnl Free Software Foundation, Inc.
1060 dnl Boston, MA 02111-1307, USA.
1061 dnl ####################################################################
1063 dnl @synopsis FPTOOLS_HAVE_OPENGL
1065 dnl Search for OpenGL. We search first for Mesa (a GPL'ed version of
1066 dnl OpenGL) before a vendor's version of OpenGL if we were specifically
1067 dnl asked to with `--with-Mesa=yes' or `--with-Mesa'.
1069 dnl The four "standard" OpenGL libraries are searched for: "-lGL",
1070 dnl "-lGLU", "-lGLX" (or "-lMesaGL", "-lMesaGLU" as the case may be) and
1073 dnl All of the libraries that are found (since "-lglut" or "-lGLX" might
1074 dnl be missing) are added to the shell output variable "GL_LIBS", along
1075 dnl with any other libraries that are necessary to successfully link an
1076 dnl OpenGL application (e.g. the X11 libraries). Care has been taken to
1077 dnl make sure that all of the libraries in "GL_LIBS" are listed in the
1080 dnl Additionally, the shell output variable "GL_CFLAGS" is set to any
1081 dnl flags (e.g. "-I" flags) that are necessary to successfully compile
1082 dnl an OpenGL application.
1084 dnl The following shell variable (which are not output variables) are
1085 dnl also set to either "yes" or "no" (depending on which libraries were
1086 dnl found) to help you determine exactly what was found.
1093 dnl A complete little toy "Automake `make distcheck'" package of how to
1094 dnl use this macro is available at:
1096 dnl ftp://ftp.slac.stanford.edu/users/langston/autoconf/ac_opengl-0.01.tar.gz
1098 dnl Please note that as the ac_opengl macro and the toy example evolves,
1099 dnl the version number increases, so you may have to adjust the above
1100 dnl URL accordingly.
1102 dnl @author Matthew D. Langston <langston@SLAC.Stanford.EDU>
1104 AC_DEFUN(FPTOOLS_HAVE_OPENGL,
1106 AC_REQUIRE([AC_PROG_CC])
1107 AC_REQUIRE([AC_PATH_X])
1108 AC_REQUIRE([AC_PATH_XTRA])
1109 AC_REQUIRE([FPTOOLS_CHECK_LIBM])
1111 dnl Check for Mesa first if we were asked to.
1114 Prefer Mesa over a vendor's native OpenGL library (default=no)
1116 use_Mesa=$enableval,
1119 if test x"$use_Mesa" = xyes; then
1120 GL_search_list="MesaGL GL opengl32"
1121 GLU_search_list="MesaGLU GLU glu32"
1122 GLX_search_list="MesaGLX GLX"
1124 GL_search_list="GL opengl32 MesaGL"
1125 GLU_search_list="GLU glu32 MesaGLU"
1126 GLX_search_list="GLX MesaGLX"
1132 dnl If we are running under X11 then add in the appropriate libraries.
1133 if test x"$no_x" != xyes; then
1134 dnl Add everything we need to compile and link X programs to GL_CFLAGS
1135 dnl and GL_X_LIBS/GLUT_X_LIBS.
1136 GL_CFLAGS="$CPPFLAGS $X_CFLAGS"
1137 GL_X_LIBS="$X_LIBS $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS $LIBM"
1138 GLUT_X_LIBS="$X_LIBS $X_PRE_LIBS -lXmu -lXt -lXi -lXext -lX11 $X_EXTRA_LIBS $LIBM"
1140 GL_save_CPPFLAGS="$CPPFLAGS"
1141 CPPFLAGS="$GL_CFLAGS"
1143 GL_save_LIBS="$LIBS"
1146 FPTOOLS_SEARCH_LIBS([#include <GL/gl.h>], glEnd, $GL_search_list, have_GL=yes, have_GL=no)
1147 FPTOOLS_SEARCH_LIBS([#include <GL/glu.h>], gluNewQuadric, $GLU_search_list, have_GLU=yes, have_GLU=no)
1148 FPTOOLS_SEARCH_LIBS([#include <GL/glx.h>], glXWaitX, $GLX_search_list, have_GLX=yes, have_GLX=no)
1150 if test -n "$LIBS"; then
1151 GL_LIBS="$LDFLAGS $LIBS"
1159 FPTOOLS_SEARCH_LIBS([#include <GL/glut.h>], glutMainLoop, glut32 glut, have_glut=yes, have_glut=no)
1161 if test -n "$LIBS"; then
1162 GLUT_LIBS="$LDFLAGS $LIBS"
1165 AC_CACHE_CHECK([OpenGL flags], mdl_cv_gl_cflags, [mdl_cv_gl_cflags="$GL_CFLAGS"])
1166 GL_CFLAGS="$mdl_cv_gl_cflags"
1168 AC_CACHE_CHECK([OpenGL libs], mdl_cv_gl_libs, [mdl_cv_gl_libs="$GL_LIBS"])
1169 GL_LIBS="$mdl_cv_gl_libs"
1171 AC_CACHE_CHECK([GLUT libs], mdl_cv_glut_libs, [mdl_cv_glut_libs="$GLUT_LIBS"])
1172 GLUT_LIBS="$mdl_cv_glut_libs"
1175 dnl Reset GL_X_LIBS/GLUT_X_LIBS regardless, since they were just temporary variables
1176 dnl and we don't want to be global namespace polluters.
1180 LIBS="$GL_save_LIBS"
1181 CPPFLAGS="$GL_save_CPPFLAGS"
1189 dnl acspecific.m4's defn of AC_PROG_LEX is a bit too permissive, as it
1190 dnl defaults to 'lex' if 'flex' isn't found (without checking whether
1191 dnl 'lex' is actually present along the user's PATH).
1193 AC_DEFUN(AC_PROG_LEX_STRICT,
1194 [AC_CHECK_PROG(LEX, flex, flex)
1197 AC_CHECK_PROG(LEX,lex,lex)
1198 test -z "$LEX" && AC_MSG_ERROR(['lex' or 'flex' is required to compile GHC.])
1203 dnl Check to see whether CC (gcc) supports a particular option.
1205 AC_DEFUN(FPTOOLS_CC_FLAG,
1207 AC_CACHE_CHECK([whether $CC accepts $1], [ac_cv_cc_$2],
1208 [save_CFLAGS="$CFLAGS"
1211 AC_TRY_COMPILE(,[int main(){return(0);}],
1214 CFLAGS="$save_CFLAGS"
1216 if test "$ac_cv_cc_$2"x = "yesx"; then
1224 dnl Check to see whether 'struct msghdr' contains msg_control
1226 AC_DEFUN(FPTOOLS_MSGHDR_MSG_CONTROL,
1227 [AC_CACHE_CHECK([for msg_control in struct msghdr], fptools_cv_struct_msghdr_msg_control,
1228 [AC_TRY_COMPILE([#include <sys/types.h>
1229 #include <sys/uio.h>
1230 #include <sys/socket.h>], [struct msghdr m; m.msg_control;],
1231 fptools_cv_struct_msghdr_msg_control=yes, fptools_cv_struct_msghdr_msg_control=no)])
1232 if test $fptools_cv_struct_msghdr_msg_control = yes; then
1233 AC_DEFINE(HAVE_MSGHDR_MSG_CONTROL)
1235 AC_SUBST(HAVE_MSGHDR_MSG_CONTROL)dnl
1239 dnl Check to see whether 'struct msghdr' contains msg_accrights
1241 AC_DEFUN(FPTOOLS_MSGHDR_MSG_ACCRIGHTS,
1242 [AC_CACHE_CHECK([for msg_accrights in struct msghdr], fptools_cv_struct_msghdr_msg_accrights,
1243 [AC_TRY_COMPILE([#include <sys/types.h>
1244 #include <sys/uio.h>
1245 #include <sys/socket.h>], [struct msghdr m; m.msg_accrights;],
1246 fptools_cv_struct_msghdr_msg_accrights=yes, fptools_cv_struct_msghdr_msg_accrights=no)])
1247 if test $fptools_cv_struct_msghdr_msg_accrights = yes; then
1248 AC_DEFINE(HAVE_MSGHDR_MSG_ACCRIGHTS)
1250 AC_SUBST(HAVE_MSGHDR_MSG_ACCRIGHTS)dnl