From d6983529905256b62386cee7338a6bb42772e581 Mon Sep 17 00:00:00 2001
From: thomas <kreitler@molgen.mpg.de>
Date: Wed, 9 Oct 2019 16:56:06 +0200
Subject: [PATCH] R-3.6.1 build: fix interoperation w. rstudio

Rstudio sets an own environment for its bin/rsession.
Unfortunately it sets the LD_LIBRARY_PATH only for
'the detected R binary-rootdir'/lib/R/lib.

Since the geospatial goodies required by 'sf' are installed
under pkg/Rxyz/lib the rpath set in the sf module isn't
sufficient.

The patchelf addition fixes this. In the next build it could
also be done with compile time flags.

Doing it this way keeps the option to run rstudio with
other R versions (e.g. source /pkg/R-3.5/profile; rstudio).
---
 R-3.6.1-0.build.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/R-3.6.1-0.build.sh b/R-3.6.1-0.build.sh
index 2a0806d..d64923a 100755
--- a/R-3.6.1-0.build.sh
+++ b/R-3.6.1-0.build.sh
@@ -254,6 +254,14 @@ cat <<- RCODEXXX | Rscript -
   }
 RCODEXXX
 
+# rstudios rsession does a lot of magic to detect the true R binary, thus bypassing
+# our friendly 'hints' from the wrapper.
+# tell lib/R/library/sf/libs/sf.so about lib -- yes it's the beloved sf package again!
+# the original rpath is only set to /pkg/R-3.6.1-0/lib/R/lib, add /pkg/R-3.6.1-0/lib.
+
+patchelf --set-rpath $PREFIX/lib/R/lib:$PREFIX/lib \
+         $PREFIX/lib/R/library/sf/libs/sf.so
+
 exit
 
 # NOTES: