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