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