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