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