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