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