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