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