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