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