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