1 dnl $Id: aclocal.m4,v 1.125 2003/08/18 09:23:09 dons Exp $
3 dnl Extra autoconf macros for the Glasgow fptools
5 dnl To be a good autoconf citizen, names of local macros have
6 dnl prefixed with FPTOOLS_ to ensure we don't clash
7 dnl with any pre-supplied autoconf ones.
10 dnl Is timezone around? (in a header file)
12 AC_DEFUN(FPTOOLS_HAVE_TIMEZONE,
13 [AC_CACHE_CHECK([timezone], fptools_cv_have_timezone,
14 [AC_TRY_COMPILE([#if TIME_WITH_SYS_TIME
15 # include <sys/time.h>
19 # include <sys/time.h>
24 ], [return timezone;],
25 fptools_cv_have_timezone=yes, fptools_cv_have_timezone=no)])
26 if test "$fptools_cv_have_timezone" = yes; then
27 AC_DEFINE(HAVE_TIMEZONE)
32 dnl Has timezone the type time_t or long (HP-UX 10.20 apparently
35 AC_DEFUN(FPTOOLS_TYPE_TIMEZONE,
36 [AC_CACHE_CHECK([type of timezone], fptools_cv_type_timezone,
37 [AC_TRY_COMPILE([#if TIME_WITH_SYS_TIME
38 # include <sys/time.h>
42 # include <sys/time.h>
48 extern time_t timezone;
50 [int i;], fptools_cv_type_timezone=time_t, fptools_cv_type_timezone=long)])
51 AC_DEFINE_UNQUOTED(TYPE_TIMEZONE, $fptools_cv_type_timezone)
54 dnl *** Is altzone available? ***
56 AC_DEFUN(FPTOOLS_ALTZONE,
57 [AC_CACHE_CHECK([altzone], fptools_cv_altzone,
58 [AC_TRY_LINK([#if TIME_WITH_SYS_TIME
59 # include <sys/time.h>
63 # include <sys/time.h>
69 fptools_cv_altzone=yes, fptools_cv_altzone=no)])
70 if test "$fptools_cv_altzone" = yes; then
71 AC_DEFINE(HAVE_ALTZONE)
76 dnl *** Does libc contain GNU regex? ***
78 AC_DEFUN(FPTOOLS_REGEX_IN_LIBC,
79 [AC_CACHE_CHECK([for GNU regex in libc], fptools_cv_have_regex,
80 [AC_TRY_LINK([#if HAVE_UNISTD_H
84 ],[ struct re_pattern_buffer patbuf;
85 re_compile_pattern("",0,&patbuf);
86 re_search_2 (&patbuf, "", 0, "",0, 0,0,0,0); ],
87 fptools_cv_have_regex=yes, fptools_cv_have_regex=no)])
88 if test "$fptools_cv_have_regex" = yes; then
93 AC_SUBST(HaveGNURegex)
97 dnl ** check for leading underscores in symbol names
99 dnl Test for determining whether symbol names have a leading
102 dnl We assume that they _haven't_ if anything goes wrong.
104 dnl Some nlist implementations seem to try to be compatible by ignoring
105 dnl a leading underscore sometimes (eg. FreeBSD). We therefore have
106 dnl to work around this by checking for *no* leading underscore first.
109 dnl Similarly on OpenBSD, but this test doesn't help. -- dons
111 AC_DEFUN(FPTOOLS_UNDERSCORE,
112 [AC_CHECK_LIB(elf, nlist, LIBS="-lelf $LIBS")dnl
113 AC_CACHE_CHECK([leading underscore in symbol names], fptools_cv_lead_uscore,
116 dnl Hack!: nlist() under Digital UNIX insist on there being an _,
117 dnl but symbol table listings shows none. What is going on here?!?
119 dnl Another hack: cygwin doesn't come with nlist.h , so we hardwire
120 dnl the underscoredness of that "platform"
121 changequote(<<, >>)dnl
123 case $HostPlatform in
124 *openbsd*) # x86 openbsd is ELF from 3.4 >, meaning no leading uscore
126 i386-*2\.[[0-9]] | i386-*3\.[[0-3]] ) fptools_cv_lead_uscore='yes' ;;
127 *) fptools_cv_lead_uscore='no' ;;
129 alpha-dec-osf*) fptools_cv_lead_uscore='no';;
130 *cygwin32) fptools_cv_lead_uscore='yes';;
131 *mingw32) fptools_cv_lead_uscore='yes';;
134 AC_TRY_RUN([#ifdef HAVE_NLIST_H
136 changequote(<<, >>)dnl
138 struct nlist xYzzY1[] = {{"xYzzY1", 0},{0}};
139 struct nlist xYzzY2[] = {{"_xYzzY2", 0},{0}};
147 if(nlist(argv[0], xYzzY1) == 0 && xYzzY1[0].n_value != 0)
149 if(nlist(argv[0], xYzzY2) == 0 && xYzzY2[0].n_value != 0)
154 }], fptools_cv_lead_uscore=yes, fptools_cv_lead_uscore=no, fptools_cv_lead_uscore=NO)
157 LeadingUnderscore=`echo $fptools_cv_lead_uscore | sed 'y/yesno/YESNO/'`
158 AC_SUBST(LeadingUnderscore)
159 case $LeadingUnderscore in
160 YES) AC_DEFINE(LEADING_UNDERSCORE);;
165 dnl FPTOOLS_PROG_CHECK_VERSION(VERSIONSTR1, TEST, VERSIONSTR2,
166 dnl ACTION-IF-TRUE [, ACTION-IF-FALSE])
168 dnl compare versions field-wise (separator is '.')
169 dnl TEST is one of {-lt,-le,-eq,-ge,-gt}
171 dnl quite shell-independant and SUSv2 compliant code
173 dnl NOTE: the loop could be unrolled within autoconf, but the
174 dnl macro code would be a) longer and b) harder to debug... ;)
176 AC_DEFUN(FPTOOLS_PROG_CHECK_VERSION,
181 set -- [$]a; h1="[$]1"; shift 2>/dev/null; a="[$]*"
182 set -- [$]b; h2="[$]1"; shift 2>/dev/null; b="[$]*"
183 test -n "[$]h1" || h1=0; test -n "[$]h2" || h2=0
184 test [$]{h1} -eq [$]{h2} || break
186 test [$]{h1} [$2] [$]{h2}
188 then ifelse([$4],,[:],[
198 dnl Check for Greencard and version.
200 AC_DEFUN(FPTOOLS_GREENCARD,
202 AC_PATH_PROG(GreencardCmd,greencard)
203 AC_CACHE_CHECK([for version of greencard], fptools_cv_greencard_version,
205 [if test x"$GreencardCmd" != x; then
206 fptools_cv_greencard_version="`$GreencardCmd --version |
207 grep 'version' | sed -e 's/greencard. version \([^ ]*\).*/\1/g'`"
209 fptools_cv_greencard_version=""
213 FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_greencard_version],-lt,$1,
214 [AC_MSG_ERROR([greencard version $1 or later is required (found '$fptools_cv_greencard_version')])])dnl
215 GreencardVersion=$fptools_cv_greencard_version
216 AC_SUBST(GreencardVersion)
220 dnl Check for Happy and version. If we're building GHC, then we need
221 dnl at least Happy version 1.13. If there's no installed Happy, we look
222 dnl for a happy source tree and point the build system at that instead.
224 AC_DEFUN(FPTOOLS_HAPPY,
226 if test -d $srcdir/happy; then
227 SrcTreeHappyCmd=$hardtop/happy/src/happy-inplace
229 if test x"$UseSrcTreeHappy" = xYES; then
230 HappyCmd=$SrcTreeHappyCmd
232 AC_PATH_PROG(HappyCmd,happy,$SrcTreeHappyCmd)
234 AC_CACHE_CHECK([for version of happy], fptools_cv_happy_version,
236 [if test x"$HappyCmd" = x"$SrcTreeHappyCmd"; then
237 fptools_cv_happy_version=`grep '^ProjectVersion[ ]*=' $srcdir/happy/mk/version.mk | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`;
238 elif test x"$HappyCmd" != x; then
239 fptools_cv_happy_version="`$HappyCmd -v |
240 grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'`" ;
242 fptools_cv_happy_version="";
246 if test -d $srcdir/ghc -a ! -f $srcdir/ghc/compiler/parser/Parser.hs; then
247 FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_happy_version],-lt,[1.13],
248 [AC_MSG_ERROR([Happy version 1.13 or later is required to compile GHC.])])dnl
250 HappyVersion=$fptools_cv_happy_version;
251 AC_SUBST(HappyVersion)
255 dnl Check for Haddock and version. If there's no installed Haddock, we look
256 dnl for a haddock source tree and point the build system at that instead.
258 AC_DEFUN(FPTOOLS_HADDOCK,
260 if test -d $srcdir/haddock; then
261 SrcTreeHaddockCmd=$hardtop/haddock/src/haddock-inplace
263 if test x"$UseSrcTreeHaddock" = xYES; then
264 HaddockCmd=$SrcTreeHaddockCmd
266 AC_PATH_PROG(HaddockCmd,haddock,$SrcTreeHaddockCmd)
268 dnl Darn, I forgot to make Haddock print out its version number when
269 dnl invoked with -v. We could try generating some HTML and grepping
270 dnl through that to find the version number, but I think we'll make
271 dnl do without it for now.
275 dnl Check for Alex and version. If we're building GHC, then we need
276 dnl at least Alex version 2.0. If there's no installed Alex, we look
277 dnl for a alex source tree and point the build system at that instead.
279 AC_DEFUN(FPTOOLS_ALEX,
281 if test -d $srcdir/alex; then
282 SrcTreeAlexCmd=$hardtop/alex/src/alex-inplace
284 if test x"$UseSrcTreeAlex" = xYES; then
285 AlexCmd=$SrcTreeAlexCmd
287 AC_PATH_PROG(AlexCmd,alex,$SrcTreeAlexCmd)
289 AC_CACHE_CHECK([for version of alex], fptools_cv_alex_version,
291 [if test x"$AlexCmd" = x"$SrcTreeAlexCmd"; then
292 fptools_cv_alex_version=`grep '^ProjectVersion[ ]*=' $srcdir/alex/mk/version.mk | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`;
293 elif test x"$AlexCmd" != x; then
294 fptools_cv_alex_version="`$AlexCmd -v |
295 grep 'Alex [Vv]ersion' | sed -e 's/Alex [Vv]ersion \([0-9\.]*\).*/\1/g'`" ;
297 fptools_cv_alex_version="";
301 dnl if test -d $srcdir/ghc -a ! -f $srcdir/ghc/compiler/parser/Lexer.hs; then
302 dnl FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_alex_version],-lt,[2.0],
303 dnl [AC_MSG_ERROR([Alex version 2.0 or later is required to compile GHC.])])dnl
305 AlexVersion=$fptools_cv_alex_version;
306 AC_SUBST(AlexVersion)
310 dnl What's the best way of doing context diffs?
312 dnl (NB: NeXTStep thinks diff'ing a file against itself is "trouble")
314 AC_DEFUN(FPTOOLS_PROG_DIFF,
315 [AC_CACHE_CHECK([for ok way to do context diffs], fptools_cv_context_diffs,
316 [echo foo > conftest1
318 if diff -C 1 conftest1 conftest2 > /dev/null 2>&1 ; then
319 fptools_cv_context_diffs='diff -C 1'
321 if diff -c1 conftest1 conftest2 > /dev/null 2>&1 ; then
322 fptools_cv_context_diffs='diff -c1'
324 echo "Can't figure out how to do context diffs."
325 echo "Neither \`diff -C 1' nor \`diff -c1' works."
329 rm -f conftest1 conftest2
331 ContextDiffCmd=$fptools_cv_context_diffs
332 AC_SUBST(ContextDiffCmd)
336 dnl Check whether ld supports -x
338 AC_DEFUN(FPTOOLS_LD_X,
339 [AC_CACHE_CHECK([whether ld understands -x], fptools_cv_ld_x,
341 echo 'foo() {}' > conftest.c
342 ${CC-cc} -c conftest.c
343 if ${LdCmd} -r -x -o foo.o conftest.o; then
348 rm -rf conftest.c conftest.o foo.o
350 if test "$fptools_cv_ld_x" = yes; then
359 dnl Finding the Right Yacc
361 AC_DEFUN(FPTOOLS_PROG_YACCY,
363 if test "$YACC" = "yacc"; then
364 AC_CACHE_CHECK([if it is an OK yacc], ac_cv_prog_yacc,
365 [AC_CHECK_PROG(WhatCmd, what, what, :)
366 $WhatCmd $YACC > conftest.out
367 if egrep 'y1\.c 1\..*SMI' conftest.out >/dev/null 2>&1; then
368 echo "I don't trust your $YaccCmd; it looks like an old Sun yacc"
369 if test -f /usr/lang/yacc; then
370 echo "I'm going to use /usr/lang/yacc instead"
371 ac_cv_prog_yacc=/usr/lang/yacc
373 echo "I'm assuming the worst...no parser generator at all"
376 elif egrep 'y1\.c.*Revision: 4\.2\.6\.3.*DEC' conftest.out >/dev/null 2>&1; then
377 echo "I don't trust your $YaccCmd; it looks like a lame DEC yacc"
378 echo "I'm assuming the worst...no parser generator at all"
381 ac_cv_prog_yacc=$YACC
386 ac_cv_prog_yacc=$YACC
388 YaccCmd=$ac_cv_prog_yacc
392 dnl *** Checking for ar and its arguments + whether we need ranlib.
394 dnl ArCmd, ArSupportsInput and RANLIB are AC_SUBST'ed
395 dnl On Digital UNIX, we test for the -Z (compress) and
396 dnl -input (take list of files from external file) flags.
398 AC_DEFUN(FPTOOLS_PROG_AR_AND_RANLIB,
399 [AC_PATH_PROG(ArCmdRaw,ar)
400 if test -z "$ArCmdRaw"; then
401 echo "You don't seem to have ar in your PATH...I have no idea how to make a library"
404 dnl GNU ar needs special treatment: it appears to have problems with
405 dnl object files with the same name if you use the 's' modifier, but
406 dnl simple 'ar q' works fine, and doesn't need a separate ranlib.
407 if $ArCmdRaw --version | grep 'GNU' >/dev/null 2>/dev/null; then
410 elif $ArCmdRaw clqsZ conftest.a >/dev/null 2>/dev/null; then
413 elif $ArCmdRaw clqs conftest.a >/dev/null 2>/dev/null; then
416 elif $ArCmdRaw cqs conftest.a >/dev/null 2>/dev/null; then
419 elif $ArCmdRaw clq conftest.a >/dev/null 2>/dev/null; then
422 elif $ArCmdRaw cq conftest.a >/dev/null 2>/dev/null; then
425 elif $ArCmdRaw cq conftest.a 2>&1 | grep 'no archive members specified' >/dev/null 2>/dev/null; then
429 echo "I can't figure out how to use your $ArCmd"
433 case $HostPlatform in
435 ArCmd="`cygpath -w ${ArCmdRaw} | sed -e 's@\\\\@/@g' ` ${ArCmdArgs}"
437 *) ArCmd="${ArCmdRaw} ${ArCmdArgs}"
440 test -n "$ArCmd" && test -n "$verbose" && echo " setting ArCmd to $ArCmd"
442 if $ArCmd conftest.a -input /dev/null >/dev/null 2>/dev/null; then
443 ArSupportsInput='-input'
448 test -n "$ArSupportsInput" && test -n "$verbose" && echo " setting ArSupportsInput to $ArSupportsInput"
449 AC_SUBST(ArSupportsInput)
450 if test -z "$NeedRanLib"; then
452 test -n "$verbose" && echo " setting RANLIB to $RANLIB"
460 dnl AC_SHEBANG_PERL - can we she-bang perl?
462 AC_DEFUN(FPTOOLS_SHEBANG_PERL,
463 [AC_CACHE_CHECK([if your perl works in shell scripts], fptools_cv_shebang_perl,
468 (SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
469 if test $? -ne 69; then
470 fptools_cv_shebang_perl=yes
472 fptools_cv_shebang_perl=no
478 dnl Extra testing of the result AC_PROG_CC, testing the gcc version no.
479 dnl *Must* be called after AC_PROG_CC
481 AC_DEFUN(FPTOOLS_HAVE_GCC,
482 [AC_CACHE_CHECK([whether you have an ok gcc], fptools_cv_have_gcc,
483 [if test -z "$GCC"; then
485 echo "You would be better off with gcc"
486 echo "Perhaps it is already installed, but not in your PATH?"
487 fptools_cv_have_gcc='no'
490 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' `"
492 fptools_cv_have_gcc='yes'
493 FPTOOLS_PROG_CHECK_VERSION($gcc_version_str, -lt, "2.0",
494 fptools_cv_have_gcc='no'
496 echo "your gcc version appears to be ..."
498 echo "gcc prior to 2.0 and have never worked with ghc."
499 echo "we recommend 2.95.3, although versions back to 2.7.2 should be ok."
500 AC_MSG_ERROR([gcc 1.X has never been supported])
504 HaveGcc=`echo $fptools_cv_have_gcc | sed 'y/yesno/YESNO/'`
509 dnl Some OSs (Mandrake Linux, in particular) configure GCC with
510 dnl -momit-leaf-frame-pointer on by default. If this is the case, we
511 dnl need to turn it off for mangling to work. The test is currently a bit
512 dnl crude, using only the version number of gcc.
514 AC_DEFUN(FPTOOLS_GCC_NEEDS_NO_OMIT_LFPTR,
515 [AC_CACHE_CHECK([whether gcc needs -mno-omit-leaf-frame-pointer], fptools_cv_gcc_needs_no_omit_lfptr,
517 fptools_cv_gcc_needs_no_omit_lfptr='no'
518 FPTOOLS_PROG_CHECK_VERSION($gcc_version_str, -ge, "3.2",
519 fptools_cv_gcc_needs_no_omit_lfptr='yes')
521 if test "$fptools_cv_gcc_needs_no_omit_lfptr" = "yes"; then
522 AC_DEFINE(HAVE_GCC_MNO_OMIT_LFPTR)
526 dnl Small feature test for perl version. Assumes PerlCmd
527 dnl contains path to perl binary
529 AC_DEFUN(FPTOOLS_CHECK_PERL_VERSION,
530 [$PerlCmd -v >conftest.out 2>&1
531 if grep "version 5" conftest.out >/dev/null 2>&1; then
534 if grep "v5.6" conftest.out >/dev/null 2>&1; then
537 if grep "v5.8" conftest.out >/dev/null 2>&1; then
540 if grep "version 6" conftest.out >/dev/null 2>&1; then
543 echo "Your version of perl probably won't work."
552 dnl Getting at the right version of 'find'
553 dnl (i.e., not the MS util on a Win32 box).
555 AC_DEFUN(FPTOOLS_FIND_FIND,
557 AC_PATH_PROG(Find2Cmd, find)
558 $Find2Cmd --version > conftest.out 2>&1
559 if grep "FIND: Parameter format" conftest.out >/dev/null 2>&1 ; then
560 # Encountered MS' find utility, which is not what we're after.
562 # HACK - AC_CHECK_PROG is useful here in that does let you reject
563 # an (absolute) entry in the path (Find2Cmd). It is not so useful
564 # in that it doesn't let you (AFAIU) set VARIABLE equal to the
565 # absolute path eventually found. So, hack around this by inspecting
566 # what variables hold the abs. path & use them directly.
567 AC_CHECK_PROG(FindCmd,find,`echo $ac_dir/$ac_word`,find,,$Find2Cmd)
575 dnl FPTOOLS_NOCACHE_CHECK prints a message, then sets the
576 dnl values of the second argument to the result of running
577 dnl the commands given by the third. It does not cache its
578 dnl result, so it is suitable for checks which should be
581 AC_DEFUN(FPTOOLS_NOCACHE_CHECK,
582 [AC_MSG_CHECKING([$1])
584 AC_MSG_RESULT([$][$2])
588 dnl FPTOOLS_GHC_VERSION(version)
589 dnl FPTOOLS_GHC_VERSION(major, minor [, patchlevel])
590 dnl FPTOOLS_GHC_VERSION(version, major, minor, patchlevel)
592 dnl Test for version of installed ghc. Uses $GHC.
593 dnl [original version pinched from c2hs]
595 AC_DEFUN(FPTOOLS_GHC_VERSION,
596 [FPTOOLS_NOCACHE_CHECK([version of ghc], [fptools_version_of_ghc],
597 ["${WithGhc-ghc}" --version > conftestghc 2>&1
598 cat conftestghc >&AC_FD_CC
599 #Useless Use Of cat award...
600 fptools_version_of_ghc=`cat conftestghc | sed -n -e 's/, patchlevel *\([[0-9]]\)/.\1/;s/.* version \([[0-9]][[0-9.]]*\).*/\1/p'`
602 if test "[$]fptools_version_of_ghc" = ""
604 fptools_version_of_ghc='unknown'
606 fptools_version_of_ghc[_major]=`echo [$]fptools_version_of_ghc | sed -e 's/^\([[0-9]]\).*/\1/'`
607 fptools_version_of_ghc[_minor]=`echo [$]fptools_version_of_ghc | sed -e 's/^[[0-9]]\.\([[0-9]]*\).*/\1/'`
608 fptools_version_of_ghc[_pl]=`echo [$]fptools_version_of_ghc | sed -n -e 's/^[[0-9]]\.[[0-9]]*\.\([[0-9]]*\)/\1/p'`
610 if test "[$]fptools_version_of_ghc[_pl]" = ""
612 fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor]"
613 fptools_version_of_ghc[_pl]="0"
615 fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor].[$]fptools_version_of_ghc[_pl]"
619 [$1]="[$]fptools_version_of_ghc[_all]"
621 [$1]="[$]fptools_version_of_ghc[_major]"
622 [$2]="[$]fptools_version_of_ghc[_minor]"
624 [$1]="[$]fptools_version_of_ghc[_major]"
625 [$2]="[$]fptools_version_of_ghc[_minor]"
626 [$3]="[$]fptools_version_of_ghc[_pl]"
628 [$1]="[$]fptools_version_of_ghc[_all]"
629 [$2]="[$]fptools_version_of_ghc[_major]"
630 [$3]="[$]fptools_version_of_ghc[_minor]"
631 [$4]="[$]fptools_version_of_ghc[_pl]"
637 dnl ** figure out the alignment restriction of a type
638 dnl (required SIZEOF test but AC_CHECK_SIZEOF doesn't call PROVIDE
639 dnl so we can't call REQUIRE)
641 dnl FPTOOLS_CHECK_ALIGNMENT(TYPE)
642 AC_DEFUN(FPTOOLS_CHECK_ALIGNMENT,
643 [changequote(<<, >>)dnl
644 dnl The name to #define.
645 define(<<AC_TYPE_NAME>>, translit(alignment_$1, [a-z *], [A-Z_P]))dnl
646 dnl The cache variable name.
647 define(<<AC_CV_NAME>>, translit(ac_cv_alignment_$1, [ *], [_p]))dnl
648 dnl The name of the corresponding size.
649 define(<<AC_CV_SIZEOF_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
651 AC_MSG_CHECKING(alignment of $1)
652 AC_CACHE_VAL(AC_CV_NAME,
659 #define offsetof(ty,field) ((size_t)((char *)&((ty *)0)->field - (char *)(ty *)0))
664 FILE *f=fopen("conftestval", "w");
666 fprintf(f, "%d", offsetof(struct { char c; $1 ty;},ty));
669 AC_CV_NAME=`cat conftestval`,
670 AC_CV_NAME=$AC_CV_SIZEOF_NAME,
671 AC_CV_NAME=$AC_CV_SIZEOF_NAME)])
672 AC_MSG_RESULT($AC_CV_NAME)
673 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
674 AC_PROVIDE($AC_TYPE_NAME)
675 undefine([AC_TYPE_NAME])dnl
676 undefine([AC_CV_NAME])dnl
677 undefine([AC_CV_SIZEOF_NAME])dnl
680 dnl ** Map an arithmetic C type to a Haskell type.
681 dnl Based on autconf's AC_CHECK_SIZEOF.
683 dnl FPTOOLS_CHECK_HTYPE(TYPE [, DEFAULT_VALUE, [, VALUE-FOR-CROSS-COMPILATION])
684 AC_DEFUN(FPTOOLS_CHECK_HTYPE,
685 [changequote(<<, >>)dnl
686 dnl The name to #define.
687 define(<<AC_TYPE_NAME>>, translit(htype_$1, [a-z *], [A-Z_P]))dnl
688 dnl The cache variable name.
689 define(<<AC_CV_NAME>>, translit(fptools_cv_htype_$1, [ *], [_p]))dnl
691 AC_MSG_CHECKING(Haskell type for $1)
692 AC_CACHE_VAL(AC_CV_NAME,
693 [AC_TRY_RUN([#include <stdio.h>
696 #ifdef HAVE_SYS_TYPES_H
697 # include <sys/types.h>
704 #ifdef HAVE_SYS_STAT_H
705 # include <sys/stat.h>
720 #ifdef HAVE_TERMIOS_H
721 # include <termios.h>
736 #ifdef HAVE_OPENGL_GL_H
737 # include <OpenGL/gl.h>
740 #ifdef HAVE_SYS_RESOURCE_H
741 # include <sys/resource.h>
747 FILE *f=fopen("conftestval", "w");
749 if (((testing)((int)((testing)1.4))) == ((testing)1.4)) {
751 ((testing)(-1) < (testing)0) ? "Int" : "Word",
755 (sizeof(testing) > sizeof(double)) ? "LDouble" :
756 (sizeof(testing) == sizeof(double)) ? "Double" : "Float");
760 }], AC_CV_NAME=`cat conftestval`,
761 ifelse([$2], , AC_CV_NAME=NotReallyAType, AC_CV_NAME=$2),
762 ifelse([$3], , AC_CV_NAME=NotReallyATypeCross, AC_CV_NAME=$3))]) dnl
763 AC_MSG_RESULT($AC_CV_NAME)
764 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
765 undefine([AC_TYPE_NAME])dnl
766 undefine([AC_CV_NAME])dnl
769 dnl ** figure out whether C compiler supports 'long long's
770 dnl (Closely based on Andreas Zeller's macro for testing
771 dnl for this under C++)
773 dnl If the C compiler supports `long long' types,
774 dnl define `HAVE_LONG_LONG'.
776 AC_DEFUN(FPTOOLS_C_LONG_LONG,
778 AC_REQUIRE([AC_PROG_CC])
779 AC_MSG_CHECKING(whether ${CC} supports long long types)
780 AC_CACHE_VAL(fptools_cv_have_long_long,
784 AC_TRY_COMPILE(,[long long a;],
785 fptools_cv_have_long_long=yes,
786 fptools_cv_have_long_long=no)
789 AC_MSG_RESULT($fptools_cv_have_long_long)
790 if test "$fptools_cv_have_long_long" = yes; then
791 AC_DEFINE(HAVE_LONG_LONG)
795 dnl ** Obtain the value of a C constant.
796 dnl The value will be `(-1)' if the constant is undefined.
798 dnl This is set up so that the argument can be a shell variable.
800 AC_DEFUN(FPTOOLS_CHECK_CCONST,
802 eval "cv_name=ac_cv_cconst_$1"
803 AC_MSG_CHECKING(value of $1)
804 AC_CACHE_VAL($cv_name,
805 [AC_TRY_RUN([#include <stdio.h>
809 FILE *f=fopen("conftestval", "w");
811 fprintf(f, "%d\n", $1);
814 eval "$cv_name=`cat conftestval`",
816 eval "$cv_name=-1")])dnl
817 eval "fptools_check_cconst_result=`echo '$'{$cv_name}`"
818 AC_MSG_RESULT($fptools_check_cconst_result)
819 AC_DEFINE_UNQUOTED(CCONST_$1, $fptools_check_cconst_result)
820 unset fptools_check_cconst_result
823 dnl ** Invoke AC_CHECK_CCONST on each argument (which have to separate with
826 AC_DEFUN(FPTOOLS_CHECK_CCONSTS,
827 [for ac_const_name in $1
829 FPTOOLS_CHECK_CCONST($ac_const_name)dnl
834 dnl *** Can we open files in binary mode? ***
836 AC_DEFUN(FPTOOLS_O_BINARY,
838 AC_REQUIRE([AC_PROG_CC])
839 AC_MSG_CHECKING(whether we can open files in binary mode)
840 AC_CACHE_VAL(fptools_cv_have_o_binary,
849 fptools_cv_have_o_binary=yes,
850 fptools_cv_have_o_binary=no)
853 AC_MSG_RESULT($fptools_cv_have_o_binary)
854 if test "$fptools_cv_have_o_binary" = yes; then
855 AC_DEFINE(HAVE_O_BINARY)
859 dnl *** Helper function **
861 AC_DEFUN(FPTOOLS_IN_SCOPE,
862 [AC_TRY_LINK([extern char* $1;],[return (int)&$2], $3=yes, $3=no)
866 dnl Based on AC_TRY_LINK - run iftrue if links cleanly with no warning
868 dnl FPTOOLS_TRY_LINK_NOWARN(flags,main?,iftrue,iffalse)
870 AC_DEFUN(FPTOOLS_TRY_LINK_NOWARN,
874 cat > conftest.$ac_ext <<EOF
875 dnl This sometimes fails to find confdefs.h, for some reason.
876 dnl [#]line __oline__ "[$]0"
877 [#]line __oline__ "configure"
878 #include "confdefs.h"
880 int t() { return 0; }
882 if AC_TRY_EVAL(ac_link); then
887 ifelse([$4], , , [else
897 dnl Loosely based on AC_CHECK_LIB in acgeneral.m4 in autoconf distribution
899 dnl FPTOOLS_CHECK_FLAG_NOWARN(NAME, FLAG, CODE, iftrue, iffalse)
901 AC_DEFUN(FPTOOLS_CHECK_FLAG_NOWARN,
902 [AC_MSG_CHECKING([for $1])
903 AC_CACHE_VAL(ac_cv_flag_$1,
904 [FPTOOLS_TRY_LINK_NOWARN("$2", [main() { $3; exit(0); } ],
905 eval "ac_cv_flag_$1=yes",
906 eval "ac_cv_flag_$1=no"
909 if eval "test \"`echo '$ac_cv_flag_'$1`\" = yes"; then
919 dnl FPTOOLS_CHECK_LIB_NOWARN(LIBRARY, FUNCTION)
921 AC_DEFUN(FPTOOLS_CHECK_LIB_NOWARN,
922 [FPTOOLS_CHECK_FLAG_NOWARN([function_$2],[],[extern char $2(); $2();],
924 ac_tr_lib=HAVE_LIB`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
926 AC_DEFINE_UNQUOTED($ac_tr_lib)
928 [FPTOOLS_CHECK_FLAG_NOWARN([library_$1],[-l$1],[extern char $2(); $2();],
930 ac_tr_lib=HAVE_LIB`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
932 AC_DEFINE_UNQUOTED($ac_tr_lib)
938 dnl check for prototypes
940 AC_DEFUN([AC_C_PROTOTYPES],
941 [AC_CACHE_CHECK([prototypes], ac_cv_prototypes,
950 ac_cv_prototypes=yes,
951 ac_cv_prototypes=no)])
952 if test "$ac_cv_prototypes" = yes; then
953 AC_DEFINE([HAVE_PROTOTYPES])
957 dnl ** Check which CATALOG file we have to use with DocBook SGML.
959 dnl FPTOOLS_DOCBOOK_CATALOG(VARIABLE, JADE, STYLESHEET, CATALOGS-TO-CHECK-FOR)
961 dnl If any of the catalogs given in CATALOGS-TO-CHECK-FOR works on this
962 dnl platform, let VARIABLE refer to this catalog; otherwise, VARIABLE
963 dnl is set to "no". JADE is the jade executable and STYLESHEET
964 dnl a DocBook style sheet.
966 AC_DEFUN(FPTOOLS_DOCBOOK_CATALOG,
967 [AC_CACHE_CHECK([for DocBook CATALOG], fptools_cv_sgml_catalog,
969 cat > conftest.sgml << EOF
970 <!DOCTYPE Article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
974 <Author><OtherName>Test</OtherName></Author>
975 <Address>Test</Address>
976 <PubDate>Test</PubDate>
978 <Sect1><Title>Test</Title>
985 fptools_cv_sgml_catalog=no
986 if test -z "$SGML_CATALOG_FILES" ; then
987 for fptools_catalog in $4; do
988 ac_try="$2 -t rtf -d $3#print -c $fptools_catalog conftest.sgml"
989 if AC_TRY_EVAL(ac_try); then
990 fptools_cv_sgml_catalog=[$]fptools_catalog
995 # If the env var SGML_CATALOG_FILES is defined, assume things are cool.
996 fptools_cv_sgml_catalog="yes"
1000 if test $fptools_cv_sgml_catalog != "no"; then
1001 $1=$fptools_cv_sgml_catalog
1005 dnl ######################################################################
1006 dnl FPTOOLS_SEARCH_LIBS(INCLUDES, FUNCTION, SEARCH-LIBS [, ACTION-IF-FOUND
1007 dnl [, ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
1008 dnl Search for a library defining FUNC, if it's not already available.
1009 dnl This is almost the same as AC_SEARCH_LIBS, but the INCLUDES can be
1011 dnl ######################################################################
1013 AC_DEFUN(FPTOOLS_SEARCH_LIBS,
1015 AC_CACHE_CHECK([for library containing $2], [ac_cv_search_$2],
1016 [ac_func_search_save_LIBS="$LIBS"
1017 ac_cv_search_$2="no"
1018 AC_TRY_LINK([$1], [$2()], [ac_cv_search_$2="none required"])
1019 test "$ac_cv_search_$2" = "no" && for i in $3; do
1020 LIBS="-l$i $6 $ac_func_search_save_LIBS"
1021 AC_TRY_LINK([$1], [$2()],
1022 [ac_cv_search_$2="-l$i"
1025 LIBS="$ac_func_search_save_LIBS"])
1026 if test "$ac_cv_search_$2" != "no"; then
1027 test "$ac_cv_search_$2" = "none required" || LIBS="$ac_cv_search_$2 $LIBS"
1033 dnl ####################### -*- Mode: M4 -*- ###########################
1034 dnl Copyright (C) 98, 1999 Matthew D. Langston <langston@SLAC.Stanford.EDU>
1036 dnl This file is free software; you can redistribute it and/or modify it
1037 dnl under the terms of the GNU General Public License as published by
1038 dnl the Free Software Foundation; either version 2 of the License, or
1039 dnl (at your option) any later version.
1041 dnl This file is distributed in the hope that it will be useful, but
1042 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
1043 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1044 dnl General Public License for more details.
1046 dnl You should have received a copy of the GNU General Public License
1047 dnl along with this file; if not, write to:
1049 dnl Free Software Foundation, Inc.
1052 dnl Boston, MA 02111-1307, USA.
1053 dnl ####################################################################
1056 dnl @synopsis FPTOOLS_CHECK_LIBM
1058 dnl Search for math library (typically -lm).
1060 dnl The variable LIBM (which is not an output variable by default) is
1061 dnl set to a value which is suitable for use in a Makefile (for example,
1062 dnl in make's LOADLIBES macro) provided you AC_SUBST it first.
1064 dnl @author Matthew D. Langston <langston@SLAC.Stanford.EDU>
1066 # FPTOOLS_CHECK_LIBM - check for math library
1067 AC_DEFUN(FPTOOLS_CHECK_LIBM,
1068 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
1072 # These system don't have libm
1075 AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
1076 AC_CHECK_LIB(m, main, LIBM="$LIBM -lm")
1079 AC_CHECK_LIB(m, main, LIBM="-lm")
1084 dnl ######################################################################
1085 dnl Note: Caching has been completely rewritten, but is still no perfect yet.
1086 dnl ######################################################################
1088 dnl ########################### -*- Mode: M4 -*- #######################
1089 dnl Copyright (C) 98, 1999 Matthew D. Langston <langston@SLAC.Stanford.EDU>
1091 dnl This file is free software; you can redistribute it and/or modify it
1092 dnl under the terms of the GNU General Public License as published by
1093 dnl the Free Software Foundation; either version 2 of the License, or
1094 dnl (at your option) any later version.
1096 dnl This file is distributed in the hope that it will be useful, but
1097 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
1098 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1099 dnl General Public License for more details.
1101 dnl You should have received a copy of the GNU General Public License
1102 dnl along with this file; if not, write to:
1104 dnl Free Software Foundation, Inc.
1107 dnl Boston, MA 02111-1307, USA.
1108 dnl ####################################################################
1110 dnl @synopsis FPTOOLS_HAVE_OPENGL
1112 dnl Search for OpenGL. We search first for Mesa (a GPL'ed version of
1113 dnl OpenGL) before a vendor's version of OpenGL if we were specifically
1114 dnl asked to with `--with-Mesa=yes' or `--with-Mesa'.
1116 dnl The four "standard" OpenGL libraries are searched for: "-lGL",
1117 dnl "-lGLU", "-lGLX" (or "-lMesaGL", "-lMesaGLU" as the case may be) and
1120 dnl All of the libraries that are found (since "-lglut" or "-lGLX" might
1121 dnl be missing) are added to the shell output variable "GL_LIBS", along
1122 dnl with any other libraries that are necessary to successfully link an
1123 dnl OpenGL application (e.g. the X11 libraries). Care has been taken to
1124 dnl make sure that all of the libraries in "GL_LIBS" are listed in the
1127 dnl Additionally, the shell output variable "GL_CFLAGS" is set to any
1128 dnl flags (e.g. "-I" flags) that are necessary to successfully compile
1129 dnl an OpenGL application.
1131 dnl The following shell variable (which are not output variables) are
1132 dnl also set to either "yes" or "no" (depending on which libraries were
1133 dnl found) to help you determine exactly what was found.
1140 dnl A complete little toy "Automake `make distcheck'" package of how to
1141 dnl use this macro is available at:
1143 dnl ftp://ftp.slac.stanford.edu/users/langston/autoconf/ac_opengl-0.01.tar.gz
1145 dnl Please note that as the ac_opengl macro and the toy example evolves,
1146 dnl the version number increases, so you may have to adjust the above
1147 dnl URL accordingly.
1149 dnl @author Matthew D. Langston <langston@SLAC.Stanford.EDU>
1151 AC_DEFUN(FPTOOLS_HAVE_OPENGL,
1153 AC_REQUIRE([AC_PROG_CC])
1154 AC_REQUIRE([AC_PATH_X])
1155 AC_REQUIRE([AC_PATH_XTRA])
1156 AC_REQUIRE([FPTOOLS_CHECK_LIBM])
1158 dnl Check for Mesa first if we were asked to.
1161 Prefer Mesa over a vendor's native OpenGL library (default=no)
1163 use_Mesa=$enableval,
1166 if test x"$use_Mesa" = xyes; then
1167 GL_search_list="MesaGL GL opengl32"
1168 GLU_search_list="MesaGLU GLU glu32"
1169 GLX_search_list="MesaGLX GLX"
1171 GL_search_list="GL opengl32 MesaGL"
1172 GLU_search_list="GLU glu32 MesaGLU"
1173 GLX_search_list="GLX MesaGLX"
1179 dnl If we are running under X11 then add in the appropriate libraries.
1180 if test x"$no_x" != xyes; then
1181 dnl Add everything we need to compile and link X programs to GL_CFLAGS
1182 dnl and GL_X_LIBS/GLUT_X_LIBS.
1183 GL_CFLAGS="$CPPFLAGS $X_CFLAGS"
1184 GL_X_LIBS="$X_LIBS $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS $LIBM"
1185 GLUT_X_LIBS="$X_LIBS $X_PRE_LIBS -lXmu -lXt -lXi -lXext -lX11 $X_EXTRA_LIBS $LIBM"
1187 GL_save_CPPFLAGS="$CPPFLAGS"
1188 CPPFLAGS="$GL_CFLAGS"
1190 GL_save_LIBS="$LIBS"
1193 FPTOOLS_SEARCH_LIBS([#include <GL/gl.h>], glEnd, $GL_search_list, have_GL=yes, have_GL=no)
1194 FPTOOLS_SEARCH_LIBS([#include <GL/glu.h>], gluNewQuadric, $GLU_search_list, have_GLU=yes, have_GLU=no)
1195 FPTOOLS_SEARCH_LIBS([#include <GL/glx.h>], glXWaitX, $GLX_search_list, have_GLX=yes, have_GLX=no)
1197 if test -n "$LIBS"; then
1198 GL_LIBS="$LDFLAGS $LIBS"
1206 FPTOOLS_SEARCH_LIBS([#include <GL/glut.h>], glutMainLoop, glut32 glut, have_glut=yes, have_glut=no)
1208 if test -n "$LIBS"; then
1209 GLUT_LIBS="$LDFLAGS $LIBS"
1212 AC_CACHE_CHECK([OpenGL flags], mdl_cv_gl_cflags, [mdl_cv_gl_cflags="$GL_CFLAGS"])
1213 GL_CFLAGS="$mdl_cv_gl_cflags"
1215 AC_CACHE_CHECK([OpenGL libs], mdl_cv_gl_libs, [mdl_cv_gl_libs="$GL_LIBS"])
1216 GL_LIBS="$mdl_cv_gl_libs"
1218 AC_CACHE_CHECK([GLUT libs], mdl_cv_glut_libs, [mdl_cv_glut_libs="$GLUT_LIBS"])
1219 GLUT_LIBS="$mdl_cv_glut_libs"
1222 dnl Reset GL_X_LIBS/GLUT_X_LIBS regardless, since they were just temporary variables
1223 dnl and we don't want to be global namespace polluters.
1227 LIBS="$GL_save_LIBS"
1228 CPPFLAGS="$GL_save_CPPFLAGS"
1236 dnl acspecific.m4's defn of AC_PROG_LEX is a bit too permissive, as it
1237 dnl defaults to 'lex' if 'flex' isn't found (without checking whether
1238 dnl 'lex' is actually present along the user's PATH).
1240 AC_DEFUN(AC_PROG_LEX_STRICT,
1241 [AC_CHECK_PROG(LEX, flex, flex)
1244 AC_CHECK_PROG(LEX,lex,lex)
1245 test -z "$LEX" && AC_MSG_ERROR(['lex' or 'flex' is required to compile GHC.])
1250 dnl Check to see whether CC (gcc) supports a particular option.
1252 AC_DEFUN(FPTOOLS_CC_FLAG,
1254 AC_CACHE_CHECK([whether $CC accepts $1], [ac_cv_cc_$2],
1255 [save_CFLAGS="$CFLAGS"
1258 AC_TRY_COMPILE(,[int main(){return(0);}],
1261 CFLAGS="$save_CFLAGS"
1263 if test "$ac_cv_cc_$2"x = "yesx"; then
1271 dnl Check to see whether 'struct msghdr' contains msg_control
1273 AC_DEFUN(FPTOOLS_MSGHDR_MSG_CONTROL,
1274 [AC_CACHE_CHECK([for msg_control in struct msghdr], fptools_cv_struct_msghdr_msg_control,
1275 [AC_TRY_COMPILE([#include <sys/types.h>
1276 #include <sys/uio.h>
1277 #include <sys/socket.h>], [struct msghdr m; m.msg_control;],
1278 fptools_cv_struct_msghdr_msg_control=yes, fptools_cv_struct_msghdr_msg_control=no)])
1279 if test $fptools_cv_struct_msghdr_msg_control = yes; then
1280 AC_DEFINE(HAVE_MSGHDR_MSG_CONTROL)
1282 AC_SUBST(HAVE_MSGHDR_MSG_CONTROL)dnl
1286 dnl Check to see whether 'struct msghdr' contains msg_accrights
1288 AC_DEFUN(FPTOOLS_MSGHDR_MSG_ACCRIGHTS,
1289 [AC_CACHE_CHECK([for msg_accrights in struct msghdr], fptools_cv_struct_msghdr_msg_accrights,
1290 [AC_TRY_COMPILE([#include <sys/types.h>
1291 #include <sys/uio.h>
1292 #include <sys/socket.h>], [struct msghdr m; m.msg_accrights;],
1293 fptools_cv_struct_msghdr_msg_accrights=yes, fptools_cv_struct_msghdr_msg_accrights=no)])
1294 if test $fptools_cv_struct_msghdr_msg_accrights = yes; then
1295 AC_DEFINE(HAVE_MSGHDR_MSG_ACCRIGHTS)
1297 AC_SUBST(HAVE_MSGHDR_MSG_ACCRIGHTS)dnl