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