more portable;
authorwenzelm
Tue, 13 Oct 2020 16:17:08 +0200
changeset 72460 e79294c4230c
parent 72458 b44e894796d5
child 72461 4c6f318bcf9c
more portable; tuned;
src/Pure/System/executable.scala
--- a/src/Pure/System/executable.scala	Mon Oct 12 18:59:44 2020 +0200
+++ b/src/Pure/System/executable.scala	Tue Oct 13 16:17:08 2020 +0200
@@ -9,11 +9,12 @@
 
 object Executable
 {
-  def libraries_closure(exe_path0: Path,
+  def libraries_closure(path: Path,
     mingw: MinGW = MinGW.none,
-    filter: String => Boolean = _ => true): List[String] =
+    filter: String => Boolean = _ => true,
+    patchelf: Boolean = false): List[String] =
   {
-    val exe_path = exe_path0.expand
+    val exe_path = path.expand
     val exe_dir = exe_path.dir
     val exe = exe_path.base
 
@@ -51,8 +52,16 @@
       libs.foreach(lib => File.copy(Path.explode(lib), exe_dir))
 
       if (Platform.is_linux) {
-        // requires "LDFLAGS=-Wl,-rpath,_DUMMY_"
-        Isabelle_System.bash("chrpath -r '$ORIGIN' " + File.bash_path(exe_path)).check
+        if (patchelf) {
+          // requires e.g. Ubuntu 16.04 LTS
+          Isabelle_System.require_command("patchelf")
+          Isabelle_System.bash("patchelf --force-rpath --set-rpath '$ORIGIN' " + File.bash_path(exe_path)).check
+        }
+        else {
+          // requires e.g. LDFLAGS=-Wl,-rpath,_DUMMY_
+          Isabelle_System.require_command("chrpath")
+          Isabelle_System.bash("chrpath -r '$ORIGIN' " + File.bash_path(exe_path)).check
+        }
       }
       else if (Platform.is_macos) {
         val script =