From 0a777847ecb63df3a89f595e6033af7d56364081 Mon Sep 17 00:00:00 2001
From: "Alex Xu (Hello71)" <alex_y_xu@yahoo.ca>
Date: Sat, 4 Mar 2023 02:02:35 +0100
Subject: [PATCH] Fix run-time linking issue

Add $ORIGIN to rpath to fix finding of libraries at /usr/lib/wine/...

Origin: Alpine Linux
Ref: https://gitlab.alpinelinux.org/alpine/aports/-/issues/13249
Ref: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/27930
[ismael@sourcemage.org: Added commit message and ported to wine 8.3]
Signed-off-by: Ismael Luceno <ismael@sourcemage.org>
Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
---
 configure    | 33 +++++++++++++++++++++++++++++++++
 configure.ac |  3 +++
 2 files changed, 36 insertions(+)

diff --git a/configure b/configure
index 4f4c37756c10..9eee210221e6 100755
--- a/configure
+++ b/configure
@@ -10295,6 +10295,39 @@ fi
         esac
         ;;
     esac
+    # Allow to find dependencies in the same directory
+    as_ac_var=`printf "%s\n" "ac_cv_cflags_-Wl,-rpath,\\\\\\$ORIGIN" | sed "$as_sed_sh"`
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports -Wl,-rpath,\\\$ORIGIN" >&5
+printf %s "checking whether the compiler supports -Wl,-rpath,\\\$ORIGIN... " >&6; }
+if eval test \${$as_ac_var+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) ac_wine_try_cflags_saved=$CFLAGS
+CFLAGS="$CFLAGS -Wl,-rpath,\\\$ORIGIN"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int main(int argc, char **argv) { return 0; }
+_ACEOF
+if ac_fn_c_try_link "$LINENO"
+then :
+  eval "$as_ac_var=yes"
+else case e in #(
+  e) eval "$as_ac_var=no" ;;
+esac
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam \
+    conftest$ac_exeext conftest.$ac_ext
+CFLAGS=$ac_wine_try_cflags_saved ;;
+esac
+fi
+eval ac_res=\$$as_ac_var
+	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+printf "%s\n" "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_var"\" = x"yes"
+then :
+  UNIXLDFLAGS="$UNIXLDFLAGS '-Wl,-rpath,\$\$ORIGIN'"
+fi
     ;;
 esac
 
diff --git a/configure.ac b/configure.ac
index 3f54230b46bb..34feb05b8265 100644
--- a/configure.ac
+++ b/configure.ac
@@ -762,6 +762,9 @@ case $host_os in
         esac
         ;;
     esac
+    # Allow to find dependencies in the same directory
+    WINE_TRY_CFLAGS([-Wl,-rpath,\\\$ORIGIN],
+        [UNIXLDFLAGS="$UNIXLDFLAGS '-Wl,-rpath,\$\$ORIGIN'"])
     ;;
 esac
 
-- 
2.44.0

