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