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