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