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