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