fix #2434: we weren't waiting long enough for the signal
[ghc-hetmet.git] / aclocal.m4
1     struct sigevent ev;
2     timer_t timer;
3     ev.sigev_notify = SIGEV_SIGNAL;
4     ev.sigev_signo  = SIGVTALRM;
5     if (timer_create(CLOCK_PROCESS_CPUTIME_ID, &ev, &timer) != 0) {
6        exit(1);
7     }
8 #else
9     exit(1)
10 #endif
11     exit(0);
12 }
13 # Extra autoconf macros for the Glasgow fptools
14 #
15 # To be a good autoconf citizen, names of local macros have prefixed with FP_ to
16 # ensure we don't clash with any pre-supplied autoconf ones.
17
18
19 # FPTOOLS_FLOAT_WORD_ORDER_BIGENDIAN
20 # ----------------------------------
21 # Little endian Arm on Linux with some ABIs has big endian word order
22 # in doubles. Define FLOAT_WORDS_BIGENDIAN if this is the case.
23 AC_DEFUN([FPTOOLS_FLOAT_WORD_ORDER_BIGENDIAN],
24   [AC_CACHE_CHECK([whether float word order is big endian], [fptools_cv_float_word_order_bigendian],
25     [AC_COMPILE_IFELSE(
26       [AC_LANG_PROGRAM(
27         [#include <endian.h>],
28         [#if defined(__FLOAT_WORD_ORDER) && __FLOAT_WORD_ORDER == BIG_ENDIAN
29              return 0;
30          #else
31              not float word order big endian
32          #endif]
33       )],
34       [fptools_cv_float_word_order_bigendian=yes],
35       [fptools_cv_float_word_order_bigendian=no])
36     ])
37   case $fptools_cv_float_word_order_bigendian in
38       yes)
39           AC_DEFINE([FLOAT_WORDS_BIGENDIAN], 1,
40           [Define to 1 if your processor stores words of floats with
41            the most significant byte first]) ;;
42   esac
43 ])
44
45
46 # FP_EVAL_STDERR(COMMAND)
47 # -----------------------
48 # Eval COMMAND, save its stderr (without lines resulting from shell tracing)
49 # into the file conftest.err and the exit status in the variable fp_status.
50 AC_DEFUN([FP_EVAL_STDERR],
51 [{ (eval $1) 2>conftest.er1
52   fp_status=$?
53   grep -v '^ *+' conftest.er1 >conftest.err
54   rm -f conftest.er1
55   (exit $fp_status); }[]dnl
56 ])# FP_EVAL_STDERR
57
58
59 # FP_PROG_CONTEXT_DIFF
60 # --------------------
61 # Figure out how to do context diffs. Sets the output variable ContextDiffCmd.
62 #
63 # Note: NeXTStep thinks diff'ing a file against itself is "trouble".
64 #
65 # Used by ghc, glafp-utils/ltx, and glafp-utils/runstdtest.
66 AC_DEFUN([FP_PROG_CONTEXT_DIFF],
67 [AC_CACHE_CHECK([for a working context diff], [fp_cv_context_diff],
68 [echo foo > conftest1
69 echo foo > conftest2
70 fp_cv_context_diff=no
71 for fp_var in '-U 1' '-u1' '-C 1' '-c1'
72 do
73   if diff $fp_var conftest1 conftest2 > /dev/null 2>&1; then
74     fp_cv_context_diff="diff $fp_var"
75     break
76   fi
77 done])
78 if test x"$fp_cv_context_diff" = xno; then
79    AC_MSG_ERROR([cannot figure out how to do context diffs])
80 fi
81 AC_SUBST(ContextDiffCmd, [$fp_cv_context_diff])
82 ])# FP_PROG_CONTEXT_DIFF
83
84
85 # FP_COMPUTE_INT(EXPRESSION, VARIABLE, INCLUDES, IF-FAILS)
86 # --------------------------------------------------------
87 # Assign VARIABLE the value of the compile-time EXPRESSION using INCLUDES for
88 # compilation. Execute IF-FAILS when unable to determine the value. Works for
89 # cross-compilation, too.
90 #
91 # Implementation note: We are lazy and use an internal autoconf macro, but it
92 # is supported in autoconf versions 2.50 up to the actual 2.57, so there is
93 # little risk.
94 AC_DEFUN([FP_COMPUTE_INT],
95 [_AC_COMPUTE_INT([$1], [$2], [$3], [$4])[]dnl
96 ])# FP_COMPUTE_INT
97
98
99 # FP_CHECK_ALIGNMENT(TYPE, [IGNORED], [INCLUDES = DEFAULT-INCLUDES])
100 # ------------------------------------------------------------------
101 # A variation of AC_CHECK_SIZEOF for computing the alignment restrictions of a
102 # given type. Defines ALIGNMENT_TYPE.
103 AC_DEFUN([FP_CHECK_ALIGNMENT],
104 [AS_LITERAL_IF([$1], [],
105                [AC_FATAL([$0: requires literal arguments])])[]dnl
106 AC_CHECK_TYPE([$1], [], [], [$3])[]dnl
107 m4_pushdef([fp_Cache], [AS_TR_SH([fp_cv_alignment_$1])])[]dnl
108 AC_CACHE_CHECK([alignment of $1], [fp_Cache],
109 [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
110   FP_COMPUTE_INT([(long) (&((struct { char c; $1 ty; } *)0)->ty)],
111                  [fp_Cache],
112                  [AC_INCLUDES_DEFAULT([$3])],
113                  [AC_MSG_ERROR([cannot compute alignment ($1)
114 See `config.log' for more details.], [77])])
115 else
116   fp_Cache=0
117 fi])[]dnl
118 AC_DEFINE_UNQUOTED(AS_TR_CPP(alignment_$1), $fp_Cache, [The alignment of a `$1'.])[]dnl
119 m4_popdef([fp_Cache])[]dnl
120 ])# FP_CHECK_ALIGNMENT
121
122
123 # FP_LEADING_UNDERSCORE
124 # ---------------------
125 # Test for determining whether symbol names have a leading underscore. We assume
126 # that they _haven't_ if anything goes wrong. Sets the output variable
127 # LeadingUnderscore to YES or NO and defines LEADING_UNDERSCORE correspondingly.
128 #
129 # Some nlist implementations seem to try to be compatible by ignoring a leading
130 # underscore sometimes (eg. FreeBSD). We therefore have to work around this by
131 # checking for *no* leading underscore first. Sigh.  --SDM
132 #
133 # Similarly on OpenBSD, but this test doesn't help. -- dons
134 AC_DEFUN([FP_LEADING_UNDERSCORE],
135 [AC_CHECK_LIB([elf], [nlist], [LIBS="-lelf $LIBS"])
136 AC_CACHE_CHECK([leading underscore in symbol names], [fptools_cv_leading_underscore], [
137 # Hack!: nlist() under Digital UNIX insist on there being an _,
138 # but symbol table listings shows none. What is going on here?!?
139 #
140 # Another hack: cygwin doesn't come with nlist.h , so we hardwire
141 # the underscoredness of that "platform"
142 case $HostPlatform in
143 *openbsd*) # x86 openbsd is ELF from 3.4 >, meaning no leading uscore
144   case $build in
145     i386-*2\.@<:@0-9@:>@ | i386-*3\.@<:@0-3@:>@ ) fptools_cv_leading_underscore=yes ;;
146     *) fptools_cv_leading_underscore=no ;;
147   esac ;;
148 alpha-dec-osf*) fptools_cv_leading_underscore=no;;
149 *cygwin32) fptools_cv_leading_underscore=yes;;
150 *mingw32) fptools_cv_leading_underscore=yes;;
151
152     # HACK: Apple doesn't seem to provide nlist in the 64-bit-libraries
153 x86_64-apple-darwin*) fptools_cv_leading_underscore=yes;;
154
155 *) AC_RUN_IFELSE([AC_LANG_SOURCE([[#ifdef HAVE_NLIST_H
156 #include <nlist.h>
157 struct nlist xYzzY1[] = {{"xYzzY1", 0},{0}};
158 struct nlist xYzzY2[] = {{"_xYzzY2", 0},{0}};
159 #endif
160
161 int main(argc, argv)
162 int argc;
163 char **argv;
164 {
165 #ifdef HAVE_NLIST_H
166     if(nlist(argv[0], xYzzY1) == 0 && xYzzY1[0].n_value != 0)
167         exit(1);
168     if(nlist(argv[0], xYzzY2) == 0 && xYzzY2[0].n_value != 0)
169         exit(0);
170 #endif
171     exit(1);
172 }]])],[fptools_cv_leading_underscore=yes],[fptools_cv_leading_underscore=no],[fptools_cv_leading_underscore=no])
173 ;;
174 esac]);
175 AC_SUBST([LeadingUnderscore], [`echo $fptools_cv_leading_underscore | sed 'y/yesno/YESNO/'`])
176 if test x"$fptools_cv_leading_underscore" = xyes; then
177    AC_DEFINE([LEADING_UNDERSCORE], [1], [Define to 1 if C symbols have a leading underscore added by the compiler.])
178 fi])# FP_LEADING_UNDERSCORE
179
180
181 # FP_COMPARE_VERSIONS(VERSION1, TEST, VERSION2, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
182 # ----------------------------------------------------------------------------------
183 # Compare dotted version numbers VERSION1 and VERSION2 lexicographically according
184 # to TEST (one of -eq, -ne, -lt, -le, -gt, or -ge).
185 AC_DEFUN([FP_COMPARE_VERSIONS],
186 [fp_version1=$1; fp_version2=$3
187 fp_save_IFS=$IFS; IFS='.'
188 while test x"$fp_version1" != x || test x"$fp_version2" != x
189 do
190
191   set dummy $fp_version1; shift
192   fp_num1=""
193   test $[@%:@] = 0 || { fp_num1="[$]1"; shift; }
194   test x"$fp_num1" = x && fp_num1="0"
195   fp_version1="[$]*"
196
197   set dummy $fp_version2; shift
198   fp_num2=""
199   test $[@%:@] = 0 || { fp_num2="[$]1"; shift; }
200   test x"$fp_num2" = x && fp_num2="0"
201   fp_version2="[$]*"
202
203   test "$fp_num1" = "$fp_num2" || break;
204 done
205 IFS=$fp_save_IFS
206 AS_IF([test "$fp_num1" $2 "$fp_num2"], [$4], [$5])[]dnl
207 ])# FP_COMPARE_VERSIONS
208
209
210 dnl
211 dnl Check for GreenCard and version.
212 dnl
213 AC_DEFUN([FPTOOLS_GREENCARD],
214 [
215 AC_PATH_PROG(GreenCardCmd,greencard)
216 AC_CACHE_CHECK([for version of greencard], fptools_cv_greencard_version,
217 changequote(, )dnl
218 [if test x"$GreenCardCmd" != x; then
219    fptools_cv_greencard_version="`$GreenCardCmd --version |
220                           grep 'version' | sed -e 's/greencard. version \([^ ]*\).*/\1/g'`"
221 else
222    fptools_cv_greencard_version=""
223 fi
224 changequote([, ])dnl
225 ])
226 FP_COMPARE_VERSIONS([$fptools_cv_greencard_version],[-lt],[$1],
227   [AC_MSG_ERROR([greencard version $1 or later is required (found '$fptools_cv_greencard_version')])])[]dnl
228 GreenCardVersion=$fptools_cv_greencard_version
229 AC_SUBST(GreenCardVersion)
230 ])
231
232 dnl
233 dnl Check for Happy and version.  If we're building GHC, then we need
234 dnl at least Happy version 1.14.  If there's no installed Happy, we look
235 dnl for a happy source tree and point the build system at that instead.
236 dnl
237 AC_DEFUN([FPTOOLS_HAPPY],
238 [AC_PATH_PROG(HappyCmd,happy,)
239 # Happy is passed to Cabal, so we need a native path
240 if test "x$HostPlatform"  = "xi386-unknown-mingw32" && \
241    test "${OSTYPE}"      != "msys"                  && \
242    test "${HappyCmd}"    != ""
243 then
244     # Canonicalise to <drive>:/path/to/gcc
245     HappyCmd=`cygpath -m ${HappyCmd}`
246     AC_MSG_NOTICE([normalized happy command to $HappyCmd])
247 fi
248
249 AC_CACHE_CHECK([for version of happy], fptools_cv_happy_version,
250 changequote(, )dnl
251 [if test x"$HappyCmd" != x; then
252    fptools_cv_happy_version="`$HappyCmd -v |
253                           grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'`" ;
254 else
255    fptools_cv_happy_version="";
256 fi;
257 changequote([, ])dnl
258 ])
259 if test ! -f compiler/parser/Parser.hs || test ! -f compiler/main/ParsePkgConf.hs || test ! -f compiler/cmm/CmmParse.hs || test ! -f compiler/parser/ParserCore.hs
260 then
261     FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.15],
262       [AC_MSG_ERROR([Happy version 1.15 or later is required to compile GHC.])])[]dnl
263 fi
264 HappyVersion=$fptools_cv_happy_version;
265 AC_SUBST(HappyVersion)
266 ])
267
268 dnl
269 dnl Check for Haddock and version.  If there's no installed Haddock, we look
270 dnl for a haddock source tree and point the build system at that instead.
271 dnl
272 AC_DEFUN([FPTOOLS_HADDOCK],
273 [AC_PATH_PROG(HaddockCmd,haddock,)
274 dnl Darn, I forgot to make Haddock print out its version number when
275 dnl invoked with -v.  We could try generating some HTML and grepping
276 dnl through that to find the version number, but I think we'll make
277 dnl do without it for now.
278 # Haddock is passed to Cabal, so we need a native path
279 if test "x$HostPlatform"  = "xi386-unknown-mingw32" && \
280    test "${OSTYPE}"      != "msys"                  && \
281    test "${HaddockCmd}"  != ""
282 then
283     # Canonicalise to <drive>:/path/to/gcc
284     HaddockCmd=`cygpath -m ${HaddockCmd}`
285     AC_MSG_NOTICE([normalized haddock command to $HaddockCmd])
286 fi
287 ])
288
289 dnl
290 dnl Check for Alex and version.  If we're building GHC, then we need
291 dnl at least Alex version 2.0.1.
292 dnl
293 AC_DEFUN([FPTOOLS_ALEX],
294 [
295 AC_PATH_PROG(AlexCmd,alex,)
296 # Alex is passed to Cabal, so we need a native path
297 if test "x$HostPlatform"  = "xi386-unknown-mingw32" && \
298    test "${OSTYPE}"      != "msys"                  && \
299    test "${AlexCmd}"     != ""
300 then
301     # Canonicalise to <drive>:/path/to/gcc
302     AlexCmd=`cygpath -m ${AlexCmd}`
303 fi
304
305 AC_CACHE_CHECK([for version of alex], fptools_cv_alex_version,
306 changequote(, )dnl
307 [if test x"$AlexCmd" != x; then
308    fptools_cv_alex_version="`$AlexCmd -v |
309                           grep 'Alex [Vv]ersion' | sed -e 's/Alex [Vv]ersion \([0-9\.]*\).*/\1/g'`" ;
310 else
311    fptools_cv_alex_version="";
312 fi;
313 changequote([, ])dnl
314 ])
315 if test ! -f compiler/cmm/CmmLex.hs || test ! -f compiler/parser/Lexer.hs
316 then
317     FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-lt],[2.0.1],
318       [AC_MSG_ERROR([Alex version 2.0.1 or later is required to compile GHC.])])[]dnl
319 fi
320 AlexVersion=$fptools_cv_alex_version;
321 AC_SUBST(AlexVersion)
322 ])
323
324
325 # FP_PROG_LD
326 # ----------
327 # Sets the output variable LdCmd to the (non-Cygwin version of the) full path
328 # of ld. Exits if no ld can be found
329 AC_DEFUN([FP_PROG_LD],
330 [
331 if test -z "$1"
332 then
333   AC_PATH_PROG([fp_prog_ld_raw], [ld])
334   if test -z "$fp_prog_ld_raw"; then
335     AC_MSG_ERROR([cannot find ld in your PATH, no idea how to link])
336   fi
337   LdCmd=$fp_prog_ld_raw
338   case $HostPlatform in
339     *mingw32) if test x${OSTYPE} != xmsys; then
340               LdCmd="`cygpath -w ${fp_prog_ld_raw} | sed -e 's@\\\\@/@g'`"
341                 AC_MSG_NOTICE([normalized ld command to $LdCmd])
342               fi
343             # Insist on >= ld-2.15.x, since earlier versions doesn't handle
344             # the generation of relocatable object files with large amounts
345             # of relocations correctly. (cf. HSbase.o splittage-hack)
346             fp_prog_ld_version=`${LdCmd} --version | sed -n '/GNU ld/p' | tr -cd 0-9 | cut -b1-3`
347             FP_COMPARE_VERSIONS([$fp_prog_ld_version],[-lt],[214],
348                                   [AC_MSG_ERROR([GNU ld version later than 2.14 required to compile GHC on Windows.])])[]dnl
349               ;;
350   esac
351 else
352   LdCmd="$1"
353 fi
354 AC_SUBST([LdCmd])
355 ])# FP_PROG_LD
356
357
358 # FP_PROG_LD_X
359 # ------------
360 # Sets the output variable LdXFlag to -x if ld supports this flag, otherwise the
361 # variable's value is empty.
362 AC_DEFUN([FP_PROG_LD_X],
363 [AC_REQUIRE([FP_PROG_LD])
364 AC_CACHE_CHECK([whether ld understands -x], [fp_cv_ld_x],
365 [echo 'foo() {}' > conftest.c
366 ${CC-cc} -c conftest.c
367 if ${LdCmd} -r -x -o conftest2.o conftest.o > /dev/null 2>&1; then
368    fp_cv_ld_x=yes
369 else
370    fp_cv_ld_x=no
371 fi
372 rm -rf conftest*])
373 if test "$fp_cv_ld_x" = yes; then
374   LdXFlag=-x
375 else
376   LdXFlag=
377 fi
378 AC_SUBST([LdXFlag])
379 ])# FP_PROG_LD_X
380
381
382 # FP_PROG_LD_IS_GNU
383 # -----------------
384 # Sets the output variable LdIsGNULd to YES or NO, depending on whether it is
385 # GNU ld or not.
386 AC_DEFUN([FP_PROG_LD_IS_GNU],
387 [AC_REQUIRE([FP_PROG_LD])
388 AC_CACHE_CHECK([whether ld is GNU ld], [fp_cv_gnu_ld],
389 [if ${LdCmd} --version 2> /dev/null | grep "GNU" > /dev/null 2>&1; then
390   fp_cv_gnu_ld=yes
391 else
392   fp_cv_gnu_ld=no
393 fi])
394 AC_SUBST([LdIsGNULd], [`echo $fp_cv_gnu_ld | sed 'y/yesno/YESNO/'`])
395 ])# FP_PROG_LD_IS_GNU
396
397
398 # FP_PROG_AR
399 # ----------
400 # Sets fp_prog_ar_raw to the full path of ar and fp_prog_ar to a non-Cygwin
401 # version of it. Exits if no ar can be found
402 AC_DEFUN([FP_PROG_AR],
403 [AC_PATH_PROG([fp_prog_ar_raw], [ar])
404 if test -z "$fp_prog_ar_raw"; then
405   AC_MSG_ERROR([cannot find ar in your PATH, no idea how to make a library])
406 fi
407 fp_prog_ar=$fp_prog_ar_raw
408 case $HostPlatform in
409   *mingw32) if test x${OSTYPE} != xmsys; then
410               fp_prog_ar="`cygpath -w ${fp_prog_ar_raw} | sed -e 's@\\\\@/@g'`"
411               AC_MSG_NOTICE([normalized ar command to $fp_prog_ar])
412             fi
413             ;;
414 esac
415 ])# FP_PROG_AR
416
417
418 # FP_PROG_AR_IS_GNU
419 # -----------------
420 # Sets fp_prog_ar_is_gnu to yes or no, depending on whether it is GNU ar or not.
421 AC_DEFUN([FP_PROG_AR_IS_GNU],
422 [AC_REQUIRE([FP_PROG_AR])
423 AC_CACHE_CHECK([whether $fp_prog_ar_raw is GNU ar], [fp_cv_prog_ar_is_gnu],
424 [if $fp_prog_ar_raw --version 2> /dev/null | grep "GNU" > /dev/null 2>&1; then
425   fp_cv_prog_ar_is_gnu=yes
426 else
427   fp_cv_prog_ar_is_gnu=no
428 fi])
429 fp_prog_ar_is_gnu=$fp_cv_prog_ar_is_gnu
430 ])# FP_PROG_AR_IS_GNU
431
432
433 # FP_PROG_AR_ARGS
434 # ---------------
435 # Sets fp_prog_ar_args to the arguments for ar and the output variable ArCmd
436 # to a non-Cygwin invocation of ar including these arguments.
437 AC_DEFUN([FP_PROG_AR_ARGS],
438 [AC_REQUIRE([FP_PROG_AR_IS_GNU])
439 AC_CACHE_CHECK([for ar arguments], [fp_cv_prog_ar_args],
440 [
441 # GNU ar needs special treatment: it appears to have problems with
442 # object files with the same name if you use the 's' modifier, but
443 # simple 'ar q' works fine, and doesn't need a separate ranlib.
444 if test $fp_prog_ar_is_gnu = yes; then
445   fp_cv_prog_ar_args="q"
446 else
447   touch conftest.dummy
448   for fp_var in clqsZ clqs cqs clq cq ; do
449      rm -f conftest.a
450      if $fp_prog_ar_raw $fp_var conftest.a conftest.dummy > /dev/null 2> /dev/null; then
451         fp_cv_prog_ar_args=$fp_var
452         break
453      fi
454   done
455   rm -f conftest*
456   if test -z "$fp_cv_prog_ar_args"; then
457     AC_MSG_ERROR([cannot figure out how to use your $fp_prog_ar_raw])
458   fi
459 fi])
460 fp_prog_ar_args=$fp_cv_prog_ar_args
461 AC_SUBST([ArCmd], ["$fp_prog_ar $fp_prog_ar_args"])
462
463 ])# FP_PROG_AR_ARGS
464
465
466 # FP_PROG_AR_NEEDS_RANLIB
467 # -----------------------
468 # Sets the output variable RANLIB to "ranlib" if it is needed and found,
469 # to ":" otherwise.
470 AC_DEFUN([FP_PROG_AR_NEEDS_RANLIB],
471 [AC_REQUIRE([FP_PROG_AR_IS_GNU])
472 AC_REQUIRE([FP_PROG_AR_ARGS])
473 AC_REQUIRE([AC_PROG_CC])
474 AC_CACHE_CHECK([whether ranlib is needed], [fp_cv_prog_ar_needs_ranlib],
475 [if test $fp_prog_ar_is_gnu = yes; then
476   fp_cv_prog_ar_needs_ranlib=no
477 elif echo $TargetPlatform | grep "^.*-apple-darwin$"  > /dev/null 2> /dev/null; then
478   # It's quite tedious to check for Apple's crazy timestamps in .a files,
479   # so we hardcode it.
480   fp_cv_prog_ar_needs_ranlib=yes
481 elif echo $fp_prog_ar_args | grep "s" > /dev/null 2> /dev/null; then
482   fp_cv_prog_ar_needs_ranlib=no
483 else
484   fp_cv_prog_ar_needs_ranlib=yes
485 fi])
486 if test $fp_cv_prog_ar_needs_ranlib = yes; then
487    AC_PROG_RANLIB
488 else
489   RANLIB=":"
490   AC_SUBST([RANLIB])
491 fi
492 ])# FP_PROG_AR_NEEDS_RANLIB
493
494
495 # FP_PROG_AR_SUPPORTS_INPUT
496 # -------------------------
497 # Sets the output variable ArSupportsInput to "-input" or "", depending on
498 # whether ar supports -input flag is supported or not.
499 AC_DEFUN([FP_PROG_AR_SUPPORTS_INPUT],
500 [AC_REQUIRE([FP_PROG_AR_IS_GNU])
501 AC_REQUIRE([FP_PROG_AR_ARGS])
502 AC_CACHE_CHECK([whether $fp_prog_ar_raw supports -input], [fp_cv_prog_ar_supports_input],
503 [fp_cv_prog_ar_supports_input=no
504 if test $fp_prog_ar_is_gnu = no; then
505   rm -f conftest*
506   touch conftest.lst
507   if FP_EVAL_STDERR([$fp_prog_ar_raw $fp_prog_ar_args conftest.a -input conftest.lst]) >/dev/null; then
508     test -s conftest.err || fp_cv_prog_ar_supports_input=yes
509   fi
510   rm -f conftest*
511 fi])
512 if test $fp_cv_prog_ar_supports_input = yes; then
513     ArSupportsInput="-input"
514 else
515     ArSupportsInput=""
516 fi
517 AC_SUBST([ArSupportsInput])
518 ])# FP_PROG_AR_SUPPORTS_INPUT
519
520
521 dnl
522 dnl AC_SHEBANG_PERL - can we she-bang perl?
523 dnl
524 AC_DEFUN([FPTOOLS_SHEBANG_PERL],
525 [AC_CACHE_CHECK([if your perl works in shell scripts], fptools_cv_shebang_perl,
526 [echo "#!$PerlCmd"'
527 exit $1;
528 ' > conftest
529 chmod u+x conftest
530 (SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
531 if test $? -ne 69; then
532    fptools_cv_shebang_perl=yes
533 else
534    fptools_cv_shebang_perl=no
535 fi
536 rm -f conftest
537 ])])
538
539
540 # FP_HAVE_GCC
541 # -----------
542 # Extra testing of the result AC_PROG_CC, testing the gcc version no. Sets the
543 # output variables HaveGcc and GccVersion.
544 AC_DEFUN([FP_HAVE_GCC],
545 [AC_REQUIRE([AC_PROG_CC])
546 if test -z "$GCC"; then
547    fp_have_gcc=NO
548 else
549    fp_have_gcc=YES
550 fi
551 if test "$fp_have_gcc" = "NO" -a -d $srcdir/ghc; then
552   AC_MSG_ERROR([gcc is required])
553 fi
554 AC_CACHE_CHECK([version of gcc], [fp_gcc_version],
555 [if test "$fp_have_gcc" = "YES"; then
556    fp_gcc_version="`$CC -v 2>&1 | grep 'version ' | sed -e 's/.*version [[^0-9]]*\([[0-9.]]*\).*/\1/g'`"
557    FP_COMPARE_VERSIONS([$fp_gcc_version], [-lt], [2.0],
558      [AC_MSG_ERROR([Need at least gcc version 2.0 (3.4+ recommended)])])
559  else
560    fp_gcc_version="not-installed"
561  fi
562 ])
563 AC_SUBST([HaveGcc], [$fp_have_gcc])
564 AC_SUBST([GccVersion], [$fp_gcc_version])
565 ])# FP_HAVE_GCC
566
567 AC_DEFUN([FP_MINGW_GCC],
568 [
569   case $HostOS_CPP in
570     mingw*)  AC_MSG_CHECKING([whether $CC is a mingw gcc])
571              if $CC -v 2>&1 | grep mingw >/dev/null; then
572                 AC_MSG_RESULT([yes])
573              else
574                 AC_MSG_RESULT([no])
575                 AC_MSG_ERROR([Please use --with-gcc to specify a mingw gcc])
576              fi;;
577     *) ;;       
578   esac
579 ])
580
581 dnl Small feature test for perl version. Assumes PerlCmd
582 dnl contains path to perl binary.
583 dnl
584 dnl (Perl versions prior to v5.6 does not contain the string "v5";
585 dnl instead they display version strings such as "version 5.005".)
586 dnl
587 AC_DEFUN([FPTOOLS_CHECK_PERL_VERSION],
588 [$PerlCmd -v >conftest.out 2>&1
589    if grep "v5" conftest.out >/dev/null 2>&1; then
590       :
591    else
592       AC_MSG_ERROR([your version of perl probably won't work, try upgrading it.])
593    fi
594 rm -fr conftest*
595 ])
596
597
598 # FP_CHECK_PROG(VARIABLE, PROG-TO-CHECK-FOR,
599 #               [VALUE-IF-NOT-FOUND], [PATH], [REJECT])
600 # -----------------------------------------------------
601 # HACK: A small wrapper around AC_CHECK_PROG, setting VARIABLE to the full path
602 # of PROG-TO-CHECK-FOR when found.
603 AC_DEFUN([FP_CHECK_PROG],
604 [AC_CHECK_PROG([$1], [$2], [$as_dir/$ac_word$ac_exec_ext], [$3], [$4], [$5])][]dnl
605 )# FP_CHECK_PROC
606
607
608 # FP_PROG_FIND
609 # ------------
610 # Find a non-WinDoze version of the "find" utility.
611 AC_DEFUN([FP_PROG_FIND],
612 [AC_PATH_PROG([fp_prog_find], [find])
613 echo foo > conftest.txt
614 $fp_prog_find conftest.txt -print > conftest.out 2>&1
615 if grep '^conftest.txt$' conftest.out > /dev/null 2>&1 ; then
616   # OK, looks like a real "find".
617   case $HostPlatform in
618     *mingw32)
619       if test x${OSTYPE} != xmsys
620       then
621             fp_prog_find="`cygpath --mixed ${fp_prog_find}`"
622         AC_MSG_NOTICE([normalized find command to $fp_prog_find])
623       fi ;;
624     *) ;;
625   esac
626   FindCmd="$fp_prog_find"
627 else
628   # Found a poor WinDoze version of "find", ignore it.
629   AC_MSG_WARN([$fp_prog_find looks like a non-*nix find, ignoring it])
630   FP_CHECK_PROG([FindCmd], [find], [], [], [$fp_prog_find])
631 fi
632 rm -f conftest.txt conftest.out
633 AC_SUBST([FindCmd])[]dnl
634 ])# FP_PROG_FIND
635
636
637 # FP_PROG_SORT
638 # ------------
639 # Find a Unix-like sort
640 AC_DEFUN([FP_PROG_SORT],
641 [AC_PATH_PROG([fp_prog_sort], [sort])
642 echo conwip > conftest.txt
643 $fp_prog_sort -f conftest.txt > conftest.out 2>&1
644 if grep 'conwip' conftest.out > /dev/null 2>&1 ; then
645   # The goods
646   SortCmd="$fp_prog_sort"
647 else
648   # Summink else..pick next one.
649   AC_MSG_WARN([$fp_prog_sort looks like a non-*nix sort, ignoring it])
650   FP_CHECK_PROG([SortCmd], [sort], [], [], [$fp_prog_sort])
651 fi
652 rm -f conftest.txt conftest.out
653 AC_SUBST([SortCmd])[]dnl
654 ])# FP_PROG_SORT
655
656 dnl
657 dnl FPTOOLS_NOCACHE_CHECK prints a message, then sets the
658 dnl values of the second argument to the result of running
659 dnl the commands given by the third. It does not cache its
660 dnl result, so it is suitable for checks which should be
661 dnl run every time.
662 dnl
663 AC_DEFUN([FPTOOLS_NOCACHE_CHECK],
664 [AC_MSG_CHECKING([$1])
665  $3
666  AC_MSG_RESULT([$][$2])
667 ])
668
669 dnl
670 dnl FPTOOLS_GHC_VERSION(version)
671 dnl FPTOOLS_GHC_VERSION(major, minor [, patchlevel])
672 dnl FPTOOLS_GHC_VERSION(version, major, minor, patchlevel)
673 dnl
674 dnl Test for version of installed ghc.  Uses $GHC.
675 dnl [original version pinched from c2hs]
676 dnl
677 AC_DEFUN([FPTOOLS_GHC_VERSION],
678 [FPTOOLS_NOCACHE_CHECK([version of ghc], [fptools_version_of_ghc],
679 ["${WithGhc-ghc}" --version > conftestghc 2>&1
680   cat conftestghc >&AS_MESSAGE_LOG_FD
681 #Useless Use Of cat award...
682   fptools_version_of_ghc=`cat conftestghc | sed -n -e 's/, patchlevel *\([[0-9]]\)/.\1/;s/.* version \([[0-9]][[0-9.]]*\).*/\1/p'`
683   rm -fr conftest*
684   if test "[$]fptools_version_of_ghc" = ""
685   then
686     fptools_version_of_ghc='unknown'
687   fi
688 fptools_version_of_ghc[_major]=`echo [$]fptools_version_of_ghc | sed -e 's/^\([[0-9]]\).*/\1/'`
689 fptools_version_of_ghc[_minor]=`echo [$]fptools_version_of_ghc | sed -e 's/^[[0-9]]\.\([[0-9]]*\).*/\1/'`
690 fptools_version_of_ghc[_pl]=`echo [$]fptools_version_of_ghc | sed -n -e 's/^[[0-9]]\.[[0-9]]*\.\([[0-9]]*\)/\1/p'`
691 #
692 if test "[$]fptools_version_of_ghc[_pl]" = ""
693 then
694   fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor]"
695   fptools_version_of_ghc[_pl]="0"
696 else
697   fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor].[$]fptools_version_of_ghc[_pl]"
698 fi
699 #
700 ifelse($#, [1], [dnl
701 [$1]="[$]fptools_version_of_ghc[_all]"
702 ], $#, [2], [dnl
703 [$1]="[$]fptools_version_of_ghc[_major]"
704 [$2]="[$]fptools_version_of_ghc[_minor]"
705 ], $#, [3], [dnl
706 [$1]="[$]fptools_version_of_ghc[_major]"
707 [$2]="[$]fptools_version_of_ghc[_minor]"
708 [$3]="[$]fptools_version_of_ghc[_pl]"
709 ], $#, [4], [dnl
710 [$1]="[$]fptools_version_of_ghc[_all]"
711 [$2]="[$]fptools_version_of_ghc[_major]"
712 [$3]="[$]fptools_version_of_ghc[_minor]"
713 [$4]="[$]fptools_version_of_ghc[_pl]"
714 ])
715 ])
716 ])dnl
717
718
719 # FP_CHECK_FUNC(FUNCTION, PROLOGUE, BODY, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
720 # ---------------------------------------------------------------------------------
721 # A variant of AC_CHECK_FUNCS, limited to a single FUNCTION, but with the
722 # additional flexibility of specifying the PROLOGUE and BODY.
723 AC_DEFUN([FP_CHECK_FUNC],
724 [AS_VAR_PUSHDEF([fp_func], [fp_cv_func_$1])dnl
725 AC_CACHE_CHECK([for $1], fp_func,
726 [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2], [$3])],
727                 [AS_VAR_SET(fp_func, yes)],
728                 [AS_VAR_SET(fp_func, no)])])
729 AS_IF([test AS_VAR_GET(fp_func) = yes],
730       [AC_DEFINE(AS_TR_CPP(HAVE_$1), [1],
731                 [Define to 1 if you have the `]$1[' function.]) $4],
732       [$5])dnl
733 AS_VAR_POPDEF([fp_func])dnl
734 ])# FP_CHECK_FUNC
735
736
737 # FP_GEN_DOCBOOK_XML
738 # ------------------
739 # Generates a DocBook XML V4.2 document in conftest.xml.
740 AC_DEFUN([FP_GEN_DOCBOOK_XML],
741 [rm -f conftest.xml
742 cat > conftest.xml << EOF
743 <?xml version="1.0" encoding="iso-8859-1"?>
744 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
745    "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
746 <book id="test">
747   <title>A DocBook Test Document</title>
748   <chapter id="id-one">
749     <title>A Chapter Title</title>
750     <para>This is a paragraph, referencing <xref linkend="id-two"/>.</para>
751   </chapter>
752   <chapter id="id-two">
753     <title>Another Chapter Title</title>
754     <para>This is another paragraph, referencing <xref linkend="id-one"/>.</para>
755   </chapter>
756 </book>
757 EOF
758 ]) # FP_GEN_DOCBOOK_XML
759
760
761 # FP_PROG_XSLTPROC
762 # ----------------
763 # Sets the output variable XsltprocCmd to the full path of the XSLT processor
764 # xsltproc. XsltprocCmd is empty if xsltproc could not be found.
765 AC_DEFUN([FP_PROG_XSLTPROC],
766 [AC_PATH_PROG([XsltprocCmd], [xsltproc])
767 if test -z "$XsltprocCmd"; then
768   AC_MSG_WARN([cannot find xsltproc in your PATH, you will not be able to build the documentation])
769 fi
770 ])# FP_PROG_XSLTPROC
771
772
773 # FP_DIR_DOCBOOK_XSL(XSL-DIRS)
774 # ----------------------------
775 # Check which of the directories XSL-DIRS contains DocBook XSL stylesheets. The
776 # output variable DIR_DOCBOOK_XSL will contain the first usable directory or
777 # will be empty if none could be found.
778 AC_DEFUN([FP_DIR_DOCBOOK_XSL],
779 [AC_REQUIRE([FP_PROG_XSLTPROC])dnl
780 if test -n "$XsltprocCmd"; then
781   AC_CACHE_CHECK([for DocBook XSL stylesheet directory], fp_cv_dir_docbook_xsl,
782   [FP_GEN_DOCBOOK_XML
783   fp_cv_dir_docbook_xsl=no
784   for fp_var in $1; do
785      if $XsltprocCmd ${fp_var}/html/docbook.xsl conftest.xml > /dev/null 2>&1; then
786         fp_cv_dir_docbook_xsl=$fp_var
787         break
788      fi
789   done
790   rm -rf conftest*])
791 fi
792 if test x"$fp_cv_dir_docbook_xsl" = xno; then
793   AC_MSG_WARN([cannot find DocBook XSL stylesheets, you will not be able to build the documentation])
794   DIR_DOCBOOK_XSL=
795 else
796   DIR_DOCBOOK_XSL=$fp_cv_dir_docbook_xsl
797 fi
798 AC_SUBST([DIR_DOCBOOK_XSL])
799 ])# FP_DIR_DOCBOOK_XSL
800
801
802 # FP_PROG_XMLLINT
803 # ----------------
804 # Sets the output variable XmllintCmd to the full path of the XSLT processor
805 # xmllint. XmllintCmd is empty if xmllint could not be found.
806 AC_DEFUN([FP_PROG_XMLLINT],
807 [AC_PATH_PROG([XmllintCmd], [xmllint])
808 if test -z "$XmllintCmd"; then
809   AC_MSG_WARN([cannot find xmllint in your PATH, you will not be able to validate your documentation])
810 fi
811 ])# FP_PROG_XMLLINT
812
813
814 # FP_CHECK_DOCBOOK_DTD
815 # --------------------
816 AC_DEFUN([FP_CHECK_DOCBOOK_DTD],
817 [AC_REQUIRE([FP_PROG_XMLLINT])dnl
818 if test -n "$XmllintCmd"; then
819   AC_MSG_CHECKING([for DocBook DTD])
820   FP_GEN_DOCBOOK_XML
821   if $XmllintCmd --valid --noout conftest.xml > /dev/null 2>&1; then
822     AC_MSG_RESULT([ok])
823   else
824     AC_MSG_RESULT([failed])
825     AC_MSG_WARN([cannot find a DTD for DocBook XML V4.2, you will not be able to validate your documentation])
826     AC_MSG_WARN([check your XML_CATALOG_FILES environment variable and/or /etc/xml/catalog])
827   fi
828   rm -rf conftest*
829 fi
830 ])# FP_CHECK_DOCBOOK_DTD
831
832
833 # FP_GEN_FO
834 # ------------------
835 # Generates a formatting objects document in conftest.fo.
836 AC_DEFUN([FP_GEN_FO],
837 [rm -f conftest.fo
838 cat > conftest.fo << EOF
839 <?xml version="1.0"?>
840 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
841   <fo:layout-master-set>
842     <fo:simple-page-master master-name="blank">
843       <fo:region-body/>
844     </fo:simple-page-master>
845   </fo:layout-master-set>
846   <fo:page-sequence master-reference="blank">
847     <fo:flow flow-name="xsl-region-body">
848       <fo:block>
849         Test!
850       </fo:block>
851     </fo:flow>
852   </fo:page-sequence>
853 </fo:root>
854 EOF
855 ]) # FP_GEN_FO
856
857
858 # FP_PROG_FOP
859 # -----------
860 # Set the output variable 'FopCmd' to the first working 'fop' in the current
861 # 'PATH'. Note that /usr/bin/fop is broken in SuSE 9.1 (unpatched), so try
862 # /usr/share/fop/fop.sh in that case (or no 'fop'), too.
863 AC_DEFUN([FP_PROG_FOP],
864 [AC_PATH_PROGS([FopCmd1], [fop fop.sh])
865 if test -n "$FopCmd1"; then
866   AC_CACHE_CHECK([for $FopCmd1 usability], [fp_cv_fop_usability],
867     [FP_GEN_FO
868     if "$FopCmd1" -fo conftest.fo -ps conftest.ps > /dev/null 2>&1; then
869       fp_cv_fop_usability=yes
870     else
871       fp_cv_fop_usability=no
872     fi
873     rm -rf conftest*])
874   if test x"$fp_cv_fop_usability" = xyes; then
875      FopCmd=$FopCmd1
876   fi
877 fi
878 if test -z "$FopCmd"; then
879   AC_PATH_PROGS([FopCmd2], [fop.sh], , [/usr/share/fop])
880   FopCmd=$FopCmd2
881 fi
882 AC_SUBST([FopCmd])
883 ])# FP_PROG_FOP
884
885
886 # FP_PROG_FO_PROCESSOR
887 # --------------------
888 # Try to find an FO processor. PassiveTeX output is sometimes a bit strange, so
889 # try FOP first. Sets the output variables FopCmd, XmltexCmd, DvipsCmd, and
890 # PdfxmltexCmd.
891 AC_DEFUN([FP_PROG_FO_PROCESSOR],
892 [AC_REQUIRE([FP_PROG_FOP])
893 AC_PATH_PROG([XmltexCmd], [xmltex])
894 AC_PATH_PROG([DvipsCmd], [dvips])
895 if test -z "$FopCmd"; then
896   if test -z "$XmltexCmd"; then
897     AC_MSG_WARN([cannot find an FO => DVI converter, you will not be able to build DVI or PostScript documentation])
898   else
899     if test -z "$DvipsCmd"; then
900       AC_MSG_WARN([cannot find a DVI  => PS converter, you will not be able to build PostScript documentation])
901     fi
902   fi
903   AC_PATH_PROG([PdfxmltexCmd], [pdfxmltex])
904   if test -z "$PdfxmltexCmd"; then
905     AC_MSG_WARN([cannot find an FO => PDF converter, you will not be able to build PDF documentation])
906   fi
907 elif test -z "$XmltexCmd"; then
908   AC_MSG_WARN([cannot find an FO => DVI converter, you will not be able to build DVI documentation])
909 fi
910 ])# FP_PROG_FO_PROCESSOR
911
912
913 # FP_PROG_GHC_PKG
914 # ----------------
915 # Try to find a ghc-pkg matching the ghc mentioned in the environment variable
916 # WithGhc. If the latter is unset or no matching ghc-pkg can be found, try to
917 # find a plain ghc-pkg. Sets the output variable GhcPkgCmd.
918 AC_DEFUN([FP_PROG_GHC_PKG],
919 [AC_CACHE_CHECK([for ghc-pkg matching $WithGhc], fp_cv_matching_ghc_pkg,
920 [fp_ghc_pkg_guess=`echo $WithGhc | sed 's,ghc\(@<:@^/\\@:>@*\)$,ghc-pkg\1,'`
921 if "$fp_ghc_pkg_guess" -l > /dev/null 2>&1; then
922   fp_cv_matching_ghc_pkg=$fp_ghc_pkg_guess
923 else
924   fp_cv_matching_ghc_pkg=no
925 fi])
926 if test x"$fp_cv_matching_ghc_pkg" = xno; then
927   AC_PATH_PROG([GhcPkgCmd], [ghc-pkg])
928 else
929   GhcPkgCmd=$fp_cv_matching_ghc_pkg
930 fi])# FP_PROG_GHC_PKG
931
932
933 # FP_GHC_HAS_EDITLINE
934 # -------------------
935 AC_DEFUN([FP_GHC_HAS_EDITLINE],
936 [AC_REQUIRE([FP_PROG_GHC_PKG])
937 AC_CACHE_CHECK([whether ghc has editline package], [fp_cv_ghc_has_editline],
938 [if "${GhcPkgCmd-ghc-pkg}" --show-package editline >/dev/null 2>&1; then
939   fp_cv_ghc_has_editline=yes
940 else
941   fp_cv_ghc_has_editline=no
942  fi])
943 AC_SUBST([GhcHasEditline], [`echo $fp_cv_ghc_has_editline | sed 'y/yesno/YESNO/'`])
944 ])# FP_GHC_HAS_EDITLINE
945
946
947 # FP_GCC_EXTRA_FLAGS
948 # ------------------
949 # Determine which extra flags we need to pass gcc when we invoke it
950 # to compile .hc code.
951 #
952 # Some OSs (Mandrake Linux, in particular) configure GCC with
953 # -momit-leaf-frame-pointer on by default. If this is the case, we
954 # need to turn it off for mangling to work. The test is currently a
955 # bit crude, using only the version number of gcc.
956
957 # -fwrapv is needed for gcc to emit well-behaved code in the presence of
958 # integer wrap around. (Trac #952)
959 #
960 # -fno-unit-at-a-time or -fno-toplevel-reoder is necessary to avoid gcc
961 # reordering things in the module and confusing the manger and/or splitter.
962 # (eg. Trac #1427)
963 #
964 AC_DEFUN([FP_GCC_EXTRA_FLAGS],
965 [AC_REQUIRE([FP_HAVE_GCC])
966 AC_CACHE_CHECK([for extra options to pass gcc when compiling via C], [fp_cv_gcc_extra_opts],
967 [fp_cv_gcc_extra_opts=
968  FP_COMPARE_VERSIONS([$fp_gcc_version], [-ge], [3.4],
969   [fp_cv_gcc_extra_opts="$fp_cv_gcc_extra_opts -fwrapv"],
970   [])
971  case $TargetPlatform in
972   i386-*|x86_64-*) 
973      FP_COMPARE_VERSIONS([$fp_gcc_version], [-ge], [3.2],
974       [fp_cv_gcc_extra_opts="$fp_cv_gcc_extra_opts -mno-omit-leaf-frame-pointer"],
975       [])
976     FP_COMPARE_VERSIONS([$fp_gcc_version], [-ge], [3.4],
977      [FP_COMPARE_VERSIONS([$fp_gcc_version], [-ge], [4.2],
978        [fp_cv_gcc_extra_opts="$fp_cv_gcc_extra_opts -fno-toplevel-reorder"],
979        [fp_cv_gcc_extra_opts="$fp_cv_gcc_extra_opts -fno-unit-at-a-time"]
980      )],
981      [])
982   ;;
983   sparc-*-solaris2) 
984     FP_COMPARE_VERSIONS([$fp_gcc_version], [-ge], [4.2],
985       [fp_cv_gcc_extra_opts="$fp_cv_gcc_extra_opts -fno-toplevel-reorder"],
986       [])
987   ;;
988  esac
989 ])
990 AC_SUBST([GccExtraViaCOpts],$fp_cv_gcc_extra_opts)
991 ])
992
993
994 # FP_SETUP_PROJECT_VERSION
995 # ---------------------
996 AC_DEFUN([FP_SETUP_PROJECT_VERSION],
997 [
998 if test "$RELEASE" = "NO"; then
999     AC_MSG_CHECKING([for GHC version date])
1000     if test -f VERSION_DATE; then
1001         PACKAGE_VERSION=${PACKAGE_VERSION}.`cat VERSION_DATE`
1002         AC_MSG_RESULT(given $PACKAGE_VERSION)
1003     elif test -d _darcs; then
1004         changequote(, )dnl
1005         ver_date=`darcs changes --quiet --no-summary --xml | head -500 | grep 'date=' | sed "s/^.*date='\([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\).*$/\1/g" | sort -n | tail -1`
1006         if echo $ver_date | grep '^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$' 2>&1 >/dev/null; then true; else
1007         changequote([, ])dnl
1008                 AC_MSG_ERROR([failed to detect version date: check that darcs is in your path])
1009         fi
1010         PACKAGE_VERSION=${PACKAGE_VERSION}.$ver_date
1011         AC_MSG_RESULT(inferred $PACKAGE_VERSION)
1012     elif test -f VERSION; then
1013         PACKAGE_VERSION=`cat VERSION`
1014         AC_MSG_RESULT(given $PACKAGE_VERSION)
1015     else
1016         AC_MSG_WARN([cannot determine snapshot version: no _darcs directory and no VERSION file])
1017     fi
1018 fi
1019
1020 # Some renamings
1021 AC_SUBST([ProjectName], [$PACKAGE_NAME])
1022 AC_SUBST([ProjectVersion], [$PACKAGE_VERSION])
1023
1024 # Split PACKAGE_VERSION into (possibly empty) parts
1025 VERSION_MAJOR=`echo $PACKAGE_VERSION | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\1'/`
1026 VERSION_TMP=`echo $PACKAGE_VERSION | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\3'/`
1027 VERSION_MINOR=`echo $VERSION_TMP | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\1'/`
1028 ProjectPatchLevel=`echo $VERSION_TMP | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\3'/`
1029
1030 # Calculate project version as an integer, using 2 digits for minor version
1031 case $VERSION_MINOR in
1032   ?) ProjectVersionInt=${VERSION_MAJOR}0${VERSION_MINOR} ;;
1033   ??) ProjectVersionInt=${VERSION_MAJOR}${VERSION_MINOR} ;;
1034   *) AC_MSG_ERROR([bad minor version in $PACKAGE_VERSION]) ;;
1035 esac
1036 AC_SUBST([ProjectVersionInt])
1037
1038 # The project patchlevel is zero unless stated otherwise
1039 test -z "$ProjectPatchLevel" && ProjectPatchLevel=0
1040
1041 # Remove dots from the patch level; this allows us to have versions like 6.4.1.20050508
1042 ProjectPatchLevel=`echo $ProjectPatchLevel | sed 's/\.//'`
1043
1044 AC_SUBST([ProjectPatchLevel])
1045 ])# FP_SETUP_PROJECT_VERSION
1046
1047
1048 # Check for a working timer_create().  We need a pretty detailed check
1049 # here, because there exist partially-working implementations of
1050 # timer_create() in certain versions of Linux (see bug #1933).
1051 #
1052 AC_DEFUN([FP_CHECK_TIMER_CREATE],
1053   [AC_CACHE_CHECK([for a working timer_create(CLOCK_REALTIME)], 
1054     [fptools_cv_timer_create_works],
1055     [AC_TRY_RUN([
1056 #include <stdio.h>
1057 #ifdef HAVE_STDLIB_H
1058 #include <stdlib.h>
1059 #endif
1060 #ifdef HAVE_TIME_H
1061 #include <time.h>
1062 #endif
1063 #ifdef HAVE_SIGNAL_H
1064 #include <signal.h>
1065 #endif
1066 #ifdef HAVE_UNISTD_H
1067 #include <unistd.h>
1068 #endif
1069
1070 static volatile int tock = 0;
1071 static void handler(int i)
1072 {
1073    tock = 1;
1074 }
1075
1076 static void timeout(int i)
1077 {
1078   // timer_settime() has been known to hang, so just in case
1079   // we install a 1-second timeout (see #2257)
1080   exit(99);
1081 }
1082
1083 int main(int argc, char *argv[])
1084 {
1085
1086     struct sigevent ev;
1087     timer_t timer;
1088     struct itimerspec it;
1089     struct sigaction action;
1090     int m,n,count = 0;
1091
1092     ev.sigev_notify = SIGEV_SIGNAL;
1093     ev.sigev_signo  = SIGVTALRM;
1094
1095     action.sa_handler = handler;
1096     action.sa_flags = 0;
1097     sigemptyset(&action.sa_mask);
1098     if (sigaction(SIGVTALRM, &action, NULL) == -1) {
1099         fprintf(stderr,"SIGVTALRM problem\n");
1100         exit(3);
1101     }
1102
1103     action.sa_handler = timeout;
1104     action.sa_flags = 0;
1105     sigemptyset(&action.sa_mask);
1106     if (sigaction(SIGALRM, &action, NULL) == -1) {
1107       fprintf(stderr,"SIGALRM problem\n");
1108       exit(3);
1109     }
1110     alarm(1);
1111
1112     if (timer_create(CLOCK_PROCESS_CPUTIME_ID, &ev, &timer) != 0) {
1113         fprintf(stderr,"No CLOCK_PROCESS_CPUTIME_ID timer\n");
1114        exit(1);
1115     }
1116
1117     it.it_value.tv_sec = 0;
1118     it.it_value.tv_nsec = 1;
1119     it.it_interval = it.it_value;
1120     if (timer_settime(timer, 0, &it, NULL) != 0) {
1121         fprintf(stderr,"settime problem\n");
1122         exit(4);
1123     }
1124
1125     tock = 0;
1126
1127     for(n = 3; n < 20000; n++){
1128         for(m = 2; m <= n/2; m++){
1129             if (!(n%m)) count++;
1130             if (tock) goto out;
1131         }
1132     }
1133 out:
1134
1135     if (!tock) {
1136         fprintf(stderr,"no CLOCK_PROCESS_CPUTIME_ID signal\n");
1137         exit(5);
1138     }
1139
1140     timer_delete(timer);
1141
1142     if (timer_create(CLOCK_REALTIME, &ev, &timer) != 0) {
1143         fprintf(stderr,"No CLOCK_REALTIME timer\n");
1144         exit(2);
1145     }
1146
1147     it.it_value.tv_sec = 0;
1148     it.it_value.tv_nsec = 1000000;
1149     it.it_interval = it.it_value;
1150     if (timer_settime(timer, 0, &it, NULL) != 0) {
1151         fprintf(stderr,"settime problem\n");
1152         exit(4);
1153     }
1154
1155     tock = 0;
1156
1157     usleep(3000);
1158
1159     if (!tock) {
1160         fprintf(stderr,"no CLOCK_REALTIME signal\n");
1161         exit(5);
1162     }
1163
1164     timer_delete(timer);
1165
1166     exit(0);
1167 }
1168      ],
1169      [fptools_cv_timer_create_works=yes],
1170      [fptools_cv_timer_create_works=no])
1171   ])
1172 case $fptools_cv_timer_create_works in
1173     yes) AC_DEFINE([USE_TIMER_CREATE], 1, 
1174                    [Define to 1 if we can use timer_create(CLOCK_PROCESS_CPUTIME_ID,...)]);;
1175 esac
1176 ])
1177
1178 # FP_ARG_GMP
1179 # -------------
1180 AC_DEFUN([FP_ARG_GMP],
1181 [
1182 AC_ARG_WITH([gmp-includes],
1183   [AC_HELP_STRING([--with-gmp-includes],
1184     [directory containing gmp.h])],
1185     [gmp_includes=$withval],
1186     [gmp_includes=NONE])
1187
1188 AC_ARG_WITH([gmp-libraries],
1189   [AC_HELP_STRING([--with-gmp-libraries],
1190     [directory containing gmp library])],
1191     [gmp_libraries=$withval],
1192     [gmp_libraries=NONE])
1193 ])# FP_ARG_GMP
1194
1195 AC_DEFUN([CHECK_GMP],
1196 [AC_REQUIRE([AC_PROG_CPP])
1197 AC_REQUIRE([AC_PROG_CC])
1198 ])
1199
1200 # FP_CHECK_MACOSX_DEPLOYMENT_TARGET
1201 # ---------------------------------
1202 AC_DEFUN([FP_CHECK_MACOSX_DEPLOYMENT_TARGET],
1203 [
1204 if test "x$TargetOS_CPP-$TargetVendor_CPP" = "xdarwin-apple"; then
1205   AC_MSG_CHECKING([Mac OS X deployment target])
1206   case $FP_MACOSX_DEPLOYMENT_TARGET in
1207     none)  ;;
1208     10.4)  MACOSX_DEPLOYMENT_VERSION=10.4
1209            MACOSX_DEPLOYMENT_SDK=/Developer/SDKs/MacOSX10.4u.sdk
1210            ;;
1211     10.4u) MACOSX_DEPLOYMENT_VERSION=10.4
1212            MACOSX_DEPLOYMENT_SDK=/Developer/SDKs/MacOSX10.4u.sdk
1213            ;;
1214     *)     MACOSX_DEPLOYMENT_VERSION=$FP_MACOSX_DEPLOYMENT_TARGET
1215            MACOSX_DEPLOYMENT_SDK=/Developer/SDKs/MacOSX${FP_MACOSX_DEPLOYMENT_TARGET}.sdk
1216            ;;
1217   esac
1218   if test "x$FP_MACOSX_DEPLOYMENT_TARGET" = "xnone"; then
1219     AC_MSG_RESULT(none)
1220   else
1221     if test ! -d $MACOSX_DEPLOYMENT_SDK; then
1222       AC_MSG_ERROR([Unknown deployment target $FP_MACOSX_DEPLOYMENT_TARGET])
1223     fi
1224     AC_MSG_RESULT([${MACOSX_DEPLOYMENT_VERSION} (${MACOSX_DEPLOYMENT_SDK})])
1225   fi
1226 fi
1227 ])
1228
1229 # --------------------------------------------------------------
1230 # Calculate absolute path to build tree
1231 # --------------------------------------------------------------
1232
1233 AC_DEFUN([FP_FIND_ROOT],[
1234 AC_MSG_CHECKING(for path to top of build tree)
1235
1236 dnl This would be
1237 dnl     make -C utils/pwd clean && make -C utils/pwd
1238 dnl except we don't want to have to know what make is called. Sigh.
1239 if test ! -f utils/pwd/pwd && test ! -f utils/pwd/pwd.exe; then
1240   cd utils/pwd
1241   rm -f *.o
1242   rm -f *.hi
1243   rm -f pwd
1244   rm -f pwd.exe
1245   $WithGhc -v0 --make pwd -o pwd
1246   cd ../..
1247 fi
1248
1249 hardtop=`utils/pwd/pwd forwardslash`
1250
1251 if ! test -d "$hardtop"; then
1252   AC_MSG_ERROR([cannot determine current directory])
1253 fi   
1254
1255 dnl Remove common automounter nonsense
1256 dnl
1257 hardtop=`echo $hardtop | sed 's|^/tmp_mnt.*\(/local/.*\)$|\1|' | sed 's|^/tmp_mnt/|/|'`
1258
1259 AC_SUBST(hardtop)
1260
1261 AC_MSG_RESULT(${hardtop})
1262
1263 # We don't support building in directories with spaces.
1264 case "$hardtop" in
1265   *' '*) AC_MSG_ERROR([
1266    The build system does not support building in a directory containing
1267    space characters.  Suggestion: move the build tree somewhere else.])
1268  ;;
1269 esac
1270 ])
1271
1272 # LocalWords:  fi