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