Replace usages of `-w` by `-fno-warn`s
[ghc.git] / aclocal.m4
index eb57cbe..9773168 100644 (file)
@@ -4,6 +4,34 @@
 # ensure we don't clash with any pre-supplied autoconf ones.
 
 
+AC_DEFUN([GHC_SELECT_FILE_EXTENSIONS],
+[
+    $2=''
+    $3='.so'
+    case $1 in
+    *-unknown-cygwin32)
+        AC_MSG_WARN([GHC does not support the Cygwin target at the moment])
+        AC_MSG_WARN([I'm assuming you wanted to build for i386-unknown-mingw32])
+        exit 1
+        ;;
+    *-unknown-mingw32)
+        windows=YES
+        $2='.exe'
+        $3='.dll'
+        ;;
+    i386-apple-darwin|powerpc-apple-darwin)
+        $3='.dylib'
+        ;;
+    x86_64-apple-darwin)
+        $3='.dylib'
+        ;;
+    arm-apple-darwin10|i386-apple-darwin11|aarch64-apple-darwin14)
+        $2='.a'
+        $3='.dylib'
+        ;;
+    esac
+])
+
 # FPTOOLS_SET_PLATFORM_VARS
 # ----------------------------------
 # Set the platform variables
@@ -36,7 +64,7 @@ AC_DEFUN([FPTOOLS_SET_PLATFORM_VARS],
     else
         GHC_CONVERT_CPU([$build_cpu], [BuildArch])
         GHC_CONVERT_VENDOR([$build_vendor], [BuildVendor])
-        GHC_CONVERT_OS([$build_os], [BuildOS])
+        GHC_CONVERT_OS([$build_os], [$BuildArch], [BuildOS])
     fi
 
     if test "$host_alias" = ""
@@ -56,7 +84,7 @@ AC_DEFUN([FPTOOLS_SET_PLATFORM_VARS],
     else
         GHC_CONVERT_CPU([$host_cpu], [HostArch])
         GHC_CONVERT_VENDOR([$host_vendor], [HostVendor])
-        GHC_CONVERT_OS([$host_os], [HostOS])
+        GHC_CONVERT_OS([$host_os], [$HostArch], [HostOS])
     fi
 
     if test "$target_alias" = ""
@@ -65,7 +93,7 @@ AC_DEFUN([FPTOOLS_SET_PLATFORM_VARS],
         then
             GHC_CONVERT_CPU([$host_cpu], [TargetArch])
             GHC_CONVERT_VENDOR([$host_vendor], [TargetVendor])
-            GHC_CONVERT_OS([$host_os], [TargetOS])
+            GHC_CONVERT_OS([$host_os], [$TargetArch],[TargetOS])
         else
             if test "$bootstrap_target" != ""
             then
@@ -75,7 +103,7 @@ AC_DEFUN([FPTOOLS_SET_PLATFORM_VARS],
                 echo "Can't work out target platform"
                 exit 1
             fi
-    
+
             TargetArch=`echo "$target" | sed 's/-.*//'`
             TargetVendor=`echo "$target" | sed -e 's/.*-\(.*\)-.*/\1/'`
             TargetOS=`echo "$target" | sed 's/.*-//'`
@@ -83,28 +111,15 @@ AC_DEFUN([FPTOOLS_SET_PLATFORM_VARS],
     else
         GHC_CONVERT_CPU([$target_cpu], [TargetArch])
         GHC_CONVERT_VENDOR([$target_vendor], [TargetVendor])
-        GHC_CONVERT_OS([$target_os], [TargetOS])
+        GHC_CONVERT_OS([$target_os], [$TargetArch], [TargetOS])
     fi
 
+    GHC_SELECT_FILE_EXTENSIONS([$host], [exeext_host], [soext_host])
+    GHC_SELECT_FILE_EXTENSIONS([$target], [exeext_target], [soext_target])
     windows=NO
-    exeext=''
-    soext='.so'
     case $host in
-    *-unknown-cygwin32)
-        AC_MSG_WARN([GHC does not support the Cygwin target at the moment])
-        AC_MSG_WARN([I'm assuming you wanted to build for i386-unknown-mingw32])
-        exit 1
-        ;;
     *-unknown-mingw32)
         windows=YES
-        exeext='.exe'
-        soext='.dll'
-        ;;
-    i386-apple-darwin|powerpc-apple-darwin)
-        soext='.dylib'
-        ;;
-    x86_64-apple-darwin)
-        soext='.dylib'
         ;;
     esac
 
@@ -149,8 +164,10 @@ AC_DEFUN([FPTOOLS_SET_PLATFORM_VARS],
     AC_SUBST(BuildVendor_CPP)
     AC_SUBST(TargetVendor_CPP)
 
-    AC_SUBST(exeext)
-    AC_SUBST(soext)
+    AC_SUBST(exeext_host)
+    AC_SUBST(exeext_target)
+    AC_SUBST(soext_host)
+    AC_SUBST(soext_target)
 ])
 
 
@@ -164,14 +181,17 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
         i386)
             test -z "[$]2" || eval "[$]2=ArchX86"
             ;;
-        x86_64)
+        x86_64|amd64)
             test -z "[$]2" || eval "[$]2=ArchX86_64"
             ;;
         powerpc)
             test -z "[$]2" || eval "[$]2=ArchPPC"
             ;;
         powerpc64)
-            test -z "[$]2" || eval "[$]2=ArchPPC_64"
+            test -z "[$]2" || eval "[$]2=\"ArchPPC_64 {ppc_64ABI = ELF_V1}\""
+            ;;
+        powerpc64le)
+            test -z "[$]2" || eval "[$]2=\"ArchPPC_64 {ppc_64ABI = ELF_V2}\""
             ;;
         sparc)
             test -z "[$]2" || eval "[$]2=ArchSPARC"
@@ -180,6 +200,9 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
             GET_ARM_ISA()
             test -z "[$]2" || eval "[$]2=\"ArchARM {armISA = \$ARM_ISA, armISAExt = \$ARM_ISA_EXT, armABI = \$ARM_ABI}\""
             ;;
+        aarch64)
+            test -z "[$]2" || eval "[$]2=ArchARM64"
+            ;;
         alpha)
             test -z "[$]2" || eval "[$]2=ArchAlpha"
             ;;
@@ -201,7 +224,7 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
 
     checkVendor() {
         case [$]1 in
-        dec|unknown|hp|apple|next|sun|sgi|ibm|montavista)
+        dec|unknown|hp|apple|next|sun|sgi|ibm|montavista|portbld)
             ;;
         *)
             echo "Unknown vendor [$]1"
@@ -215,6 +238,9 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
         linux)
             test -z "[$]2" || eval "[$]2=OSLinux"
             ;;
+        ios)
+            test -z "[$]2" || eval "[$]2=OSiOS"
+            ;;
         darwin)
             test -z "[$]2" || eval "[$]2=OSDarwin"
             ;;
@@ -302,11 +328,11 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
          HaskellHaveGnuNonexecStack=False])
     CFLAGS="$CFLAGS2"
 
-    checkArch "$BuildArch" ""
+    checkArch "$BuildArch" "HaskellBuildArch"
     checkVendor "$BuildVendor"
     checkOS "$BuildOS" ""
 
-    checkArch "$HostArch" ""
+    checkArch "$HostArch" "HaskellHostArch"
     checkVendor "$HostVendor"
     checkOS "$HostOS" ""
 
@@ -431,6 +457,8 @@ AC_DEFUN([FP_SETTINGS],
     then
         mingw_bin_prefix=mingw/bin/
         SettingsCCompilerCommand="\$topdir/../${mingw_bin_prefix}gcc.exe"
+        SettingsHaskellCPPCommand="\$topdir/../${mingw_bin_prefix}gcc.exe"
+        SettingsHaskellCPPFlags="$HaskellCPPArgs"
         SettingsLdCommand="\$topdir/../${mingw_bin_prefix}ld.exe"
         SettingsArCommand="\$topdir/../${mingw_bin_prefix}ar.exe"
         SettingsPerlCommand='$topdir/../perl/perl.exe'
@@ -439,35 +467,43 @@ AC_DEFUN([FP_SETTINGS],
         SettingsTouchCommand='$topdir/touchy.exe'
     else
         SettingsCCompilerCommand="$WhatGccIsCalled"
+        SettingsHaskellCPPCommand="$HaskellCPPCmd"
+        SettingsHaskellCPPFlags="$HaskellCPPArgs"
         SettingsLdCommand="$LdCmd"
         SettingsArCommand="$ArCmd"
         SettingsPerlCommand="$PerlCmd"
         SettingsDllWrapCommand="/bin/false"
         SettingsWindresCommand="/bin/false"
+        SettingsLibtoolCommand="libtool"
         SettingsTouchCommand='touch'
-        if test -z "$LlcCmd"
-        then
-          SettingsLlcCommand="llc"
-        else
-          SettingsLlcCommand="$LlcCmd"
-        fi
-        if test -z "$OptCmd"
-        then
-          SettingsOptCommand="opt"
-        else
-          SettingsOptCommand="$OptCmd"
-        fi
     fi
-    SettingsCCompilerFlags="$CONF_CC_OPTS_STAGE2 $CONF_GCC_LINKER_OPTS_STAGE2"
+    if test -z "$LlcCmd"
+    then
+      SettingsLlcCommand="llc"
+    else
+      SettingsLlcCommand="$LlcCmd"
+    fi
+    if test -z "$OptCmd"
+    then
+      SettingsOptCommand="opt"
+    else
+      SettingsOptCommand="$OptCmd"
+    fi
+    SettingsCCompilerFlags="$CONF_CC_OPTS_STAGE2"
+    SettingsCCompilerLinkFlags="$CONF_GCC_LINKER_OPTS_STAGE2"
     SettingsLdFlags="$CONF_LD_LINKER_OPTS_STAGE2"
     AC_SUBST(SettingsCCompilerCommand)
+    AC_SUBST(SettingsHaskellCPPCommand)
+    AC_SUBST(SettingsHaskellCPPFlags)
     AC_SUBST(SettingsCCompilerFlags)
+    AC_SUBST(SettingsCCompilerLinkFlags)
     AC_SUBST(SettingsLdCommand)
     AC_SUBST(SettingsLdFlags)
     AC_SUBST(SettingsArCommand)
     AC_SUBST(SettingsPerlCommand)
     AC_SUBST(SettingsDllWrapCommand)
     AC_SUBST(SettingsWindresCommand)
+    AC_SUBST(SettingsLibtoolCommand)
     AC_SUBST(SettingsTouchCommand)
     AC_SUBST(SettingsLlcCommand)
     AC_SUBST(SettingsOptCommand)
@@ -486,6 +522,19 @@ AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS],
 [
     AC_MSG_CHECKING([Setting up $2, $3, $4 and $5])
     case $$1 in
+    i386-*)
+        # Workaround for #7799
+        $2="$$2 -U__i686"
+        ;;
+    esac
+
+    case $$1 in
+    i386-unknown-mingw32)
+        $2="$$2 -march=i686"
+        ;;
+    i386-portbld-freebsd*)
+        $2="$$2 -march=i686"
+        ;;
     i386-apple-darwin)
         $2="$$2 -m32"
         $3="$$3 -m32"
@@ -498,6 +547,12 @@ AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS],
         $4="$$4 -arch x86_64"
         $5="$$5 -m64"
         ;;
+    x86_64-unknown-solaris2)
+        $2="$$2 -m64"
+        $3="$$3 -m64"
+        $4="$$4 -m64"
+        $5="$$5 -m64"
+        ;;
     alpha-*)
         # For now, to suppress the gcc warning "call-clobbered
         # register used for global register variable", we simply
@@ -513,6 +568,14 @@ AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS],
         $3="$$3 -D_HPUX_SOURCE"
         $5="$$5 -D_HPUX_SOURCE"
         ;;
+    arm*linux*       | \
+    aarch64*linux*   )
+        # On arm/linux, aarch64/linux, arm/android and aarch64/android, tell
+        # gcc to link using the gold linker.
+        # Forcing LD to be ld.gold is done in FIND_LD m4 macro.
+        $3="$$3 -fuse-ld=gold -Wl,-z,noexecstack"
+        $4="$$4 -z noexecstack"
+        ;;
     esac
 
     # If gcc knows about the stack protector, turn it off.
@@ -523,18 +586,6 @@ AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS],
         $2="$$2 -fno-stack-protector"
     fi
 
-    # Reduce memory usage when linking. See trac #5240.
-    if test -n "$LdHashSize31"
-    then
-        $3="$$3 -Wl,$LdHashSize31"
-        $4="$$4     $LdHashSize31"
-    fi
-    if test -n "$LdReduceMemoryOverheads"
-    then
-        $3="$$3 -Wl,$LdReduceMemoryOverheads"
-        $4="$$4     $LdReduceMemoryOverheads"
-    fi
-
     rm -f conftest.c conftest.o
     AC_MSG_RESULT([done])
 ])
@@ -600,19 +651,20 @@ AC_DEFUN([FPTOOLS_FLOAT_WORD_ORDER_BIGENDIAN],
 ])
 
 
-# FP_ARG_WITH_PATH_GNU_PROG
+# FP_ARG_WITH_PATH_GNU_PROG_GENERAL
 # --------------------
 # Find the specified command on the path or allow a user to set it manually
-# with a --with-<command> option. An error will be thrown if the command isn't
-# found.
+# with a --with-<command> option.
 #
 # This is ignored on the mingw32 platform.
 #
 # $1 = the variable to set
 # $2 = the with option name
 # $3 = the command to look for
+# $4 = prepend target to program name? if 'no', use the name unchanged
+# $5 = optional? if 'no', then raise an error if the command isn't found
 #
-AC_DEFUN([FP_ARG_WITH_PATH_GNU_PROG],
+AC_DEFUN([FP_ARG_WITH_PATH_GNU_PROG_GENERAL],
 [
 AC_ARG_WITH($2,
 [AC_HELP_STRING([--with-$2=ARG],
@@ -624,65 +676,55 @@ AC_ARG_WITH($2,
     else
         $1=$withval
     fi
+
+    # Remember that we set this manually.  Used to override CC_STAGE0
+    # and friends later, if we are not cross-compiling.
+    With_$2=$withval
 ],
 [
     if test "$HostOS" != "mingw32"
     then
-        if test "$target_alias" = "" ; then
+        if test "$4" = "no" -o "$target_alias" = "" ; then
             AC_PATH_PROG([$1], [$3])
         else
             AC_PATH_PROG([$1], [$target_alias-$3])
         fi
-        if test -z "$$1"
+        if test "$5" = "no" -a -z "$$1"
         then
             AC_MSG_ERROR([cannot find $3 in your PATH])
         fi
     fi
 ]
 )
-]) # FP_ARG_WITH_PATH_GNU_PROG
+]) # FP_ARG_WITH_PATH_GNU_PROG_GENERAL
 
 
+# FP_ARG_WITH_PATH_GNU_PROG
+# --------------------
+# The usual case: prepend the target, and the program is not optional.
+AC_DEFUN([FP_ARG_WITH_PATH_GNU_PROG],
+[FP_ARG_WITH_PATH_GNU_PROG_GENERAL([$1], [$2], [$3], [yes], [no])])
+
 # FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL
 # --------------------
 # Same as FP_ARG_WITH_PATH_GNU_PROG but no error will be thrown if the command
 # isn't found.
-#
-# This is ignored on the mingw32 platform.
-#
-# $1 = the variable to set
-# $2 = the with option name
-# $3 = the command to look for
-#
 AC_DEFUN([FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL],
-[
-AC_ARG_WITH($2,
-[AC_HELP_STRING([--with-$2=ARG],
-        [Use ARG as the path to $2 [default=autodetect]])],
-[
-    if test "$HostOS" = "mingw32"
-    then
-        AC_MSG_WARN([Request to use $withval will be ignored])
-    else
-        $1=$withval
-    fi
-],
-[
-    if test "$HostOS" != "mingw32"
-    then
-        AC_PATH_PROG([$1], [$3])
-    fi
-]
-)
-]) # FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL
+[FP_ARG_WITH_PATH_GNU_PROG_GENERAL([$1], [$2], [$3], [yes], [yes])])
+
+# FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL_NOTARGET
+# --------------------
+# Same as FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL but don't prepend the target name
+# (used for LLVM).
+AC_DEFUN([FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL_NOTARGET],
+[FP_ARG_WITH_PATH_GNU_PROG_GENERAL([$1], [$2], [$3], [no], [yes])])
+
 
 # FP_PROG_CONTEXT_DIFF
 # --------------------
 # Figure out how to do context diffs. Sets the output variable ContextDiffCmd.
 #
 # Note: NeXTStep thinks diff'ing a file against itself is "trouble".
-#
-# Used by ghc, glafp-utils/ltx, and glafp-utils/runstdtest.
 AC_DEFUN([FP_PROG_CONTEXT_DIFF],
 [AC_CACHE_CHECK([for a working context diff], [fp_cv_context_diff],
 [echo foo > conftest1
@@ -772,6 +814,7 @@ x86_64-unknown-mingw32) fptools_cv_leading_underscore=no;;
 
     # HACK: Apple doesn't seem to provide nlist in the 64-bit-libraries
 x86_64-apple-darwin*) fptools_cv_leading_underscore=yes;;
+*-apple-ios) fptools_cv_leading_underscore=yes;;
 
 *) AC_RUN_IFELSE([AC_LANG_SOURCE([[#ifdef HAVE_NLIST_H
 #include <nlist.h>
@@ -829,9 +872,11 @@ AS_IF([test "$fp_num1" $2 "$fp_num2"], [$4], [$5])[]dnl
 
 
 dnl
-dnl Check for Happy and version.  If we're building GHC, then we need
-dnl at least Happy version 1.14.  If there's no installed Happy, we look
+dnl Check for Happy and version.
+dnl If there's no installed Happy, we look
 dnl for a happy source tree and point the build system at that instead.
+dnl If you increase the minimum version requirement, please also update:
+dnl https://ghc.haskell.org/trac/ghc/wiki/Building/Preparation/Tools
 dnl
 AC_DEFUN([FPTOOLS_HAPPY],
 [FP_PATH_PROG(HappyCmd,happy,)
@@ -840,24 +885,25 @@ AC_CACHE_CHECK([for version of happy], fptools_cv_happy_version,
 changequote(, )dnl
 [if test x"$HappyCmd" != x; then
    fptools_cv_happy_version=`"$HappyCmd" -v |
-                         grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'` ;
+              grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'` ;
 else
    fptools_cv_happy_version="";
 fi;
 changequote([, ])dnl
 ])
-if test ! -f compiler/parser/Parser.hs || test ! -f compiler/cmm/CmmParse.hs || test ! -f compiler/parser/ParserCore.hs
+if test ! -f compiler/parser/Parser.hs || test ! -f compiler/cmm/CmmParse.hs
 then
-    FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.16],
-      [AC_MSG_ERROR([Happy version 1.16 or later is required to compile GHC.])])[]
+    FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.19.4],
+      [AC_MSG_ERROR([Happy version 1.19.4 or later is required to compile GHC.])])[]
 fi
 HappyVersion=$fptools_cv_happy_version;
 AC_SUBST(HappyVersion)
 ])
 
 dnl
-dnl Check for Alex and version.  If we're building GHC, then we need
-dnl at least Alex version 2.0.1.
+dnl Check for Alex and version.
+dnl If you increase the minimum version requirement, please also update:
+dnl https://ghc.haskell.org/trac/ghc/wiki/Building/Preparation/Tools
 dnl
 AC_DEFUN([FPTOOLS_ALEX],
 [
@@ -867,18 +913,18 @@ AC_CACHE_CHECK([for version of alex], fptools_cv_alex_version,
 changequote(, )dnl
 [if test x"$AlexCmd" != x; then
    fptools_cv_alex_version=`"$AlexCmd" -v |
-                         grep 'Alex [Vv]ersion' | sed -e 's/Alex [Vv]ersion \([0-9\.]*\).*/\1/g'` ;
+              grep 'Alex [Vv]ersion' | sed -e 's/Alex [Vv]ersion \([0-9\.]*\).*/\1/g'` ;
 else
    fptools_cv_alex_version="";
 fi;
 changequote([, ])dnl
 ])
+FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-ge],[3.0],
+  [Alex3=YES],[Alex3=NO])
 if test ! -f compiler/cmm/CmmLex.hs || test ! -f compiler/parser/Lexer.hs
 then
-    FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-lt],[2.1.0],
-      [AC_MSG_ERROR([Alex version 2.1.0 or later is required to compile GHC.])])[]
-    FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-ge],[3.0],
-      [Alex3=YES],[Alex3=NO])
+    FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-lt],[3.1.0],
+      [AC_MSG_ERROR([Alex version 3.1.0 or later is required to compile GHC.])])[]
 fi
 AlexVersion=$fptools_cv_alex_version;
 AC_SUBST(AlexVersion)
@@ -905,27 +951,6 @@ $2=$fp_cv_$2
 ])# FP_PROG_LD_FLAG
 
 
-# FP_PROG_LD_HashSize31
-# ------------
-# Sets the output variable LdHashSize31 to --hash-size=31 if ld supports
-# this flag. Otherwise the variable's value is empty.
-AC_DEFUN([FP_PROG_LD_HashSize31],
-[
-FP_PROG_LD_FLAG([--hash-size=31],[LdHashSize31])
-])# FP_PROG_LD_HashSize31
-
-
-# FP_PROG_LD_ReduceMemoryOverheads
-# ------------
-# Sets the output variable LdReduceMemoryOverheads to
-# --reduce-memory-overheads if ld supports this flag.
-# Otherwise the variable's value is empty.
-AC_DEFUN([FP_PROG_LD_ReduceMemoryOverheads],
-[
-FP_PROG_LD_FLAG([--reduce-memory-overheads],[LdReduceMemoryOverheads])
-])# FP_PROG_LD_ReduceMemoryOverheads
-
-
 # FP_PROG_LD_BUILD_ID
 # ------------
 
@@ -992,6 +1017,38 @@ AC_SUBST([LdHasNoCompactUnwind])
 ])# FP_PROG_LD_NO_COMPACT_UNWIND
 
 
+# FP_PROG_LD_FILELIST
+# -------------------
+
+# Sets the output variable LdHasFilelist to YES if ld supports
+# -filelist, or NO otherwise.
+AC_DEFUN([FP_PROG_LD_FILELIST],
+[
+AC_CACHE_CHECK([whether ld understands -filelist], [fp_cv_ld_has_filelist],
+[
+    echo 'int foo() { return 0; }' > conftest1.c
+    echo 'int bar() { return 0; }' > conftest2.c
+    ${CC-cc} -c conftest1.c
+    ${CC-cc} -c conftest2.c
+    echo conftest1.o  > conftest.o-files
+    echo conftest2.o >> conftest.o-files
+    if ${LdCmd} -r -filelist conftest.o-files -o conftest.o > /dev/null 2>&1
+    then
+        fp_cv_ld_has_filelist=yes
+    else
+        fp_cv_ld_has_filelist=no
+    fi
+    rm -rf conftest*
+])
+if test "$fp_cv_ld_has_filelist" = yes; then
+    LdHasFilelist=YES
+else
+    LdHasFilelist=NO
+fi
+AC_SUBST([LdHasFilelist])
+])# FP_PROG_LD_FILELIST
+
+
 # FP_PROG_AR
 # ----------
 # Sets fp_prog_ar to a (non-Cygwin) path to ar. Exits if no ar can be found
@@ -1081,30 +1138,52 @@ AC_SUBST([ArArgs], ["$fp_prog_ar_args"])
 
 # FP_PROG_AR_NEEDS_RANLIB
 # -----------------------
-# Sets the output variable RANLIB to "ranlib" if it is needed and found,
-# to "true" otherwise.
-AC_DEFUN([FP_PROG_AR_NEEDS_RANLIB],
-[AC_REQUIRE([FP_PROG_AR_IS_GNU])
-AC_REQUIRE([FP_PROG_AR_ARGS])
-AC_REQUIRE([AC_PROG_CC])
-AC_CACHE_CHECK([whether ranlib is needed], [fp_cv_prog_ar_needs_ranlib],
-[if test $fp_prog_ar_is_gnu = yes; then
-  fp_cv_prog_ar_needs_ranlib=no
-elif echo $TargetPlatform | grep "^.*-apple-darwin$"  > /dev/null 2> /dev/null; then
-  # It's quite tedious to check for Apple's crazy timestamps in .a files,
-  # so we hardcode it.
-  fp_cv_prog_ar_needs_ranlib=yes
-elif echo $fp_prog_ar_args | grep "s" > /dev/null 2> /dev/null; then
-  fp_cv_prog_ar_needs_ranlib=no
-else
-  fp_cv_prog_ar_needs_ranlib=yes
-fi])
-if test $fp_cv_prog_ar_needs_ranlib = yes; then
-   AC_PROG_RANLIB
-else
-  RANLIB="true"
-  AC_SUBST([RANLIB])
-fi
+# Sets the output variable RANLIB_CMD to "ranlib" if it is needed and
+# found, to "true" otherwise. Sets REAL_RANLIB_CMD to the ranlib program,
+# even if we don't need ranlib (libffi might still need it).
+AC_DEFUN([FP_PROG_AR_NEEDS_RANLIB],[
+    AC_REQUIRE([FP_PROG_AR_IS_GNU])
+    AC_REQUIRE([FP_PROG_AR_ARGS])
+    AC_REQUIRE([AC_PROG_CC])
+
+    AC_PROG_RANLIB
+
+    if test $fp_prog_ar_is_gnu = yes
+    then
+        fp_cv_prog_ar_needs_ranlib=no
+    elif test "$TargetOS_CPP" = "darwin"
+    then
+        # It's quite tedious to check for Apple's crazy timestamps in
+        # .a files, so we hardcode it.
+        fp_cv_prog_ar_needs_ranlib=yes
+    else
+        case $fp_prog_ar_args in
+        *s*)
+            fp_cv_prog_ar_needs_ranlib=no;;
+        *)
+            fp_cv_prog_ar_needs_ranlib=yes;;
+        esac
+    fi
+
+    # workaround for AC_PROG_RANLIB which sets RANLIB to `:' when
+    # ranlib is missing on the target OS. The problem is that
+    # ghc-cabal cannot execute `:' which is a shell built-in but can
+    # execute `true' which is usually simple program supported by the
+    # OS.
+    # Fixes #8795
+    if test "$RANLIB" = ":"
+    then
+        RANLIB="true"
+    fi
+    REAL_RANLIB_CMD="$RANLIB"
+    if test $fp_cv_prog_ar_needs_ranlib = yes
+    then
+        RANLIB_CMD="$RANLIB"
+    else
+        RANLIB_CMD="true"
+    fi
+    AC_SUBST([REAL_RANLIB_CMD])
+    AC_SUBST([RANLIB_CMD])
 ])# FP_PROG_AR_NEEDS_RANLIB
 
 
@@ -1138,6 +1217,7 @@ AC_SUBST(GccLT46)
 
 dnl Check to see if the C compiler is clang or llvm-gcc
 dnl
+GccIsClang=NO
 AC_DEFUN([FP_CC_LLVM_BACKEND],
 [AC_REQUIRE([AC_PROG_CC])
 AC_MSG_CHECKING([whether C compiler is clang])
@@ -1145,6 +1225,7 @@ $CC -x c /dev/null -dM -E > conftest.txt 2>&1
 if grep "__clang__" conftest.txt >/dev/null 2>&1; then
   AC_SUBST([CC_CLANG_BACKEND], [1])
   AC_SUBST([CC_LLVM_BACKEND], [1])
+  GccIsClang=YES
   AC_MSG_RESULT([yes])
 else
   AC_MSG_RESULT([no])
@@ -1159,6 +1240,7 @@ else
     AC_MSG_RESULT([no])
   fi
 fi
+AC_SUBST(GccIsClang)
 
 rm -f conftest.txt
 ])
@@ -1203,7 +1285,7 @@ if grep '^conftest.txt$' conftest.out > /dev/null 2>&1 ; then
     *mingw32)
       if test x${OSTYPE} != xmsys
       then
-           fp_prog_find="`cygpath --mixed ${fp_prog_find}`"
+        fp_prog_find="`cygpath --mixed ${fp_prog_find}`"
         AC_MSG_NOTICE([normalized find command to $fp_prog_find])
       fi ;;
     *) ;;
@@ -1219,6 +1301,26 @@ AC_SUBST([FindCmd])[]dnl
 ])# FP_PROG_FIND
 
 
+# FP_PROG_SORT
+# ------------
+# Find a Unix-like sort
+AC_DEFUN([FP_PROG_SORT],
+[AC_PATH_PROG([fp_prog_sort], [sort])
+echo conwip > conftest.txt
+$fp_prog_sort -f conftest.txt > conftest.out 2>&1
+if grep 'conwip' conftest.out > /dev/null 2>&1 ; then
+  # The goods
+  SortCmd="$fp_prog_sort"
+else
+  # Summink else..pick next one.
+  AC_MSG_WARN([$fp_prog_sort looks like a non-*nix sort, ignoring it])
+  FP_CHECK_PROG([SortCmd], [sort], [], [], [$fp_prog_sort])
+fi
+rm -f conftest.txt conftest.out
+AC_SUBST([SortCmd])[]dnl
+])# FP_PROG_SORT
+
+
 dnl
 dnl FPTOOLS_NOCACHE_CHECK prints a message, then sets the
 dnl values of the second argument to the result of running
@@ -1478,27 +1580,44 @@ if test "$RELEASE" = "NO"; then
         fi
         PACKAGE_VERSION=${PACKAGE_VERSION}.$ver_date
         AC_MSG_RESULT(inferred $PACKAGE_VERSION)
-    elif test -d _darcs; then
-        # TODO: Remove this branch after conversion to Git
-        changequote(, )dnl
-        ver_date=`darcs changes --quiet --no-summary --xml | head -500 | grep 'date=' | sed "s/^.*date='\([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\).*$/\1/g" | ${SortCmd} -n | tail -1`
-        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
-        changequote([, ])dnl
-                AC_MSG_ERROR([failed to detect version date: check that darcs is in your path])
-        fi
-        PACKAGE_VERSION=${PACKAGE_VERSION}.$ver_date
-        AC_MSG_RESULT(inferred $PACKAGE_VERSION)
     elif test -f VERSION; then
         PACKAGE_VERSION=`cat VERSION`
         AC_MSG_RESULT(given $PACKAGE_VERSION)
     else
-        AC_MSG_WARN([cannot determine snapshot version: no .git or _darcs directory and no VERSION file])
+        AC_MSG_WARN([cannot determine snapshot version: no .git directory and no VERSION file])
+        dnl We'd really rather this case didn't happen, but it might
+        dnl do (in particular, people using lndir trees may find that
+        dnl the build system can't find any other date). If it does
+        dnl happen, then we use the current date.
+        dnl This way we get some idea about how recent a build is.
+        dnl It also means that packages built for 2 different builds
+        dnl will probably use different version numbers, so things are
+        dnl less likely to go wrong.
+        PACKAGE_VERSION=${PACKAGE_VERSION}.`date +%Y%m%d`
     fi
 fi
 
+    AC_MSG_CHECKING([for GHC Git commit id])
+    if test -d .git; then
+        git_commit_id=`git rev-parse HEAD`
+        if test -n "$git_commit_id" 2>&1 >/dev/null; then true; else
+            AC_MSG_ERROR([failed to detect revision: check that git is in your path])
+        fi
+        PACKAGE_GIT_COMMIT_ID=$git_commit_id
+        AC_MSG_RESULT(inferred $PACKAGE_GIT_COMMIT_ID)
+    elif test -f GIT_COMMIT_ID; then
+        PACKAGE_GIT_COMMIT_ID=`cat GIT_COMMIT_ID`
+        AC_MSG_RESULT(given $PACKAGE_GIT_COMMIT_ID)
+    else
+        AC_MSG_WARN([cannot determine snapshot revision: no .git directory and no 'GIT_COMMIT_ID' file])
+        PACKAGE_GIT_COMMIT_ID="0000000000000000000000000000000000000000"
+    fi
+
+
 # Some renamings
 AC_SUBST([ProjectName], [$PACKAGE_NAME])
 AC_SUBST([ProjectVersion], [$PACKAGE_VERSION])
+AC_SUBST([ProjectGitCommitId], [$PACKAGE_GIT_COMMIT_ID])
 
 # Split PACKAGE_VERSION into (possibly empty) parts
 VERSION_MAJOR=`echo $PACKAGE_VERSION | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\1'/`
@@ -1517,6 +1636,13 @@ AC_SUBST([ProjectVersionInt])
 # The project patchlevel is zero unless stated otherwise
 test -z "$ProjectPatchLevel" && ProjectPatchLevel=0
 
+# Save split version of ProjectPatchLevel
+ProjectPatchLevel1=`echo $ProjectPatchLevel | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\1/'`
+ProjectPatchLevel2=`echo $ProjectPatchLevel | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\3/'`
+
+AC_SUBST([ProjectPatchLevel1])
+AC_SUBST([ProjectPatchLevel2])
+
 # Remove dots from the patch level; this allows us to have versions like 6.4.1.20050508
 ProjectPatchLevel=`echo $ProjectPatchLevel | sed 's/\.//'`
 
@@ -1537,9 +1663,9 @@ then
   then
     # We can't test timer_create when we're cross-compiling, so we
     # optimistiaclly assume that it actually works properly.
-    AC_DEFINE([USE_TIMER_CREATE], 1,  [Define to 1 if we can use timer_create(CLOCK_PROCESS_CPUTIME_ID,...)])
+    AC_DEFINE([USE_TIMER_CREATE], 1,  [Define to 1 if we can use timer_create(CLOCK_REALTIME,...)])
   else
-  AC_CACHE_CHECK([for a working timer_create(CLOCK_REALTIME)], 
+  AC_CACHE_CHECK([for a working timer_create(CLOCK_REALTIME)],
     [fptools_cv_timer_create_works],
     [AC_TRY_RUN([
 #include <stdio.h>
@@ -1598,36 +1724,6 @@ int main(int argc, char *argv[])
     }
     alarm(1);
 
-    if (timer_create(CLOCK_PROCESS_CPUTIME_ID, &ev, &timer) != 0) {
-        fprintf(stderr,"No CLOCK_PROCESS_CPUTIME_ID timer\n");
-       exit(1);
-    }
-
-    it.it_value.tv_sec = 0;
-    it.it_value.tv_nsec = 1;
-    it.it_interval = it.it_value;
-    if (timer_settime(timer, 0, &it, NULL) != 0) {
-        fprintf(stderr,"settime problem\n");
-        exit(4);
-    }
-
-    tock = 0;
-
-    for(n = 3; n < 20000; n++){
-        for(m = 2; m <= n/2; m++){
-            if (!(n%m)) count++;
-            if (tock) goto out;
-        }
-    }
-out:
-
-    if (!tock) {
-        fprintf(stderr,"no CLOCK_PROCESS_CPUTIME_ID signal\n");
-        exit(5);
-    }
-
-    timer_delete(timer);
-
     if (timer_create(CLOCK_REALTIME, &ev, &timer) != 0) {
         fprintf(stderr,"No CLOCK_REALTIME timer\n");
         exit(2);
@@ -1659,8 +1755,8 @@ out:
      [fptools_cv_timer_create_works=no])
   ])
 case $fptools_cv_timer_create_works in
-    yes) AC_DEFINE([USE_TIMER_CREATE], 1, 
-                   [Define to 1 if we can use timer_create(CLOCK_PROCESS_CPUTIME_ID,...)]);;
+    yes) AC_DEFINE([USE_TIMER_CREATE], 1,
+                   [Define to 1 if we can use timer_create(CLOCK_REALTIME,...)]);;
 esac
   fi
 fi
@@ -1714,34 +1810,27 @@ AC_DEFUN([FP_GMP],
   AC_SUBST(GMP_LIB_DIRS)
 ])# FP_GMP
 
-# FP_CHECK_MACOSX_DEPLOYMENT_TARGET
-# ---------------------------------
-AC_DEFUN([FP_CHECK_MACOSX_DEPLOYMENT_TARGET],
+# FP_CURSES
+# -------------
+AC_DEFUN([FP_CURSES],
 [
-if test "x$TargetOS_CPP-$TargetVendor_CPP" = "xdarwin-apple"; then
-  AC_MSG_CHECKING([Mac OS X deployment target])
-  case $FP_MACOSX_DEPLOYMENT_TARGET in
-    none)  ;;
-    10.4)  MACOSX_DEPLOYMENT_VERSION=10.4
-          MACOSX_DEPLOYMENT_SDK=/Developer/SDKs/MacOSX10.4u.sdk
-          ;;
-    10.4u) MACOSX_DEPLOYMENT_VERSION=10.4
-          MACOSX_DEPLOYMENT_SDK=/Developer/SDKs/MacOSX10.4u.sdk
-          ;;
-    *)     MACOSX_DEPLOYMENT_VERSION=$FP_MACOSX_DEPLOYMENT_TARGET
-          MACOSX_DEPLOYMENT_SDK=/Developer/SDKs/MacOSX${FP_MACOSX_DEPLOYMENT_TARGET}.sdk
-          ;;
-  esac
-  if test "x$FP_MACOSX_DEPLOYMENT_TARGET" = "xnone"; then
-    AC_MSG_RESULT(none)
-  else
-    if test ! -d $MACOSX_DEPLOYMENT_SDK; then
-      AC_MSG_ERROR([Unknown deployment target $FP_MACOSX_DEPLOYMENT_TARGET])
-    fi
-    AC_MSG_RESULT([${MACOSX_DEPLOYMENT_VERSION} (${MACOSX_DEPLOYMENT_SDK})])
-  fi
-fi
-])
+  dnl--------------------------------------------------------------------
+  dnl * Deal with arguments telling us curses is somewhere odd
+  dnl--------------------------------------------------------------------
+
+  AC_ARG_WITH([curses-includes],
+    [AC_HELP_STRING([--with-curses-includes],
+      [directory containing curses headers])],
+      [CURSES_INCLUDE_DIRS=$withval])
+
+  AC_ARG_WITH([curses-libraries],
+    [AC_HELP_STRING([--with-curses-libraries],
+      [directory containing curses libraries])],
+      [CURSES_LIB_DIRS=$withval])
+
+  AC_SUBST(CURSES_INCLUDE_DIRS)
+  AC_SUBST(CURSES_LIB_DIRS)
+])# FP_CURSES
 
 # --------------------------------------------------------------
 # Calculate absolute path to build tree
@@ -1754,7 +1843,12 @@ AC_MSG_NOTICE(Building in-tree ghc-pwd)
     dnl except we don't want to have to know what make is called. Sigh.
     rm -rf utils/ghc-pwd/dist-boot
     mkdir  utils/ghc-pwd/dist-boot
-    if ! "$WithGhc" -v0 -no-user-$GHC_PACKAGE_DB_FLAG -hidir utils/ghc-pwd/dist-boot -odir utils/ghc-pwd/dist-boot -stubdir utils/ghc-pwd/dist-boot --make utils/ghc-pwd/Main.hs -o utils/ghc-pwd/dist-boot/ghc-pwd
+    dnl If special linker flags are needed to build things, then allow
+    dnl the user to pass them in via LDFLAGS.
+    changequote(, )dnl
+    GHC_LDFLAGS=`perl -e 'foreach (@ARGV) { print "-optl$_ " }' -- $LDFLAGS`
+    changequote([, ])dnl
+    if ! "$WithGhc" $GHC_LDFLAGS -v0 -no-user-$GHC_PACKAGE_DB_FLAG -hidir utils/ghc-pwd/dist-boot -odir utils/ghc-pwd/dist-boot -stubdir utils/ghc-pwd/dist-boot --make utils/ghc-pwd/Main.hs -o utils/ghc-pwd/dist-boot/ghc-pwd
     then
         AC_MSG_ERROR([Building ghc-pwd failed])
     fi
@@ -1797,6 +1891,9 @@ AC_MSG_CHECKING(for path to top of build tree)
 # converts cpu from gnu to ghc naming, and assigns the result to $target_var
 AC_DEFUN([GHC_CONVERT_CPU],[
 case "$1" in
+  aarch64*)
+    $2="aarch64"
+    ;;
   alpha*)
     $2="alpha"
     ;;
@@ -1827,6 +1924,9 @@ case "$1" in
   mips*)
     $2="mips"
     ;;
+  powerpc64le*)
+    $2="powerpc64le"
+    ;;
   powerpc64*)
     $2="powerpc64"
     ;;
@@ -1851,7 +1951,7 @@ case "$1" in
   vax)
     $2="vax"
     ;;
-  x86_64)
+  x86_64|amd64)
     $2="x86_64"
     ;;
   *)
@@ -1872,6 +1972,9 @@ AC_DEFUN([GHC_CONVERT_VENDOR],[
   softfloat) # like armv5tel-softfloat-linux-gnueabi
     $2="unknown"
     ;;
+  hardfloat) # like armv7a-hardfloat-linux-gnueabi
+    $2="unknown"
+    ;;
   *)
     #pass thru by default
     $2="$1"
@@ -1879,33 +1982,40 @@ AC_DEFUN([GHC_CONVERT_VENDOR],[
   esac
 ])
 
-# GHC_CONVERT_OS(os, target_var)
+# GHC_CONVERT_OS(os, converted_cpu, target_var)
 # --------------------------------
 # converts os from gnu to ghc naming, and assigns the result to $target_var
 AC_DEFUN([GHC_CONVERT_OS],[
-case "$1" in
-  linux-android*)
-    $2="linux-android"
-    ;;
-  linux-*|linux)
-    $2="linux"
-    ;;
-  # As far as I'm aware, none of these have relevant variants
-  freebsd|netbsd|openbsd|dragonfly|osf1|osf3|hpux|linuxaout|kfreebsdgnu|freebsd2|solaris2|cygwin32|mingw32|darwin|gnu|nextstep2|nextstep3|sunos4|ultrix|irix|aix|haiku)
-    $2="$1"
-    ;;
-  freebsd*) # like i686-gentoo-freebsd7
-            #      i686-gentoo-freebsd8
-            #      i686-gentoo-freebsd8.2
-    $2="freebsd"
-    ;;
-  nto-qnx*)
-    $2="nto-qnx"
+case "$1-$2" in
+  darwin10-arm|darwin11-i386|darwin14-aarch64)
+    $3="ios"
     ;;
   *)
-    echo "Unknown OS $1"
-    exit 1
-    ;;
+    case "$1" in
+      linux-android*)
+        $3="linux-android"
+        ;;
+      linux-*|linux)
+        $3="linux"
+        ;;
+      # As far as I'm aware, none of these have relevant variants
+      freebsd|netbsd|openbsd|dragonfly|osf1|osf3|hpux|linuxaout|kfreebsdgnu|freebsd2|solaris2|cygwin32|mingw32|darwin|gnu|nextstep2|nextstep3|sunos4|ultrix|irix|aix|haiku)
+        $3="$1"
+        ;;
+      freebsd*) # like i686-gentoo-freebsd7
+                #      i686-gentoo-freebsd8
+                #      i686-gentoo-freebsd8.2
+        $3="freebsd"
+        ;;
+      nto-qnx*)
+        $3="nto-qnx"
+        ;;
+      *)
+        echo "Unknown OS $1"
+        exit 1
+        ;;
+      esac
+      ;;
   esac
 ])
 
@@ -1960,6 +2070,75 @@ AC_DEFUN([XCODE_VERSION],[
     fi
 ])
 
+# FIND_LLVM_PROG()
+# --------------------------------
+# Find where the llvm tools are. We have a special function to handle when they
+# are installed with a version suffix (e.g., llc-3.1).
+#
+# $1 = the variable to set
+# $2 = the with option name
+# $3 = the command to look for
+# $4 = the version of the command to look for
+#
+AC_DEFUN([FIND_LLVM_PROG],[
+    # Test for program with version name.
+    FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL_NOTARGET([$1], [$2], [$3-$4])
+    if test "$$1" = ""; then
+        # Test for program without version name.
+        FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL_NOTARGET([$1], [$2], [$3])
+        AC_MSG_CHECKING([$$1 is version $4])
+        if test `$$1 --version | grep -c "version $4"` -gt 0 ; then
+            AC_MSG_RESULT(yes)
+        else
+            AC_MSG_RESULT(no)
+            $1=""
+        fi
+    fi
+])
+
+# FIND_LD
+# Find the version of `ld` to use. This is used in both in the top level
+# configure.ac and in distrib/configure.ac.in.
+#
+# $1 = the variable to set
+#
+AC_DEFUN([FIND_LD],[
+    FP_ARG_WITH_PATH_GNU_PROG([LD], [ld], [ld])
+    case $target in
+        arm*linux*       | \
+        aarch64*linux*   )
+            # Arm and Aarch64 requires use of the binutils ld.gold linker.
+            # This case should catch at least arm-unknown-linux-gnueabihf,
+            # arm-linux-androideabi, arm64-unknown-linux and
+            # aarch64-linux-android
+            FP_ARG_WITH_PATH_GNU_PROG([LD_GOLD], [ld.gold], [ld.gold])
+            $1="$LD_GOLD"
+            ;;
+        *)
+            $1="$LD"
+            ;;
+    esac
+])
+
+# FIND_GHC_BOOTSTRAP_PROG()
+# --------------------------------
+# Parse the bootstrap GHC's compier settings file for the location of things
+# like the `llc` and `opt` commands.
+#
+# $1 = the variable to set
+# $2 = The bootstrap compiler.
+# $3 = The string to grep for to find the correct line.
+#
+AC_DEFUN([FIND_GHC_BOOTSTRAP_PROG],[
+    BootstrapTmpCmd=`grep $3 $($2 --print-libdir)/settings 2>/dev/null | sed 's/.*", "//;s/".*//'`
+    if test -n "$BootstrapTmpCmd" && test `basename $BootstrapTmpCmd` = $BootstrapTmpCmd ; then
+        AC_PATH_PROG([$1], [$BootstrapTmpCmd], "")
+    else
+        $1=$BootstrapTmpCmd
+    fi
+])
+
+
 # FIND_GCC()
 # --------------------------------
 # Finds where gcc is
@@ -1980,9 +2159,176 @@ AC_DEFUN([FIND_GCC],[
     then
         $1="$CC"
     else
-        FP_ARG_WITH_PATH_GNU_PROG([$1], [$2], [$3])
+        FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL([$1], [$2], [$3])
+        # From Xcode 5 on/, OS X command line tools do not include gcc
+        # anymore. Use clang.
+        if test -z "$$1"
+        then
+            FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL([$1], [clang], [clang])
+        fi
+        if test -z "$$1"
+        then
+            AC_MSG_ERROR([cannot find $3 nor clang in your PATH])
+        fi
     fi
     AC_SUBST($1)
 ])
 
+AC_DEFUN([MAYBE_OVERRIDE_STAGE0],[
+  if test ! -z "$With_$1" -a "$CrossCompiling" != "YES"; then
+      AC_MSG_NOTICE([Not cross-compiling, so --with-$1 also sets $2])
+      $2=$With_$1
+  fi
+])
+
+
+# FP_CPP_CMD_WITH_ARGS()
+# ----------------------
+# sets CPP command and its arguments
+#
+# $1 = the variable to set to CPP command
+# $2 = the varibale to set to CPP command arguments
+
+AC_DEFUN([FP_CPP_CMD_WITH_ARGS],[
+dnl ** what cpp to use?
+dnl --------------------------------------------------------------
+AC_ARG_WITH(hs-cpp,
+[AC_HELP_STRING([--with-hs-cpp=ARG],
+      [Path to the (C) preprocessor for Haskell files [default=autodetect]])],
+[
+    if test "$HostOS" = "mingw32"
+    then
+        AC_MSG_WARN([Request to use $withval will be ignored])
+    else
+        HS_CPP_CMD=$withval
+    fi
+],
+[
+
+    # We can't use $CPP here, since HS_CPP_CMD is expected to be a single
+    # command (no flags), and AC_PROG_CPP defines CPP as "/usr/bin/gcc -E".
+    HS_CPP_CMD=$WhatGccIsCalled
+
+    SOLARIS_GCC_CPP_BROKEN=NO
+    SOLARIS_FOUND_GOOD_CPP=NO
+    case $host in
+        i386-*-solaris2)
+        GCC_MAJOR_MINOR=`$WhatGccIsCalled --version|grep "gcc (GCC)"|cut -d ' ' -f 3-3|cut -d '.' -f 1-2`
+        if test "$GCC_MAJOR_MINOR" != "3.4"; then
+          # this is not 3.4.x release so with broken CPP
+          SOLARIS_GCC_CPP_BROKEN=YES
+        fi
+        ;;
+    esac
+
+    if test "$SOLARIS_GCC_CPP_BROKEN" = "YES"; then
+      # let's try to find if GNU C 3.4.x is installed
+      if test -x /usr/sfw/bin/gcc; then
+        # something executable is in expected path so let's
+        # see if it's really GNU C
+        NEW_GCC_MAJOR_MINOR=`/usr/sfw/bin/gcc --version|grep "gcc (GCC)"|cut -d ' ' -f 3-3|cut -d '.' -f 1-2`
+        if test "$NEW_GCC_MAJOR_MINOR" = "3.4"; then
+          # this is GNU C 3.4.x which provides non-broken CPP on Solaris
+          # let's use it as CPP then.
+          HS_CPP_CMD=/usr/sfw/bin/gcc
+          SOLARIS_FOUND_GOOD_CPP=YES
+        fi
+      fi
+      if test "$SOLARIS_FOUND_GOOD_CPP" = "NO"; then
+        AC_MSG_WARN([Your GNU C provides broken CPP and you do not have GNU C 3.4.x installed.])
+        AC_MSG_WARN([Please install GNU C 3.4.x to solve this issue. It will be used as CPP only.])
+      fi
+    fi
+]
+)
+
+
+
+dnl ** what cpp flags to use?
+dnl -----------------------------------------------------------
+AC_ARG_WITH(hs-cpp-flags,
+  [AC_HELP_STRING([--with-hs-cpp-flags=ARG],
+      [Flags to the (C) preprocessor for Haskell files [default=autodetect]])],
+  [
+      if test "$HostOS" = "mingw32"
+      then
+          AC_MSG_WARN([Request to use $withval will be ignored])
+      else
+          HS_CPP_ARGS=$withval
+      fi
+  ],
+[
+  $HS_CPP_CMD -x c /dev/null -dM -E > conftest.txt 2>&1
+  if grep "__clang__" conftest.txt >/dev/null 2>&1; then
+    HS_CPP_ARGS="-E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs"
+  else
+      $HS_CPP_CMD  -v > conftest.txt 2>&1
+      if  grep "gcc" conftest.txt >/dev/null 2>&1; then
+          HS_CPP_ARGS="-E -undef -traditional"
+        else
+          $HS_CPP_CMD  --version > conftest.txt 2>&1
+          if grep "cpphs" conftest.txt >/dev/null 2>&1; then
+            HS_CPP_ARGS="--cpp -traditional"
+          else
+            AC_MSG_WARN([configure can't recognize your CPP program, you may need to set --with-hs-cpp-flags=FLAGS explicitly])
+            HS_CPP_ARGS=""
+          fi
+      fi
+  fi
+  ]
+)
+
+$1=$HS_CPP_CMD
+$2=$HS_CPP_ARGS
+
+])
+
+# FP_BFD_SUPPORT()
+# ----------------------
+# whether to use libbfd for debugging RTS
+AC_DEFUN([FP_BFD_SUPPORT], [
+    AC_ARG_ENABLE(bfd-debug,
+        [AC_HELP_STRING([--enable-bfd-debug],
+              [Enable symbol resolution for -debug rts ('+RTS -Di') via binutils' libbfd [default=no]])],
+        [
+            # don't pollute general LIBS environment
+            save_LIBS="$LIBS"
+            AC_CHECK_HEADERS([bfd.h])
+            dnl ** check whether this machine has BFD and libiberty installed (used for debugging)
+            dnl    the order of these tests matters: bfd needs libiberty
+            AC_CHECK_LIB(iberty, xmalloc)
+            dnl 'bfd_init' is a rare non-macro in libbfd
+            AC_CHECK_LIB(bfd,    bfd_init)
+
+            AC_TRY_LINK([#include <bfd.h>],
+                        [
+                                /* mimic our rts/Printer.c */
+                                bfd* abfd;
+                                const char * name;
+                                char **matching;
+
+                                name = "some.executable";
+                                bfd_init();
+                                abfd = bfd_openr(name, "default");
+                                bfd_check_format_matches (abfd, bfd_object, &matching);
+                                {
+                                    long storage_needed;
+                                    storage_needed = bfd_get_symtab_upper_bound (abfd);
+                                }
+                                {
+                                    asymbol **symbol_table;
+                                    long number_of_symbols;
+                                    symbol_info info;
+
+                                    number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
+                                    bfd_get_symbol_info(abfd,symbol_table[0],&info);
+                                }
+                        ],
+                        [],dnl bfd seems to work
+                        [AC_MSG_ERROR([can't use 'bfd' library])])
+            LIBS="$save_LIBS"
+        ]
+    )
+])
+
 # LocalWords:  fi