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