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