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