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