fix configure's generation of settings file on ARM platform
[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 {armISA = \$ARM_ISA, armISAExt = \$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_LD_NO_COMPACT_UNWIND
835 # ----------------------------
836
837 # Sets the output variable LdHasNoCompactUnwind to YES if ld supports
838 # -no_compact_unwind, or NO otherwise.
839 AC_DEFUN([FP_PROG_LD_NO_COMPACT_UNWIND],
840 [
841 AC_CACHE_CHECK([whether ld understands -no_compact_unwind], [fp_cv_ld_no_compact_unwind],
842 [echo 'foo() {}' > conftest.c
843 ${CC-cc} -c conftest.c
844 if ${LdCmd} -r -no_compact_unwind -o conftest2.o conftest.o > /dev/null 2>&1; then
845    fp_cv_ld_no_compact_unwind=yes
846 else
847    fp_cv_ld_no_compact_unwind=no
848 fi
849 rm -rf conftest*])
850 if test "$fp_cv_ld_no_compact_unwind" = yes; then
851   LdHasNoCompactUnwind=YES
852 else
853   LdHasNoCompactUnwind=NO
854 fi
855 AC_SUBST([LdHasNoCompactUnwind])
856 ])# FP_PROG_LD_NO_COMPACT_UNWIND
857
858
859 # FP_PROG_AR
860 # ----------
861 # Sets fp_prog_ar_raw to the full path of ar and fp_prog_ar to a non-Cygwin
862 # version of it. Exits if no ar can be found
863 AC_DEFUN([FP_PROG_AR],
864 [AC_PATH_PROG([fp_prog_ar_raw], [ar])
865 if test -z "$fp_prog_ar_raw"; then
866   AC_MSG_ERROR([cannot find ar in your PATH, no idea how to make a library])
867 fi
868 fp_prog_ar="$fp_prog_ar_raw"
869 case $HostPlatform in
870   *mingw32) if test x${OSTYPE} != xmsys; then
871               fp_prog_ar="`cygpath -w "${fp_prog_ar_raw}" | sed -e 's@\\\\@/@g'`"
872               AC_MSG_NOTICE([normalized ar command to $fp_prog_ar])
873             fi
874             ;;
875 esac
876 ])# FP_PROG_AR
877
878
879 # FP_PROG_AR_IS_GNU
880 # -----------------
881 # Sets fp_prog_ar_is_gnu to yes or no, depending on whether it is GNU ar or not.
882 AC_DEFUN([FP_PROG_AR_IS_GNU],
883 [AC_REQUIRE([FP_PROG_AR])
884 AC_CACHE_CHECK([whether $fp_prog_ar_raw is GNU ar], [fp_cv_prog_ar_is_gnu],
885 [if "$fp_prog_ar_raw" --version 2> /dev/null | grep "GNU" > /dev/null 2>&1; then
886   fp_cv_prog_ar_is_gnu=yes
887 else
888   fp_cv_prog_ar_is_gnu=no
889 fi])
890 fp_prog_ar_is_gnu=$fp_cv_prog_ar_is_gnu
891 AC_SUBST([ArIsGNUAr], [`echo $fp_prog_ar_is_gnu | tr 'a-z' 'A-Z'`])
892 ])# FP_PROG_AR_IS_GNU
893
894
895 # FP_PROG_AR_SUPPORTS_ATFILE
896 # -----------------
897 # Sets fp_prog_ar_supports_atfile to yes or no, depending on whether
898 # or not it supports the @file syntax
899 AC_DEFUN([FP_PROG_AR_SUPPORTS_ATFILE],
900 [AC_REQUIRE([FP_PROG_AR])
901  AC_REQUIRE([FP_PROG_AR_ARGS])
902 AC_CACHE_CHECK([whether $fp_prog_ar_raw supports @file], [fp_cv_prog_ar_supports_atfile],
903 [
904 rm -f conftest*
905 touch conftest.file
906 echo conftest.file  > conftest.atfile
907 echo conftest.file >> conftest.atfile
908 "$fp_prog_ar_raw" $fp_prog_ar_args conftest.a @conftest.atfile > /dev/null 2>&1
909 fp_prog_ar_supports_atfile_tmp=`"$fp_prog_ar_raw" t conftest.a 2> /dev/null | grep -c conftest.file`
910 rm -f conftest*
911 if test "$fp_prog_ar_supports_atfile_tmp" -eq 2
912 then
913   fp_cv_prog_ar_supports_atfile=yes
914 else
915   fp_cv_prog_ar_supports_atfile=no
916 fi])
917 fp_prog_ar_supports_atfile=$fp_cv_prog_ar_supports_atfile
918 AC_SUBST([ArSupportsAtFile], [`echo $fp_prog_ar_supports_atfile | tr 'a-z' 'A-Z'`])
919 ])# FP_PROG_AR_SUPPORTS_ATFILE
920
921 # FP_PROG_AR_ARGS
922 # ---------------
923 # Sets fp_prog_ar_args to the arguments for ar and the output variable ArCmd
924 # to a non-Cygwin invocation of ar including these arguments.
925 AC_DEFUN([FP_PROG_AR_ARGS],
926 [AC_REQUIRE([FP_PROG_AR_IS_GNU])
927 AC_CACHE_CHECK([for ar arguments], [fp_cv_prog_ar_args],
928 [
929 # GNU ar needs special treatment: it appears to have problems with
930 # object files with the same name if you use the 's' modifier, but
931 # simple 'ar q' works fine, and doesn't need a separate ranlib.
932 if test $fp_prog_ar_is_gnu = yes; then
933   fp_cv_prog_ar_args="q"
934 else
935   touch conftest.dummy
936   for fp_var in clqsZ clqs cqs clq cq ; do
937      rm -f conftest.a
938      if "$fp_prog_ar_raw" $fp_var conftest.a conftest.dummy > /dev/null 2> /dev/null; then
939         fp_cv_prog_ar_args=$fp_var
940         break
941      fi
942   done
943   rm -f conftest*
944   if test -z "$fp_cv_prog_ar_args"; then
945     AC_MSG_ERROR([cannot figure out how to use your $fp_prog_ar_raw])
946   fi
947 fi])
948 fp_prog_ar_args=$fp_cv_prog_ar_args
949 AC_SUBST([ArCmd], ["$fp_prog_ar"])
950 AC_SUBST([ArArgs], ["$fp_prog_ar_args"])
951
952 ])# FP_PROG_AR_ARGS
953
954
955 # FP_PROG_AR_NEEDS_RANLIB
956 # -----------------------
957 # Sets the output variable RANLIB to "ranlib" if it is needed and found,
958 # to "true" otherwise.
959 AC_DEFUN([FP_PROG_AR_NEEDS_RANLIB],
960 [AC_REQUIRE([FP_PROG_AR_IS_GNU])
961 AC_REQUIRE([FP_PROG_AR_ARGS])
962 AC_REQUIRE([AC_PROG_CC])
963 AC_CACHE_CHECK([whether ranlib is needed], [fp_cv_prog_ar_needs_ranlib],
964 [if test $fp_prog_ar_is_gnu = yes; then
965   fp_cv_prog_ar_needs_ranlib=no
966 elif echo $TargetPlatform | grep "^.*-apple-darwin$"  > /dev/null 2> /dev/null; then
967   # It's quite tedious to check for Apple's crazy timestamps in .a files,
968   # so we hardcode it.
969   fp_cv_prog_ar_needs_ranlib=yes
970 elif echo $fp_prog_ar_args | grep "s" > /dev/null 2> /dev/null; then
971   fp_cv_prog_ar_needs_ranlib=no
972 else
973   fp_cv_prog_ar_needs_ranlib=yes
974 fi])
975 if test $fp_cv_prog_ar_needs_ranlib = yes; then
976    AC_PROG_RANLIB
977 else
978   RANLIB="true"
979   AC_SUBST([RANLIB])
980 fi
981 ])# FP_PROG_AR_NEEDS_RANLIB
982
983
984 dnl
985 dnl AC_SHEBANG_PERL - can we she-bang perl?
986 dnl
987 AC_DEFUN([FPTOOLS_SHEBANG_PERL],
988 [AC_CACHE_CHECK([if your perl works in shell scripts], fptools_cv_shebang_perl,
989 [echo "#!$PerlCmd"'
990 exit $1;
991 ' > conftest
992 chmod u+x conftest
993 (SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
994 if test $? -ne 69; then
995    fptools_cv_shebang_perl=yes
996 else
997    fptools_cv_shebang_perl=no
998 fi
999 rm -f conftest
1000 ])])
1001
1002
1003 # FP_GCC_VERSION
1004 # -----------
1005 # Extra testing of the result AC_PROG_CC, testing the gcc version no. Sets the
1006 # output variable GccVersion.
1007 AC_DEFUN([FP_GCC_VERSION],
1008 [AC_REQUIRE([AC_PROG_CC])
1009 if test -z "$GCC"
1010 then
1011   AC_MSG_ERROR([gcc is required])
1012 fi
1013 GccLT34=NO
1014 GccLT46=NO
1015 AC_CACHE_CHECK([version of gcc], [fp_cv_gcc_version],
1016 [
1017     fp_cv_gcc_version="`$CC -v 2>&1 | grep 'version ' | sed -e 's/.*version [[^0-9]]*\([[0-9.]]*\).*/\1/g'`"
1018     FP_COMPARE_VERSIONS([$fp_cv_gcc_version], [-lt], [3.0],
1019                         [AC_MSG_ERROR([Need at least gcc version 3.0 (3.4+ recommended)])])
1020     # See #2770: gcc 2.95 doesn't work any more, apparently.  There probably
1021     # isn't a very good reason for that, but for now just make configure
1022     # fail.
1023     FP_COMPARE_VERSIONS([$fp_cv_gcc_version], [-lt], [3.4], GccLT34=YES)
1024     FP_COMPARE_VERSIONS([$fp_cv_gcc_version], [-lt], [4.6], GccLT46=YES)
1025 ])
1026 AC_SUBST([GccVersion], [$fp_cv_gcc_version])
1027 AC_SUBST(GccLT34)
1028 AC_SUBST(GccLT46)
1029 ])# FP_GCC_VERSION
1030
1031 dnl Small feature test for perl version. Assumes PerlCmd
1032 dnl contains path to perl binary.
1033 dnl
1034 dnl (Perl versions prior to v5.6 does not contain the string "v5";
1035 dnl instead they display version strings such as "version 5.005".)
1036 dnl
1037 AC_DEFUN([FPTOOLS_CHECK_PERL_VERSION],
1038 [$PerlCmd -v >conftest.out 2>&1
1039    if grep "v5" conftest.out >/dev/null 2>&1; then
1040       :
1041    else
1042       AC_MSG_ERROR([your version of perl probably won't work, try upgrading it.])
1043    fi
1044 rm -fr conftest*
1045 ])
1046
1047
1048 # FP_CHECK_PROG(VARIABLE, PROG-TO-CHECK-FOR,
1049 #               [VALUE-IF-NOT-FOUND], [PATH], [REJECT])
1050 # -----------------------------------------------------
1051 # HACK: A small wrapper around AC_CHECK_PROG, setting VARIABLE to the full path
1052 # of PROG-TO-CHECK-FOR when found.
1053 AC_DEFUN([FP_CHECK_PROG],
1054 [AC_CHECK_PROG([$1], [$2], [$as_dir/$ac_word$ac_exec_ext], [$3], [$4], [$5])][]dnl
1055 )# FP_CHECK_PROC
1056
1057
1058 # FP_PROG_FIND
1059 # ------------
1060 # Find a non-WinDoze version of the "find" utility.
1061 AC_DEFUN([FP_PROG_FIND],
1062 [AC_PATH_PROGS([fp_prog_find], [gfind find], find)
1063 echo foo > conftest.txt
1064 $fp_prog_find conftest.txt -print > conftest.out 2>&1
1065 if grep '^conftest.txt$' conftest.out > /dev/null 2>&1 ; then
1066   # OK, looks like a real "find".
1067   case $HostPlatform in
1068     *mingw32)
1069       if test x${OSTYPE} != xmsys
1070       then
1071             fp_prog_find="`cygpath --mixed ${fp_prog_find}`"
1072         AC_MSG_NOTICE([normalized find command to $fp_prog_find])
1073       fi ;;
1074     *) ;;
1075   esac
1076   FindCmd="$fp_prog_find"
1077 else
1078   # Found a poor WinDoze version of "find", ignore it.
1079   AC_MSG_WARN([$fp_prog_find looks like a non-*nix find, ignoring it])
1080   FP_CHECK_PROG([FindCmd], [find], [], [], [$fp_prog_find])
1081 fi
1082 rm -f conftest.txt conftest.out
1083 AC_SUBST([FindCmd])[]dnl
1084 ])# FP_PROG_FIND
1085
1086
1087 # FP_PROG_SORT
1088 # ------------
1089 # Find a Unix-like sort
1090 AC_DEFUN([FP_PROG_SORT],
1091 [AC_PATH_PROG([fp_prog_sort], [sort])
1092 echo conwip > conftest.txt
1093 $fp_prog_sort -f conftest.txt > conftest.out 2>&1
1094 if grep 'conwip' conftest.out > /dev/null 2>&1 ; then
1095   # The goods
1096   SortCmd="$fp_prog_sort"
1097 else
1098   # Summink else..pick next one.
1099   AC_MSG_WARN([$fp_prog_sort looks like a non-*nix sort, ignoring it])
1100   FP_CHECK_PROG([SortCmd], [sort], [], [], [$fp_prog_sort])
1101 fi
1102 rm -f conftest.txt conftest.out
1103 AC_SUBST([SortCmd])[]dnl
1104 ])# FP_PROG_SORT
1105
1106 dnl
1107 dnl FPTOOLS_NOCACHE_CHECK prints a message, then sets the
1108 dnl values of the second argument to the result of running
1109 dnl the commands given by the third. It does not cache its
1110 dnl result, so it is suitable for checks which should be
1111 dnl run every time.
1112 dnl
1113 AC_DEFUN([FPTOOLS_NOCACHE_CHECK],
1114 [AC_MSG_CHECKING([$1])
1115  $3
1116  AC_MSG_RESULT([$][$2])
1117 ])
1118
1119 dnl
1120 dnl FPTOOLS_GHC_VERSION(version)
1121 dnl FPTOOLS_GHC_VERSION(major, minor [, patchlevel])
1122 dnl FPTOOLS_GHC_VERSION(version, major, minor, patchlevel)
1123 dnl
1124 dnl Test for version of installed ghc.  Uses $GHC.
1125 dnl [original version pinched from c2hs]
1126 dnl
1127 AC_DEFUN([FPTOOLS_GHC_VERSION],
1128 [FPTOOLS_NOCACHE_CHECK([version of ghc], [fptools_version_of_ghc],
1129 ["${WithGhc-ghc}" --version > conftestghc 2>&1
1130   cat conftestghc >&AS_MESSAGE_LOG_FD
1131 #Useless Use Of cat award...
1132   fptools_version_of_ghc=`cat conftestghc | sed -n -e 's/, patchlevel *\([[0-9]]\)/.\1/;s/.* version \([[0-9]][[0-9.]]*\).*/\1/p'`
1133   rm -fr conftest*
1134   if test "[$]fptools_version_of_ghc" = ""
1135   then
1136     fptools_version_of_ghc='unknown'
1137   fi
1138 fptools_version_of_ghc[_major]=`echo [$]fptools_version_of_ghc | sed -e 's/^\([[0-9]]\).*/\1/'`
1139 fptools_version_of_ghc[_minor]=`echo [$]fptools_version_of_ghc | sed -e 's/^[[0-9]]\.\([[0-9]]*\).*/\1/'`
1140 fptools_version_of_ghc[_pl]=`echo [$]fptools_version_of_ghc | sed -n -e 's/^[[0-9]]\.[[0-9]]*\.\([[0-9]]*\)/\1/p'`
1141 #
1142 if test "[$]fptools_version_of_ghc[_pl]" = ""
1143 then
1144   fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor]"
1145   fptools_version_of_ghc[_pl]="0"
1146 else
1147   fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor].[$]fptools_version_of_ghc[_pl]"
1148 fi
1149 #
1150 ifelse($#, [1], [dnl
1151 [$1]="[$]fptools_version_of_ghc[_all]"
1152 ], $#, [2], [dnl
1153 [$1]="[$]fptools_version_of_ghc[_major]"
1154 [$2]="[$]fptools_version_of_ghc[_minor]"
1155 ], $#, [3], [dnl
1156 [$1]="[$]fptools_version_of_ghc[_major]"
1157 [$2]="[$]fptools_version_of_ghc[_minor]"
1158 [$3]="[$]fptools_version_of_ghc[_pl]"
1159 ], $#, [4], [dnl
1160 [$1]="[$]fptools_version_of_ghc[_all]"
1161 [$2]="[$]fptools_version_of_ghc[_major]"
1162 [$3]="[$]fptools_version_of_ghc[_minor]"
1163 [$4]="[$]fptools_version_of_ghc[_pl]"
1164 ])
1165 ])
1166 ])dnl
1167
1168
1169 # FP_CHECK_FUNC(FUNCTION, PROLOGUE, BODY, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1170 # ---------------------------------------------------------------------------------
1171 # A variant of AC_CHECK_FUNCS, limited to a single FUNCTION, but with the
1172 # additional flexibility of specifying the PROLOGUE and BODY.
1173 AC_DEFUN([FP_CHECK_FUNC],
1174 [AS_VAR_PUSHDEF([fp_func], [fp_cv_func_$1])dnl
1175 AC_CACHE_CHECK([for $1], fp_func,
1176 [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2], [$3])],
1177                 [AS_VAR_SET(fp_func, yes)],
1178                 [AS_VAR_SET(fp_func, no)])])
1179 AS_IF([test AS_VAR_GET(fp_func) = yes],
1180       [AC_DEFINE(AS_TR_CPP(HAVE_$1), [1],
1181                 [Define to 1 if you have the `]$1[' function.]) $4],
1182       [$5])dnl
1183 AS_VAR_POPDEF([fp_func])dnl
1184 ])# FP_CHECK_FUNC
1185
1186
1187 # FP_GEN_DOCBOOK_XML
1188 # ------------------
1189 # Generates a DocBook XML V4.5 document in conftest.xml.
1190 #
1191 # It took a lot of experimentation to find a document that will cause
1192 # xsltproc to fail with an error code when the relevant
1193 # stylesheets/DTDs are not found.  I couldn't make xsltproc fail with
1194 # a single-file document, it seems a multi-file document is needed.
1195 # -- SDM 2009-06-03
1196 #
1197 AC_DEFUN([FP_GEN_DOCBOOK_XML],
1198 [rm -f conftest.xml conftest-book.xml
1199 cat > conftest.xml << EOF
1200 <?xml version="1.0" encoding="iso-8859-1"?>
1201 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
1202    "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [[
1203 <!ENTITY conftest-book SYSTEM "conftest-book.xml">
1204 ]]>
1205 <book id="test">
1206 &conftest-book;
1207 </book>
1208 EOF
1209 cat >conftest-book.xml << EOF
1210 <?xml version="1.0" encoding="iso-8859-1"?>
1211   <title>A DocBook &ldquo;Test Document&rdquo;</title>
1212   <chapter id="id-one">
1213     <title>A Chapter Title</title>
1214     <para>This is a paragraph, referencing <xref linkend="id-two"/>.</para>
1215   </chapter>
1216   <chapter id="id-two">
1217     <title>Another Chapter Title</title>
1218     <para>This is another paragraph, referencing <xref linkend="id-one"/>.</para>
1219   </chapter>
1220 EOF
1221 ]) # FP_GEN_DOCBOOK_XML
1222
1223
1224 # FP_PROG_DBLATEX
1225 # ----------------
1226 # Sets the output variable DblatexCmd to the full path of dblatex,
1227 # which we use for building PDF and PS docs.
1228 # DblatexCmd is empty if dblatex could not be found.
1229 AC_DEFUN([FP_PROG_DBLATEX],
1230 [AC_PATH_PROG([DblatexCmd], [dblatex])
1231 if test -z "$DblatexCmd"; then
1232   AC_MSG_WARN([cannot find dblatex in your PATH, you will not be able to build the PDF and PS documentation])
1233 fi
1234 ])# FP_PROG_DBLATEX
1235
1236
1237 # FP_PROG_XSLTPROC
1238 # ----------------
1239 # Sets the output variable XsltprocCmd to the full path of the XSLT processor
1240 # xsltproc. XsltprocCmd is empty if xsltproc could not be found.
1241 AC_DEFUN([FP_PROG_XSLTPROC],
1242 [AC_PATH_PROG([XsltprocCmd], [xsltproc])
1243 if test -z "$XsltprocCmd"; then
1244   AC_MSG_WARN([cannot find xsltproc in your PATH, you will not be able to build the HTML documentation])
1245 fi
1246 ])# FP_PROG_XSLTPROC
1247
1248
1249 # FP_DOCBOOK_XSL
1250 # ----------------------------
1251 # Check that we can process a DocBook XML document to HTML using xsltproc.
1252 AC_DEFUN([FP_DOCBOOK_XSL],
1253 [AC_REQUIRE([FP_PROG_XSLTPROC])dnl
1254 if test -n "$XsltprocCmd"; then
1255   AC_CACHE_CHECK([for DocBook XSL stylesheet], fp_cv_dir_docbook_xsl,
1256   [FP_GEN_DOCBOOK_XML
1257   fp_cv_dir_docbook_xsl=no
1258   if $XsltprocCmd --nonet http://docbook.sourceforge.net/release/xsl/current/html/chunk.xsl conftest.xml > /dev/null 2>&1; then
1259      fp_cv_dir_docbook_xsl=yes
1260   fi
1261   rm -rf conftest*])
1262 fi
1263 if test x"$fp_cv_dir_docbook_xsl" = xno; then
1264   AC_MSG_WARN([cannot find DocBook XSL stylesheets, you will not be able to build the documentation])
1265   HAVE_DOCBOOK_XSL=NO
1266 else
1267   HAVE_DOCBOOK_XSL=YES
1268 fi
1269 AC_SUBST([HAVE_DOCBOOK_XSL])
1270 ])# FP_DOCBOOK_XSL
1271
1272
1273 # FP_PROG_XMLLINT
1274 # ----------------
1275 # Sets the output variable XmllintCmd to the full path of the XSLT processor
1276 # xmllint. XmllintCmd is empty if xmllint could not be found.
1277 AC_DEFUN([FP_PROG_XMLLINT],
1278 [AC_PATH_PROG([XmllintCmd], [xmllint])
1279 if test -z "$XmllintCmd"; then
1280   AC_MSG_WARN([cannot find xmllint in your PATH, you will not be able to validate your documentation])
1281 fi
1282 ])# FP_PROG_XMLLINT
1283
1284
1285 # FP_CHECK_DOCBOOK_DTD
1286 # --------------------
1287 AC_DEFUN([FP_CHECK_DOCBOOK_DTD],
1288 [AC_REQUIRE([FP_PROG_XMLLINT])dnl
1289 if test -n "$XmllintCmd"; then
1290   AC_MSG_CHECKING([for DocBook DTD])
1291   FP_GEN_DOCBOOK_XML
1292   if $XmllintCmd --nonet --valid --noout conftest.xml ; then
1293     AC_MSG_RESULT([ok])
1294   else
1295     AC_MSG_RESULT([failed])
1296     AC_MSG_WARN([cannot find a DTD for DocBook XML V4.5, you will not be able to validate your documentation])
1297     AC_MSG_WARN([check your XML_CATALOG_FILES environment variable and/or /etc/xml/catalog])
1298   fi
1299   rm -rf conftest*
1300 fi
1301 ])# FP_CHECK_DOCBOOK_DTD
1302
1303
1304 # FP_GEN_FO
1305 # ------------------
1306 # Generates a formatting objects document in conftest.fo.
1307 AC_DEFUN([FP_GEN_FO],
1308 [rm -f conftest.fo
1309 cat > conftest.fo << EOF
1310 <?xml version="1.0"?>
1311 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
1312   <fo:layout-master-set>
1313     <fo:simple-page-master master-name="blank">
1314       <fo:region-body/>
1315     </fo:simple-page-master>
1316   </fo:layout-master-set>
1317   <fo:page-sequence master-reference="blank">
1318     <fo:flow flow-name="xsl-region-body">
1319       <fo:block>
1320         Test!
1321       </fo:block>
1322     </fo:flow>
1323   </fo:page-sequence>
1324 </fo:root>
1325 EOF
1326 ]) # FP_GEN_FO
1327
1328
1329 # FP_PROG_FOP
1330 # -----------
1331 # Set the output variable 'FopCmd' to the first working 'fop' in the current
1332 # 'PATH'. Note that /usr/bin/fop is broken in SuSE 9.1 (unpatched), so try
1333 # /usr/share/fop/fop.sh in that case (or no 'fop'), too.
1334 AC_DEFUN([FP_PROG_FOP],
1335 [AC_PATH_PROGS([FopCmd1], [fop fop.sh])
1336 if test -n "$FopCmd1"; then
1337   AC_CACHE_CHECK([for $FopCmd1 usability], [fp_cv_fop_usability],
1338     [FP_GEN_FO
1339     if "$FopCmd1" -fo conftest.fo -ps conftest.ps > /dev/null 2>&1; then
1340       fp_cv_fop_usability=yes
1341     else
1342       fp_cv_fop_usability=no
1343     fi
1344     rm -rf conftest*])
1345   if test x"$fp_cv_fop_usability" = xyes; then
1346      FopCmd=$FopCmd1
1347   fi
1348 fi
1349 if test -z "$FopCmd"; then
1350   AC_PATH_PROGS([FopCmd2], [fop.sh], , [/usr/share/fop])
1351   FopCmd=$FopCmd2
1352 fi
1353 AC_SUBST([FopCmd])
1354 ])# FP_PROG_FOP
1355
1356
1357 # FP_PROG_GHC_PKG
1358 # ----------------
1359 # Try to find a ghc-pkg matching the ghc mentioned in the environment variable
1360 # WithGhc. Sets the output variable GhcPkgCmd.
1361 AC_DEFUN([FP_PROG_GHC_PKG],
1362 [AC_CACHE_CHECK([for ghc-pkg matching $WithGhc], fp_cv_matching_ghc_pkg,
1363 [
1364 # If we are told to use ghc-stage2, then we're using an in-tree
1365 # compiler. In this case, we just want ghc-pkg, not ghc-pkg-stage2,
1366 # so we sed off -stage[0-9]$. However, if we are told to use
1367 # ghc-6.12.1 then we want to use ghc-pkg-6.12.1, so we keep any
1368 # other suffix.
1369 fp_ghc_pkg_guess=`echo $WithGhc | sed -e 's/-stage@<:@0-9@:>@$//' -e 's,ghc\(@<:@^/\\@:>@*\)$,ghc-pkg\1,'`
1370 if "$fp_ghc_pkg_guess" list > /dev/null 2>&1; then
1371   fp_cv_matching_ghc_pkg=$fp_ghc_pkg_guess
1372 else
1373   AC_MSG_ERROR([Cannot find matching ghc-pkg])
1374 fi])
1375 GhcPkgCmd=$fp_cv_matching_ghc_pkg
1376 AC_SUBST([GhcPkgCmd])
1377 ])# FP_PROG_GHC_PKG
1378
1379
1380 # FP_GCC_EXTRA_FLAGS
1381 # ------------------
1382 # Determine which extra flags we need to pass gcc when we invoke it
1383 # to compile .hc code.
1384 #
1385 # -fwrapv is needed for gcc to emit well-behaved code in the presence of
1386 # integer wrap around. (Trac #952)
1387 #
1388 AC_DEFUN([FP_GCC_EXTRA_FLAGS],
1389 [AC_REQUIRE([FP_GCC_VERSION])
1390 AC_CACHE_CHECK([for extra options to pass gcc when compiling via C], [fp_cv_gcc_extra_opts],
1391 [fp_cv_gcc_extra_opts=
1392  FP_COMPARE_VERSIONS([$fp_cv_gcc_version], [-ge], [3.4],
1393   [fp_cv_gcc_extra_opts="$fp_cv_gcc_extra_opts -fwrapv"],
1394   [])
1395 ])
1396 AC_SUBST([GccExtraViaCOpts],$fp_cv_gcc_extra_opts)
1397 ])
1398
1399
1400 # FP_SETUP_PROJECT_VERSION
1401 # ---------------------
1402 AC_DEFUN([FP_SETUP_PROJECT_VERSION],
1403 [
1404 if test "$RELEASE" = "NO"; then
1405     AC_MSG_CHECKING([for GHC version date])
1406     if test -f VERSION_DATE; then
1407         PACKAGE_VERSION=${PACKAGE_VERSION}.`cat VERSION_DATE`
1408         AC_MSG_RESULT(given $PACKAGE_VERSION)
1409     elif test -d .git; then
1410         changequote(, )dnl
1411         ver_date=`git log -n 1 --date=short --pretty=format:%ci | cut -d ' ' -f 1 | tr -d -`
1412         if echo $ver_date | grep '^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$' 2>&1 >/dev/null; then true; else
1413         changequote([, ])dnl
1414                 AC_MSG_ERROR([failed to detect version date: check that git is in your path])
1415         fi
1416         PACKAGE_VERSION=${PACKAGE_VERSION}.$ver_date
1417         AC_MSG_RESULT(inferred $PACKAGE_VERSION)
1418     elif test -d _darcs; then
1419         # TODO: Remove this branch after conversion to Git
1420         changequote(, )dnl
1421         ver_date=`darcs changes --quiet --no-summary --xml | head -500 | grep 'date=' | sed "s/^.*date='\([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\).*$/\1/g" | ${SortCmd} -n | tail -1`
1422         if echo $ver_date | grep '^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$' 2>&1 >/dev/null; then true; else
1423         changequote([, ])dnl
1424                 AC_MSG_ERROR([failed to detect version date: check that darcs is in your path])
1425         fi
1426         PACKAGE_VERSION=${PACKAGE_VERSION}.$ver_date
1427         AC_MSG_RESULT(inferred $PACKAGE_VERSION)
1428     elif test -f VERSION; then
1429         PACKAGE_VERSION=`cat VERSION`
1430         AC_MSG_RESULT(given $PACKAGE_VERSION)
1431     else
1432         AC_MSG_WARN([cannot determine snapshot version: no .git or _darcs directory and no VERSION file])
1433     fi
1434 fi
1435
1436 # Some renamings
1437 AC_SUBST([ProjectName], [$PACKAGE_NAME])
1438 AC_SUBST([ProjectVersion], [$PACKAGE_VERSION])
1439
1440 # Split PACKAGE_VERSION into (possibly empty) parts
1441 VERSION_MAJOR=`echo $PACKAGE_VERSION | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\1'/`
1442 VERSION_TMP=`echo $PACKAGE_VERSION | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\3'/`
1443 VERSION_MINOR=`echo $VERSION_TMP | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\1'/`
1444 ProjectPatchLevel=`echo $VERSION_TMP | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\3'/`
1445
1446 # Calculate project version as an integer, using 2 digits for minor version
1447 case $VERSION_MINOR in
1448   ?) ProjectVersionInt=${VERSION_MAJOR}0${VERSION_MINOR} ;;
1449   ??) ProjectVersionInt=${VERSION_MAJOR}${VERSION_MINOR} ;;
1450   *) AC_MSG_ERROR([bad minor version in $PACKAGE_VERSION]) ;;
1451 esac
1452 AC_SUBST([ProjectVersionInt])
1453
1454 # The project patchlevel is zero unless stated otherwise
1455 test -z "$ProjectPatchLevel" && ProjectPatchLevel=0
1456
1457 # Remove dots from the patch level; this allows us to have versions like 6.4.1.20050508
1458 ProjectPatchLevel=`echo $ProjectPatchLevel | sed 's/\.//'`
1459
1460 AC_SUBST([ProjectPatchLevel])
1461 ])# FP_SETUP_PROJECT_VERSION
1462
1463
1464 # Check for a working timer_create().  We need a pretty detailed check
1465 # here, because there exist partially-working implementations of
1466 # timer_create() in certain versions of Linux (see bug #1933).
1467 #
1468 AC_DEFUN([FP_CHECK_TIMER_CREATE],
1469   [AC_CACHE_CHECK([for a working timer_create(CLOCK_REALTIME)], 
1470     [fptools_cv_timer_create_works],
1471     [AC_TRY_RUN([
1472 #include <stdio.h>
1473 #ifdef HAVE_STDLIB_H
1474 #include <stdlib.h>
1475 #endif
1476 #ifdef HAVE_TIME_H
1477 #include <time.h>
1478 #endif
1479 #ifdef HAVE_SIGNAL_H
1480 #include <signal.h>
1481 #endif
1482 #ifdef HAVE_UNISTD_H
1483 #include <unistd.h>
1484 #endif
1485
1486 static volatile int tock = 0;
1487 static void handler(int i)
1488 {
1489    tock = 1;
1490 }
1491
1492 static void timeout(int i)
1493 {
1494   // timer_settime() has been known to hang, so just in case
1495   // we install a 1-second timeout (see #2257)
1496   exit(99);
1497 }
1498
1499 int main(int argc, char *argv[])
1500 {
1501
1502     struct sigevent ev;
1503     timer_t timer;
1504     struct itimerspec it;
1505     struct sigaction action;
1506     int m,n,count = 0;
1507
1508     ev.sigev_notify = SIGEV_SIGNAL;
1509     ev.sigev_signo  = SIGVTALRM;
1510
1511     action.sa_handler = handler;
1512     action.sa_flags = 0;
1513     sigemptyset(&action.sa_mask);
1514     if (sigaction(SIGVTALRM, &action, NULL) == -1) {
1515         fprintf(stderr,"SIGVTALRM problem\n");
1516         exit(3);
1517     }
1518
1519     action.sa_handler = timeout;
1520     action.sa_flags = 0;
1521     sigemptyset(&action.sa_mask);
1522     if (sigaction(SIGALRM, &action, NULL) == -1) {
1523       fprintf(stderr,"SIGALRM problem\n");
1524       exit(3);
1525     }
1526     alarm(1);
1527
1528     if (timer_create(CLOCK_PROCESS_CPUTIME_ID, &ev, &timer) != 0) {
1529         fprintf(stderr,"No CLOCK_PROCESS_CPUTIME_ID timer\n");
1530        exit(1);
1531     }
1532
1533     it.it_value.tv_sec = 0;
1534     it.it_value.tv_nsec = 1;
1535     it.it_interval = it.it_value;
1536     if (timer_settime(timer, 0, &it, NULL) != 0) {
1537         fprintf(stderr,"settime problem\n");
1538         exit(4);
1539     }
1540
1541     tock = 0;
1542
1543     for(n = 3; n < 20000; n++){
1544         for(m = 2; m <= n/2; m++){
1545             if (!(n%m)) count++;
1546             if (tock) goto out;
1547         }
1548     }
1549 out:
1550
1551     if (!tock) {
1552         fprintf(stderr,"no CLOCK_PROCESS_CPUTIME_ID signal\n");
1553         exit(5);
1554     }
1555
1556     timer_delete(timer);
1557
1558     if (timer_create(CLOCK_REALTIME, &ev, &timer) != 0) {
1559         fprintf(stderr,"No CLOCK_REALTIME timer\n");
1560         exit(2);
1561     }
1562
1563     it.it_value.tv_sec = 0;
1564     it.it_value.tv_nsec = 1000000;
1565     it.it_interval = it.it_value;
1566     if (timer_settime(timer, 0, &it, NULL) != 0) {
1567         fprintf(stderr,"settime problem\n");
1568         exit(4);
1569     }
1570
1571     tock = 0;
1572
1573     usleep(3000);
1574
1575     if (!tock) {
1576         fprintf(stderr,"no CLOCK_REALTIME signal\n");
1577         exit(5);
1578     }
1579
1580     timer_delete(timer);
1581
1582     exit(0);
1583 }
1584      ],
1585      [fptools_cv_timer_create_works=yes],
1586      [fptools_cv_timer_create_works=no])
1587   ])
1588 case $fptools_cv_timer_create_works in
1589     yes) AC_DEFINE([USE_TIMER_CREATE], 1, 
1590                    [Define to 1 if we can use timer_create(CLOCK_PROCESS_CPUTIME_ID,...)]);;
1591 esac
1592 ])
1593
1594 # FP_ICONV
1595 # -------------
1596 AC_DEFUN([FP_ICONV],
1597 [
1598   dnl--------------------------------------------------------------------
1599   dnl * Deal with arguments telling us iconv is somewhere odd
1600   dnl--------------------------------------------------------------------
1601
1602   dnl Note: ICONV_LIB_DIRS and ICONV_INCLUDE_DIRS are not predefined
1603   dnl to the empty string to allow them to be overridden from the
1604   dnl environment.
1605
1606   AC_ARG_WITH([iconv-includes],
1607     [AC_HELP_STRING([--with-iconv-includes],
1608       [directory containing iconv.h])],
1609       [ICONV_INCLUDE_DIRS=$withval])
1610
1611   AC_ARG_WITH([iconv-libraries],
1612     [AC_HELP_STRING([--with-iconv-libraries],
1613       [directory containing iconv library])],
1614       [ICONV_LIB_DIRS=$withval])
1615
1616   AC_SUBST(ICONV_INCLUDE_DIRS)
1617   AC_SUBST(ICONV_LIB_DIRS)
1618 ])# FP_ICONV
1619
1620 # FP_GMP
1621 # -------------
1622 AC_DEFUN([FP_GMP],
1623 [
1624   dnl--------------------------------------------------------------------
1625   dnl * Deal with arguments telling us gmp is somewhere odd
1626   dnl--------------------------------------------------------------------
1627
1628   AC_ARG_WITH([gmp-includes],
1629     [AC_HELP_STRING([--with-gmp-includes],
1630       [directory containing gmp.h])],
1631       [GMP_INCLUDE_DIRS=$withval])
1632
1633   AC_ARG_WITH([gmp-libraries],
1634     [AC_HELP_STRING([--with-gmp-libraries],
1635       [directory containing gmp library])],
1636       [GMP_LIB_DIRS=$withval])
1637
1638   AC_SUBST(GMP_INCLUDE_DIRS)
1639   AC_SUBST(GMP_LIB_DIRS)
1640 ])# FP_GMP
1641
1642 # FP_CHECK_MACOSX_DEPLOYMENT_TARGET
1643 # ---------------------------------
1644 AC_DEFUN([FP_CHECK_MACOSX_DEPLOYMENT_TARGET],
1645 [
1646 if test "x$TargetOS_CPP-$TargetVendor_CPP" = "xdarwin-apple"; then
1647   AC_MSG_CHECKING([Mac OS X deployment target])
1648   case $FP_MACOSX_DEPLOYMENT_TARGET in
1649     none)  ;;
1650     10.4)  MACOSX_DEPLOYMENT_VERSION=10.4
1651            MACOSX_DEPLOYMENT_SDK=/Developer/SDKs/MacOSX10.4u.sdk
1652            ;;
1653     10.4u) MACOSX_DEPLOYMENT_VERSION=10.4
1654            MACOSX_DEPLOYMENT_SDK=/Developer/SDKs/MacOSX10.4u.sdk
1655            ;;
1656     *)     MACOSX_DEPLOYMENT_VERSION=$FP_MACOSX_DEPLOYMENT_TARGET
1657            MACOSX_DEPLOYMENT_SDK=/Developer/SDKs/MacOSX${FP_MACOSX_DEPLOYMENT_TARGET}.sdk
1658            ;;
1659   esac
1660   if test "x$FP_MACOSX_DEPLOYMENT_TARGET" = "xnone"; then
1661     AC_MSG_RESULT(none)
1662   else
1663     if test ! -d $MACOSX_DEPLOYMENT_SDK; then
1664       AC_MSG_ERROR([Unknown deployment target $FP_MACOSX_DEPLOYMENT_TARGET])
1665     fi
1666     AC_MSG_RESULT([${MACOSX_DEPLOYMENT_VERSION} (${MACOSX_DEPLOYMENT_SDK})])
1667   fi
1668 fi
1669 ])
1670
1671 # --------------------------------------------------------------
1672 # Calculate absolute path to build tree
1673 # --------------------------------------------------------------
1674
1675 AC_DEFUN([FP_INTREE_GHC_PWD],[
1676 AC_MSG_NOTICE(Building in-tree ghc-pwd)
1677     dnl This would be
1678     dnl     make -C utils/ghc-pwd clean && make -C utils/ghc-pwd
1679     dnl except we don't want to have to know what make is called. Sigh.
1680     rm -rf utils/ghc-pwd/dist-boot
1681     mkdir  utils/ghc-pwd/dist-boot
1682     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
1683     then
1684         AC_MSG_ERROR([Building ghc-pwd failed])
1685     fi
1686
1687     GHC_PWD=utils/ghc-pwd/dist-boot/ghc-pwd
1688 ])
1689
1690 AC_DEFUN([FP_BINDIST_GHC_PWD],[
1691     GHC_PWD=utils/ghc-pwd/dist-install/build/tmp/ghc-pwd
1692 ])
1693
1694 AC_DEFUN([FP_FIND_ROOT],[
1695 AC_MSG_CHECKING(for path to top of build tree)
1696     hardtop=`$GHC_PWD`
1697
1698     dnl Remove common automounter nonsense
1699     hardtop=`echo $hardtop | sed 's|^/tmp_mnt.*\(/local/.*\)$|\1|' | sed 's|^/tmp_mnt/|/|'`
1700
1701     if ! test -d "$hardtop"; then
1702         AC_MSG_ERROR([cannot determine current directory])
1703     fi
1704
1705     dnl We don't support building in directories with spaces.
1706     case "$hardtop" in
1707     *' '*)
1708         AC_MSG_ERROR([
1709         The build system does not support building in a directory
1710         containing space characters.
1711         Suggestion: move the build tree somewhere else.])
1712         ;;
1713     esac
1714
1715     AC_SUBST(hardtop)
1716
1717     AC_MSG_RESULT($hardtop)
1718 ])
1719
1720 # GHC_CONVERT_CPU(cpu, target_var)
1721 # --------------------------------
1722 # converts cpu from gnu to ghc naming, and assigns the result to $target_var
1723 AC_DEFUN([GHC_CONVERT_CPU],[
1724 case "$1" in
1725   alpha*)
1726     $2="alpha"
1727     ;;
1728   arm*)
1729     $2="arm"
1730     ;;
1731   hppa1.1*)
1732     $2="hppa1_1"
1733     ;;
1734   hppa*)
1735     $2="hppa"
1736     ;;
1737   i386|i486|i586|i686)
1738     $2="i386"
1739     ;;
1740   ia64)
1741     $2="ia64"
1742     ;;
1743   m68k*)
1744     $2="m68k"
1745     ;;
1746   mipseb*)
1747     $2="mipseb"
1748     ;;
1749   mipsel*)
1750     $2="mipsel"
1751     ;;
1752   mips*)
1753     $2="mips"
1754     ;;
1755   powerpc64*)
1756     $2="powerpc64"
1757     ;;
1758   powerpc*)
1759     $2="powerpc"
1760     ;;
1761   rs6000)
1762     $2="rs6000"
1763     ;;
1764   s390x*)
1765     $2="s390x"
1766     ;;
1767   s390*)
1768     $2="s390"
1769     ;;
1770   sparc64*)
1771     $2="sparc64"
1772     ;;
1773   sparc*)
1774     $2="sparc"
1775     ;;
1776   vax)
1777     $2="vax"
1778     ;;
1779   x86_64)
1780     $2="x86_64"
1781     ;;
1782   *)
1783     echo "Unknown CPU $1"
1784     exit 1
1785     ;;
1786   esac
1787 ])
1788
1789 # GHC_CONVERT_VENDOR(vendor, target_var)
1790 # --------------------------------
1791 # converts vendor from gnu to ghc naming, and assigns the result to $target_var
1792 AC_DEFUN([GHC_CONVERT_VENDOR],[
1793   case "$1" in
1794   pc|gentoo) # like i686-pc-linux-gnu and i686-gentoo-freebsd8
1795     $2="unknown"
1796     ;;
1797   softfloat) # like armv5tel-softfloat-linux-gnueabi
1798     $2="unknown"
1799     ;;
1800   *)
1801     #pass thru by default
1802     $2="$1"
1803     ;;
1804   esac
1805 ])
1806
1807 # GHC_CONVERT_OS(os, target_var)
1808 # --------------------------------
1809 # converts os from gnu to ghc naming, and assigns the result to $target_var
1810 AC_DEFUN([GHC_CONVERT_OS],[
1811 case "$1" in
1812   linux-*|linux)
1813     $2="linux"
1814     ;;
1815   # As far as I'm aware, none of these have relevant variants
1816   freebsd|netbsd|openbsd|dragonfly|osf1|osf3|hpux|linuxaout|kfreebsdgnu|freebsd2|solaris2|cygwin32|mingw32|darwin|gnu|nextstep2|nextstep3|sunos4|ultrix|irix|aix|haiku)
1817     $2="$1"
1818     ;;
1819   freebsd8) # like i686-gentoo-freebsd8
1820     $2="freebsd"
1821     ;;
1822   *)
1823     echo "Unknown OS $1"
1824     exit 1
1825     ;;
1826   esac
1827 ])
1828
1829 # BOOTSTRAPPING_GHC_INFO_FIELD
1830 # --------------------------------
1831 # If the bootstrapping compiler is >= 7.1, then set the variable
1832 # $1 to the value of the ghc --info field $2. Otherwise, set it to
1833 # $3.
1834 AC_DEFUN([BOOTSTRAPPING_GHC_INFO_FIELD],[
1835 if test $GhcCanonVersion -ge 701
1836 then
1837     $1=`"$WithGhc" --info | grep "^ ,(\"$2\"," | sed -e 's/.*","//' -e 's/")$//'`
1838 else
1839     $1=$3
1840 fi
1841 AC_SUBST($1)
1842 ])
1843
1844 # LIBRARY_VERSION(lib, [dir])
1845 # --------------------------------
1846 # Gets the version number of a library.
1847 # If $1 is ghc-prim, then we define LIBRARY_ghc_prim_VERSION as 1.2.3
1848 # $2 points to the directory under libraries/
1849 AC_DEFUN([LIBRARY_VERSION],[
1850 dir=m4_default([$2],[$1])
1851 LIBRARY_[]translit([$1], [-], [_])[]_VERSION=`grep -i "^version:" libraries/${dir}/$1.cabal | sed "s/.* //"`
1852 AC_SUBST(LIBRARY_[]translit([$1], [-], [_])[]_VERSION)
1853 ])
1854
1855 # XCODE_VERSION()
1856 # --------------------------------
1857 # Gets the version number of XCode, if on a Mac
1858 AC_DEFUN([XCODE_VERSION],[
1859     if test "$TargetOS_CPP" = "darwin"
1860     then
1861         AC_MSG_CHECKING(XCode version)
1862         XCodeVersion=`xcodebuild -version | grep Xcode | sed "s/Xcode //"`
1863         # Old XCode versions don't actually give the XCode version
1864         if test "$XCodeVersion" = ""
1865         then
1866             AC_MSG_RESULT(not found (too old?))
1867             XCodeVersion1=0
1868             XCodeVersion2=0
1869         else
1870             AC_MSG_RESULT($XCodeVersion)
1871             XCodeVersion1=`echo "$XCodeVersion" | sed 's/\..*//'`
1872             changequote(, )dnl
1873             XCodeVersion2=`echo "$XCodeVersion" | sed 's/[^.]*\.\([^.]*\).*/\1/'`
1874             changequote([, ])dnl
1875             AC_MSG_NOTICE(XCode version component 1: $XCodeVersion1)
1876             AC_MSG_NOTICE(XCode version component 2: $XCodeVersion2)
1877         fi
1878     fi
1879 ])
1880
1881 # FIND_GCC()
1882 # --------------------------------
1883 # Finds where gcc is
1884 AC_DEFUN([FIND_GCC],[
1885     if test "$TargetOS_CPP" = "darwin" &&
1886         test "$XCodeVersion1" -ge 4
1887     then
1888         # From Xcode 4, use 'gcc-4.2' to force the use of the gcc legacy
1889         # backend (instead of the LLVM backend)
1890         FP_ARG_WITH_PATH_GNU_PROG([CC], [gcc-4.2])
1891     else
1892         FP_ARG_WITH_PATH_GNU_PROG([CC], [gcc])
1893     fi
1894     export CC
1895     WhatGccIsCalled="$CC"
1896     AC_SUBST(WhatGccIsCalled)
1897 ])
1898
1899 # LocalWords:  fi