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