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