libgo: handle --with-toolexeclibdir=.

Patch by Maciej W. Rozycki.

Change-Id: Ifeeae4e164f4e5bc7039faffea20b993add820d7
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/216239
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/libgo/Makefile.in b/libgo/Makefile.in
index 88c6874..0ff6ba1 100644
--- a/libgo/Makefile.in
+++ b/libgo/Makefile.in
@@ -114,6 +114,7 @@
 	$(top_srcdir)/../config/lead-dot.m4 \
 	$(top_srcdir)/../config/multi.m4 \
 	$(top_srcdir)/../config/override.m4 \
+	$(top_srcdir)/../config/toolexeclibdir.m4 \
 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
 	$(top_srcdir)/config/libtool.m4 \
 	$(top_srcdir)/config/ltoptions.m4 \
diff --git a/libgo/aclocal.m4 b/libgo/aclocal.m4
index 951aed3..739b97a 100644
--- a/libgo/aclocal.m4
+++ b/libgo/aclocal.m4
@@ -1192,6 +1192,7 @@
 m4_include([../config/lead-dot.m4])
 m4_include([../config/multi.m4])
 m4_include([../config/override.m4])
+m4_include([../config/toolexeclibdir.m4])
 m4_include([../config/unwind_ipinfo.m4])
 m4_include([config/libtool.m4])
 m4_include([config/ltoptions.m4])
diff --git a/libgo/configure b/libgo/configure
index 385ca9a..2f78739 100755
--- a/libgo/configure
+++ b/libgo/configure
@@ -849,6 +849,7 @@
 enable_libtool_lock
 enable_werror
 enable_version_specific_runtime_libs
+with_toolexeclibdir
 with_libffi
 with_libatomic
 with_system_libunwind
@@ -1503,6 +1504,9 @@
   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
   --with-pic              try to use only PIC/non-PIC objects [default=use
                           both]
+  --with-toolexeclibdir=DIR
+                          install libraries built with a cross compiler within
+                          DIR
   --without-libffi        don't use libffi
   --without-libatomic     don't use libatomic
   --with-system-libunwind use installed libunwind
@@ -11486,7 +11490,7 @@
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11489 "configure"
+#line 11493 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11592,7 +11596,7 @@
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11595 "configure"
+#line 11599 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -13800,6 +13804,22 @@
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $version_specific_libs" >&5
 $as_echo "$version_specific_libs" >&6; }
 
+
+# Check whether --with-toolexeclibdir was given.
+if test "${with_toolexeclibdir+set}" = set; then :
+  withval=$with_toolexeclibdir; case ${with_toolexeclibdir} in
+  /)
+    ;;
+  */)
+    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
+    ;;
+esac
+else
+  with_toolexeclibdir=no
+fi
+
+
+
 # Version-specific runtime libs processing.
 if test $version_specific_libs = yes; then
   glibgo_toolexecdir='${libdir}/gcc/${host_alias}'
@@ -13811,7 +13831,14 @@
 if test -n "$with_cross_host" &&
    test x"$with_cross_host" != x"no"; then
   nover_glibgo_toolexecdir='${exec_prefix}/${host_alias}'
-  nover_glibgo_toolexeclibdir='${toolexecdir}/lib'
+  case ${with_toolexeclibdir} in
+    no)
+      nover_glibgo_toolexeclibdir='${toolexecdir}/lib'
+      ;;
+    *)
+      nover_glibgo_toolexeclibdir=${with_toolexeclibdir}
+      ;;
+  esac
 else
   nover_glibgo_toolexecdir='${libdir}/gcc/${host_alias}'
   nover_glibgo_toolexeclibdir='${libdir}'
diff --git a/libgo/configure.ac b/libgo/configure.ac
index 07c03bc..f800d44 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -80,6 +80,8 @@
   [version_specific_libs=no])
 AC_MSG_RESULT($version_specific_libs)
 
+GCC_WITH_TOOLEXECLIBDIR
+
 # Version-specific runtime libs processing.
 if test $version_specific_libs = yes; then
   glibgo_toolexecdir='${libdir}/gcc/${host_alias}'
@@ -91,7 +93,14 @@
 if test -n "$with_cross_host" &&
    test x"$with_cross_host" != x"no"; then
   nover_glibgo_toolexecdir='${exec_prefix}/${host_alias}'
-  nover_glibgo_toolexeclibdir='${toolexecdir}/lib'
+  case ${with_toolexeclibdir} in
+    no)
+      nover_glibgo_toolexeclibdir='${toolexecdir}/lib'
+      ;;
+    *)
+      nover_glibgo_toolexeclibdir=${with_toolexeclibdir}
+      ;;
+  esac
 else
   nover_glibgo_toolexecdir='${libdir}/gcc/${host_alias}'
   nover_glibgo_toolexeclibdir='${libdir}'
diff --git a/libgo/testsuite/Makefile.in b/libgo/testsuite/Makefile.in
index 7b4b27f..3d55e26 100644
--- a/libgo/testsuite/Makefile.in
+++ b/libgo/testsuite/Makefile.in
@@ -95,6 +95,7 @@
 	$(top_srcdir)/../config/lead-dot.m4 \
 	$(top_srcdir)/../config/multi.m4 \
 	$(top_srcdir)/../config/override.m4 \
+	$(top_srcdir)/../config/toolexeclibdir.m4 \
 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
 	$(top_srcdir)/config/libtool.m4 \
 	$(top_srcdir)/config/ltoptions.m4 \