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