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