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