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