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