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