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