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