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