Fix warning in GhciMonad.
[ghc.git] / aclocal.m4
1 # Extra autoconf macros for the Glasgow fptools
2 #
3 # To be a good autoconf citizen, names of local macros have prefixed with FP_ to
4 # ensure we don't clash with any pre-supplied autoconf ones.
5
6
7 # 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     windows=NO
83     exeext=''
84     soext='.so'
85     case $host in
86     *-unknown-cygwin32)
87         AC_MSG_WARN([GHC does not support the Cygwin target at the moment])
88         AC_MSG_WARN([I'm assuming you wanted to build for i386-unknown-mingw32])
89         exit 1
90         ;;
91     *-unknown-mingw32)
92         windows=YES
93         exeext='.exe'
94         soext='.dll'
95         ;;
96     i386-apple-darwin|powerpc-apple-darwin)
97         soext='.dylib'
98         ;;
99     x86_64-apple-darwin)
100         soext='.dylib'
101         ;;
102     esac
103
104     BuildPlatform="$BuildArch-$BuildVendor-$BuildOS"
105     BuildPlatform_CPP=`echo "$BuildPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'`
106     BuildArch_CPP=`    echo "$BuildArch"     | sed -e 's/\./_/g' -e 's/-/_/g'`
107     BuildVendor_CPP=`  echo "$BuildVendor"   | sed -e 's/\./_/g' -e 's/-/_/g'`
108     BuildOS_CPP=`      echo "$BuildOS"       | sed -e 's/\./_/g' -e 's/-/_/g'`
109
110     HostPlatform="$HostArch-$HostVendor-$HostOS"
111     HostPlatform_CPP=`echo "$HostPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'`
112     HostArch_CPP=`    echo "$HostArch"     | sed -e 's/\./_/g' -e 's/-/_/g'`
113     HostVendor_CPP=`  echo "$HostVendor"   | sed -e 's/\./_/g' -e 's/-/_/g'`
114     HostOS_CPP=`      echo "$HostOS"       | sed -e 's/\./_/g' -e 's/-/_/g'`
115
116     TargetPlatform="$TargetArch-$TargetVendor-$TargetOS"
117     TargetPlatform_CPP=`echo "$TargetPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'`
118     TargetArch_CPP=`    echo "$TargetArch"     | sed -e 's/\./_/g' -e 's/-/_/g'`
119     TargetVendor_CPP=`  echo "$TargetVendor"   | sed -e 's/\./_/g' -e 's/-/_/g'`
120     TargetOS_CPP=`      echo "$TargetOS"       | sed -e 's/\./_/g' -e 's/-/_/g'`
121
122     echo "GHC build  : $BuildPlatform"
123     echo "GHC host   : $HostPlatform"
124     echo "GHC target : $TargetPlatform"
125
126     AC_SUBST(BuildPlatform)
127     AC_SUBST(HostPlatform)
128     AC_SUBST(TargetPlatform)
129     AC_SUBST(HostPlatform_CPP)
130     AC_SUBST(BuildPlatform_CPP)
131     AC_SUBST(TargetPlatform_CPP)
132
133     AC_SUBST(HostArch_CPP)
134     AC_SUBST(BuildArch_CPP)
135     AC_SUBST(TargetArch_CPP)
136
137     AC_SUBST(HostOS_CPP)
138     AC_SUBST(BuildOS_CPP)
139     AC_SUBST(TargetOS_CPP)
140
141     AC_SUBST(HostVendor_CPP)
142     AC_SUBST(BuildVendor_CPP)
143     AC_SUBST(TargetVendor_CPP)
144
145     AC_SUBST(exeext)
146     AC_SUBST(soext)
147 ])
148
149
150 # FPTOOLS_SET_HASKELL_PLATFORM_VARS
151 # ----------------------------------
152 # Set the Haskell platform variables
153 AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
154 [
155     checkArch() {
156         case [$]1 in
157         i386)
158             test -z "[$]2" || eval "[$]2=ArchX86"
159             ;;
160         x86_64)
161             test -z "[$]2" || eval "[$]2=ArchX86_64"
162             ;;
163         powerpc)
164             test -z "[$]2" || eval "[$]2=ArchPPC"
165             ;;
166         powerpc64)
167             test -z "[$]2" || eval "[$]2=ArchPPC_64"
168             ;;
169         sparc)
170             test -z "[$]2" || eval "[$]2=ArchSPARC"
171             ;;
172         arm)
173             GET_ARM_ISA()
174             test -z "[$]2" || eval "[$]2=\"ArchARM {armISA = \$ARM_ISA, armISAExt = \$ARM_ISA_EXT}\""
175             ;;
176         alpha|mips|mipseb|mipsel|hppa|hppa1_1|ia64|m68k|rs6000|s390|s390x|sparc64|vax)
177             test -z "[$]2" || eval "[$]2=ArchUnknown"
178             ;;
179         *)
180             echo "Unknown arch [$]1"
181             exit 1
182             ;;
183         esac
184     }
185
186     checkVendor() {
187         case [$]1 in
188         dec|unknown|hp|apple|next|sun|sgi|ibm)
189             ;;
190         *)
191             echo "Unknown vendor [$]1"
192             exit 1
193             ;;
194         esac
195     }
196
197     checkOS() {
198         case [$]1 in
199         linux)
200             test -z "[$]2" || eval "[$]2=OSLinux"
201             ;;
202         darwin)
203             test -z "[$]2" || eval "[$]2=OSDarwin"
204             ;;
205         solaris2)
206             test -z "[$]2" || eval "[$]2=OSSolaris2"
207             ;;
208         mingw32)
209             test -z "[$]2" || eval "[$]2=OSMinGW32"
210             ;;
211         freebsd)
212             test -z "[$]2" || eval "[$]2=OSFreeBSD"
213             ;;
214         kfreebsdgnu)
215             test -z "[$]2" || eval "[$]2=OSKFreeBSD"
216             ;;
217         openbsd)
218             test -z "[$]2" || eval "[$]2=OSOpenBSD"
219             ;;
220         netbsd)
221             test -z "[$]2" || eval "[$]2=OSNetBSD"
222             ;;
223         dragonfly|osf1|osf3|hpux|linuxaout|freebsd2|cygwin32|gnu|nextstep2|nextstep3|sunos4|ultrix|irix|aix|haiku)
224             test -z "[$]2" || eval "[$]2=OSUnknown"
225             ;;
226         *)
227             echo "Unknown OS '[$]1'"
228             exit 1
229             ;;
230         esac
231     }
232
233     dnl ** check for Apple-style dead-stripping support
234     dnl    (.subsections-via-symbols assembler directive)
235
236     AC_MSG_CHECKING(for .subsections_via_symbols)
237     AC_COMPILE_IFELSE(
238         [AC_LANG_PROGRAM([], [__asm__ (".subsections_via_symbols");])],
239         [AC_MSG_RESULT(yes)
240          HaskellHaveSubsectionsViaSymbols=True
241          AC_DEFINE([HAVE_SUBSECTIONS_VIA_SYMBOLS],[1],
242                    [Define to 1 if Apple-style dead-stripping is supported.])
243         ],
244         [HaskellHaveSubsectionsViaSymbols=False
245          AC_MSG_RESULT(no)])
246
247     dnl ** check for .ident assembler directive
248
249     AC_MSG_CHECKING(whether your assembler supports .ident directive)
250     AC_COMPILE_IFELSE(
251         [AC_LANG_SOURCE([__asm__ (".ident \"GHC x.y.z\"");])],
252         [AC_MSG_RESULT(yes)
253          HaskellHaveIdentDirective=True],
254         [AC_MSG_RESULT(no)
255          HaskellHaveIdentDirective=False])
256
257     dnl *** check for GNU non-executable stack note support (ELF only)
258     dnl     (.section .note.GNU-stack,"",@progbits)
259
260     dnl This test doesn't work with "gcc -g" in gcc 4.4 (GHC trac #3889:
261     dnl     Error: can't resolve `.note.GNU-stack' {.note.GNU-stack section} - `.Ltext0' {.text section}
262     dnl so we empty CFLAGS while running this test
263     CFLAGS2="$CFLAGS"
264     CFLAGS=
265     AC_MSG_CHECKING(for GNU non-executable stack support)
266     AC_COMPILE_IFELSE(
267         [AC_LANG_PROGRAM([__asm__ (".section .note.GNU-stack,\"\",@progbits");], [0])],
268         [AC_MSG_RESULT(yes)
269          HaskellHaveGnuNonexecStack=True],
270         [AC_MSG_RESULT(no)
271          HaskellHaveGnuNonexecStack=False])
272     CFLAGS="$CFLAGS2"
273
274     checkArch "$BuildArch" ""
275     checkVendor "$BuildVendor"
276     checkOS "$BuildOS" ""
277
278     checkArch "$HostArch" ""
279     checkVendor "$HostVendor"
280     checkOS "$HostOS" ""
281
282     checkArch "$TargetArch" "HaskellTargetArch"
283     checkVendor "$TargetVendor"
284     checkOS "$TargetOS" "HaskellTargetOs"
285
286     AC_SUBST(HaskellTargetArch)
287     AC_SUBST(HaskellTargetOs)
288     AC_SUBST(HaskellHaveSubsectionsViaSymbols)
289     AC_SUBST(HaskellHaveIdentDirective)
290     AC_SUBST(HaskellHaveGnuNonexecStack)
291 ])
292
293
294 # GET_ARM_ISA
295 # ----------------------------------
296 # Get info about the ISA on the Arm arch
297 AC_DEFUN([GET_ARM_ISA],
298 [
299     AC_COMPILE_IFELSE([
300         AC_LANG_PROGRAM(
301             [],
302             [#if defined(__ARM_ARCH_2__)  || \
303                  defined(__ARM_ARCH_3__)  || \
304                  defined(__ARM_ARCH_3M__) || \
305                  defined(__ARM_ARCH_4__)  || \
306                  defined(__ARM_ARCH_4T__) || \
307                  defined(__ARM_ARCH_5__)  || \
308                  defined(__ARM_ARCH_5T__) || \
309                  defined(__ARM_ARCH_5E__) || \
310                  defined(__ARM_ARCH_5TE__)
311                  return 0;
312              #else
313                  not pre arm v6
314              #endif]
315         )],
316         [AC_DEFINE(arm_HOST_ARCH_PRE_ARMv6, 1, [ARM pre v6])
317          AC_DEFINE(arm_HOST_ARCH_PRE_ARMv7, 1, [ARM pre v7])
318          changequote(, )dnl
319          ARM_ISA=ARMv5
320          ARM_ISA_EXT="[]"
321          changequote([, ])dnl
322         ],
323         [
324             AC_COMPILE_IFELSE([
325                 AC_LANG_PROGRAM(
326                     [],
327                     [#if defined(__ARM_ARCH_6__)   || \
328                          defined(__ARM_ARCH_6J__)  || \
329                          defined(__ARM_ARCH_6T2__) || \
330                          defined(__ARM_ARCH_6Z__)  || \
331                          defined(__ARM_ARCH_6ZK__) || \
332                          defined(__ARM_ARCH_6M__)
333                          return 0;
334                      #else
335                          not pre arm v7
336                      #endif]
337                 )],
338                 [AC_DEFINE(arm_HOST_ARCH_PRE_ARMv7, 1, [ARM pre v7])
339                  changequote(, )dnl
340                  ARM_ISA=ARMv6
341                  ARM_ISA_EXT="[]"
342                  changequote([, ])dnl
343                 ],
344                 [changequote(, )dnl
345                  ARM_ISA=ARMv7
346                  ARM_ISA_EXT="[VFPv3,NEON]"
347                  changequote([, ])dnl
348                 ])
349         ])
350 ])
351
352
353 # FP_SETTINGS
354 # ----------------------------------
355 # Set the variables used in the settings file
356 AC_DEFUN([FP_SETTINGS],
357 [
358     if test "$windows" = YES
359     then
360         SettingsCCompilerCommand='$topdir/../mingw/bin/gcc.exe'
361         SettingsCCompilerFlags="$CONF_CC_OPTS_STAGE2 $CONF_GCC_LINKER_OPTS_STAGE2"
362         SettingsArCommand='$topdir/../mingw/bin/ar.exe'
363         SettingsPerlCommand='$topdir/../perl/perl.exe'
364         SettingsDllWrapCommand='$topdir/../mingw/bin/dllwrap.exe'
365         SettingsWindresCommand='$topdir/../mingw/bin/windres.exe'
366         SettingsTouchCommand='$topdir/touchy.exe'
367     else
368         SettingsCCompilerCommand="$WhatGccIsCalled"
369         SettingsCCompilerFlags="$CONF_CC_OPTS_STAGE2 $CONF_GCC_LINKER_OPTS_STAGE2"
370         SettingsArCommand="$ArCmd"
371         SettingsPerlCommand="$PerlCmd"
372         SettingsDllWrapCommand="/bin/false"
373         SettingsWindresCommand="/bin/false"
374         SettingsTouchCommand='touch'
375         if test -z "$LlcCmd"
376         then
377           SettingsLlcCommand="llc"
378         else
379           SettingsLlcCommand="$LlcCmd"
380         fi
381         if test -z "$OptCmd"
382         then
383           SettingsOptCommand="opt"
384         else
385           SettingsOptCommand="$OptCmd"
386         fi
387     fi
388     AC_SUBST(SettingsCCompilerCommand)
389     AC_SUBST(SettingsCCompilerFlags)
390     AC_SUBST(SettingsArCommand)
391     AC_SUBST(SettingsPerlCommand)
392     AC_SUBST(SettingsDllWrapCommand)
393     AC_SUBST(SettingsWindresCommand)
394     AC_SUBST(SettingsTouchCommand)
395     AC_SUBST(SettingsLlcCommand)
396     AC_SUBST(SettingsOptCommand)
397 ])
398
399
400 # FPTOOLS_SET_C_LD_FLAGS
401 # ----------------------------------
402 # Set the C, LD and CPP flags for a given platform
403 # $1 is the platform
404 # $2 is the name of the CC flags variable
405 # $3 is the name of the linker flags variable when linking with gcc
406 # $4 is the name of the linker flags variable when linking with ld
407 # $5 is the name of the CPP flags variable
408 AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS],
409 [
410     AC_MSG_CHECKING([Setting up $2, $3, $4 and $5])
411     case $$1 in
412     i386-apple-darwin)
413         $2="$$2 -m32"
414         $3="$$3 -m32"
415         $4="$$4 -arch i386"
416         $5="$$5 -m32"
417         ;;
418     x86_64-apple-darwin)
419         $2="$$2 -m64"
420         $3="$$3 -m64"
421         $4="$$4 -arch x86_64"
422         $5="$$5 -m64"
423         ;;
424     alpha-*)
425         # For now, to suppress the gcc warning "call-clobbered
426         # register used for global register variable", we simply
427         # disable all warnings altogether using the -w flag. Oh well.
428         $2="$$2 -w -mieee -D_REENTRANT"
429         $3="$$3 -w -mieee -D_REENTRANT"
430         $5="$$5 -w -mieee -D_REENTRANT"
431         ;;
432     hppa*)
433         # ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
434         # (very nice, but too bad the HP /usr/include files don't agree.)
435         $2="$$2 -D_HPUX_SOURCE"
436         $3="$$3 -D_HPUX_SOURCE"
437         $5="$$5 -D_HPUX_SOURCE"
438         ;;
439     esac
440
441     # If gcc knows about the stack protector, turn it off.
442     # Otherwise the stack-smash handler gets triggered.
443     echo 'int main(void) {return 0;}' > conftest.c
444     if $CC -c conftest.c -fno-stack-protector > /dev/null 2>&1
445     then
446         $2="$$2 -fno-stack-protector"
447     fi
448
449     # Reduce memory usage when linking. See trac #5240.
450     if test -n "$LdHashSize31"
451     then
452         $3="$$3 -Wl,$LdHashSize31"
453         $4="$$4     $LdHashSize31"
454     fi
455     if test -n "$LdReduceMemoryOverheads"
456     then
457         $3="$$3 -Wl,$LdReduceMemoryOverheads"
458         $4="$$4     $LdReduceMemoryOverheads"
459     fi
460
461     rm -f conftest.c conftest.o
462     AC_MSG_RESULT([done])
463 ])
464
465
466 # FP_VISIBILITY_HIDDEN
467 # ----------------------------------
468 # Is the visibility hidden attribute supported?
469 AC_DEFUN([FP_VISIBILITY_HIDDEN],
470 [
471     AC_MSG_CHECKING([whether __attribute__((visibility("hidden"))) is supported])
472     echo '__attribute__((visibility("hidden"))) void foo(void) {}' > conftest.c
473     if $CC -Wall -Werror -c conftest.c > /dev/null 2>&1
474     then
475         AC_MSG_RESULT([yes])
476         AC_DEFINE(HAS_VISIBILITY_HIDDEN, 1, [Has visibility hidden])
477     else
478         AC_MSG_RESULT([no])
479     fi
480     rm -f conftest.c conftest.o
481 ])
482
483
484 # FPTOOLS_FLOAT_WORD_ORDER_BIGENDIAN
485 # ----------------------------------
486 # Little endian Arm on Linux with some ABIs has big endian word order
487 # in doubles. Define FLOAT_WORDS_BIGENDIAN if this is the case.
488 AC_DEFUN([FPTOOLS_FLOAT_WORD_ORDER_BIGENDIAN],
489   [AC_CACHE_CHECK([whether float word order is big endian], [fptools_cv_float_word_order_bigendian],
490     [AC_COMPILE_IFELSE(
491       [AC_LANG_PROGRAM(
492         [#include <endian.h>],
493         [#if defined(__FLOAT_WORD_ORDER) && __FLOAT_WORD_ORDER == BIG_ENDIAN
494              return 0;
495          #else
496              not float word order big endian
497          #endif]
498       )],
499       [fptools_cv_float_word_order_bigendian=yes],
500       [fptools_cv_float_word_order_bigendian=no])
501     ])
502   case $fptools_cv_float_word_order_bigendian in
503       yes)
504           AC_DEFINE([FLOAT_WORDS_BIGENDIAN], 1,
505           [Define to 1 if your processor stores words of floats with
506            the most significant byte first]) ;;
507   esac
508 ])
509
510
511 # FP_EVAL_STDERR(COMMAND)
512 # -----------------------
513 # Eval COMMAND, save its stderr (without lines resulting from shell tracing)
514 # into the file conftest.err and the exit status in the variable fp_status.
515 AC_DEFUN([FP_EVAL_STDERR],
516 [{ (eval $1) 2>conftest.er1
517   fp_status=$?
518   grep -v '^ *+' conftest.er1 >conftest.err
519   rm -f conftest.er1
520   (exit $fp_status); }[]dnl
521 ])# FP_EVAL_STDERR
522
523
524 # FP_ARG_WITH_PATH_GNU_PROG
525 # --------------------
526 # XXX
527 #
528 # $1 = the variable to set
529 # $2 = the command to look for
530 #
531 AC_DEFUN([FP_ARG_WITH_PATH_GNU_PROG],
532 [
533 AC_ARG_WITH($2,
534 [AC_HELP_STRING([--with-$2=ARG],
535         [Use ARG as the path to $2 [default=autodetect]])],
536 [
537     if test "$HostOS" = "mingw32"
538     then
539         AC_MSG_WARN([Request to use $withval will be ignored])
540     else
541         $1=$withval
542     fi
543 ],
544 [
545     if test "$HostOS" != "mingw32"
546     then
547         AC_PATH_PROG([$1], [$2])
548         if test -z "$$1"
549         then
550             AC_MSG_ERROR([cannot find $2 in your PATH, no idea how to link])
551         fi
552     fi
553 ]
554 )
555 ]) # FP_ARG_WITH_PATH_GNU_PROG
556
557
558 # FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL
559 # --------------------
560 # XXX
561 #
562 # $1 = the variable to set
563 # $2 = the command to look for
564 #
565 AC_DEFUN([FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL],
566 [
567 AC_ARG_WITH($2,
568 [AC_HELP_STRING([--with-$2=ARG],
569         [Use ARG as the path to $2 [default=autodetect]])],
570 [
571     if test "$HostOS" = "mingw32"
572     then
573         AC_MSG_WARN([Request to use $withval will be ignored])
574     else
575         $1=$withval
576     fi
577 ],
578 [
579     if test "$HostOS" != "mingw32"
580     then
581         AC_PATH_PROG([$1], [$2])
582     fi
583 ]
584 )
585 ]) # FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL
586
587 # FP_PROG_CONTEXT_DIFF
588 # --------------------
589 # Figure out how to do context diffs. Sets the output variable ContextDiffCmd.
590 #
591 # Note: NeXTStep thinks diff'ing a file against itself is "trouble".
592 #
593 # Used by ghc, glafp-utils/ltx, and glafp-utils/runstdtest.
594 AC_DEFUN([FP_PROG_CONTEXT_DIFF],
595 [AC_CACHE_CHECK([for a working context diff], [fp_cv_context_diff],
596 [echo foo > conftest1
597 echo foo > conftest2
598 fp_cv_context_diff=no
599 for fp_var in '-U 1' '-u1' '-C 1' '-c1'
600 do
601   if diff $fp_var conftest1 conftest2 > /dev/null 2>&1; then
602     fp_cv_context_diff="diff $fp_var"
603     break
604   fi
605 done])
606 if test x"$fp_cv_context_diff" = xno; then
607    AC_MSG_ERROR([cannot figure out how to do context diffs])
608 fi
609 AC_SUBST(ContextDiffCmd, [$fp_cv_context_diff])
610 ])# FP_PROG_CONTEXT_DIFF
611
612
613 # FP_COMPUTE_INT(EXPRESSION, VARIABLE, INCLUDES, IF-FAILS)
614 # --------------------------------------------------------
615 # Assign VARIABLE the value of the compile-time EXPRESSION using INCLUDES for
616 # compilation. Execute IF-FAILS when unable to determine the value. Works for
617 # cross-compilation, too.
618 #
619 # Implementation note: We are lazy and use an internal autoconf macro, but it
620 # is supported in autoconf versions 2.50 up to the actual 2.57, so there is
621 # little risk.
622 AC_DEFUN([FP_COMPUTE_INT],
623 [_AC_COMPUTE_INT([$1], [$2], [$3], [$4])[]dnl
624 ])# FP_COMPUTE_INT
625
626
627 # FP_CHECK_ALIGNMENT(TYPE, [IGNORED], [INCLUDES = DEFAULT-INCLUDES])
628 # ------------------------------------------------------------------
629 # A variation of AC_CHECK_SIZEOF for computing the alignment restrictions of a
630 # given type. Defines ALIGNMENT_TYPE.
631 AC_DEFUN([FP_CHECK_ALIGNMENT],
632 [AS_LITERAL_IF(m4_translit([[$1]], [*], [p]), [],
633                [AC_FATAL([$0: requires literal arguments])])[]dnl
634 AC_CHECK_TYPE([$1], [], [], [$3])[]dnl
635 m4_pushdef([fp_Cache], [AS_TR_SH([fp_cv_alignment_$1])])[]dnl
636 AC_CACHE_CHECK([alignment of $1], [fp_Cache],
637 [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
638   FP_COMPUTE_INT([(long) (&((struct { char c; $1 ty; } *)0)->ty)],
639                  [fp_Cache],
640                  [AC_INCLUDES_DEFAULT([$3])],
641                  [AC_MSG_ERROR([cannot compute alignment ($1)
642 See `config.log' for more details.], [77])])
643 else
644   fp_Cache=0
645 fi])[]dnl
646 AC_DEFINE_UNQUOTED(AS_TR_CPP(alignment_$1), $fp_Cache, [The alignment of a `$1'.])[]dnl
647 m4_popdef([fp_Cache])[]dnl
648 ])# FP_CHECK_ALIGNMENT
649
650
651 # FP_LEADING_UNDERSCORE
652 # ---------------------
653 # Test for determining whether symbol names have a leading underscore. We assume
654 # that they _haven't_ if anything goes wrong. Sets the output variable
655 # LeadingUnderscore to YES or NO and defines LEADING_UNDERSCORE correspondingly.
656 #
657 # Some nlist implementations seem to try to be compatible by ignoring a leading
658 # underscore sometimes (eg. FreeBSD). We therefore have to work around this by
659 # checking for *no* leading underscore first. Sigh.  --SDM
660 #
661 # Similarly on OpenBSD, but this test doesn't help. -- dons
662 AC_DEFUN([FP_LEADING_UNDERSCORE],
663 [AC_CHECK_LIB([elf], [nlist], [LIBS="-lelf $LIBS"])
664 AC_CACHE_CHECK([leading underscore in symbol names], [fptools_cv_leading_underscore], [
665 # Hack!: nlist() under Digital UNIX insist on there being an _,
666 # but symbol table listings shows none. What is going on here?!?
667 #
668 # Another hack: cygwin doesn't come with nlist.h , so we hardwire
669 # the underscoredness of that "platform"
670 case $HostPlatform in
671 *openbsd*) # x86 openbsd is ELF from 3.4 >, meaning no leading uscore
672   case $build in
673     i386-*2\.@<:@0-9@:>@ | i386-*3\.@<:@0-3@:>@ ) fptools_cv_leading_underscore=yes ;;
674     *) fptools_cv_leading_underscore=no ;;
675   esac ;;
676 alpha-dec-osf*) fptools_cv_leading_underscore=no;;
677 *cygwin32) fptools_cv_leading_underscore=yes;;
678 *mingw32) fptools_cv_leading_underscore=yes;;
679
680     # HACK: Apple doesn't seem to provide nlist in the 64-bit-libraries
681 x86_64-apple-darwin*) fptools_cv_leading_underscore=yes;;
682
683 *) AC_RUN_IFELSE([AC_LANG_SOURCE([[#ifdef HAVE_NLIST_H
684 #include <nlist.h>
685 struct nlist xYzzY1[] = {{"xYzzY1", 0},{0}};
686 struct nlist xYzzY2[] = {{"_xYzzY2", 0},{0}};
687 #endif
688
689 int main(argc, argv)
690 int argc;
691 char **argv;
692 {
693 #ifdef HAVE_NLIST_H
694     if(nlist(argv[0], xYzzY1) == 0 && xYzzY1[0].n_value != 0)
695         exit(1);
696     if(nlist(argv[0], xYzzY2) == 0 && xYzzY2[0].n_value != 0)
697         exit(0);
698 #endif
699     exit(1);
700 }]])],[fptools_cv_leading_underscore=yes],[fptools_cv_leading_underscore=no],[fptools_cv_leading_underscore=no])
701 ;;
702 esac]);
703 AC_SUBST([LeadingUnderscore], [`echo $fptools_cv_leading_underscore | sed 'y/yesno/YESNO/'`])
704 if test x"$fptools_cv_leading_underscore" = xyes; then
705    AC_DEFINE([LEADING_UNDERSCORE], [1], [Define to 1 if C symbols have a leading underscore added by the compiler.])
706 fi])# FP_LEADING_UNDERSCORE
707
708
709 # FP_COMPARE_VERSIONS(VERSION1, TEST, VERSION2, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
710 # ----------------------------------------------------------------------------------
711 # Compare dotted version numbers VERSION1 and VERSION2 lexicographically according
712 # to TEST (one of -eq, -ne, -lt, -le, -gt, or -ge).
713 AC_DEFUN([FP_COMPARE_VERSIONS],
714 [fp_version1=$1; fp_version2=$3
715 fp_save_IFS=$IFS; IFS='.'
716 while test x"$fp_version1" != x || test x"$fp_version2" != x
717 do
718
719   set dummy $fp_version1; shift
720   fp_num1=""
721   test $[@%:@] = 0 || { fp_num1="[$]1"; shift; }
722   test x"$fp_num1" = x && fp_num1="0"
723   fp_version1="[$]*"
724
725   set dummy $fp_version2; shift
726   fp_num2=""
727   test $[@%:@] = 0 || { fp_num2="[$]1"; shift; }
728   test x"$fp_num2" = x && fp_num2="0"
729   fp_version2="[$]*"
730
731   test "$fp_num1" = "$fp_num2" || break;
732 done
733 IFS=$fp_save_IFS
734 AS_IF([test "$fp_num1" $2 "$fp_num2"], [$4], [$5])[]dnl
735 ])# FP_COMPARE_VERSIONS
736
737
738 dnl
739 dnl Check for GreenCard and version.
740 dnl
741 AC_DEFUN([FPTOOLS_GREENCARD],
742 [
743 AC_PATH_PROG(GreenCardCmd,greencard)
744 AC_CACHE_CHECK([for version of greencard], fptools_cv_greencard_version,
745 changequote(, )dnl
746 [if test x"$GreenCardCmd" != x; then
747    fptools_cv_greencard_version="`$GreenCardCmd --version |
748                           grep 'version' | sed -e 's/greencard. version \([^ ]*\).*/\1/g'`"
749 else
750    fptools_cv_greencard_version=""
751 fi
752 changequote([, ])dnl
753 ])
754 FP_COMPARE_VERSIONS([$fptools_cv_greencard_version],[-lt],[$1],
755   [AC_MSG_ERROR([greencard version $1 or later is required (found '$fptools_cv_greencard_version')])])[]dnl
756 GreenCardVersion=$fptools_cv_greencard_version
757 AC_SUBST(GreenCardVersion)
758 ])
759
760 dnl
761 dnl Check for Happy and version.  If we're building GHC, then we need
762 dnl at least Happy version 1.14.  If there's no installed Happy, we look
763 dnl for a happy source tree and point the build system at that instead.
764 dnl
765 AC_DEFUN([FPTOOLS_HAPPY],
766 [AC_PATH_PROG(HappyCmd,happy,)
767 # Happy is passed to Cabal, so we need a native path
768 if test "x$HostPlatform"  = "xi386-unknown-mingw32" && \
769    test "${OSTYPE}"      != "msys"                  && \
770    test "${HappyCmd}"    != ""
771 then
772     # Canonicalise to <drive>:/path/to/gcc
773     HappyCmd=`cygpath -m "${HappyCmd}"`
774     AC_MSG_NOTICE([normalized happy command to $HappyCmd])
775 fi
776
777 AC_CACHE_CHECK([for version of happy], fptools_cv_happy_version,
778 changequote(, )dnl
779 [if test x"$HappyCmd" != x; then
780    fptools_cv_happy_version=`"$HappyCmd" -v |
781                           grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'` ;
782 else
783    fptools_cv_happy_version="";
784 fi;
785 changequote([, ])dnl
786 ])
787 if test ! -f compiler/parser/Parser.hs || test ! -f compiler/cmm/CmmParse.hs || test ! -f compiler/parser/ParserCore.hs
788 then
789     FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.16],
790       [AC_MSG_ERROR([Happy version 1.16 or later is required to compile GHC.])])[]
791 fi
792 HappyVersion=$fptools_cv_happy_version;
793 AC_SUBST(HappyVersion)
794 ])
795
796 dnl
797 dnl Check for Alex and version.  If we're building GHC, then we need
798 dnl at least Alex version 2.0.1.
799 dnl
800 AC_DEFUN([FPTOOLS_ALEX],
801 [
802 AC_PATH_PROG(AlexCmd,alex,)
803 # Alex is passed to Cabal, so we need a native path
804 if test "x$HostPlatform"  = "xi386-unknown-mingw32" && \
805    test "${OSTYPE}"      != "msys"                  && \
806    test "${AlexCmd}"     != ""
807 then
808     # Canonicalise to <drive>:/path/to/gcc
809     AlexCmd=`cygpath -m "${AlexCmd}"`
810 fi
811
812 AC_CACHE_CHECK([for version of alex], fptools_cv_alex_version,
813 changequote(, )dnl
814 [if test x"$AlexCmd" != x; then
815    fptools_cv_alex_version=`"$AlexCmd" -v |
816                           grep 'Alex [Vv]ersion' | sed -e 's/Alex [Vv]ersion \([0-9\.]*\).*/\1/g'` ;
817 else
818    fptools_cv_alex_version="";
819 fi;
820 changequote([, ])dnl
821 ])
822 if test ! -f compiler/cmm/CmmLex.hs || test ! -f compiler/parser/Lexer.hs
823 then
824     FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-lt],[2.1.0],
825       [AC_MSG_ERROR([Alex version 2.1.0 or later is required to compile GHC.])])[]
826     FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-ge],[3.0],
827       [Alex3=YES],[Alex3=NO])
828 fi
829 AlexVersion=$fptools_cv_alex_version;
830 AC_SUBST(AlexVersion)
831 AC_SUBST(Alex3)
832 ])
833
834
835 # FP_PROG_LD_FLAG
836 # ---------------
837 # Sets the output variable $2 to $1 if ld supports the $1 flag.
838 # Otherwise the variable's value is empty.
839 AC_DEFUN([FP_PROG_LD_FLAG],
840 [
841 AC_CACHE_CHECK([whether ld understands $1], [fp_cv_$2],
842 [echo 'foo() {}' > conftest.c
843 ${CC-cc} -c conftest.c
844 if ${LdCmd} -r $1 -o conftest2.o conftest.o > /dev/null 2>&1; then
845    fp_cv_$2=$1
846 else
847    fp_cv_$2=
848 fi
849 rm -rf conftest*])
850 $2=$fp_cv_$2
851 ])# FP_PROG_LD_FLAG
852
853
854 # FP_PROG_LD_X
855 # ------------
856 # Sets the output variable LdXFlag to -x if ld supports this flag.
857 # Otherwise the variable's value is empty.
858 AC_DEFUN([FP_PROG_LD_X],
859 [
860 FP_PROG_LD_FLAG([-x],[LdXFlag])
861 AC_SUBST([LdXFlag])
862 ])# FP_PROG_LD_X
863
864
865 # FP_PROG_LD_HashSize31
866 # ------------
867 # Sets the output variable LdHashSize31 to --hash-size=31 if ld supports
868 # this flag. Otherwise the variable's value is empty.
869 AC_DEFUN([FP_PROG_LD_HashSize31],
870 [
871 FP_PROG_LD_FLAG([--hash-size=31],[LdHashSize31])
872 ])# FP_PROG_LD_HashSize31
873
874
875 # FP_PROG_LD_ReduceMemoryOverheads
876 # ------------
877 # Sets the output variable LdReduceMemoryOverheads to
878 # --reduce-memory-overheads if ld supports this flag.
879 # Otherwise the variable's value is empty.
880 AC_DEFUN([FP_PROG_LD_ReduceMemoryOverheads],
881 [
882 FP_PROG_LD_FLAG([--reduce-memory-overheads],[LdReduceMemoryOverheads])
883 ])# FP_PROG_LD_ReduceMemoryOverheads
884
885
886 # FP_PROG_LD_BUILD_ID
887 # ------------
888
889 # Sets the output variable LdHasBuildId to YES if ld supports
890 # --build-id, or NO otherwise.
891 AC_DEFUN([FP_PROG_LD_BUILD_ID],
892 [
893 AC_CACHE_CHECK([whether ld understands --build-id], [fp_cv_ld_build_id],
894 [echo 'foo() {}' > conftest.c
895 ${CC-cc} -c conftest.c
896 if ${LdCmd} -r --build-id=none -o conftest2.o conftest.o > /dev/null 2>&1; then
897    fp_cv_ld_build_id=yes
898 else
899    fp_cv_ld_build_id=no
900 fi
901 rm -rf conftest*])
902 if test "$fp_cv_ld_build_id" = yes; then
903   LdHasBuildId=YES
904 else
905   LdHasBuildId=NO
906 fi
907 AC_SUBST([LdHasBuildId])
908 ])# FP_PROG_LD_BUILD_ID
909
910
911 # FP_PROG_LD_IS_GNU
912 # -----------------
913 # Sets the output variable LdIsGNULd to YES or NO, depending on whether it is
914 # GNU ld or not.
915 AC_DEFUN([FP_PROG_LD_IS_GNU],
916 [
917 AC_CACHE_CHECK([whether ld is GNU ld], [fp_cv_gnu_ld],
918 [if ${LdCmd} --version 2> /dev/null | grep "GNU" > /dev/null 2>&1; then
919   fp_cv_gnu_ld=yes
920 else
921   fp_cv_gnu_ld=no
922 fi])
923 AC_SUBST([LdIsGNULd], [`echo $fp_cv_gnu_ld | sed 'y/yesno/YESNO/'`])
924 ])# FP_PROG_LD_IS_GNU
925
926
927 # FP_PROG_LD_NO_COMPACT_UNWIND
928 # ----------------------------
929
930 # Sets the output variable LdHasNoCompactUnwind to YES if ld supports
931 # -no_compact_unwind, or NO otherwise.
932 AC_DEFUN([FP_PROG_LD_NO_COMPACT_UNWIND],
933 [
934 AC_CACHE_CHECK([whether ld understands -no_compact_unwind], [fp_cv_ld_no_compact_unwind],
935 [echo 'foo() {}' > conftest.c
936 ${CC-cc} -c conftest.c
937 if ${LdCmd} -r -no_compact_unwind -o conftest2.o conftest.o > /dev/null 2>&1; then
938    fp_cv_ld_no_compact_unwind=yes
939 else
940    fp_cv_ld_no_compact_unwind=no
941 fi
942 rm -rf conftest*])
943 if test "$fp_cv_ld_no_compact_unwind" = yes; then
944   LdHasNoCompactUnwind=YES
945 else
946   LdHasNoCompactUnwind=NO
947 fi
948 AC_SUBST([LdHasNoCompactUnwind])
949 ])# FP_PROG_LD_NO_COMPACT_UNWIND
950
951
952 # FP_PROG_AR
953 # ----------
954 # Sets fp_prog_ar_raw to the full path of ar and fp_prog_ar to a non-Cygwin
955 # version of it. Exits if no ar can be found
956 AC_DEFUN([FP_PROG_AR],
957 [AC_PATH_PROG([fp_prog_ar_raw], [ar])
958 if test -z "$fp_prog_ar_raw"; then
959   AC_MSG_ERROR([cannot find ar in your PATH, no idea how to make a library])
960 fi
961 fp_prog_ar="$fp_prog_ar_raw"
962 case $HostPlatform in
963   *mingw32) if test x${OSTYPE} != xmsys; then
964               fp_prog_ar="`cygpath -w "${fp_prog_ar_raw}" | sed -e 's@\\\\@/@g'`"
965               AC_MSG_NOTICE([normalized ar command to $fp_prog_ar])
966             fi
967             ;;
968 esac
969 ])# FP_PROG_AR
970
971
972 # FP_PROG_AR_IS_GNU
973 # -----------------
974 # Sets fp_prog_ar_is_gnu to yes or no, depending on whether it is GNU ar or not.
975 AC_DEFUN([FP_PROG_AR_IS_GNU],
976 [AC_REQUIRE([FP_PROG_AR])
977 AC_CACHE_CHECK([whether $fp_prog_ar_raw is GNU ar], [fp_cv_prog_ar_is_gnu],
978 [if "$fp_prog_ar_raw" --version 2> /dev/null | grep "GNU" > /dev/null 2>&1; then
979   fp_cv_prog_ar_is_gnu=yes
980 else
981   fp_cv_prog_ar_is_gnu=no
982 fi])
983 fp_prog_ar_is_gnu=$fp_cv_prog_ar_is_gnu
984 AC_SUBST([ArIsGNUAr], [`echo $fp_prog_ar_is_gnu | tr 'a-z' 'A-Z'`])
985 ])# FP_PROG_AR_IS_GNU
986
987
988 # FP_PROG_AR_SUPPORTS_ATFILE
989 # -----------------
990 # Sets fp_prog_ar_supports_atfile to yes or no, depending on whether
991 # or not it supports the @file syntax
992 AC_DEFUN([FP_PROG_AR_SUPPORTS_ATFILE],
993 [AC_REQUIRE([FP_PROG_AR])
994  AC_REQUIRE([FP_PROG_AR_ARGS])
995 AC_CACHE_CHECK([whether $fp_prog_ar_raw supports @file], [fp_cv_prog_ar_supports_atfile],
996 [
997 rm -f conftest*
998 touch conftest.file
999 echo conftest.file  > conftest.atfile
1000 echo conftest.file >> conftest.atfile
1001 "$fp_prog_ar_raw" $fp_prog_ar_args conftest.a @conftest.atfile > /dev/null 2>&1
1002 fp_prog_ar_supports_atfile_tmp=`"$fp_prog_ar_raw" t conftest.a 2> /dev/null | grep -c conftest.file`
1003 rm -f conftest*
1004 if test "$fp_prog_ar_supports_atfile_tmp" -eq 2
1005 then
1006   fp_cv_prog_ar_supports_atfile=yes
1007 else
1008   fp_cv_prog_ar_supports_atfile=no
1009 fi])
1010 fp_prog_ar_supports_atfile=$fp_cv_prog_ar_supports_atfile
1011 AC_SUBST([ArSupportsAtFile], [`echo $fp_prog_ar_supports_atfile | tr 'a-z' 'A-Z'`])
1012 ])# FP_PROG_AR_SUPPORTS_ATFILE
1013
1014 # FP_PROG_AR_ARGS
1015 # ---------------
1016 # Sets fp_prog_ar_args to the arguments for ar and the output variable ArCmd
1017 # to a non-Cygwin invocation of ar including these arguments.
1018 AC_DEFUN([FP_PROG_AR_ARGS],
1019 [AC_REQUIRE([FP_PROG_AR_IS_GNU])
1020 AC_CACHE_CHECK([for ar arguments], [fp_cv_prog_ar_args],
1021 [
1022 # GNU ar needs special treatment: it appears to have problems with
1023 # object files with the same name if you use the 's' modifier, but
1024 # simple 'ar q' works fine, and doesn't need a separate ranlib.
1025 if test $fp_prog_ar_is_gnu = yes; then
1026   fp_cv_prog_ar_args="q"
1027 else
1028   touch conftest.dummy
1029   for fp_var in clqsZ clqs cqs clq cq ; do
1030      rm -f conftest.a
1031      if "$fp_prog_ar_raw" $fp_var conftest.a conftest.dummy > /dev/null 2> /dev/null; then
1032         fp_cv_prog_ar_args=$fp_var
1033         break
1034      fi
1035   done
1036   rm -f conftest*
1037   if test -z "$fp_cv_prog_ar_args"; then
1038     AC_MSG_ERROR([cannot figure out how to use your $fp_prog_ar_raw])
1039   fi
1040 fi])
1041 fp_prog_ar_args=$fp_cv_prog_ar_args
1042 AC_SUBST([ArCmd], ["$fp_prog_ar"])
1043 AC_SUBST([ArArgs], ["$fp_prog_ar_args"])
1044
1045 ])# FP_PROG_AR_ARGS
1046
1047
1048 # FP_PROG_AR_NEEDS_RANLIB
1049 # -----------------------
1050 # Sets the output variable RANLIB to "ranlib" if it is needed and found,
1051 # to "true" otherwise.
1052 AC_DEFUN([FP_PROG_AR_NEEDS_RANLIB],
1053 [AC_REQUIRE([FP_PROG_AR_IS_GNU])
1054 AC_REQUIRE([FP_PROG_AR_ARGS])
1055 AC_REQUIRE([AC_PROG_CC])
1056 AC_CACHE_CHECK([whether ranlib is needed], [fp_cv_prog_ar_needs_ranlib],
1057 [if test $fp_prog_ar_is_gnu = yes; then
1058   fp_cv_prog_ar_needs_ranlib=no
1059 elif echo $TargetPlatform | grep "^.*-apple-darwin$"  > /dev/null 2> /dev/null; then
1060   # It's quite tedious to check for Apple's crazy timestamps in .a files,
1061   # so we hardcode it.
1062   fp_cv_prog_ar_needs_ranlib=yes
1063 elif echo $fp_prog_ar_args | grep "s" > /dev/null 2> /dev/null; then
1064   fp_cv_prog_ar_needs_ranlib=no
1065 else
1066   fp_cv_prog_ar_needs_ranlib=yes
1067 fi])
1068 if test $fp_cv_prog_ar_needs_ranlib = yes; then
1069    AC_PROG_RANLIB
1070 else
1071   RANLIB="true"
1072   AC_SUBST([RANLIB])
1073 fi
1074 ])# FP_PROG_AR_NEEDS_RANLIB
1075
1076
1077 dnl
1078 dnl AC_SHEBANG_PERL - can we she-bang perl?
1079 dnl
1080 AC_DEFUN([FPTOOLS_SHEBANG_PERL],
1081 [AC_CACHE_CHECK([if your perl works in shell scripts], fptools_cv_shebang_perl,
1082 [echo "#!$PerlCmd"'
1083 exit $1;
1084 ' > conftest
1085 chmod u+x conftest
1086 (SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
1087 if test $? -ne 69; then
1088    fptools_cv_shebang_perl=yes
1089 else
1090    fptools_cv_shebang_perl=no
1091 fi
1092 rm -f conftest
1093 ])])
1094
1095
1096 # FP_GCC_VERSION
1097 # -----------
1098 # Extra testing of the result AC_PROG_CC, testing the gcc version no. Sets the
1099 # output variable GccVersion.
1100 AC_DEFUN([FP_GCC_VERSION],
1101 [AC_REQUIRE([AC_PROG_CC])
1102 if test -z "$GCC"
1103 then
1104   AC_MSG_ERROR([gcc is required])
1105 fi
1106 GccLT34=NO
1107 GccLT46=NO
1108 AC_CACHE_CHECK([version of gcc], [fp_cv_gcc_version],
1109 [
1110     fp_cv_gcc_version="`$CC -v 2>&1 | grep 'version ' | sed -e 's/.*version [[^0-9]]*\([[0-9.]]*\).*/\1/g'`"
1111     FP_COMPARE_VERSIONS([$fp_cv_gcc_version], [-lt], [3.0],
1112                         [AC_MSG_ERROR([Need at least gcc version 3.0 (3.4+ recommended)])])
1113     # See #2770: gcc 2.95 doesn't work any more, apparently.  There probably
1114     # isn't a very good reason for that, but for now just make configure
1115     # fail.
1116     FP_COMPARE_VERSIONS([$fp_cv_gcc_version], [-lt], [3.4], GccLT34=YES)
1117     FP_COMPARE_VERSIONS([$fp_cv_gcc_version], [-lt], [4.6], GccLT46=YES)
1118 ])
1119 AC_SUBST([GccVersion], [$fp_cv_gcc_version])
1120 AC_SUBST(GccLT34)
1121 AC_SUBST(GccLT46)
1122 ])# FP_GCC_VERSION
1123
1124 dnl Check to see if the C compiler uses an LLVM back end
1125 dnl
1126 AC_DEFUN([FP_CC_LLVM_BACKEND],
1127 [AC_REQUIRE([AC_PROG_CC])
1128 AC_MSG_CHECKING([whether C compiler has an LLVM back end])
1129 $CC -x c /dev/null -dM -E > conftest.txt 2>&1
1130 if grep "__llvm__" conftest.txt >/dev/null 2>&1; then
1131   AC_SUBST([CC_LLVM_BACKEND], [1])
1132   AC_MSG_RESULT([yes])
1133 else
1134   AC_SUBST([CC_LLVM_BACKEND], [0])
1135   AC_MSG_RESULT([no])
1136 fi
1137 rm -f conftest.txt
1138 ])
1139
1140 dnl Small feature test for perl version. Assumes PerlCmd
1141 dnl contains path to perl binary.
1142 dnl
1143 dnl (Perl versions prior to v5.6 does not contain the string "v5";
1144 dnl instead they display version strings such as "version 5.005".)
1145 dnl
1146 AC_DEFUN([FPTOOLS_CHECK_PERL_VERSION],
1147 [$PerlCmd -v >conftest.out 2>&1
1148    if grep "v5" conftest.out >/dev/null 2>&1; then
1149       :
1150    else
1151       AC_MSG_ERROR([your version of perl probably won't work, try upgrading it.])
1152    fi
1153 rm -fr conftest*
1154 ])
1155
1156
1157 # FP_CHECK_PROG(VARIABLE, PROG-TO-CHECK-FOR,
1158 #               [VALUE-IF-NOT-FOUND], [PATH], [REJECT])
1159 # -----------------------------------------------------
1160 # HACK: A small wrapper around AC_CHECK_PROG, setting VARIABLE to the full path
1161 # of PROG-TO-CHECK-FOR when found.
1162 AC_DEFUN([FP_CHECK_PROG],
1163 [AC_CHECK_PROG([$1], [$2], [$as_dir/$ac_word$ac_exec_ext], [$3], [$4], [$5])][]dnl
1164 )# FP_CHECK_PROC
1165
1166
1167 # FP_PROG_FIND
1168 # ------------
1169 # Find a non-WinDoze version of the "find" utility.
1170 AC_DEFUN([FP_PROG_FIND],
1171 [AC_PATH_PROGS([fp_prog_find], [gfind find], find)
1172 echo foo > conftest.txt
1173 $fp_prog_find conftest.txt -print > conftest.out 2>&1
1174 if grep '^conftest.txt$' conftest.out > /dev/null 2>&1 ; then
1175   # OK, looks like a real "find".
1176   case $HostPlatform in
1177     *mingw32)
1178       if test x${OSTYPE} != xmsys
1179       then
1180             fp_prog_find="`cygpath --mixed ${fp_prog_find}`"
1181         AC_MSG_NOTICE([normalized find command to $fp_prog_find])
1182       fi ;;
1183     *) ;;
1184   esac
1185   FindCmd="$fp_prog_find"
1186 else
1187   # Found a poor WinDoze version of "find", ignore it.
1188   AC_MSG_WARN([$fp_prog_find looks like a non-*nix find, ignoring it])
1189   FP_CHECK_PROG([FindCmd], [find], [], [], [$fp_prog_find])
1190 fi
1191 rm -f conftest.txt conftest.out
1192 AC_SUBST([FindCmd])[]dnl
1193 ])# FP_PROG_FIND
1194
1195
1196 # FP_PROG_SORT
1197 # ------------
1198 # Find a Unix-like sort
1199 AC_DEFUN([FP_PROG_SORT],
1200 [AC_PATH_PROG([fp_prog_sort], [sort])
1201 echo conwip > conftest.txt
1202 $fp_prog_sort -f conftest.txt > conftest.out 2>&1
1203 if grep 'conwip' conftest.out > /dev/null 2>&1 ; then
1204   # The goods
1205   SortCmd="$fp_prog_sort"
1206 else
1207   # Summink else..pick next one.
1208   AC_MSG_WARN([$fp_prog_sort looks like a non-*nix sort, ignoring it])
1209   FP_CHECK_PROG([SortCmd], [sort], [], [], [$fp_prog_sort])
1210 fi
1211 rm -f conftest.txt conftest.out
1212 AC_SUBST([SortCmd])[]dnl
1213 ])# FP_PROG_SORT
1214
1215 dnl
1216 dnl FPTOOLS_NOCACHE_CHECK prints a message, then sets the
1217 dnl values of the second argument to the result of running
1218 dnl the commands given by the third. It does not cache its
1219 dnl result, so it is suitable for checks which should be
1220 dnl run every time.
1221 dnl
1222 AC_DEFUN([FPTOOLS_NOCACHE_CHECK],
1223 [AC_MSG_CHECKING([$1])
1224  $3
1225  AC_MSG_RESULT([$][$2])
1226 ])
1227
1228 dnl
1229 dnl FPTOOLS_GHC_VERSION(version)
1230 dnl FPTOOLS_GHC_VERSION(major, minor [, patchlevel])
1231 dnl FPTOOLS_GHC_VERSION(version, major, minor, patchlevel)
1232 dnl
1233 dnl Test for version of installed ghc.  Uses $GHC.
1234 dnl [original version pinched from c2hs]
1235 dnl
1236 AC_DEFUN([FPTOOLS_GHC_VERSION],
1237 [FPTOOLS_NOCACHE_CHECK([version of ghc], [fptools_version_of_ghc],
1238 ["${WithGhc-ghc}" --version > conftestghc 2>&1
1239   cat conftestghc >&AS_MESSAGE_LOG_FD
1240 #Useless Use Of cat award...
1241   fptools_version_of_ghc=`cat conftestghc | sed -n -e 's/, patchlevel *\([[0-9]]\)/.\1/;s/.* version \([[0-9]][[0-9.]]*\).*/\1/p'`
1242   rm -fr conftest*
1243   if test "[$]fptools_version_of_ghc" = ""
1244   then
1245     fptools_version_of_ghc='unknown'
1246   fi
1247 fptools_version_of_ghc[_major]=`echo [$]fptools_version_of_ghc | sed -e 's/^\([[0-9]]\).*/\1/'`
1248 fptools_version_of_ghc[_minor]=`echo [$]fptools_version_of_ghc | sed -e 's/^[[0-9]]\.\([[0-9]]*\).*/\1/'`
1249 fptools_version_of_ghc[_pl]=`echo [$]fptools_version_of_ghc | sed -n -e 's/^[[0-9]]\.[[0-9]]*\.\([[0-9]]*\)/\1/p'`
1250 #
1251 if test "[$]fptools_version_of_ghc[_pl]" = ""
1252 then
1253   fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor]"
1254   fptools_version_of_ghc[_pl]="0"
1255 else
1256   fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor].[$]fptools_version_of_ghc[_pl]"
1257 fi
1258 #
1259 ifelse($#, [1], [dnl
1260 [$1]="[$]fptools_version_of_ghc[_all]"
1261 ], $#, [2], [dnl
1262 [$1]="[$]fptools_version_of_ghc[_major]"
1263 [$2]="[$]fptools_version_of_ghc[_minor]"
1264 ], $#, [3], [dnl
1265 [$1]="[$]fptools_version_of_ghc[_major]"
1266 [$2]="[$]fptools_version_of_ghc[_minor]"
1267 [$3]="[$]fptools_version_of_ghc[_pl]"
1268 ], $#, [4], [dnl
1269 [$1]="[$]fptools_version_of_ghc[_all]"
1270 [$2]="[$]fptools_version_of_ghc[_major]"
1271 [$3]="[$]fptools_version_of_ghc[_minor]"
1272 [$4]="[$]fptools_version_of_ghc[_pl]"
1273 ])
1274 ])
1275 ])dnl
1276
1277
1278 # FP_CHECK_FUNC(FUNCTION, PROLOGUE, BODY, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1279 # ---------------------------------------------------------------------------------
1280 # A variant of AC_CHECK_FUNCS, limited to a single FUNCTION, but with the
1281 # additional flexibility of specifying the PROLOGUE and BODY.
1282 AC_DEFUN([FP_CHECK_FUNC],
1283 [AS_VAR_PUSHDEF([fp_func], [fp_cv_func_$1])dnl
1284 AC_CACHE_CHECK([for $1], fp_func,
1285 [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2], [$3])],
1286                 [AS_VAR_SET(fp_func, yes)],
1287                 [AS_VAR_SET(fp_func, no)])])
1288 AS_IF([test AS_VAR_GET(fp_func) = yes],
1289       [AC_DEFINE(AS_TR_CPP(HAVE_$1), [1],
1290                 [Define to 1 if you have the `]$1[' function.]) $4],
1291       [$5])dnl
1292 AS_VAR_POPDEF([fp_func])dnl
1293 ])# FP_CHECK_FUNC
1294
1295
1296 # FP_GEN_DOCBOOK_XML
1297 # ------------------
1298 # Generates a DocBook XML V4.5 document in conftest.xml.
1299 #
1300 # It took a lot of experimentation to find a document that will cause
1301 # xsltproc to fail with an error code when the relevant
1302 # stylesheets/DTDs are not found.  I couldn't make xsltproc fail with
1303 # a single-file document, it seems a multi-file document is needed.
1304 # -- SDM 2009-06-03
1305 #
1306 AC_DEFUN([FP_GEN_DOCBOOK_XML],
1307 [rm -f conftest.xml conftest-book.xml
1308 cat > conftest.xml << EOF
1309 <?xml version="1.0" encoding="iso-8859-1"?>
1310 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
1311    "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [[
1312 <!ENTITY conftest-book SYSTEM "conftest-book.xml">
1313 ]]>
1314 <book id="test">
1315 &conftest-book;
1316 </book>
1317 EOF
1318 cat >conftest-book.xml << EOF
1319 <?xml version="1.0" encoding="iso-8859-1"?>
1320   <title>A DocBook &ldquo;Test Document&rdquo;</title>
1321   <chapter id="id-one">
1322     <title>A Chapter Title</title>
1323     <para>This is a paragraph, referencing <xref linkend="id-two"/>.</para>
1324   </chapter>
1325   <chapter id="id-two">
1326     <title>Another Chapter Title</title>
1327     <para>This is another paragraph, referencing <xref linkend="id-one"/>.</para>
1328   </chapter>
1329 EOF
1330 ]) # FP_GEN_DOCBOOK_XML
1331
1332
1333 # FP_PROG_DBLATEX
1334 # ----------------
1335 # Sets the output variable DblatexCmd to the full path of dblatex,
1336 # which we use for building PDF and PS docs.
1337 # DblatexCmd is empty if dblatex could not be found.
1338 AC_DEFUN([FP_PROG_DBLATEX],
1339 [AC_PATH_PROG([DblatexCmd], [dblatex])
1340 if test -z "$DblatexCmd"; then
1341   AC_MSG_WARN([cannot find dblatex in your PATH, you will not be able to build the PDF and PS documentation])
1342 fi
1343 ])# FP_PROG_DBLATEX
1344
1345
1346 # FP_PROG_XSLTPROC
1347 # ----------------
1348 # Sets the output variable XsltprocCmd to the full path of the XSLT processor
1349 # xsltproc. XsltprocCmd is empty if xsltproc could not be found.
1350 AC_DEFUN([FP_PROG_XSLTPROC],
1351 [AC_PATH_PROG([XsltprocCmd], [xsltproc])
1352 if test -z "$XsltprocCmd"; then
1353   AC_MSG_WARN([cannot find xsltproc in your PATH, you will not be able to build the HTML documentation])
1354 fi
1355 ])# FP_PROG_XSLTPROC
1356
1357
1358 # FP_DOCBOOK_XSL
1359 # ----------------------------
1360 # Check that we can process a DocBook XML document to HTML using xsltproc.
1361 AC_DEFUN([FP_DOCBOOK_XSL],
1362 [AC_REQUIRE([FP_PROG_XSLTPROC])dnl
1363 if test -n "$XsltprocCmd"; then
1364   AC_CACHE_CHECK([for DocBook XSL stylesheet], fp_cv_dir_docbook_xsl,
1365   [FP_GEN_DOCBOOK_XML
1366   fp_cv_dir_docbook_xsl=no
1367   if $XsltprocCmd --nonet http://docbook.sourceforge.net/release/xsl/current/html/chunk.xsl conftest.xml > /dev/null 2>&1; then
1368      fp_cv_dir_docbook_xsl=yes
1369   fi
1370   rm -rf conftest*])
1371 fi
1372 if test x"$fp_cv_dir_docbook_xsl" = xno; then
1373   AC_MSG_WARN([cannot find DocBook XSL stylesheets, you will not be able to build the documentation])
1374   HAVE_DOCBOOK_XSL=NO
1375 else
1376   HAVE_DOCBOOK_XSL=YES
1377 fi
1378 AC_SUBST([HAVE_DOCBOOK_XSL])
1379 ])# FP_DOCBOOK_XSL
1380
1381
1382 # FP_PROG_XMLLINT
1383 # ----------------
1384 # Sets the output variable XmllintCmd to the full path of the XSLT processor
1385 # xmllint. XmllintCmd is empty if xmllint could not be found.
1386 AC_DEFUN([FP_PROG_XMLLINT],
1387 [AC_PATH_PROG([XmllintCmd], [xmllint])
1388 if test -z "$XmllintCmd"; then
1389   AC_MSG_WARN([cannot find xmllint in your PATH, you will not be able to validate your documentation])
1390 fi
1391 ])# FP_PROG_XMLLINT
1392
1393
1394 # FP_CHECK_DOCBOOK_DTD
1395 # --------------------
1396 AC_DEFUN([FP_CHECK_DOCBOOK_DTD],
1397 [AC_REQUIRE([FP_PROG_XMLLINT])dnl
1398 if test -n "$XmllintCmd"; then
1399   AC_MSG_CHECKING([for DocBook DTD])
1400   FP_GEN_DOCBOOK_XML
1401   if $XmllintCmd --nonet --valid --noout conftest.xml ; then
1402     AC_MSG_RESULT([ok])
1403   else
1404     AC_MSG_RESULT([failed])
1405     AC_MSG_WARN([cannot find a DTD for DocBook XML V4.5, you will not be able to validate your documentation])
1406     AC_MSG_WARN([check your XML_CATALOG_FILES environment variable and/or /etc/xml/catalog])
1407   fi
1408   rm -rf conftest*
1409 fi
1410 ])# FP_CHECK_DOCBOOK_DTD
1411
1412
1413 # FP_GEN_FO
1414 # ------------------
1415 # Generates a formatting objects document in conftest.fo.
1416 AC_DEFUN([FP_GEN_FO],
1417 [rm -f conftest.fo
1418 cat > conftest.fo << EOF
1419 <?xml version="1.0"?>
1420 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
1421   <fo:layout-master-set>
1422     <fo:simple-page-master master-name="blank">
1423       <fo:region-body/>
1424     </fo:simple-page-master>
1425   </fo:layout-master-set>
1426   <fo:page-sequence master-reference="blank">
1427     <fo:flow flow-name="xsl-region-body">
1428       <fo:block>
1429         Test!
1430       </fo:block>
1431     </fo:flow>
1432   </fo:page-sequence>
1433 </fo:root>
1434 EOF
1435 ]) # FP_GEN_FO
1436
1437
1438 # FP_PROG_FOP
1439 # -----------
1440 # Set the output variable 'FopCmd' to the first working 'fop' in the current
1441 # 'PATH'. Note that /usr/bin/fop is broken in SuSE 9.1 (unpatched), so try
1442 # /usr/share/fop/fop.sh in that case (or no 'fop'), too.
1443 AC_DEFUN([FP_PROG_FOP],
1444 [AC_PATH_PROGS([FopCmd1], [fop fop.sh])
1445 if test -n "$FopCmd1"; then
1446   AC_CACHE_CHECK([for $FopCmd1 usability], [fp_cv_fop_usability],
1447     [FP_GEN_FO
1448     if "$FopCmd1" -fo conftest.fo -ps conftest.ps > /dev/null 2>&1; then
1449       fp_cv_fop_usability=yes
1450     else
1451       fp_cv_fop_usability=no
1452     fi
1453     rm -rf conftest*])
1454   if test x"$fp_cv_fop_usability" = xyes; then
1455      FopCmd=$FopCmd1
1456   fi
1457 fi
1458 if test -z "$FopCmd"; then
1459   AC_PATH_PROGS([FopCmd2], [fop.sh], , [/usr/share/fop])
1460   FopCmd=$FopCmd2
1461 fi
1462 AC_SUBST([FopCmd])
1463 ])# FP_PROG_FOP
1464
1465
1466 # FP_PROG_GHC_PKG
1467 # ----------------
1468 # Try to find a ghc-pkg matching the ghc mentioned in the environment variable
1469 # WithGhc. Sets the output variable GhcPkgCmd.
1470 AC_DEFUN([FP_PROG_GHC_PKG],
1471 [AC_CACHE_CHECK([for ghc-pkg matching $WithGhc], fp_cv_matching_ghc_pkg,
1472 [
1473 # If we are told to use ghc-stage2, then we're using an in-tree
1474 # compiler. In this case, we just want ghc-pkg, not ghc-pkg-stage2,
1475 # so we sed off -stage[0-9]$. However, if we are told to use
1476 # ghc-6.12.1 then we want to use ghc-pkg-6.12.1, so we keep any
1477 # other suffix.
1478 fp_ghc_pkg_guess=`echo $WithGhc | sed -e 's/-stage@<:@0-9@:>@$//' -e 's,ghc\(@<:@^/\\@:>@*\)$,ghc-pkg\1,'`
1479 if "$fp_ghc_pkg_guess" list > /dev/null 2>&1; then
1480   fp_cv_matching_ghc_pkg=$fp_ghc_pkg_guess
1481 else
1482   AC_MSG_ERROR([Cannot find matching ghc-pkg])
1483 fi])
1484 GhcPkgCmd=$fp_cv_matching_ghc_pkg
1485 AC_SUBST([GhcPkgCmd])
1486 ])# FP_PROG_GHC_PKG
1487
1488
1489 # FP_GCC_EXTRA_FLAGS
1490 # ------------------
1491 # Determine which extra flags we need to pass gcc when we invoke it
1492 # to compile .hc code.
1493 #
1494 # -fwrapv is needed for gcc to emit well-behaved code in the presence of
1495 # integer wrap around. (Trac #952)
1496 #
1497 AC_DEFUN([FP_GCC_EXTRA_FLAGS],
1498 [AC_REQUIRE([FP_GCC_VERSION])
1499 AC_CACHE_CHECK([for extra options to pass gcc when compiling via C], [fp_cv_gcc_extra_opts],
1500 [fp_cv_gcc_extra_opts=
1501  FP_COMPARE_VERSIONS([$fp_cv_gcc_version], [-ge], [3.4],
1502   [fp_cv_gcc_extra_opts="$fp_cv_gcc_extra_opts -fwrapv"],
1503   [])
1504 ])
1505 AC_SUBST([GccExtraViaCOpts],$fp_cv_gcc_extra_opts)
1506 ])
1507
1508
1509 # FP_SETUP_PROJECT_VERSION
1510 # ---------------------
1511 AC_DEFUN([FP_SETUP_PROJECT_VERSION],
1512 [
1513 if test "$RELEASE" = "NO"; then
1514     AC_MSG_CHECKING([for GHC version date])
1515     if test -f VERSION_DATE; then
1516         PACKAGE_VERSION=${PACKAGE_VERSION}.`cat VERSION_DATE`
1517         AC_MSG_RESULT(given $PACKAGE_VERSION)
1518     elif test -d .git; then
1519         changequote(, )dnl
1520         ver_date=`git log -n 1 --date=short --pretty=format:%ci | cut -d ' ' -f 1 | tr -d -`
1521         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
1522         changequote([, ])dnl
1523                 AC_MSG_ERROR([failed to detect version date: check that git is in your path])
1524         fi
1525         PACKAGE_VERSION=${PACKAGE_VERSION}.$ver_date
1526         AC_MSG_RESULT(inferred $PACKAGE_VERSION)
1527     elif test -d _darcs; then
1528         # TODO: Remove this branch after conversion to Git
1529         changequote(, )dnl
1530         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`
1531         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
1532         changequote([, ])dnl
1533                 AC_MSG_ERROR([failed to detect version date: check that darcs is in your path])
1534         fi
1535         PACKAGE_VERSION=${PACKAGE_VERSION}.$ver_date
1536         AC_MSG_RESULT(inferred $PACKAGE_VERSION)
1537     elif test -f VERSION; then
1538         PACKAGE_VERSION=`cat VERSION`
1539         AC_MSG_RESULT(given $PACKAGE_VERSION)
1540     else
1541         AC_MSG_WARN([cannot determine snapshot version: no .git or _darcs directory and no VERSION file])
1542     fi
1543 fi
1544
1545 # Some renamings
1546 AC_SUBST([ProjectName], [$PACKAGE_NAME])
1547 AC_SUBST([ProjectVersion], [$PACKAGE_VERSION])
1548
1549 # Split PACKAGE_VERSION into (possibly empty) parts
1550 VERSION_MAJOR=`echo $PACKAGE_VERSION | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\1'/`
1551 VERSION_TMP=`echo $PACKAGE_VERSION | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\3'/`
1552 VERSION_MINOR=`echo $VERSION_TMP | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\1'/`
1553 ProjectPatchLevel=`echo $VERSION_TMP | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\3'/`
1554
1555 # Calculate project version as an integer, using 2 digits for minor version
1556 case $VERSION_MINOR in
1557   ?) ProjectVersionInt=${VERSION_MAJOR}0${VERSION_MINOR} ;;
1558   ??) ProjectVersionInt=${VERSION_MAJOR}${VERSION_MINOR} ;;
1559   *) AC_MSG_ERROR([bad minor version in $PACKAGE_VERSION]) ;;
1560 esac
1561 AC_SUBST([ProjectVersionInt])
1562
1563 # The project patchlevel is zero unless stated otherwise
1564 test -z "$ProjectPatchLevel" && ProjectPatchLevel=0
1565
1566 # Remove dots from the patch level; this allows us to have versions like 6.4.1.20050508
1567 ProjectPatchLevel=`echo $ProjectPatchLevel | sed 's/\.//'`
1568
1569 AC_SUBST([ProjectPatchLevel])
1570 ])# FP_SETUP_PROJECT_VERSION
1571
1572
1573 # Check for a working timer_create().  We need a pretty detailed check
1574 # here, because there exist partially-working implementations of
1575 # timer_create() in certain versions of Linux (see bug #1933).
1576 #
1577 AC_DEFUN([FP_CHECK_TIMER_CREATE],
1578   [AC_CACHE_CHECK([for a working timer_create(CLOCK_REALTIME)], 
1579     [fptools_cv_timer_create_works],
1580     [AC_TRY_RUN([
1581 #include <stdio.h>
1582 #ifdef HAVE_STDLIB_H
1583 #include <stdlib.h>
1584 #endif
1585 #ifdef HAVE_TIME_H
1586 #include <time.h>
1587 #endif
1588 #ifdef HAVE_SIGNAL_H
1589 #include <signal.h>
1590 #endif
1591 #ifdef HAVE_UNISTD_H
1592 #include <unistd.h>
1593 #endif
1594
1595 static volatile int tock = 0;
1596 static void handler(int i)
1597 {
1598    tock = 1;
1599 }
1600
1601 static void timeout(int i)
1602 {
1603   // timer_settime() has been known to hang, so just in case
1604   // we install a 1-second timeout (see #2257)
1605   exit(99);
1606 }
1607
1608 int main(int argc, char *argv[])
1609 {
1610
1611     struct sigevent ev;
1612     timer_t timer;
1613     struct itimerspec it;
1614     struct sigaction action;
1615     int m,n,count = 0;
1616
1617     ev.sigev_notify = SIGEV_SIGNAL;
1618     ev.sigev_signo  = SIGVTALRM;
1619
1620     action.sa_handler = handler;
1621     action.sa_flags = 0;
1622     sigemptyset(&action.sa_mask);
1623     if (sigaction(SIGVTALRM, &action, NULL) == -1) {
1624         fprintf(stderr,"SIGVTALRM problem\n");
1625         exit(3);
1626     }
1627
1628     action.sa_handler = timeout;
1629     action.sa_flags = 0;
1630     sigemptyset(&action.sa_mask);
1631     if (sigaction(SIGALRM, &action, NULL) == -1) {
1632       fprintf(stderr,"SIGALRM problem\n");
1633       exit(3);
1634     }
1635     alarm(1);
1636
1637     if (timer_create(CLOCK_PROCESS_CPUTIME_ID, &ev, &timer) != 0) {
1638         fprintf(stderr,"No CLOCK_PROCESS_CPUTIME_ID timer\n");
1639        exit(1);
1640     }
1641
1642     it.it_value.tv_sec = 0;
1643     it.it_value.tv_nsec = 1;
1644     it.it_interval = it.it_value;
1645     if (timer_settime(timer, 0, &it, NULL) != 0) {
1646         fprintf(stderr,"settime problem\n");
1647         exit(4);
1648     }
1649
1650     tock = 0;
1651
1652     for(n = 3; n < 20000; n++){
1653         for(m = 2; m <= n/2; m++){
1654             if (!(n%m)) count++;
1655             if (tock) goto out;
1656         }
1657     }
1658 out:
1659
1660     if (!tock) {
1661         fprintf(stderr,"no CLOCK_PROCESS_CPUTIME_ID signal\n");
1662         exit(5);
1663     }
1664
1665     timer_delete(timer);
1666
1667     if (timer_create(CLOCK_REALTIME, &ev, &timer) != 0) {
1668         fprintf(stderr,"No CLOCK_REALTIME timer\n");
1669         exit(2);
1670     }
1671
1672     it.it_value.tv_sec = 0;
1673     it.it_value.tv_nsec = 1000000;
1674     it.it_interval = it.it_value;
1675     if (timer_settime(timer, 0, &it, NULL) != 0) {
1676         fprintf(stderr,"settime problem\n");
1677         exit(4);
1678     }
1679
1680     tock = 0;
1681
1682     usleep(3000);
1683
1684     if (!tock) {
1685         fprintf(stderr,"no CLOCK_REALTIME signal\n");
1686         exit(5);
1687     }
1688
1689     timer_delete(timer);
1690
1691     exit(0);
1692 }
1693      ],
1694      [fptools_cv_timer_create_works=yes],
1695      [fptools_cv_timer_create_works=no])
1696   ])
1697 case $fptools_cv_timer_create_works in
1698     yes) AC_DEFINE([USE_TIMER_CREATE], 1, 
1699                    [Define to 1 if we can use timer_create(CLOCK_PROCESS_CPUTIME_ID,...)]);;
1700 esac
1701 ])
1702
1703 # FP_ICONV
1704 # -------------
1705 AC_DEFUN([FP_ICONV],
1706 [
1707   dnl--------------------------------------------------------------------
1708   dnl * Deal with arguments telling us iconv is somewhere odd
1709   dnl--------------------------------------------------------------------
1710
1711   dnl Note: ICONV_LIB_DIRS and ICONV_INCLUDE_DIRS are not predefined
1712   dnl to the empty string to allow them to be overridden from the
1713   dnl environment.
1714
1715   AC_ARG_WITH([iconv-includes],
1716     [AC_HELP_STRING([--with-iconv-includes],
1717       [directory containing iconv.h])],
1718       [ICONV_INCLUDE_DIRS=$withval])
1719
1720   AC_ARG_WITH([iconv-libraries],
1721     [AC_HELP_STRING([--with-iconv-libraries],
1722       [directory containing iconv library])],
1723       [ICONV_LIB_DIRS=$withval])
1724
1725   AC_SUBST(ICONV_INCLUDE_DIRS)
1726   AC_SUBST(ICONV_LIB_DIRS)
1727 ])# FP_ICONV
1728
1729 # FP_GMP
1730 # -------------
1731 AC_DEFUN([FP_GMP],
1732 [
1733   dnl--------------------------------------------------------------------
1734   dnl * Deal with arguments telling us gmp is somewhere odd
1735   dnl--------------------------------------------------------------------
1736
1737   AC_ARG_WITH([gmp-includes],
1738     [AC_HELP_STRING([--with-gmp-includes],
1739       [directory containing gmp.h])],
1740       [GMP_INCLUDE_DIRS=$withval])
1741
1742   AC_ARG_WITH([gmp-libraries],
1743     [AC_HELP_STRING([--with-gmp-libraries],
1744       [directory containing gmp library])],
1745       [GMP_LIB_DIRS=$withval])
1746
1747   AC_SUBST(GMP_INCLUDE_DIRS)
1748   AC_SUBST(GMP_LIB_DIRS)
1749 ])# FP_GMP
1750
1751 # FP_CHECK_MACOSX_DEPLOYMENT_TARGET
1752 # ---------------------------------
1753 AC_DEFUN([FP_CHECK_MACOSX_DEPLOYMENT_TARGET],
1754 [
1755 if test "x$TargetOS_CPP-$TargetVendor_CPP" = "xdarwin-apple"; then
1756   AC_MSG_CHECKING([Mac OS X deployment target])
1757   case $FP_MACOSX_DEPLOYMENT_TARGET in
1758     none)  ;;
1759     10.4)  MACOSX_DEPLOYMENT_VERSION=10.4
1760            MACOSX_DEPLOYMENT_SDK=/Developer/SDKs/MacOSX10.4u.sdk
1761            ;;
1762     10.4u) MACOSX_DEPLOYMENT_VERSION=10.4
1763            MACOSX_DEPLOYMENT_SDK=/Developer/SDKs/MacOSX10.4u.sdk
1764            ;;
1765     *)     MACOSX_DEPLOYMENT_VERSION=$FP_MACOSX_DEPLOYMENT_TARGET
1766            MACOSX_DEPLOYMENT_SDK=/Developer/SDKs/MacOSX${FP_MACOSX_DEPLOYMENT_TARGET}.sdk
1767            ;;
1768   esac
1769   if test "x$FP_MACOSX_DEPLOYMENT_TARGET" = "xnone"; then
1770     AC_MSG_RESULT(none)
1771   else
1772     if test ! -d $MACOSX_DEPLOYMENT_SDK; then
1773       AC_MSG_ERROR([Unknown deployment target $FP_MACOSX_DEPLOYMENT_TARGET])
1774     fi
1775     AC_MSG_RESULT([${MACOSX_DEPLOYMENT_VERSION} (${MACOSX_DEPLOYMENT_SDK})])
1776   fi
1777 fi
1778 ])
1779
1780 # --------------------------------------------------------------
1781 # Calculate absolute path to build tree
1782 # --------------------------------------------------------------
1783
1784 AC_DEFUN([FP_INTREE_GHC_PWD],[
1785 AC_MSG_NOTICE(Building in-tree ghc-pwd)
1786     dnl This would be
1787     dnl     make -C utils/ghc-pwd clean && make -C utils/ghc-pwd
1788     dnl except we don't want to have to know what make is called. Sigh.
1789     rm -rf utils/ghc-pwd/dist-boot
1790     mkdir  utils/ghc-pwd/dist-boot
1791     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
1792     then
1793         AC_MSG_ERROR([Building ghc-pwd failed])
1794     fi
1795
1796     GHC_PWD=utils/ghc-pwd/dist-boot/ghc-pwd
1797 ])
1798
1799 AC_DEFUN([FP_BINDIST_GHC_PWD],[
1800     GHC_PWD=utils/ghc-pwd/dist-install/build/tmp/ghc-pwd
1801 ])
1802
1803 AC_DEFUN([FP_FIND_ROOT],[
1804 AC_MSG_CHECKING(for path to top of build tree)
1805     hardtop=`$GHC_PWD`
1806
1807     dnl Remove common automounter nonsense
1808     hardtop=`echo $hardtop | sed 's|^/tmp_mnt.*\(/local/.*\)$|\1|' | sed 's|^/tmp_mnt/|/|'`
1809
1810     if ! test -d "$hardtop"; then
1811         AC_MSG_ERROR([cannot determine current directory])
1812     fi
1813
1814     dnl We don't support building in directories with spaces.
1815     case "$hardtop" in
1816     *' '*)
1817         AC_MSG_ERROR([
1818         The build system does not support building in a directory
1819         containing space characters.
1820         Suggestion: move the build tree somewhere else.])
1821         ;;
1822     esac
1823
1824     AC_SUBST(hardtop)
1825
1826     AC_MSG_RESULT($hardtop)
1827 ])
1828
1829 # GHC_CONVERT_CPU(cpu, target_var)
1830 # --------------------------------
1831 # converts cpu from gnu to ghc naming, and assigns the result to $target_var
1832 AC_DEFUN([GHC_CONVERT_CPU],[
1833 case "$1" in
1834   alpha*)
1835     $2="alpha"
1836     ;;
1837   arm*)
1838     $2="arm"
1839     ;;
1840   hppa1.1*)
1841     $2="hppa1_1"
1842     ;;
1843   hppa*)
1844     $2="hppa"
1845     ;;
1846   i386|i486|i586|i686)
1847     $2="i386"
1848     ;;
1849   ia64)
1850     $2="ia64"
1851     ;;
1852   m68k*)
1853     $2="m68k"
1854     ;;
1855   mipseb*)
1856     $2="mipseb"
1857     ;;
1858   mipsel*)
1859     $2="mipsel"
1860     ;;
1861   mips*)
1862     $2="mips"
1863     ;;
1864   powerpc64*)
1865     $2="powerpc64"
1866     ;;
1867   powerpc*)
1868     $2="powerpc"
1869     ;;
1870   rs6000)
1871     $2="rs6000"
1872     ;;
1873   s390x*)
1874     $2="s390x"
1875     ;;
1876   s390*)
1877     $2="s390"
1878     ;;
1879   sparc64*)
1880     $2="sparc64"
1881     ;;
1882   sparc*)
1883     $2="sparc"
1884     ;;
1885   vax)
1886     $2="vax"
1887     ;;
1888   x86_64)
1889     $2="x86_64"
1890     ;;
1891   *)
1892     echo "Unknown CPU $1"
1893     exit 1
1894     ;;
1895   esac
1896 ])
1897
1898 # GHC_CONVERT_VENDOR(vendor, target_var)
1899 # --------------------------------
1900 # converts vendor from gnu to ghc naming, and assigns the result to $target_var
1901 AC_DEFUN([GHC_CONVERT_VENDOR],[
1902   case "$1" in
1903   pc|gentoo) # like i686-pc-linux-gnu and i686-gentoo-freebsd8
1904     $2="unknown"
1905     ;;
1906   softfloat) # like armv5tel-softfloat-linux-gnueabi
1907     $2="unknown"
1908     ;;
1909   *)
1910     #pass thru by default
1911     $2="$1"
1912     ;;
1913   esac
1914 ])
1915
1916 # GHC_CONVERT_OS(os, target_var)
1917 # --------------------------------
1918 # converts os from gnu to ghc naming, and assigns the result to $target_var
1919 AC_DEFUN([GHC_CONVERT_OS],[
1920 case "$1" in
1921   linux-*|linux)
1922     $2="linux"
1923     ;;
1924   # As far as I'm aware, none of these have relevant variants
1925   freebsd|netbsd|openbsd|dragonfly|osf1|osf3|hpux|linuxaout|kfreebsdgnu|freebsd2|solaris2|cygwin32|mingw32|darwin|gnu|nextstep2|nextstep3|sunos4|ultrix|irix|aix|haiku)
1926     $2="$1"
1927     ;;
1928   freebsd8) # like i686-gentoo-freebsd8
1929     $2="freebsd"
1930     ;;
1931   *)
1932     echo "Unknown OS $1"
1933     exit 1
1934     ;;
1935   esac
1936 ])
1937
1938 # BOOTSTRAPPING_GHC_INFO_FIELD
1939 # --------------------------------
1940 # If the bootstrapping compiler is >= 7.1, then set the variable
1941 # $1 to the value of the ghc --info field $2. Otherwise, set it to
1942 # $3.
1943 AC_DEFUN([BOOTSTRAPPING_GHC_INFO_FIELD],[
1944 if test $GhcCanonVersion -ge 701
1945 then
1946     $1=`"$WithGhc" --info | grep "^ ,(\"$2\"," | sed -e 's/.*","//' -e 's/")$//'`
1947     tmp=${$1#\$topdir/}
1948     if test "${$1}" != "$tmp"
1949     then
1950         topdir=`"$WithGhc" --print-libdir | sed 's#\\\\#/#g'`
1951         $1="$topdir/$tmp"
1952     fi
1953 else
1954     $1=$3
1955 fi
1956 AC_SUBST($1)
1957 ])
1958
1959 # LIBRARY_VERSION(lib, [dir])
1960 # --------------------------------
1961 # Gets the version number of a library.
1962 # If $1 is ghc-prim, then we define LIBRARY_ghc_prim_VERSION as 1.2.3
1963 # $2 points to the directory under libraries/
1964 AC_DEFUN([LIBRARY_VERSION],[
1965 dir=m4_default([$2],[$1])
1966 LIBRARY_[]translit([$1], [-], [_])[]_VERSION=`grep -i "^version:" libraries/${dir}/$1.cabal | sed "s/.* //"`
1967 AC_SUBST(LIBRARY_[]translit([$1], [-], [_])[]_VERSION)
1968 ])
1969
1970 # XCODE_VERSION()
1971 # --------------------------------
1972 # Gets the version number of XCode, if on a Mac
1973 AC_DEFUN([XCODE_VERSION],[
1974     if test "$TargetOS_CPP" = "darwin"
1975     then
1976         AC_MSG_CHECKING(XCode version)
1977         XCodeVersion=`xcodebuild -version | grep Xcode | sed "s/Xcode //"`
1978         # Old XCode versions don't actually give the XCode version
1979         if test "$XCodeVersion" = ""
1980         then
1981             AC_MSG_RESULT(not found (too old?))
1982             XCodeVersion1=0
1983             XCodeVersion2=0
1984         else
1985             AC_MSG_RESULT($XCodeVersion)
1986             XCodeVersion1=`echo "$XCodeVersion" | sed 's/\..*//'`
1987             changequote(, )dnl
1988             XCodeVersion2=`echo "$XCodeVersion" | sed 's/[^.]*\.\([^.]*\).*/\1/'`
1989             changequote([, ])dnl
1990             AC_MSG_NOTICE(XCode version component 1: $XCodeVersion1)
1991             AC_MSG_NOTICE(XCode version component 2: $XCodeVersion2)
1992         fi
1993     fi
1994 ])
1995
1996 # FIND_GCC()
1997 # --------------------------------
1998 # Finds where gcc is
1999 AC_DEFUN([FIND_GCC],[
2000     if test "$TargetOS_CPP" = "darwin" &&
2001        test "$XCodeVersion1" -eq 4 &&
2002        test "$XCodeVersion2" -lt 2
2003     then
2004         # In Xcode 4.1, 'gcc-4.2' is the gcc legacy backend (rather
2005         # than the LLVM backend). We prefer the legacy gcc, but in
2006         # Xcode 4.2 'gcc-4.2' was removed.
2007         FP_ARG_WITH_PATH_GNU_PROG([CC], [gcc-4.2])
2008     else
2009         FP_ARG_WITH_PATH_GNU_PROG([CC], [gcc])
2010     fi
2011     export CC
2012     WhatGccIsCalled="$CC"
2013     AC_SUBST(WhatGccIsCalled)
2014 ])
2015
2016 # LocalWords:  fi