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