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