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