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