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