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