Typo in note
[ghc.git] / aclocal.m4
index af492df..5923e97 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)
+        $2='.a'
+        $3='.dylib'
+        ;;
+    esac
+])
+
 # FPTOOLS_SET_PLATFORM_VARS
 # ----------------------------------
 # Set the platform variables
@@ -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/.*-//'`
@@ -86,25 +114,12 @@ AC_DEFUN([FPTOOLS_SET_PLATFORM_VARS],
         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,7 +181,7 @@ 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)
@@ -180,6 +197,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"
             ;;
@@ -189,7 +209,7 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
         mipsel)
             test -z "[$]2" || eval "[$]2=ArchMipsel"
             ;;
-        hppa|hppa1_1|ia64|m68k|rs6000|s390|s390x|sparc64|vax)
+        hppa|hppa1_1|ia64|m68k|powerpc64le|rs6000|s390|s390x|sparc64|vax)
             test -z "[$]2" || eval "[$]2=ArchUnknown"
             ;;
         *)
@@ -447,6 +467,7 @@ AC_DEFUN([FP_SETTINGS],
         SettingsPerlCommand="$PerlCmd"
         SettingsDllWrapCommand="/bin/false"
         SettingsWindresCommand="/bin/false"
+        SettingsLibtoolCommand="libtool"
         SettingsTouchCommand='touch'
         if test -z "$LlcCmd"
         then
@@ -473,6 +494,7 @@ AC_DEFUN([FP_SETTINGS],
     AC_SUBST(SettingsPerlCommand)
     AC_SUBST(SettingsDllWrapCommand)
     AC_SUBST(SettingsWindresCommand)
+    AC_SUBST(SettingsLibtoolCommand)
     AC_SUBST(SettingsTouchCommand)
     AC_SUBST(SettingsLlcCommand)
     AC_SUBST(SettingsOptCommand)
@@ -624,6 +646,10 @@ 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"
@@ -666,6 +692,10 @@ 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"
@@ -829,7 +859,7 @@ 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 at least Happy version 1.19.  If there's no installed Happy, we look
 dnl for a happy source tree and point the build system at that instead.
 dnl
 AC_DEFUN([FPTOOLS_HAPPY],
@@ -845,10 +875,10 @@ else
 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],
+      [AC_MSG_ERROR([Happy version 1.19 or later is required to compile GHC.])])[]
 fi
 HappyVersion=$fptools_cv_happy_version;
 AC_SUBST(HappyVersion)
@@ -876,13 +906,8 @@ 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.])])[]
-fi
-if test ! -f utils/haddock/src/Haddock/Lex.hs
-then
-    FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-lt],[3.0],
-      [AC_MSG_ERROR([Alex version 3.0 or later is required to compile Haddock.])])[]
+    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)
@@ -1096,30 +1121,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
 
 
@@ -1153,6 +1200,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])
@@ -1160,6 +1208,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])
@@ -1174,6 +1223,7 @@ else
     AC_MSG_RESULT([no])
   fi
 fi
+AC_SUBST(GccIsClang)
 
 rm -f conftest.txt
 ])
@@ -1573,7 +1623,7 @@ then
     # 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,...)])
   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>
@@ -1693,7 +1743,7 @@ out:
      [fptools_cv_timer_create_works=no])
   ])
 case $fptools_cv_timer_create_works in
-    yes) AC_DEFINE([USE_TIMER_CREATE], 1, 
+    yes) AC_DEFINE([USE_TIMER_CREATE], 1,
                    [Define to 1 if we can use timer_create(CLOCK_PROCESS_CPUTIME_ID,...)]);;
 esac
   fi
@@ -1759,7 +1809,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=`echo $LDFLAGS | sed 's/\(^\| \)\([^ ]\)/\1-optl\2/g'`
+    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
@@ -1802,6 +1857,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"
     ;;
@@ -1832,6 +1890,9 @@ case "$1" in
   mips*)
     $2="mips"
     ;;
+  powerpc64le*)
+    $2="powerpc64le"
+    ;;
   powerpc64*)
     $2="powerpc64"
     ;;
@@ -1856,7 +1917,7 @@ case "$1" in
   vax)
     $2="vax"
     ;;
-  x86_64)
+  x86_64|amd64)
     $2="x86_64"
     ;;
   *)
@@ -1889,7 +1950,7 @@ AC_DEFUN([GHC_CONVERT_VENDOR],[
 # converts os from gnu to ghc naming, and assigns the result to $target_var
 AC_DEFUN([GHC_CONVERT_OS],[
 case "$1-$2" in
-  darwin10-arm)
+  darwin10-arm|darwin11-i386)
     $3="ios"
     ;;
   *)
@@ -2018,9 +2079,26 @@ 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
+])
+
 # LocalWords:  fi