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