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