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