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