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