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