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