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