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