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