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