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