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