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