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