From fc77ab3c9e413c3a17f711a5bccd1d1c85d49a5b Mon Sep 17 00:00:00 2001
From: Iain Sandoe <iain@sandoe.co.uk>
Date: Sat, 10 Apr 2021 14:10:45 +0100
Subject: [PATCH] configure, Darwin : Adjust RPATH_ENVVAR for embedded
 run-paths.

Darwin versions later than Darwin14 cannot use DYLD_LIBRARY_PATH to
provide the run-path for stage 1 target and stage 2+ configure, since
system tools like /bin/sh remove the environment variable.  If we want
to access this info we will have to do so explicitly; so provide a
separate (non DYLD_) environment variable for this.  We default to an
embedded run-path for these OS versions.
Embedded run-paths are optional (but recommended) on Darwin9 to 14.

Signed-off-by: Kirill A. Korinsky <kirill@korins.ky>
---
 configure    | 16 +++++++++++++++-
 configure.ac | 16 +++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git configure configure
index a7c063be9a6..049090f755e 100755
--- configure
+++ configure
@@ -7218,7 +7218,21 @@ rm -f conftest*
 # Decide which environment variable is used to find dynamic libraries.
 case "${host}" in
   *-*-hpux*) RPATH_ENVVAR=SHLIB_PATH ;;
-  *-*-darwin*) RPATH_ENVVAR=DYLD_LIBRARY_PATH ;;
+  *-*-darwin[45678]*) RPATH_ENVVAR=DYLD_LIBRARY_PATH ;;
+  *-*-darwin*)
+    if test "x$enable_darwin_at_rpath" != "xyes"; then
+      RPATH_ENVVAR=DYLD_LIBRARY_PATH
+    else
+      # Darwin versions later than Darwin14 cannot use DYLD_LIBRARY_PATH to
+      # provide the run-path for stage 1 target and stage 2+ configure, since
+      # system tools like /bin/sh remove the environment variable.  If we want
+      # to access this info we will have to do so explicitly; so provide a
+      # separate (non DYLD_) environment variable for this.  We default to an
+      # embedded run-path for these OS versions.
+      # Embedded run-paths are optional (but recommended) on Darwin9 to 14.
+      RPATH_ENVVAR=GCC_HOST_LIBRARY_PATH
+    fi
+    ;;
   *-*-mingw* | *-*-cygwin ) RPATH_ENVVAR=PATH ;;
   *) RPATH_ENVVAR=LD_LIBRARY_PATH ;;
 esac
diff --git configure.ac configure.ac
index 93bd64dcc2d..292bdeab64b 100644
--- configure.ac
+++ configure.ac
@@ -2720,7 +2720,21 @@ rm -f conftest*
 # Decide which environment variable is used to find dynamic libraries.
 case "${host}" in
   *-*-hpux*) RPATH_ENVVAR=SHLIB_PATH ;;
-  *-*-darwin*) RPATH_ENVVAR=DYLD_LIBRARY_PATH ;;
+  *-*-darwin[[45678]]*) RPATH_ENVVAR=DYLD_LIBRARY_PATH ;;
+  *-*-darwin*)
+    if test "x$enable_darwin_at_rpath" != "xyes"; then
+      RPATH_ENVVAR=DYLD_LIBRARY_PATH
+    else
+      # Darwin versions later than Darwin14 cannot use DYLD_LIBRARY_PATH to
+      # provide the run-path for stage 1 target and stage 2+ configure, since
+      # system tools like /bin/sh remove the environment variable.  If we want
+      # to access this info we will have to do so explicitly; so provide a
+      # separate (non DYLD_) environment variable for this.  We default to an
+      # embedded run-path for these OS versions.
+      # Embedded run-paths are optional (but recommended) on Darwin9 to 14. 
+      RPATH_ENVVAR=GCC_HOST_LIBRARY_PATH
+    fi
+    ;;
   *-*-mingw* | *-*-cygwin ) RPATH_ENVVAR=PATH ;;
   *) RPATH_ENVVAR=LD_LIBRARY_PATH ;;
 esac
-- 
2.42.1

