[project @ 2004-01-06 18:50:22 by panne]
[ghc.git] / aclocal.m4
1 # Extra autoconf macros for the Glasgow fptools
2 #
3 # To be a good autoconf citizen, names of local macros have prefixed with FP_ to
4 # ensure we don't clash with any pre-supplied autoconf ones.
5
6
7 # FP_EVAL_STDERR(COMMAND)
8 # ------------------------
9 # Eval COMMAND, save its stderr (without lines resulting from shell tracing)
10 # into the file conftest.err and the exit status in the variable fp_status.
11 AC_DEFUN([FP_EVAL_STDERR],
12 [{ (eval $1) 2>conftest.er1
13   fp_status=$?
14   grep -v '^ *+' conftest.er1 >conftest.err
15   rm -f conftest.er1
16   (exit $fp_status); }[]dnl
17 ])# FP_EVAL_STDERR
18
19
20 # FP_CHECK_FLAG(FLAG, [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED])
21 # -----------------------------------------------------------------------
22 # Check to see whether the compiler for the current language supports a
23 # particular option.
24 #
25 # Implementation note: When given an unkown option, GCC issues an warning on
26 # stderr only, but returns an exit value of 0 nevertheless. Consequently we have
27 # to check stderr *and* the exit value.
28 #
29 # Used by ghc.
30 AC_DEFUN(FP_CHECK_FLAG,
31 [AC_LANG_COMPILER_REQUIRE()dnl
32 AC_LANG_CASE([C],          [fp_compiler="$CC"  m4_pushdef([fp_Flags], [CFLAGS])],
33              [C++],        [fp_compiler="$CXX" m4_pushdef([fp_Flags], [CXXFLAGS])],
34              [Fortran 77], [fp_compiler="$F77" m4_pushdef([fp_Flags], [FFLAGS])])
35 m4_pushdef([fp_Cache], [fp_cv_[]fp_Flags[]AS_TR_SH([$1])])[]dnl
36 AC_CACHE_CHECK([whether $fp_compiler accepts $1], [fp_Cache],
37 [AC_LANG_CONFTEST([AC_LANG_PROGRAM()])
38 fp_save_flags="$fp_Flags"
39 fp_Flags="$fp_Flags $1"
40 fp_Cache=no
41 if FP_EVAL_STDERR([$ac_compile conftest.$ac_ext]) >/dev/null; then
42   test -s conftest.err || fp_Cache=yes
43 fi
44 fp_Flags="$fp_save_flags"
45 rm -f conftest.err conftest.$ac_ext])
46 AS_IF([test $fp_Cache = yes], [$2], [$3])[]dnl
47 m4_popdef([fp_Cache])[]dnl
48 m4_popdef([fp_Flags])[]dnl
49 ])# FP_CHECK_FLAG
50
51
52 # FP_PROG_CONTEXT_DIFF
53 # --------------------
54 # Figure out how to do context diffs. Sets the output variable ContextDiffCmd.
55 #
56 # Note: NeXTStep thinks diff'ing a file against itself is "trouble".
57 #
58 # Used by ghc, glafp-utils/ltx, and glafp-utils/runstdtest.
59 AC_DEFUN([FP_PROG_CONTEXT_DIFF],
60 [AC_CACHE_CHECK([for a working context diff], [fp_cv_context_diff],
61 [echo foo > conftest1
62 echo foo > conftest2
63 fp_cv_context_diff=no
64 for fp_var in '-C 1' '-c1'
65 do
66   if diff $fp_var conftest1 conftest2 > /dev/null 2>&1; then
67     fp_cv_context_diff="diff $fp_var"
68     break
69   fi
70 done])
71 if test x"$fp_cv_context_diff" = xno; then
72    AC_MSG_ERROR([cannot figure out how to do context diffs])
73 fi
74 AC_SUBST(ContextDiffCmd, [$fp_cv_context_diff])
75 ])# FP_PROG_CONTEXT_DIFF
76
77
78 # FP_DECL_ALTZONE
79 # -------------------
80 # Defines HAVE_DECL_ALTZONE to 1 if declared, 0 otherwise.
81 #
82 # Used by base package.
83 AC_DEFUN([FP_DECL_ALTZONE],
84 [AC_REQUIRE([AC_HEADER_TIME])dnl
85 AC_CHECK_HEADERS([sys/time.h])
86 AC_CHECK_DECLS([altzone], [], [],[#if TIME_WITH_SYS_TIME
87 # include <sys/time.h>
88 # include <time.h>
89 #else
90 # if HAVE_SYS_TIME_H
91 #  include <sys/time.h>
92 # else
93 #  include <time.h>
94 # endif
95 #endif])
96 ])# FP_DECL_ALTZONE
97
98
99 # FP_COMPUTE_INT(EXPRESSION, VARIABLE, INCLUDES, IF-FAILS)
100 # ---------------------------------------------------------
101 # Assign VARIABLE the value of the compile-time EXPRESSION using INCLUDES for
102 # compilation. Execute IF-FAILS when unable to determine the value. Works for
103 # cross-compilation, too.
104 #
105 # Implementation note: We are lazy and use an internal autoconf macro, but it
106 # is supported in autoconf versions 2.50 up to the actual 2.57, so there is
107 # little risk.
108 AC_DEFUN([FP_COMPUTE_INT],
109 [_AC_COMPUTE_INT([$1], [$2], [$3], [$4])[]dnl
110 ])# FP_COMPUTE_INT
111
112
113 # FP_CHECK_ALIGNMENT(TYPE, [IGNORED], [INCLUDES = DEFAULT-INCLUDES])
114 # ------------------------------------------------------------------
115 # A variation of AC_CHECK_SIZEOF for computing the alignment restrictions of a
116 # given type. Defines ALIGNMENT_TYPE.
117 AC_DEFUN([FP_CHECK_ALIGNMENT],
118 [AS_LITERAL_IF([$1], [],
119                [AC_FATAL([$0: requires literal arguments])])[]dnl
120 AC_CHECK_TYPE([$1], [], [], [$3])[]dnl
121 m4_pushdef([fp_Cache], [AS_TR_SH([fp_cv_alignment_$1])])[]dnl
122 AC_CACHE_CHECK([alignment of $1], [fp_Cache],
123 [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
124   FP_COMPUTE_INT([(long) (&((struct { char c; $1 ty; } *)0)->ty)],
125                  [fp_Cache],
126                  [AC_INCLUDES_DEFAULT([$3])],
127                  [AC_MSG_ERROR([cannot compute alignment ($1)
128 See `config.log' for more details.], [77])])
129 else
130   fp_Cache=0
131 fi])[]dnl
132 AC_DEFINE_UNQUOTED(AS_TR_CPP(alignment_$1), $fp_Cache, [The alignment of a `$1'.])[]dnl
133 m4_popdef([fp_Cache])[]dnl
134 ])# FP_CHECK_ALIGNMENT
135
136
137 # FP_CHECK_CONST(EXPRESSION, [INCLUDES = DEFAULT-INCLUDES], [VALUE-IF-FAIL = -1])
138 # ---------------------------------------------------------------------------------
139 # Defines CONST_EXPRESSION to the value of the compile-time EXPRESSION, using
140 # INCLUDES. If the value cannot be determined, use VALUE-IF-FAIL.
141 AC_DEFUN([FP_CHECK_CONST],
142 [AS_VAR_PUSHDEF([fp_Cache], [fp_cv_const_$1])[]dnl
143 AC_CACHE_CHECK([value of $1], fp_Cache,
144 [FP_COMPUTE_INT([$1], fp_check_const_result, [AC_INCLUDES_DEFAULT([$2])],
145                 [fp_check_const_result=m4_default([$3], ['-1'])])
146 AS_VAR_SET(fp_Cache, [$fp_check_const_result])])[]dnl
147 AC_DEFINE_UNQUOTED(AS_TR_CPP([CONST_$1]), AS_VAR_GET(fp_Cache), [The value of $1.])[]dnl
148 AS_VAR_POPDEF([fp_Cache])[]dnl
149 ])# FP_CHECK_CONST
150
151
152 # FP_CHECK_CONSTS_TEMPLATE(EXPRESSION...)
153 # ----------------------------------
154 # autoheader helper for FP_CHECK_CONSTS
155 m4_define([FP_CHECK_CONSTS_TEMPLATE],
156 [AC_FOREACH([fp_Const], [$1],
157   [AH_TEMPLATE(AS_TR_CPP(CONST_[]fp_Const),
158                [The value of ]fp_Const[.])])[]dnl
159 ])# FP_CHECK_CONSTS_TEMPLATE
160
161
162 # FP_CHECK_CONSTS(EXPRESSION..., [INCLUDES = DEFAULT-INCLUDES], [VALUE-IF-FAIL = -1])
163 # -------------------------------------------------------------------------------------
164 # List version of FP_CHECK_CONST
165 AC_DEFUN(FP_CHECK_CONSTS,
166 [FP_CHECK_CONSTS_TEMPLATE([$1])dnl
167 for fp_const_name in $1
168 do
169 FP_CHECK_CONST([$fp_const_name], [$2], [$3])
170 done
171 ])# FP_CHECK_CONSTS
172
173
174 dnl ** check for leading underscores in symbol names
175 dnl 
176 dnl Test for determining whether symbol names have a leading
177 dnl underscore.
178 dnl 
179 dnl We assume that they _haven't_ if anything goes wrong.
180 dnl
181 dnl Some nlist implementations seem to try to be compatible by ignoring
182 dnl a leading underscore sometimes (eg. FreeBSD).  We therefore have
183 dnl to work around this by checking for *no* leading underscore first.
184 dnl Sigh.  --SDM
185 dnl
186 dnl Similarly on OpenBSD, but this test doesn't help. -- dons
187 dnl
188 AC_DEFUN(FPTOOLS_UNDERSCORE,
189 [AC_CHECK_LIB(elf, nlist, LIBS="-lelf $LIBS")dnl
190 AC_CACHE_CHECK([leading underscore in symbol names], fptools_cv_lead_uscore,
191
192 dnl
193 dnl Hack!: nlist() under Digital UNIX insist on there being an _,
194 dnl but symbol table listings shows none. What is going on here?!?
195 dnl
196 dnl Another hack: cygwin doesn't come with nlist.h , so we hardwire
197 dnl the underscoredness of that "platform"
198 changequote(<<, >>)dnl
199 <<
200 case $HostPlatform in
201 *openbsd*) # x86 openbsd is ELF from 3.4 >, meaning no leading uscore
202     case $build in
203         i386-*2\.[[0-9]] | i386-*3\.[[0-3]] ) fptools_cv_lead_uscore='yes' ;;
204         *)      fptools_cv_lead_uscore='no' ;;
205     esac ;;
206 alpha-dec-osf*) fptools_cv_lead_uscore='no';;
207 *cygwin32) fptools_cv_lead_uscore='yes';;
208 *mingw32) fptools_cv_lead_uscore='yes';;
209 *) >>
210 changequote([, ])dnl
211 AC_TRY_RUN([#ifdef HAVE_NLIST_H
212 #include <nlist.h>
213 changequote(<<, >>)dnl
214 <<
215 struct nlist xYzzY1[] = {{"xYzzY1", 0},{0}};
216 struct nlist xYzzY2[] = {{"_xYzzY2", 0},{0}};
217 #endif
218
219 main(argc, argv)
220 int argc;
221 char **argv;
222 {
223 #ifdef HAVE_NLIST_H
224     if(nlist(argv[0], xYzzY1) == 0 && xYzzY1[0].n_value != 0)
225         exit(1);
226     if(nlist(argv[0], xYzzY2) == 0 && xYzzY2[0].n_value != 0)
227         exit(0);>>
228 changequote([, ])dnl
229 #endif
230     exit(1);
231 }], fptools_cv_lead_uscore=yes, fptools_cv_lead_uscore=no, fptools_cv_lead_uscore=NO)
232 ;;
233 esac);
234 LeadingUnderscore=`echo $fptools_cv_lead_uscore | sed 'y/yesno/YESNO/'`
235 AC_SUBST(LeadingUnderscore)
236 case $LeadingUnderscore in
237 YES) AC_DEFINE([LEADING_UNDERSCORE], [1], [Define to 1 if C symbols have a leading underscore added by the compiler.]);;
238 esac
239 ])
240
241
242 # FP_COMPARE_VERSIONS(VERSION1, TEST, VERSION2, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
243 # ----------------------------------------------------------------------------------
244 # Compare dotted version numbers VERSION1 and VERSION2 lexicographically according
245 # to TEST (one of -eq, -ne, -lt, -le, -gt, or -ge).
246 AC_DEFUN([FP_COMPARE_VERSIONS],
247 [fp_version1=$1; fp_version2=$3
248 fp_save_IFS=$IFS; IFS='.'
249 while test x"$fp_version1" != x || test x"$fp_version2" != x
250 do
251
252   set dummy $fp_version1; shift
253   fp_num1=""
254   test $[@%:@] = 0 || { fp_num1="[$]1"; shift; }
255   test x"$fp_num1" = x && fp_num1="0"
256   fp_version1="[$]*"
257
258   set dummy $fp_version2; shift
259   fp_num2=""
260   test $[@%:@] = 0 || { fp_num2="[$]1"; shift; }
261   test x"$fp_num2" = x && fp_num2="0"
262   fp_version2="[$]*"
263
264   test "$fp_num1" = "$fp_num2" || break;
265 done
266 IFS=$fp_save_IFS
267 AS_IF([test "$fp_num1" $2 "$fp_num2"], [$4], [$5])[]dnl
268 ])# FP_COMPARE_VERSIONS
269
270
271 dnl
272 dnl Check for GreenCard and version.
273 dnl
274 AC_DEFUN(FPTOOLS_GREENCARD,
275 [
276 AC_PATH_PROG(GreenCardCmd,greencard)
277 AC_CACHE_CHECK([for version of greencard], fptools_cv_greencard_version,
278 changequote(, )dnl
279 [if test x"$GreenCardCmd" != x; then
280    fptools_cv_greencard_version="`$GreenCardCmd --version |
281                           grep 'version' | sed -e 's/greencard. version \([^ ]*\).*/\1/g'`"
282 else
283    fptools_cv_greencard_version=""
284 fi
285 changequote([, ])dnl
286 ])
287 FP_COMPARE_VERSIONS([$fptools_cv_greencard_version],[-lt],[$1],
288   [AC_MSG_ERROR([greencard version $1 or later is required (found '$fptools_cv_greencard_version')])])[]dnl
289 GreenCardVersion=$fptools_cv_greencard_version
290 AC_SUBST(GreenCardVersion)
291 ])
292
293 dnl
294 dnl Check for Happy and version.  If we're building GHC, then we need
295 dnl at least Happy version 1.13.  If there's no installed Happy, we look
296 dnl for a happy source tree and point the build system at that instead.
297 dnl
298 AC_DEFUN(FPTOOLS_HAPPY,
299 [
300 if test -d $srcdir/happy; then
301    SrcTreeHappyCmd=$hardtop/happy/src/happy-inplace
302 fi
303 if test x"$UseSrcTreeHappy" = xYES; then
304   HappyCmd=$SrcTreeHappyCmd
305 else
306   AC_PATH_PROG(HappyCmd,happy,$SrcTreeHappyCmd)
307 fi
308 AC_CACHE_CHECK([for version of happy], fptools_cv_happy_version,
309 changequote(, )dnl
310 [if test x"$HappyCmd" = x"$SrcTreeHappyCmd"; then
311    fptools_cv_happy_version=`grep '^ProjectVersion[     ]*=' $srcdir/happy/mk/version.mk | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`;
312 elif test x"$HappyCmd" != x; then
313    fptools_cv_happy_version="`$HappyCmd -v |
314                           grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'`" ;
315 else
316    fptools_cv_happy_version="";
317 fi;
318 changequote([, ])dnl
319 ])
320 if test -d $srcdir/ghc -a ! -f $srcdir/ghc/compiler/parser/Parser.hs; then
321   FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.13],
322   [AC_MSG_ERROR([Happy version 1.13 or later is required to compile GHC.])])[]dnl
323 fi
324 HappyVersion=$fptools_cv_happy_version;
325 AC_SUBST(HappyVersion)
326 ])
327
328 dnl
329 dnl Check for Haddock and version.  If there's no installed Haddock, we look
330 dnl for a haddock source tree and point the build system at that instead.
331 dnl
332 AC_DEFUN(FPTOOLS_HADDOCK,
333 [
334 if test -d $srcdir/haddock; then
335    SrcTreeHaddockCmd=$hardtop/haddock/src/haddock-inplace
336 fi
337 if test x"$UseSrcTreeHaddock" = xYES; then
338   HaddockCmd=$SrcTreeHaddockCmd
339 else
340   AC_PATH_PROG(HaddockCmd,haddock,$SrcTreeHaddockCmd)
341 fi
342 dnl Darn, I forgot to make Haddock print out its version number when
343 dnl invoked with -v.  We could try generating some HTML and grepping
344 dnl through that to find the version number, but I think we'll make
345 dnl do without it for now.
346 ])
347
348 dnl
349 dnl Check for Alex and version.  If we're building GHC, then we need
350 dnl at least Alex version 2.0.  If there's no installed Alex, we look
351 dnl for a alex source tree and point the build system at that instead.
352 dnl
353 AC_DEFUN(FPTOOLS_ALEX,
354 [
355 if test -d $srcdir/alex; then
356    SrcTreeAlexCmd=$hardtop/alex/src/alex-inplace
357 fi
358 if test x"$UseSrcTreeAlex" = xYES; then
359   AlexCmd=$SrcTreeAlexCmd
360 else
361   AC_PATH_PROG(AlexCmd,alex,$SrcTreeAlexCmd)
362 fi
363 AC_CACHE_CHECK([for version of alex], fptools_cv_alex_version,
364 changequote(, )dnl
365 [if test x"$AlexCmd" = x"$SrcTreeAlexCmd"; then
366    fptools_cv_alex_version=`grep '^ProjectVersion[      ]*=' $srcdir/alex/mk/version.mk | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`;
367 elif test x"$AlexCmd" != x; then
368    fptools_cv_alex_version="`$AlexCmd -v |
369                           grep 'Alex [Vv]ersion' | sed -e 's/Alex [Vv]ersion \([0-9\.]*\).*/\1/g'`" ;
370 else
371    fptools_cv_alex_version="";
372 fi;
373 changequote([, ])dnl
374 ])
375 if test -d $srcdir/ghc -a ! -f $srcdir/ghc/compiler/parser/Lexer.hs; then
376   FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-lt],[2.0],
377   [AC_MSG_ERROR([Alex version 2.0 or later is required to compile GHC.])])[]dnl
378 fi
379 AlexVersion=$fptools_cv_alex_version;
380 AC_SUBST(AlexVersion)
381 ])
382
383
384 dnl
385 dnl Check whether ld supports -x
386 dnl
387 AC_DEFUN(FPTOOLS_LD_X,
388 [AC_CACHE_CHECK([whether ld understands -x], fptools_cv_ld_x,
389 [
390 echo 'foo() {}' > conftest.c
391 ${CC-cc} -c conftest.c
392 if ${LdCmd} -r -x -o foo.o conftest.o; then
393    fptools_cv_ld_x=yes
394 else
395    fptools_cv_ld_x=no
396 fi
397 rm -rf conftest.c conftest.o foo.o
398 ])
399 if test "$fptools_cv_ld_x" = yes; then
400         LdXFlag=-x
401 else
402         LdXFlag=
403 fi
404 AC_SUBST(LdXFlag)
405 ])
406
407
408 dnl *** Checking for ar and its arguments + whether we need ranlib.
409 dnl
410 dnl ArCmd, ArSupportsInput and RANLIB are AC_SUBST'ed
411 dnl On Digital UNIX, we test for the -Z (compress) and
412 dnl -input (take list of files from external file) flags.
413 dnl 
414 AC_DEFUN(FPTOOLS_PROG_AR_AND_RANLIB,
415 [AC_PATH_PROG(ArCmdRaw,ar)
416 if test -z "$ArCmdRaw"; then
417     echo "You don't seem to have ar in your PATH...I have no idea how to make a library"
418     exit 1;
419 fi
420 dnl GNU ar needs special treatment: it appears to have problems with
421 dnl object files with the same name if you use the 's' modifier, but
422 dnl simple 'ar q' works fine, and doesn't need a separate ranlib.
423 if $ArCmdRaw --version | grep 'GNU' >/dev/null 2>/dev/null; then
424     ArCmdArgs='q'
425     NeedRanLib=''
426 elif $ArCmdRaw clqsZ conftest.a >/dev/null 2>/dev/null; then
427     ArCmdArgs="clqsZ"
428     NeedRanLib=''
429 elif $ArCmdRaw clqs conftest.a >/dev/null 2>/dev/null; then
430     ArCmdArgs="clqs"
431     NeedRanLib=''
432 elif $ArCmdRaw cqs conftest.a >/dev/null 2>/dev/null; then
433     ArCmdArgs="cqs"
434     NeedRanLib=''
435 elif $ArCmdRaw clq conftest.a >/dev/null 2>/dev/null; then
436     ArCmdArgs="clq"
437     NeedRanLib='YES'
438 elif $ArCmdRaw cq conftest.a >/dev/null 2>/dev/null; then
439     ArCmdArgs="cq"
440     NeedRanLib='YES'
441 elif $ArCmdRaw cq conftest.a 2>&1 | grep 'no archive members specified' >/dev/null 2>/dev/null; then
442     ArCmdArgs="cq"
443     NeedRanLib='YES'
444 else
445     echo "I can't figure out how to use your $ArCmd"
446     exit 1
447 fi
448 rm -rf conftest*
449 case $HostPlatform in
450  *mingw32) 
451           ArCmd="`cygpath -w ${ArCmdRaw} | sed -e 's@\\\\@/@g' ` ${ArCmdArgs}"
452           ;;
453  *) ArCmd="${ArCmdRaw} ${ArCmdArgs}"
454     ;;
455 esac
456 test -n "$ArCmd" && test -n "$verbose" && echo "        setting ArCmd to $ArCmd"
457 AC_SUBST(ArCmd)
458 if $ArCmd conftest.a -input /dev/null >/dev/null 2>/dev/null; then
459     ArSupportsInput='-input'
460 else
461     ArSupportsInput=''
462 fi
463 rm -rf conftest*
464 test -n "$ArSupportsInput" && test -n "$verbose" && echo "        setting ArSupportsInput to $ArSupportsInput"
465 AC_SUBST(ArSupportsInput)
466 if test -z "$NeedRanLib"; then
467     RANLIB=':'
468     test -n "$verbose" && echo "        setting RANLIB to $RANLIB"
469     AC_SUBST(RANLIB)
470 else
471     AC_PROG_RANLIB
472 fi
473 ])
474
475 dnl
476 dnl AC_SHEBANG_PERL - can we she-bang perl?
477 dnl
478 AC_DEFUN(FPTOOLS_SHEBANG_PERL,
479 [AC_CACHE_CHECK([if your perl works in shell scripts], fptools_cv_shebang_perl,
480 [echo "#!$PerlCmd"'
481 exit $1;
482 ' > conftest
483 chmod u+x conftest
484 (SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
485 if test $? -ne 69; then
486    fptools_cv_shebang_perl=yes
487 else
488    fptools_cv_shebang_perl=no
489 fi
490 rm -f conftest
491 ])])
492
493 dnl
494 dnl Extra testing of the result AC_PROG_CC, testing the gcc version no.
495 dnl *Must* be called after AC_PROG_CC
496 dnl
497 AC_DEFUN(FPTOOLS_HAVE_GCC,
498 [AC_CACHE_CHECK([whether you have an ok gcc], fptools_cv_have_gcc,
499 [if test -z "$GCC"; then
500     echo ''
501     echo "You would be better off with gcc"
502     echo "Perhaps it is already installed, but not in your PATH?"
503     fptools_cv_have_gcc='no'
504 else
505 changequote(, )dnl
506     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' `"
507 changequote([, ])dnl
508     fptools_cv_have_gcc='yes'
509     FP_COMPARE_VERSIONS([$gcc_version_str], [-lt], [2.0],
510         [fptools_cv_have_gcc='no'
511         echo ""
512         echo "your gcc version appears to be ..."
513         $CC --version
514         echo "gcc prior to 2.0 and have never worked with ghc."
515         echo "we recommend 2.95.3, although versions back to 2.7.2 should be ok."
516         AC_MSG_ERROR([gcc 1.X has never been supported])])
517 fi
518 ])
519 HaveGcc=`echo $fptools_cv_have_gcc | sed 'y/yesno/YESNO/'`
520 AC_SUBST(HaveGcc)
521 ])
522
523 dnl
524 dnl Some OSs (Mandrake Linux, in particular) configure GCC with
525 dnl -momit-leaf-frame-pointer on by default.  If this is the case, we
526 dnl need to turn it off for mangling to work.  The test is currently a bit
527 dnl crude, using only the version number of gcc.
528 dnl
529 AC_DEFUN([FPTOOLS_GCC_NEEDS_NO_OMIT_LFPTR],
530 [AC_CACHE_CHECK([whether gcc needs -mno-omit-leaf-frame-pointer], [fptools_cv_gcc_needs_no_omit_lfptr],
531 [FP_COMPARE_VERSIONS([$gcc_version_str], [-ge], [3.2],
532   [fptools_cv_gcc_needs_no_omit_lfptr=yes],
533   [fptools_cv_gcc_needs_no_omit_lfptr=no])])
534 if test "$fptools_cv_gcc_needs_no_omit_lfptr" = "yes"; then
535    AC_DEFINE([HAVE_GCC_MNO_OMIT_LFPTR], [1], [Define to 1 if gcc supports -mno-omit-leaf-frame-pointer.])
536 fi])# FPTOOLS_GCC_NEEDS_NO_OMIT_LFPTR
537
538
539 dnl Small feature test for perl version. Assumes PerlCmd
540 dnl contains path to perl binary
541 dnl
542 AC_DEFUN(FPTOOLS_CHECK_PERL_VERSION,
543 [$PerlCmd -v >conftest.out 2>&1
544 if grep "version 5" conftest.out >/dev/null 2>&1; then
545    :
546 else
547    if grep "v5.6" conftest.out >/dev/null 2>&1; then
548       :
549    else
550       if grep "v5.8" conftest.out >/dev/null 2>&1; then
551          :
552       else
553          if grep "version 6" conftest.out >/dev/null 2>&1; then
554             :
555          else
556             echo "Your version of perl probably won't work."
557          fi  
558       fi
559    fi
560 fi
561 rm -fr conftest*
562 ])
563
564
565 # FP_CHECK_PROG(VARIABLE, PROG-TO-CHECK-FOR,
566 #               [VALUE-IF-NOT-FOUND], [PATH], [REJECT])
567 # -----------------------------------------------------
568 # HACK: A small wrapper around AC_CHECK_PROG, setting VARIABLE to the full path
569 # of PROG-TO-CHECK-FOR when found.
570 AC_DEFUN([FP_CHECK_PROG],
571 [AC_CHECK_PROG([$1], [$2], [$as_dir/$ac_word$ac_exec_ext], [$3], [$4], [$5])][]dnl
572 )# FP_CHECK_PROC
573
574
575 # FP_PROG_FIND
576 # ------------
577 # Find a non-WinDoze version of the "find" utility.
578 AC_DEFUN([FP_PROG_FIND],
579 [AC_PATH_PROG([fp_prog_find], [find])
580 echo foo > conftest.txt
581 $fp_prog_find conftest.txt -print > conftest.out 2>&1
582 if grep '^conftest.txt$' conftest.out > /dev/null 2>&1 ; then
583   # OK, looks like a real "find".
584   FindCmd="$fp_prog_find"
585 else
586   # Found a poor WinDoze version of "find", ignore it.
587   AC_MSG_WARN([$fp_prog_find looks like a non-*nix find, ignoring it])
588   FP_CHECK_PROG([FindCmd], [find], [], [], [$fp_prog_find])
589 fi
590 rm -f conftest.txt conftest.out
591 AC_SUBST([FindCmd])[]dnl
592 ])# FP_PROG_FIND
593
594
595 dnl
596 dnl FPTOOLS_NOCACHE_CHECK prints a message, then sets the
597 dnl values of the second argument to the result of running
598 dnl the commands given by the third. It does not cache its
599 dnl result, so it is suitable for checks which should be
600 dnl run every time.
601 dnl
602 AC_DEFUN(FPTOOLS_NOCACHE_CHECK,
603 [AC_MSG_CHECKING([$1])
604  $3
605  AC_MSG_RESULT([$][$2])
606 ])
607
608 dnl
609 dnl FPTOOLS_GHC_VERSION(version)
610 dnl FPTOOLS_GHC_VERSION(major, minor [, patchlevel])
611 dnl FPTOOLS_GHC_VERSION(version, major, minor, patchlevel)
612 dnl
613 dnl Test for version of installed ghc.  Uses $GHC.
614 dnl [original version pinched from c2hs]
615 dnl
616 AC_DEFUN(FPTOOLS_GHC_VERSION,
617 [FPTOOLS_NOCACHE_CHECK([version of ghc], [fptools_version_of_ghc],
618 ["${WithGhc-ghc}" --version > conftestghc 2>&1
619   cat conftestghc >&AC_FD_CC
620 #Useless Use Of cat award...
621   fptools_version_of_ghc=`cat conftestghc | sed -n -e 's/, patchlevel *\([[0-9]]\)/.\1/;s/.* version \([[0-9]][[0-9.]]*\).*/\1/p'`
622   rm -fr conftest*
623   if test "[$]fptools_version_of_ghc" = ""
624   then
625     fptools_version_of_ghc='unknown'
626   fi
627 fptools_version_of_ghc[_major]=`echo [$]fptools_version_of_ghc | sed -e 's/^\([[0-9]]\).*/\1/'`
628 fptools_version_of_ghc[_minor]=`echo [$]fptools_version_of_ghc | sed -e 's/^[[0-9]]\.\([[0-9]]*\).*/\1/'`
629 fptools_version_of_ghc[_pl]=`echo [$]fptools_version_of_ghc | sed -n -e 's/^[[0-9]]\.[[0-9]]*\.\([[0-9]]*\)/\1/p'`
630 #
631 if test "[$]fptools_version_of_ghc[_pl]" = ""
632 then
633   fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor]"
634   fptools_version_of_ghc[_pl]="0"
635 else
636   fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor].[$]fptools_version_of_ghc[_pl]"
637 fi
638 #
639 ifelse($#, [1], [dnl
640 [$1]="[$]fptools_version_of_ghc[_all]"
641 ], $#, [2], [dnl
642 [$1]="[$]fptools_version_of_ghc[_major]"
643 [$2]="[$]fptools_version_of_ghc[_minor]"
644 ], $#, [3], [dnl
645 [$1]="[$]fptools_version_of_ghc[_major]"
646 [$2]="[$]fptools_version_of_ghc[_minor]"
647 [$3]="[$]fptools_version_of_ghc[_pl]"
648 ], $#, [4], [dnl
649 [$1]="[$]fptools_version_of_ghc[_all]"
650 [$2]="[$]fptools_version_of_ghc[_major]"
651 [$3]="[$]fptools_version_of_ghc[_minor]"
652 [$4]="[$]fptools_version_of_ghc[_pl]"
653 ])
654 ])
655 ])dnl
656
657
658 dnl ** Map an arithmetic C type to a Haskell type.
659 dnl    Based on autconf's AC_CHECK_SIZEOF.
660
661 dnl FPTOOLS_CHECK_HTYPE(TYPE [, DEFAULT_VALUE, [, VALUE-FOR-CROSS-COMPILATION])
662 AC_DEFUN(FPTOOLS_CHECK_HTYPE,
663 [changequote(<<, >>)dnl
664 dnl The name to #define.
665 define(<<AC_TYPE_NAME>>, translit(htype_$1, [a-z *], [A-Z_P]))dnl
666 dnl The cache variable name.
667 define(<<AC_CV_NAME>>, translit(fptools_cv_htype_$1, [ *], [_p]))dnl
668 define(<<AC_CV_NAME_supported>>, translit(fptools_cv_htype_sup_$1, [ *], [_p]))dnl
669 changequote([, ])dnl
670 AC_MSG_CHECKING(Haskell type for $1)
671 AC_CACHE_VAL(AC_CV_NAME,
672 [AC_CV_NAME_supported=yes
673 fp_check_htype_save_cppflags="$CPPFLAGS"
674 CPPFLAGS="$CPPFLAGS $X_CFLAGS"
675 AC_TRY_RUN([#include <stdio.h>
676 #include <stddef.h>
677
678 #if HAVE_SYS_TYPES_H
679 # include <sys/types.h>
680 #endif
681
682 #if HAVE_UNISTD_H
683 # include <unistd.h>
684 #endif
685
686 #if HAVE_SYS_STAT_H
687 # include <sys/stat.h>
688 #endif
689
690 #if HAVE_FCNTL_H
691 # include <fcntl.h>
692 #endif
693
694 #if HAVE_SIGNAL_H
695 # include <signal.h>
696 #endif
697
698 #if HAVE_TIME_H
699 # include <time.h>
700 #endif
701
702 #if HAVE_TERMIOS_H
703 # include <termios.h>
704 #endif
705
706 #if HAVE_STRING_H
707 # include <string.h>
708 #endif
709
710 #if HAVE_CTYPE_H
711 # include <ctype.h>
712 #endif
713
714 #if defined(HAVE_GL_GL_H)
715 # include <GL/gl.h>
716 #elif defined(HAVE_OPENGL_GL_H)
717 # include <OpenGL/gl.h>
718 #endif
719
720 #if defined(HAVE_AL_ALC_H)
721 # include <AL/alc.h>
722 #elif defined(HAVE_OPENAL_ALC_H)
723 # include <OpenAL/alc.h>
724 #endif
725
726 #if HAVE_SYS_RESOURCE_H
727 # include <sys/resource.h>
728 #endif
729
730 typedef $1 testing;
731
732 main() {
733   FILE *f=fopen("conftestval", "w");
734   if (!f) exit(1);
735   if (((testing)((int)((testing)1.4))) == ((testing)1.4)) {
736     fprintf(f, "%s%d\n",
737            ((testing)(-1) < (testing)0) ? "Int" : "Word",
738            sizeof(testing)*8);
739   } else {
740     fprintf(f,"%s\n",
741            (sizeof(testing) >  sizeof(double)) ? "LDouble" :
742            (sizeof(testing) == sizeof(double)) ? "Double"  : "Float");
743   }
744   fclose(f);
745   exit(0);
746 }],AC_CV_NAME=`cat conftestval`,
747 ifelse([$2], , [AC_CV_NAME=NotReallyAType; AC_CV_NAME_supported=no], AC_CV_NAME=$2),
748 ifelse([$3], , [AC_CV_NAME=NotReallyATypeCross; AC_CV_NAME_supported=no], AC_CV_NAME=$3))]) dnl
749 CPPFLAGS="$fp_check_htype_save_cppflags"
750 if test "$AC_CV_NAME_supported" = yes; then
751   AC_MSG_RESULT($AC_CV_NAME)
752   AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [Define to Haskell type for $1])
753 else
754   AC_MSG_RESULT([not supported])
755 fi
756 undefine([AC_TYPE_NAME])dnl
757 undefine([AC_CV_NAME])dnl
758 undefine([AC_CV_NAME_supported])dnl
759 ])
760
761
762 # FP_CHECK_FUNC(FUNCTION, PROLOGUE, BODY, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
763 # ---------------------------------------------------------------------------------
764 # A variant of AC_CHECK_FUNCS, limited to a single FUNCTION, but with the
765 # additional flexibility of specifying the PROLOGUE and BODY.
766 AC_DEFUN([FP_CHECK_FUNC],
767 [AS_VAR_PUSHDEF([fp_func], [fp_cv_func_$1])dnl
768 AC_CACHE_CHECK([for $1], fp_func,
769 [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2], [$3])],
770                 [AS_VAR_SET(fp_func, yes)],
771                 [AS_VAR_SET(fp_func, no)])])
772 AS_IF([test AS_VAR_GET(fp_func) = yes],
773       [AC_DEFINE(AS_TR_CPP(HAVE_$1), [1],
774                 [Define to 1 if you have the `]$1[' function.]) $4],
775       [$5])dnl
776 AS_VAR_POPDEF([fp_func])dnl
777 ])# FP_CHECK_FUNC
778
779
780 dnl ** Check which CATALOG file we have to use with DocBook SGML.
781 dnl
782 dnl FPTOOLS_DOCBOOK_CATALOG(VARIABLE, JADE, STYLESHEET, CATALOGS-TO-CHECK-FOR)
783 dnl
784 dnl If any of the catalogs given in CATALOGS-TO-CHECK-FOR works on this
785 dnl platform, let VARIABLE refer to this catalog; otherwise, VARIABLE
786 dnl is set to "no".  JADE is the jade executable and STYLESHEET
787 dnl a DocBook style sheet.
788 dnl
789 AC_DEFUN(FPTOOLS_DOCBOOK_CATALOG,
790 [AC_CACHE_CHECK([for DocBook CATALOG], fptools_cv_sgml_catalog,
791 [
792 cat > conftest.sgml << EOF
793 <!DOCTYPE Article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
794 <Article>
795 <ArtHeader>
796 <Title>Test</Title>
797 <Author><OtherName>Test</OtherName></Author>
798 <Address>Test</Address>
799 <PubDate>Test</PubDate>
800 </ArtHeader>
801 <Sect1><Title>Test</Title>
802 <Para>
803 Test.
804 </Para>
805 </Sect1>
806 </Article>
807 EOF
808 fptools_cv_sgml_catalog=no
809 if test -z "$SGML_CATALOG_FILES" ; then
810  for fptools_catalog in $4; do
811    ac_try="$2 -t rtf -d $3#print -c $fptools_catalog conftest.sgml"
812    if AC_TRY_EVAL(ac_try); then
813      fptools_cv_sgml_catalog=[$]fptools_catalog
814      break
815    fi
816  done
817 else
818 # If the env var SGML_CATALOG_FILES is defined, assume things are cool.
819   fptools_cv_sgml_catalog="yes"
820 fi
821 ])
822 rm -rf conftest*
823 if test $fptools_cv_sgml_catalog != "no"; then
824   $1=$fptools_cv_sgml_catalog
825 fi
826 ])
827
828
829 # FP_CHECK_WIN32
830 # --------------
831 # If Windows is the target platform (e.g. MinGW/MSYS or Cygwin with
832 # -mno-cygwin), the variable "is_win32" is set to "yes", otherwise (e.g. *nix
833 # systems or plain Cygwin) it is set to "no".
834 AC_DEFUN([FP_CHECK_WIN32],
835 [AC_CACHE_CHECK([for Windows environment], [fp_cv_is_win32],
836   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
837 #if !_WIN32
838    syntax error;
839 #endif
840 ])], [fp_cv_is_win32=yes], [fp_cv_is_win32=no])])
841 is_win32="$fp_cv_is_win32"[]dnl
842 ])# FP_CHECK_WIN32
843
844
845 # FP_PATH_X
846 # ---------
847 # Same as AC_PATH_X, but works even for broken Cygwins which try to include the
848 # non-existant <gl/mesa_wgl.h> header when -mno-cygwin is used.
849 AC_DEFUN([FP_PATH_X],
850 [AC_REQUIRE([FP_CHECK_WIN32])
851 if test x"$is_win32" = xyes; then
852   no_x=yes
853 else
854   AC_PATH_X
855 fi
856 ])# FP_PATH_X
857
858
859 # FP_PATH_XTRA
860 # ------------
861 # Same as AC_PATH_XTRA, but works even for broken Cygwins which try to include
862 # the non-existant <gl/mesa_wgl.h> header when -mno-cygwin is used.
863 AC_DEFUN([FP_PATH_XTRA],
864 [AC_REQUIRE([FP_CHECK_WIN32])
865 if test x"$is_win32" = xyes; then
866   no_x=yes
867 else
868   AC_PATH_XTRA
869 fi
870 ])# FP_PATH_XTRA
871
872
873 # FP_CHECK_GL_HELPER(LIBNAME, LIBS, INCLUDES, FUNCTION-BODY)
874 # ----------------------------------------------------------
875 # Try each library in LIBS to successfully link INCLUDES plus FUNCTION-BODY,
876 # setting LIBNAME_CFLAGS and LIBNAME_LIBS to the corresponding values. Sets
877 # no_LIBNAME to "yes" if no suitable library was found. (LIBNAME_CFLAGS0
878 # contains the value of LIBNAME_CFLAGS without CPPFLAGS, and LIBNAME_LIBS0
879 # contains the value of LIBNAME_LIBS without LDFLAGS, but these are only
880 # used internally.)
881 AC_DEFUN([FP_CHECK_GL_HELPER],
882 [AC_CACHE_CHECK([for $1 library], [fp_cv_check_$1_lib],
883   [fp_cv_check_$1_lib="no"
884   fp_save_CPPFLAGS="$CPPFLAGS"
885   CPPFLAGS="$CPPFLAGS ${$1_CFLAGS}"
886   fp_save_LIBS="$LIBS"
887   for fp_try_lib in $2; do
888     # transform "-lfoo" to "foo.lib" when using cl
889     if test x"$CC" = xcl; then
890       fp_try_lib=`echo $fp_try_lib | sed -e 's/^-l//' -e 's/$/.lib/'`
891     fi
892     LIBS="$fp_try_lib ${$1_LIBS} $fp_save_LIBS"
893     AC_TRY_LINK([$3], [$4], [fp_cv_check_$1_lib="$fp_try_lib ${$1_LIBS}"; break])
894   done
895   LIBS="$fp_save_LIBS"
896   CPPFLAGS="$fp_save_CPPFLAGS"])
897
898   if test x"$fp_cv_check_$1_lib" = xno; then
899     no_$1=yes
900     $1_CFLAGS=
901     $1_LIBS=
902   else
903     $1_CFLAGS0="${$1_CFLAGS}"
904     $1_CFLAGS="$CPPFLAGS ${$1_CFLAGS0}"
905     $1_LIBS0="$fp_cv_check_$1_lib"
906     $1_LIBS="$LDFLAGS ${$1_LIBS0}"
907   fi
908 ])# FP_CHECK_GL_HELPER
909
910
911 # FP_CHECK_GL
912 # -----------
913 AC_DEFUN([FP_CHECK_GL],
914 [AC_REQUIRE([FP_PATH_X])
915 AC_REQUIRE([AC_CANONICAL_SYSTEM])
916
917 AC_ARG_ENABLE([hopengl],
918   [AC_HELP_STRING([--enable-hopengl],
919     [build a Haskell binding for OpenGL (GL/GLU). On Mac OS X, use
920      --enable-hopengl=x11 to use X11 instead of the "native" libraries.
921      (default=no)])],
922   [enable_opengl=$enableval], [enable_opengl=no])
923
924 if test x"$enable_opengl" = xno; then
925    no_GL=yes
926 else
927   use_quartz_opengl=no
928   case $target_os in
929   darwin*)
930     if test x"$enable_opengl" != xx11; then
931       AC_DEFINE([USE_QUARTZ_OPENGL], [1],
932                 [Define to 1 if native OpenGL should be used on Mac OS X])
933       use_quartz_opengl=yes
934     fi
935     ;;
936   esac
937
938   if test x"$use_quartz_opengl" != xyes; then
939     AC_CHECK_LIB([m], [atan], [GL_LIBS="-lm $GL_LIBS"])
940
941     if test x"$no_x" != xyes; then
942       test -n "$x_includes" && GL_CFLAGS="-I$x_includes $GL_CFLAGS"
943       test -n "$x_libraries" && GL_LIBS="-L$x_libraries -lX11 $GL_LIBS"
944     fi
945
946     FP_CHECK_GL_HELPER([GL], [-lGL -lopengl32], [@%:@include <GL/gl.h>], [glEnd()])
947
948     if test x"$no_GL" != xyes; then
949       # Ugly: To get wglGetProcAddress on Windows, we have to link with
950       # opengl32.dll, too, even when we are using Cygwin with X11.
951       case "$GL_LIBS" in
952         *-lopengl32*|*opengl32.lib*) ;;
953         *) fp_save_LIBS="$LIBS"
954            LIBS="$LIBS -lopengl32"
955            AC_TRY_LINK([@%:@include <GL/gl.h>], [glEnd()],
956              [GL_LIBS="$GL_LIBS -lopengl32"; GL_LIBS0="$GL_LIBS0 -lopengl32"])
957            LIBS="$fp_save_LIBS"
958            ;;
959       esac
960     fi
961   fi
962 fi
963
964 AC_SUBST([GL_CFLAGS])
965 AC_SUBST([GL_LIBS])
966 ])# FP_CHECK_GL
967
968
969 # FP_CHECK_GLU
970 # ------------
971 AC_DEFUN([FP_CHECK_GLU],
972 [AC_REQUIRE([FP_CHECK_GL])dnl
973 GLU_CFLAGS="$GL_CFLAGS0"
974 GLU_LIBS="$GL_LIBS0"
975
976 if test x"$enable_opengl" = xno; then
977    no_GLU=yes
978 elif test x"$use_quartz_opengl" != xyes; then
979   FP_CHECK_GL_HELPER([GLU], [-lglu32 -lGLU], [@%:@include <GL/glu.h>], [gluNewQuadric()])
980 fi
981
982 AC_SUBST([GLU_CFLAGS])
983 AC_SUBST([GLU_LIBS])
984 ])# FP_CHECK_GLU
985
986
987 # FP_CHECK_GLUT
988 # -------------
989 AC_DEFUN([FP_CHECK_GLUT],
990 [AC_REQUIRE([FP_CHECK_GLU])
991 FP_PATH_XTRA
992
993 if test x"$enable_opengl" = xno; then
994    no_GLUT=yes
995 elif test x"$use_quartz_opengl" != xyes; then
996   GLUT_CFLAGS="$GLU_CFLAGS0"
997   GLUT_LIBS="$GLU_LIBS0"
998
999   if test x"$no_x" != xyes; then
1000     GLUT_LIBS="$X_PRE_LIBS -lXmu -lXi $X_EXTRA_LIBS $GLUT_LIBS"
1001   fi
1002
1003   AC_CHECK_HEADERS([windows.h GL/glut.h])
1004   # Note 1: On Cygwin with X11, GL/GLU functions use the "normal" calling
1005   # convention, but GLUT functions use stdcall. To get this right, it is
1006   # necessary to include <windows.h> first.
1007   # Note 2: MinGW/MSYS comes without a GLUT header, so we use Cygwin's one in
1008   # that case.
1009   FP_CHECK_GL_HELPER([GLUT], [-lglut32 -lglut], [
1010 #if HAVE_WINDOWS_H
1011 #include <windows.h>
1012 #endif
1013 #if HAVE_GL_GLUT_H
1014 #include <GL/glut.h>
1015 #else
1016 #include "glut_local.h"
1017 #endif
1018     ], [glutMainLoop()])
1019 fi
1020
1021 AC_SUBST([GLUT_CFLAGS])
1022 AC_SUBST([GLUT_LIBS])
1023 ])# FP_CHECK_GLUT
1024
1025
1026 dnl @synopsis FP_EMPTY_STRUCTS
1027 dnl 
1028 dnl Check whether empty structs is accepted by CC.
1029 dnl
1030 AC_DEFUN(FP_EMPTY_STRUCTS,
1031 [AC_CACHE_CHECK(empty struct support, fptools_cv_empty_structs,
1032 [AC_TRY_COMPILE([
1033 typedef struct { /*empty*/ } StgFoo;
1034 ],
1035 [int i;], 
1036 fptools_cv_empty_structs=yes,
1037 fptools_cv_empty_structs=no)])
1038 if test "$fptools_cv_empty_structs" = yes; then
1039 AC_DEFINE([SUPPORTS_EMPTY_STRUCTS], [1], [Define to 1 if C compiler supports declaration of empty structure types.])
1040 fi
1041 ])
1042
1043 # LocalWords:  fi