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