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.
9 # Figure out how to do context diffs. Sets the output variable ContextDiffCmd.
10 # NB: NeXTStep thinks diff'ing a file against itself is "trouble".
11 # Used by ghc, glafp-utils/ltx, and glafp-utils/runstdtest
12 AC_DEFUN([FP_PROG_CONTEXT_DIFF],
13 [AC_CACHE_CHECK([for a working context diff], [fp_cv_context_diff],
17 for fp_var in '-C 1' '-c1'
19 if diff $fp_var conftest1 conftest2 > /dev/null 2>&1; then
20 fp_cv_context_diff="diff $fp_var"
24 if test x"$fp_cv_context_diff" = xno; then
25 AC_MSG_ERROR([cannot figure out how to do context diffs])
27 AC_SUBST(ContextDiffCmd, [$fp_cv_context_diff])
28 ])# FP_PROG_CONTEXT_DIFF
33 # Defines HAVE_DECL_ALTZONE to 1 if declared, 0 otherwise.
34 # Used by base package.
35 AC_DEFUN([FP_DECL_ALTZONE],
36 [AC_REQUIRE([AC_HEADER_TIME])dnl
37 AC_CHECK_HEADERS([sys/time.h])
38 AC_CHECK_DECLS([altzone], [], [],[#if TIME_WITH_SYS_TIME
39 # include <sys/time.h>
43 # include <sys/time.h>
51 # FP_COMPUTE_INT(EXPRESSION, VARIABLE, INCLUDES, IF-FAILS)
52 # ---------------------------------------------------------
53 # Assign VARIABLE the value of the compile-time EXPRESSION using INCLUDES for
54 # compilation. Execute IF-FAILS when unable to determine the value. Works for
55 # cross-compilation, too.
56 # Note: We are lazy and use an internal autoconf macro, but it is supported in
57 # autoconf versions 2.50 up to the actual 2.57, so there is little risk.
58 AC_DEFUN([FP_COMPUTE_INT],
59 [_AC_COMPUTE_INT([$1], [$2], [$3], [$4])[]dnl
63 # FP_CHECK_ALIGNMENT(TYPE, [IGNORED], [INCLUDES = DEFAULT-INCLUDES])
64 # ------------------------------------------------------------------
65 # A variation of AC_CHECK_SIZEOF for computing the alignment restrictions of a
66 # given type. Defines ALIGNMENT_TYPE.
67 AC_DEFUN([FP_CHECK_ALIGNMENT],
68 [AS_LITERAL_IF([$1], [],
69 [AC_FATAL([$0: requires literal arguments])])dnl
70 AC_CHECK_TYPE([$1], [], [], [$3])
71 AC_CACHE_CHECK([alignment of $1], AS_TR_SH([fp_cv_alignment_$1]),
72 [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
73 FP_COMPUTE_INT([(long) (&((struct { char c; $1 ty; } *)0)->ty)],
74 [AS_TR_SH([fp_cv_alignment_$1])],
75 [AC_INCLUDES_DEFAULT([$3])],
76 [AC_MSG_ERROR([cannot compute alignment ($1)
77 See `config.log' for more details.], [77])])
79 AS_TR_SH([fp_cv_alignment_$1])=0
81 AC_DEFINE_UNQUOTED(AS_TR_CPP(alignment_$1), $AS_TR_SH([fp_cv_alignment_$1]),
82 [The alignment of a `$1'.])
83 ])# FP_CHECK_ALIGNMENT
86 dnl ** check for leading underscores in symbol names
88 dnl Test for determining whether symbol names have a leading
91 dnl We assume that they _haven't_ if anything goes wrong.
93 dnl Some nlist implementations seem to try to be compatible by ignoring
94 dnl a leading underscore sometimes (eg. FreeBSD). We therefore have
95 dnl to work around this by checking for *no* leading underscore first.
98 dnl Similarly on OpenBSD, but this test doesn't help. -- dons
100 AC_DEFUN(FPTOOLS_UNDERSCORE,
101 [AC_CHECK_LIB(elf, nlist, LIBS="-lelf $LIBS")dnl
102 AC_CACHE_CHECK([leading underscore in symbol names], fptools_cv_lead_uscore,
105 dnl Hack!: nlist() under Digital UNIX insist on there being an _,
106 dnl but symbol table listings shows none. What is going on here?!?
108 dnl Another hack: cygwin doesn't come with nlist.h , so we hardwire
109 dnl the underscoredness of that "platform"
110 changequote(<<, >>)dnl
112 case $HostPlatform in
113 *openbsd*) # x86 openbsd is ELF from 3.4 >, meaning no leading uscore
115 i386-*2\.[[0-9]] | i386-*3\.[[0-3]] ) fptools_cv_lead_uscore='yes' ;;
116 *) fptools_cv_lead_uscore='no' ;;
118 alpha-dec-osf*) fptools_cv_lead_uscore='no';;
119 *cygwin32) fptools_cv_lead_uscore='yes';;
120 *mingw32) fptools_cv_lead_uscore='yes';;
123 AC_TRY_RUN([#ifdef HAVE_NLIST_H
125 changequote(<<, >>)dnl
127 struct nlist xYzzY1[] = {{"xYzzY1", 0},{0}};
128 struct nlist xYzzY2[] = {{"_xYzzY2", 0},{0}};
136 if(nlist(argv[0], xYzzY1) == 0 && xYzzY1[0].n_value != 0)
138 if(nlist(argv[0], xYzzY2) == 0 && xYzzY2[0].n_value != 0)
143 }], fptools_cv_lead_uscore=yes, fptools_cv_lead_uscore=no, fptools_cv_lead_uscore=NO)
146 LeadingUnderscore=`echo $fptools_cv_lead_uscore | sed 'y/yesno/YESNO/'`
147 AC_SUBST(LeadingUnderscore)
148 case $LeadingUnderscore in
149 YES) AC_DEFINE([LEADING_UNDERSCORE], [1], [Define to 1 if C symbols have a leading underscore added by the compiler.]);;
154 dnl FPTOOLS_PROG_CHECK_VERSION(VERSIONSTR1, TEST, VERSIONSTR2,
155 dnl ACTION-IF-TRUE [, ACTION-IF-FALSE])
157 dnl compare versions field-wise (separator is '.')
158 dnl TEST is one of {-lt,-le,-eq,-ge,-gt}
160 dnl quite shell-independant and SUSv2 compliant code
162 dnl NOTE: the loop could be unrolled within autoconf, but the
163 dnl macro code would be a) longer and b) harder to debug... ;)
165 AC_DEFUN(FPTOOLS_PROG_CHECK_VERSION,
170 set -- [$]a; h1="[$]1"; shift 2>/dev/null; a="[$]*"
171 set -- [$]b; h2="[$]1"; shift 2>/dev/null; b="[$]*"
172 test -n "[$]h1" || h1=0; test -n "[$]h2" || h2=0
173 test [$]{h1} -eq [$]{h2} || break
175 test [$]{h1} [$2] [$]{h2}
177 then ifelse([$4],,[:],[
187 dnl Check for Greencard and version.
189 AC_DEFUN(FPTOOLS_GREENCARD,
191 AC_PATH_PROG(GreencardCmd,greencard)
192 AC_CACHE_CHECK([for version of greencard], fptools_cv_greencard_version,
194 [if test x"$GreencardCmd" != x; then
195 fptools_cv_greencard_version="`$GreencardCmd --version |
196 grep 'version' | sed -e 's/greencard. version \([^ ]*\).*/\1/g'`"
198 fptools_cv_greencard_version=""
202 FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_greencard_version],-lt,$1,
203 [AC_MSG_ERROR([greencard version $1 or later is required (found '$fptools_cv_greencard_version')])])dnl
204 GreencardVersion=$fptools_cv_greencard_version
205 AC_SUBST(GreencardVersion)
209 dnl Check for Happy and version. If we're building GHC, then we need
210 dnl at least Happy version 1.13. If there's no installed Happy, we look
211 dnl for a happy source tree and point the build system at that instead.
213 AC_DEFUN(FPTOOLS_HAPPY,
215 if test -d $srcdir/happy; then
216 SrcTreeHappyCmd=$hardtop/happy/src/happy-inplace
218 if test x"$UseSrcTreeHappy" = xYES; then
219 HappyCmd=$SrcTreeHappyCmd
221 AC_PATH_PROG(HappyCmd,happy,$SrcTreeHappyCmd)
223 AC_CACHE_CHECK([for version of happy], fptools_cv_happy_version,
225 [if test x"$HappyCmd" = x"$SrcTreeHappyCmd"; then
226 fptools_cv_happy_version=`grep '^ProjectVersion[ ]*=' $srcdir/happy/mk/version.mk | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`;
227 elif test x"$HappyCmd" != x; then
228 fptools_cv_happy_version="`$HappyCmd -v |
229 grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'`" ;
231 fptools_cv_happy_version="";
235 if test -d $srcdir/ghc -a ! -f $srcdir/ghc/compiler/parser/Parser.hs; then
236 FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_happy_version],-lt,[1.13],
237 [AC_MSG_ERROR([Happy version 1.13 or later is required to compile GHC.])])dnl
239 HappyVersion=$fptools_cv_happy_version;
240 AC_SUBST(HappyVersion)
244 dnl Check for Haddock and version. If there's no installed Haddock, we look
245 dnl for a haddock source tree and point the build system at that instead.
247 AC_DEFUN(FPTOOLS_HADDOCK,
249 if test -d $srcdir/haddock; then
250 SrcTreeHaddockCmd=$hardtop/haddock/src/haddock-inplace
252 if test x"$UseSrcTreeHaddock" = xYES; then
253 HaddockCmd=$SrcTreeHaddockCmd
255 AC_PATH_PROG(HaddockCmd,haddock,$SrcTreeHaddockCmd)
257 dnl Darn, I forgot to make Haddock print out its version number when
258 dnl invoked with -v. We could try generating some HTML and grepping
259 dnl through that to find the version number, but I think we'll make
260 dnl do without it for now.
264 dnl Check for Alex and version. If we're building GHC, then we need
265 dnl at least Alex version 2.0. If there's no installed Alex, we look
266 dnl for a alex source tree and point the build system at that instead.
268 AC_DEFUN(FPTOOLS_ALEX,
270 if test -d $srcdir/alex; then
271 SrcTreeAlexCmd=$hardtop/alex/src/alex-inplace
273 if test x"$UseSrcTreeAlex" = xYES; then
274 AlexCmd=$SrcTreeAlexCmd
276 AC_PATH_PROG(AlexCmd,alex,$SrcTreeAlexCmd)
278 AC_CACHE_CHECK([for version of alex], fptools_cv_alex_version,
280 [if test x"$AlexCmd" = x"$SrcTreeAlexCmd"; then
281 fptools_cv_alex_version=`grep '^ProjectVersion[ ]*=' $srcdir/alex/mk/version.mk | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`;
282 elif test x"$AlexCmd" != x; then
283 fptools_cv_alex_version="`$AlexCmd -v |
284 grep 'Alex [Vv]ersion' | sed -e 's/Alex [Vv]ersion \([0-9\.]*\).*/\1/g'`" ;
286 fptools_cv_alex_version="";
290 dnl if test -d $srcdir/ghc -a ! -f $srcdir/ghc/compiler/parser/Lexer.hs; then
291 dnl FPTOOLS_PROG_CHECK_VERSION([$fptools_cv_alex_version],-lt,[2.0],
292 dnl [AC_MSG_ERROR([Alex version 2.0 or later is required to compile GHC.])])dnl
294 AlexVersion=$fptools_cv_alex_version;
295 AC_SUBST(AlexVersion)
300 dnl Check whether ld supports -x
302 AC_DEFUN(FPTOOLS_LD_X,
303 [AC_CACHE_CHECK([whether ld understands -x], fptools_cv_ld_x,
305 echo 'foo() {}' > conftest.c
306 ${CC-cc} -c conftest.c
307 if ${LdCmd} -r -x -o foo.o conftest.o; then
312 rm -rf conftest.c conftest.o foo.o
314 if test "$fptools_cv_ld_x" = yes; then
323 dnl *** Checking for ar and its arguments + whether we need ranlib.
325 dnl ArCmd, ArSupportsInput and RANLIB are AC_SUBST'ed
326 dnl On Digital UNIX, we test for the -Z (compress) and
327 dnl -input (take list of files from external file) flags.
329 AC_DEFUN(FPTOOLS_PROG_AR_AND_RANLIB,
330 [AC_PATH_PROG(ArCmdRaw,ar)
331 if test -z "$ArCmdRaw"; then
332 echo "You don't seem to have ar in your PATH...I have no idea how to make a library"
335 dnl GNU ar needs special treatment: it appears to have problems with
336 dnl object files with the same name if you use the 's' modifier, but
337 dnl simple 'ar q' works fine, and doesn't need a separate ranlib.
338 if $ArCmdRaw --version | grep 'GNU' >/dev/null 2>/dev/null; then
341 elif $ArCmdRaw clqsZ conftest.a >/dev/null 2>/dev/null; then
344 elif $ArCmdRaw clqs conftest.a >/dev/null 2>/dev/null; then
347 elif $ArCmdRaw cqs conftest.a >/dev/null 2>/dev/null; then
350 elif $ArCmdRaw clq conftest.a >/dev/null 2>/dev/null; then
353 elif $ArCmdRaw cq conftest.a >/dev/null 2>/dev/null; then
356 elif $ArCmdRaw cq conftest.a 2>&1 | grep 'no archive members specified' >/dev/null 2>/dev/null; then
360 echo "I can't figure out how to use your $ArCmd"
364 case $HostPlatform in
366 ArCmd="`cygpath -w ${ArCmdRaw} | sed -e 's@\\\\@/@g' ` ${ArCmdArgs}"
368 *) ArCmd="${ArCmdRaw} ${ArCmdArgs}"
371 test -n "$ArCmd" && test -n "$verbose" && echo " setting ArCmd to $ArCmd"
373 if $ArCmd conftest.a -input /dev/null >/dev/null 2>/dev/null; then
374 ArSupportsInput='-input'
379 test -n "$ArSupportsInput" && test -n "$verbose" && echo " setting ArSupportsInput to $ArSupportsInput"
380 AC_SUBST(ArSupportsInput)
381 if test -z "$NeedRanLib"; then
383 test -n "$verbose" && echo " setting RANLIB to $RANLIB"
391 dnl AC_SHEBANG_PERL - can we she-bang perl?
393 AC_DEFUN(FPTOOLS_SHEBANG_PERL,
394 [AC_CACHE_CHECK([if your perl works in shell scripts], fptools_cv_shebang_perl,
399 (SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
400 if test $? -ne 69; then
401 fptools_cv_shebang_perl=yes
403 fptools_cv_shebang_perl=no
409 dnl Extra testing of the result AC_PROG_CC, testing the gcc version no.
410 dnl *Must* be called after AC_PROG_CC
412 AC_DEFUN(FPTOOLS_HAVE_GCC,
413 [AC_CACHE_CHECK([whether you have an ok gcc], fptools_cv_have_gcc,
414 [if test -z "$GCC"; then
416 echo "You would be better off with gcc"
417 echo "Perhaps it is already installed, but not in your PATH?"
418 fptools_cv_have_gcc='no'
421 gcc_version_str="`$CC -v 2>&1 | grep 'version ' | sed -e 's/.*version [^0-9]*\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1\.\2/g' `"
423 fptools_cv_have_gcc='yes'
424 FPTOOLS_PROG_CHECK_VERSION($gcc_version_str, -lt, "2.0",
425 fptools_cv_have_gcc='no'
427 echo "your gcc version appears to be ..."
429 echo "gcc prior to 2.0 and have never worked with ghc."
430 echo "we recommend 2.95.3, although versions back to 2.7.2 should be ok."
431 AC_MSG_ERROR([gcc 1.X has never been supported])
435 HaveGcc=`echo $fptools_cv_have_gcc | sed 'y/yesno/YESNO/'`
440 dnl Some OSs (Mandrake Linux, in particular) configure GCC with
441 dnl -momit-leaf-frame-pointer on by default. If this is the case, we
442 dnl need to turn it off for mangling to work. The test is currently a bit
443 dnl crude, using only the version number of gcc.
445 AC_DEFUN(FPTOOLS_GCC_NEEDS_NO_OMIT_LFPTR,
446 [AC_CACHE_CHECK([whether gcc needs -mno-omit-leaf-frame-pointer], fptools_cv_gcc_needs_no_omit_lfptr,
448 fptools_cv_gcc_needs_no_omit_lfptr='no'
449 FPTOOLS_PROG_CHECK_VERSION($gcc_version_str, -ge, "3.2",
450 fptools_cv_gcc_needs_no_omit_lfptr='yes')
452 if test "$fptools_cv_gcc_needs_no_omit_lfptr" = "yes"; then
453 AC_DEFINE([HAVE_GCC_MNO_OMIT_LFPTR], [1], [Define to 1 if gcc supports -mno-omit-leaf-frame-pointer.])
457 dnl Small feature test for perl version. Assumes PerlCmd
458 dnl contains path to perl binary
460 AC_DEFUN(FPTOOLS_CHECK_PERL_VERSION,
461 [$PerlCmd -v >conftest.out 2>&1
462 if grep "version 5" conftest.out >/dev/null 2>&1; then
465 if grep "v5.6" conftest.out >/dev/null 2>&1; then
468 if grep "v5.8" conftest.out >/dev/null 2>&1; then
471 if grep "version 6" conftest.out >/dev/null 2>&1; then
474 echo "Your version of perl probably won't work."
483 dnl Getting at the right version of 'find'
484 dnl (i.e., not the MS util on a Win32 box).
486 AC_DEFUN(FPTOOLS_FIND_FIND,
488 AC_PATH_PROG(Find2Cmd, find)
489 $Find2Cmd --version > conftest.out 2>&1
490 if grep "FIND: Parameter format" conftest.out >/dev/null 2>&1 ; then
491 # Encountered MS' find utility, which is not what we're after.
493 # HACK - AC_CHECK_PROG is useful here in that does let you reject
494 # an (absolute) entry in the path (Find2Cmd). It is not so useful
495 # in that it doesn't let you (AFAIU) set VARIABLE equal to the
496 # absolute path eventually found. So, hack around this by inspecting
497 # what variables hold the abs. path & use them directly.
498 AC_CHECK_PROG(FindCmd,find,`echo $ac_dir/$ac_word`,find,,$Find2Cmd)
506 dnl FPTOOLS_NOCACHE_CHECK prints a message, then sets the
507 dnl values of the second argument to the result of running
508 dnl the commands given by the third. It does not cache its
509 dnl result, so it is suitable for checks which should be
512 AC_DEFUN(FPTOOLS_NOCACHE_CHECK,
513 [AC_MSG_CHECKING([$1])
515 AC_MSG_RESULT([$][$2])
519 dnl FPTOOLS_GHC_VERSION(version)
520 dnl FPTOOLS_GHC_VERSION(major, minor [, patchlevel])
521 dnl FPTOOLS_GHC_VERSION(version, major, minor, patchlevel)
523 dnl Test for version of installed ghc. Uses $GHC.
524 dnl [original version pinched from c2hs]
526 AC_DEFUN(FPTOOLS_GHC_VERSION,
527 [FPTOOLS_NOCACHE_CHECK([version of ghc], [fptools_version_of_ghc],
528 ["${WithGhc-ghc}" --version > conftestghc 2>&1
529 cat conftestghc >&AC_FD_CC
530 #Useless Use Of cat award...
531 fptools_version_of_ghc=`cat conftestghc | sed -n -e 's/, patchlevel *\([[0-9]]\)/.\1/;s/.* version \([[0-9]][[0-9.]]*\).*/\1/p'`
533 if test "[$]fptools_version_of_ghc" = ""
535 fptools_version_of_ghc='unknown'
537 fptools_version_of_ghc[_major]=`echo [$]fptools_version_of_ghc | sed -e 's/^\([[0-9]]\).*/\1/'`
538 fptools_version_of_ghc[_minor]=`echo [$]fptools_version_of_ghc | sed -e 's/^[[0-9]]\.\([[0-9]]*\).*/\1/'`
539 fptools_version_of_ghc[_pl]=`echo [$]fptools_version_of_ghc | sed -n -e 's/^[[0-9]]\.[[0-9]]*\.\([[0-9]]*\)/\1/p'`
541 if test "[$]fptools_version_of_ghc[_pl]" = ""
543 fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor]"
544 fptools_version_of_ghc[_pl]="0"
546 fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor].[$]fptools_version_of_ghc[_pl]"
550 [$1]="[$]fptools_version_of_ghc[_all]"
552 [$1]="[$]fptools_version_of_ghc[_major]"
553 [$2]="[$]fptools_version_of_ghc[_minor]"
555 [$1]="[$]fptools_version_of_ghc[_major]"
556 [$2]="[$]fptools_version_of_ghc[_minor]"
557 [$3]="[$]fptools_version_of_ghc[_pl]"
559 [$1]="[$]fptools_version_of_ghc[_all]"
560 [$2]="[$]fptools_version_of_ghc[_major]"
561 [$3]="[$]fptools_version_of_ghc[_minor]"
562 [$4]="[$]fptools_version_of_ghc[_pl]"
568 dnl ** Map an arithmetic C type to a Haskell type.
569 dnl Based on autconf's AC_CHECK_SIZEOF.
571 dnl FPTOOLS_CHECK_HTYPE(TYPE [, DEFAULT_VALUE, [, VALUE-FOR-CROSS-COMPILATION])
572 AC_DEFUN(FPTOOLS_CHECK_HTYPE,
573 [changequote(<<, >>)dnl
574 dnl The name to #define.
575 define(<<AC_TYPE_NAME>>, translit(htype_$1, [a-z *], [A-Z_P]))dnl
576 dnl The cache variable name.
577 define(<<AC_CV_NAME>>, translit(fptools_cv_htype_$1, [ *], [_p]))dnl
579 AC_MSG_CHECKING(Haskell type for $1)
580 AC_CACHE_VAL(AC_CV_NAME,
581 [AC_TRY_RUN([#include <stdio.h>
584 #ifdef HAVE_SYS_TYPES_H
585 # include <sys/types.h>
592 #ifdef HAVE_SYS_STAT_H
593 # include <sys/stat.h>
608 #ifdef HAVE_TERMIOS_H
609 # include <termios.h>
624 #ifdef HAVE_OPENGL_GL_H
625 # include <OpenGL/gl.h>
628 #ifdef HAVE_SYS_RESOURCE_H
629 # include <sys/resource.h>
635 FILE *f=fopen("conftestval", "w");
637 if (((testing)((int)((testing)1.4))) == ((testing)1.4)) {
639 ((testing)(-1) < (testing)0) ? "Int" : "Word",
643 (sizeof(testing) > sizeof(double)) ? "LDouble" :
644 (sizeof(testing) == sizeof(double)) ? "Double" : "Float");
648 }], AC_CV_NAME=`cat conftestval`,
649 ifelse([$2], , AC_CV_NAME=NotReallyAType, AC_CV_NAME=$2),
650 ifelse([$3], , AC_CV_NAME=NotReallyATypeCross, AC_CV_NAME=$3))]) dnl
651 AC_MSG_RESULT($AC_CV_NAME)
652 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [Define to Haskell type for $1])
653 undefine([AC_TYPE_NAME])dnl
654 undefine([AC_CV_NAME])dnl
658 dnl ** Obtain the value of a C constant.
659 dnl The value will be `(-1)' if the constant is undefined.
661 dnl This is set up so that the argument can be a shell variable.
663 AC_DEFUN(FPTOOLS_CHECK_CCONST,
665 eval "cv_name=ac_cv_cconst_$1"
666 AC_MSG_CHECKING(value of $1)
667 AC_CACHE_VAL($cv_name,
668 [AC_TRY_RUN([#include <stdio.h>
672 FILE *f=fopen("conftestval", "w");
674 fprintf(f, "%d\n", $1);
677 eval "$cv_name=`cat conftestval`",
679 eval "$cv_name=-1")])dnl
680 eval "fptools_check_cconst_result=`echo '$'{$cv_name}`"
681 AC_MSG_RESULT($fptools_check_cconst_result)
682 AC_DEFINE_UNQUOTED(CCONST_$1, $fptools_check_cconst_result, [The value of $1.])
683 unset fptools_check_cconst_result
687 # FP_CHECK_CCONSTS_TEMPLATE(CONST...)
688 # -----------------------------------
689 m4_define([FP_CHECK_CCONSTS_TEMPLATE],
690 [AC_FOREACH([FP_Const], [$1],
691 [AH_TEMPLATE(AS_TR_CPP(CCONST_[]FP_Const),
692 [The value of ]FP_Const[.])])[]dnl
693 ])# FP_CHECK_CCONSTS_TEMPLATE
696 dnl ** Invoke AC_CHECK_CCONST on each argument (which have to separate with
699 AC_DEFUN(FPTOOLS_CHECK_CCONSTS,
700 [FP_CHECK_CCONSTS_TEMPLATE([$1])dnl
701 for ac_const_name in $1
703 FPTOOLS_CHECK_CCONST($ac_const_name)dnl
708 dnl *** Can we open files in binary mode? ***
710 AC_DEFUN(FPTOOLS_O_BINARY,
712 AC_REQUIRE([AC_PROG_CC])
713 AC_MSG_CHECKING(whether we can open files in binary mode)
714 AC_CACHE_VAL(fptools_cv_have_o_binary,
723 fptools_cv_have_o_binary=yes,
724 fptools_cv_have_o_binary=no)
727 AC_MSG_RESULT($fptools_cv_have_o_binary)
728 if test "$fptools_cv_have_o_binary" = yes; then
729 AC_DEFINE([HAVE_O_BINARY], [1], [Define to 1 if fcntl.h defines O_BINARY.])
734 dnl Based on AC_TRY_LINK - run iftrue if links cleanly with no warning
736 dnl FPTOOLS_TRY_LINK_NOWARN(flags,main?,iftrue,iffalse)
738 AC_DEFUN(FPTOOLS_TRY_LINK_NOWARN,
742 cat > conftest.$ac_ext <<EOF
743 dnl This sometimes fails to find confdefs.h, for some reason.
744 dnl [#]line __oline__ "[$]0"
745 [#]line __oline__ "configure"
746 #include "confdefs.h"
748 int t() { return 0; }
750 if AC_TRY_EVAL(ac_link); then
755 ifelse([$4], , , [else
765 dnl Loosely based on AC_CHECK_LIB in acgeneral.m4 in autoconf distribution
767 dnl FPTOOLS_CHECK_FLAG_NOWARN(NAME, FLAG, CODE, iftrue, iffalse)
769 AC_DEFUN(FPTOOLS_CHECK_FLAG_NOWARN,
770 [AC_MSG_CHECKING([for $1])
771 AC_CACHE_VAL(ac_cv_flag_$1,
772 [FPTOOLS_TRY_LINK_NOWARN("$2", [main() { $3; exit(0); } ],
773 eval "ac_cv_flag_$1=yes",
774 eval "ac_cv_flag_$1=no"
777 if eval "test \"`echo '$ac_cv_flag_'$1`\" = yes"; then
787 dnl FPTOOLS_CHECK_LIB_NOWARN(LIBRARY, FUNCTION)
789 AC_DEFUN(FPTOOLS_CHECK_LIB_NOWARN,
790 [FPTOOLS_CHECK_FLAG_NOWARN([function_$2],[],[extern char $2(); $2();],
792 ac_tr_lib=HAVE_LIB`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
794 AC_DEFINE_UNQUOTED($ac_tr_lib)
796 [FPTOOLS_CHECK_FLAG_NOWARN([library_$1],[-l$1],[extern char $2(); $2();],
798 ac_tr_lib=HAVE_LIB`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
800 AC_DEFINE_UNQUOTED($ac_tr_lib)
807 dnl ** Check which CATALOG file we have to use with DocBook SGML.
809 dnl FPTOOLS_DOCBOOK_CATALOG(VARIABLE, JADE, STYLESHEET, CATALOGS-TO-CHECK-FOR)
811 dnl If any of the catalogs given in CATALOGS-TO-CHECK-FOR works on this
812 dnl platform, let VARIABLE refer to this catalog; otherwise, VARIABLE
813 dnl is set to "no". JADE is the jade executable and STYLESHEET
814 dnl a DocBook style sheet.
816 AC_DEFUN(FPTOOLS_DOCBOOK_CATALOG,
817 [AC_CACHE_CHECK([for DocBook CATALOG], fptools_cv_sgml_catalog,
819 cat > conftest.sgml << EOF
820 <!DOCTYPE Article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
824 <Author><OtherName>Test</OtherName></Author>
825 <Address>Test</Address>
826 <PubDate>Test</PubDate>
828 <Sect1><Title>Test</Title>
835 fptools_cv_sgml_catalog=no
836 if test -z "$SGML_CATALOG_FILES" ; then
837 for fptools_catalog in $4; do
838 ac_try="$2 -t rtf -d $3#print -c $fptools_catalog conftest.sgml"
839 if AC_TRY_EVAL(ac_try); then
840 fptools_cv_sgml_catalog=[$]fptools_catalog
845 # If the env var SGML_CATALOG_FILES is defined, assume things are cool.
846 fptools_cv_sgml_catalog="yes"
850 if test $fptools_cv_sgml_catalog != "no"; then
851 $1=$fptools_cv_sgml_catalog
855 dnl ######################################################################
856 dnl FPTOOLS_SEARCH_LIBS(INCLUDES, FUNCTION, SEARCH-LIBS [, ACTION-IF-FOUND
857 dnl [, ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
858 dnl Search for a library defining FUNC, if it's not already available.
859 dnl This is almost the same as AC_SEARCH_LIBS, but the INCLUDES can be
861 dnl ######################################################################
863 AC_DEFUN(FPTOOLS_SEARCH_LIBS,
865 AC_CACHE_CHECK([for library containing $2], [ac_cv_search_$2],
866 [ac_func_search_save_LIBS="$LIBS"
868 AC_TRY_LINK([$1], [$2()], [ac_cv_search_$2="none required"])
869 test "$ac_cv_search_$2" = "no" && for i in $3; do
870 LIBS="-l$i $6 $ac_func_search_save_LIBS"
871 AC_TRY_LINK([$1], [$2()],
872 [ac_cv_search_$2="-l$i"
875 LIBS="$ac_func_search_save_LIBS"])
876 if test "$ac_cv_search_$2" != "no"; then
877 test "$ac_cv_search_$2" = "none required" || LIBS="$ac_cv_search_$2 $LIBS"
883 dnl ####################### -*- Mode: M4 -*- ###########################
884 dnl Copyright (C) 98, 1999 Matthew D. Langston <langston@SLAC.Stanford.EDU>
886 dnl This file is free software; you can redistribute it and/or modify it
887 dnl under the terms of the GNU General Public License as published by
888 dnl the Free Software Foundation; either version 2 of the License, or
889 dnl (at your option) any later version.
891 dnl This file is distributed in the hope that it will be useful, but
892 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
893 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
894 dnl General Public License for more details.
896 dnl You should have received a copy of the GNU General Public License
897 dnl along with this file; if not, write to:
899 dnl Free Software Foundation, Inc.
902 dnl Boston, MA 02111-1307, USA.
903 dnl ####################################################################
906 dnl @synopsis FPTOOLS_CHECK_LIBM
908 dnl Search for math library (typically -lm).
910 dnl The variable LIBM (which is not an output variable by default) is
911 dnl set to a value which is suitable for use in a Makefile (for example,
912 dnl in make's LOADLIBES macro) provided you AC_SUBST it first.
914 dnl @author Matthew D. Langston <langston@SLAC.Stanford.EDU>
916 # FPTOOLS_CHECK_LIBM - check for math library
917 AC_DEFUN(FPTOOLS_CHECK_LIBM,
918 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
922 # These system don't have libm
925 AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
926 AC_CHECK_LIB(m, main, LIBM="$LIBM -lm")
929 AC_CHECK_LIB(m, main, LIBM="-lm")
934 dnl ######################################################################
935 dnl Note: Caching has been completely rewritten, but is still no perfect yet.
936 dnl ######################################################################
938 dnl ########################### -*- Mode: M4 -*- #######################
939 dnl Copyright (C) 98, 1999 Matthew D. Langston <langston@SLAC.Stanford.EDU>
941 dnl This file is free software; you can redistribute it and/or modify it
942 dnl under the terms of the GNU General Public License as published by
943 dnl the Free Software Foundation; either version 2 of the License, or
944 dnl (at your option) any later version.
946 dnl This file is distributed in the hope that it will be useful, but
947 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
948 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
949 dnl General Public License for more details.
951 dnl You should have received a copy of the GNU General Public License
952 dnl along with this file; if not, write to:
954 dnl Free Software Foundation, Inc.
957 dnl Boston, MA 02111-1307, USA.
958 dnl ####################################################################
960 dnl @synopsis FPTOOLS_HAVE_OPENGL
962 dnl Search for OpenGL. We search first for Mesa (a GPL'ed version of
963 dnl OpenGL) before a vendor's version of OpenGL if we were specifically
964 dnl asked to with `--with-Mesa=yes' or `--with-Mesa'.
966 dnl The four "standard" OpenGL libraries are searched for: "-lGL",
967 dnl "-lGLU", "-lGLX" (or "-lMesaGL", "-lMesaGLU" as the case may be) and
970 dnl All of the libraries that are found (since "-lglut" or "-lGLX" might
971 dnl be missing) are added to the shell output variable "GL_LIBS", along
972 dnl with any other libraries that are necessary to successfully link an
973 dnl OpenGL application (e.g. the X11 libraries). Care has been taken to
974 dnl make sure that all of the libraries in "GL_LIBS" are listed in the
977 dnl Additionally, the shell output variable "GL_CFLAGS" is set to any
978 dnl flags (e.g. "-I" flags) that are necessary to successfully compile
979 dnl an OpenGL application.
981 dnl The following shell variable (which are not output variables) are
982 dnl also set to either "yes" or "no" (depending on which libraries were
983 dnl found) to help you determine exactly what was found.
990 dnl A complete little toy "Automake `make distcheck'" package of how to
991 dnl use this macro is available at:
993 dnl ftp://ftp.slac.stanford.edu/users/langston/autoconf/ac_opengl-0.01.tar.gz
995 dnl Please note that as the ac_opengl macro and the toy example evolves,
996 dnl the version number increases, so you may have to adjust the above
999 dnl @author Matthew D. Langston <langston@SLAC.Stanford.EDU>
1001 AC_DEFUN(FPTOOLS_HAVE_OPENGL,
1003 AC_REQUIRE([AC_PROG_CC])
1004 AC_REQUIRE([AC_PATH_X])
1005 AC_REQUIRE([AC_PATH_XTRA])
1006 AC_REQUIRE([FPTOOLS_CHECK_LIBM])
1008 dnl Check for Mesa first if we were asked to.
1011 Prefer Mesa over a vendor's native OpenGL library (default=no)
1013 use_Mesa=$enableval,
1016 if test x"$use_Mesa" = xyes; then
1017 GL_search_list="MesaGL GL opengl32"
1018 GLU_search_list="MesaGLU GLU glu32"
1019 GLX_search_list="MesaGLX GLX"
1021 GL_search_list="GL opengl32 MesaGL"
1022 GLU_search_list="GLU glu32 MesaGLU"
1023 GLX_search_list="GLX MesaGLX"
1029 dnl If we are running under X11 then add in the appropriate libraries.
1030 if test x"$no_x" != xyes; then
1031 dnl Add everything we need to compile and link X programs to GL_CFLAGS
1032 dnl and GL_X_LIBS/GLUT_X_LIBS.
1033 GL_CFLAGS="$CPPFLAGS $X_CFLAGS"
1034 GL_X_LIBS="$X_LIBS $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS $LIBM"
1035 GLUT_X_LIBS="$X_LIBS $X_PRE_LIBS -lXmu -lXt -lXi -lXext -lX11 $X_EXTRA_LIBS $LIBM"
1037 GL_save_CPPFLAGS="$CPPFLAGS"
1038 CPPFLAGS="$GL_CFLAGS"
1040 GL_save_LIBS="$LIBS"
1043 FPTOOLS_SEARCH_LIBS([#include <GL/gl.h>], glEnd, $GL_search_list, have_GL=yes, have_GL=no)
1044 FPTOOLS_SEARCH_LIBS([#include <GL/glu.h>], gluNewQuadric, $GLU_search_list, have_GLU=yes, have_GLU=no)
1045 FPTOOLS_SEARCH_LIBS([#include <GL/glx.h>], glXWaitX, $GLX_search_list, have_GLX=yes, have_GLX=no)
1047 if test -n "$LIBS"; then
1048 GL_LIBS="$LDFLAGS $LIBS"
1056 FPTOOLS_SEARCH_LIBS([#include <GL/glut.h>], glutMainLoop, glut32 glut, have_glut=yes, have_glut=no)
1058 if test -n "$LIBS"; then
1059 GLUT_LIBS="$LDFLAGS $LIBS"
1062 AC_CACHE_CHECK([OpenGL flags], mdl_cv_gl_cflags, [mdl_cv_gl_cflags="$GL_CFLAGS"])
1063 GL_CFLAGS="$mdl_cv_gl_cflags"
1065 AC_CACHE_CHECK([OpenGL libs], mdl_cv_gl_libs, [mdl_cv_gl_libs="$GL_LIBS"])
1066 GL_LIBS="$mdl_cv_gl_libs"
1068 AC_CACHE_CHECK([GLUT libs], mdl_cv_glut_libs, [mdl_cv_glut_libs="$GLUT_LIBS"])
1069 GLUT_LIBS="$mdl_cv_glut_libs"
1072 dnl Reset GL_X_LIBS/GLUT_X_LIBS regardless, since they were just temporary variables
1073 dnl and we don't want to be global namespace polluters.
1077 LIBS="$GL_save_LIBS"
1078 CPPFLAGS="$GL_save_CPPFLAGS"
1087 dnl Check to see whether CC (gcc) supports a particular option.
1089 AC_DEFUN(FPTOOLS_CC_FLAG,
1091 AC_CACHE_CHECK([whether $CC accepts $1], [ac_cv_cc_$2],
1092 [save_CFLAGS="$CFLAGS"
1095 AC_TRY_COMPILE(,[int main(){return(0);}],
1098 CFLAGS="$save_CFLAGS"
1100 if test "$ac_cv_cc_$2"x = "yesx"; then