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