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