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