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