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