configure: Add detection of the linker version string.
 - Review appreciated, as long as you understand that I understand that this is
   a horrible hack.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110883 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index 29a57b8..7211fe1 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1041,6 +1041,9 @@
 AC_PATH_PROGS(OCAMLDOC, [ocamldoc])
 AC_PATH_PROGS(GAS, [gas as])
 
+dnl Get the version of the linker in use.
+AC_LINK_GET_VERSION
+
 dnl Determine whether the linker supports the -R option.
 AC_LINK_USE_R
 
diff --git a/autoconf/m4/link_options.m4 b/autoconf/m4/link_options.m4
index b48710c..4c5f2f4 100644
--- a/autoconf/m4/link_options.m4
+++ b/autoconf/m4/link_options.m4
@@ -1,4 +1,25 @@
 #
+# Get the linker version string.
+#
+# This macro is specific to LLVM.
+#
+AC_DEFUN([AC_LINK_GET_VERSION],
+  [AC_CACHE_CHECK([for linker version],[llvm_cv_link_version],
+  [
+   version_string="$(ld -v 2>&1 | head -1)"
+
+   # Check for ld64.
+   if (echo "$version_string" | grep -q "ld64"); then
+     llvm_cv_link_version=$(echo "$version_string" | sed -e "s#.*ld64-\([^ ]*\)#\1#")
+   else
+     llvm_cv_link_version=$(echo "$version_string" | sed -e "s#[^0-9]*\([0-9.]*\).*#\1#")
+   fi
+  ])
+  AC_DEFINE_UNQUOTED([HOST_LINK_VERSION],"$llvm_cv_link_version",
+                     [Linker version detected at compile time.])
+])
+
+#
 # Determine if the system can handle the -R option being passed to the linker.
 #
 # This macro is specific to LLVM.
diff --git a/configure b/configure
index 831acb6..dd61dab 100755
--- a/configure
+++ b/configure
@@ -8729,6 +8729,31 @@
 done
 
 
+{ echo "$as_me:$LINENO: checking for linker version" >&5
+echo $ECHO_N "checking for linker version... $ECHO_C" >&6; }
+if test "${llvm_cv_link_version+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+   version_string="$(ld -v 2>&1 | head -1)"
+
+   # Check for ld64.
+   if (echo "$version_string" | grep -q "ld64"); then
+     llvm_cv_link_version=$(echo "$version_string" | sed -e "s#.*ld64-\([^ ]*\)#\1#")
+   else
+     llvm_cv_link_version=$(echo "$version_string" | sed -e "s#[^0-9]*\([0-9.]*\).*#\1#")
+   fi
+
+fi
+{ echo "$as_me:$LINENO: result: $llvm_cv_link_version" >&5
+echo "${ECHO_T}$llvm_cv_link_version" >&6; }
+
+cat >>confdefs.h <<_ACEOF
+#define HOST_LINK_VERSION "$llvm_cv_link_version"
+_ACEOF
+
+
+
 { echo "$as_me:$LINENO: checking for compiler -Wl,-R<path> option" >&5
 echo $ECHO_N "checking for compiler -Wl,-R<path> option... $ECHO_C" >&6; }
 if test "${llvm_cv_link_use_r+set}" = set; then
@@ -11395,7 +11420,7 @@
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 11398 "configure"
+#line 11423 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index 5fe3da2..d0612fe 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -467,6 +467,9 @@
 /* Define to 1 if you have the `__dso_handle' function. */
 #undef HAVE___DSO_HANDLE
 
+/* Linker version detected at compile time. */
+#undef HOST_LINK_VERSION
+
 /* Installation directory for binary executables */
 #undef LLVM_BINDIR