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