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