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