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