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