gnu: Add python-mediafile.
[jackhill/guix/guix.git] / gnu / packages / patches / guile-relocatable.patch
CommitLineData
eef44fea
JN
1From 501ad55982a8f92a7a95c76c75944d644870181d Mon Sep 17 00:00:00 2001
2From: Ludovic Courtès <ludo@gnu.org>
3Date: Thu, 12 Mar 2020 15:16:04 +0100
4Subject: [PATCH] load: Make Guile run-time relocatable using /proc/self/exe.
df1fab58 5
eef44fea
JN
6Import from
7
8 http://git.savannah.gnu.org/cgit/guix.git/commit/?id=920f2c42ce3345dc1355a41377ebf01a33fdae51
9---
10 libguile/load.c | 35 +++++++++++++++++++++++++++++------
11 1 file changed, 29 insertions(+), 6 deletions(-)
12
13diff --git a/libguile/load.c b/libguile/load.c
14index c2ee5093a..128cdf95a 100644
df1fab58
LC
15--- a/libguile/load.c
16+++ b/libguile/load.c
17@@ -26,6 +26,7 @@
18
19 #include <string.h>
20 #include <stdio.h>
21+#include <libgen.h>
22
23 #include "libguile/_scm.h"
0bd86510 24 #include "libguile/alist.h"
eef44fea 25@@ -325,6 +326,32 @@ scm_init_load_path ()
df1fab58
LC
26 SCM cpath = SCM_EOL;
27
28 #ifdef SCM_LIBRARY_DIR
b7f280ee 29+ char *program, *bin_dir, *prefix, *module_dir, *ccache_dir;
df1fab58
LC
30+
31+ /* Determine the source and compiled module directories at run-time,
b7f280ee 32+ relative to the executable's location.
df1fab58 33+
b7f280ee
LC
34+ Note: Use /proc/self/exe instead of argv[0] because the latter is
35+ not necessarily an absolute, nor a valid file name. */
36+
37+ program = scm_gc_malloc_pointerless (256, "string");
38+ readlink ("/proc/self/exe", program, 256);
39+
40+ bin_dir = dirname (strdupa (program));
df1fab58
LC
41+
42+ prefix = scm_gc_malloc_pointerless (strlen (bin_dir) + 4, "string");
43+ strcpy (prefix, bin_dir);
44+ strcat (prefix, "/..");
45+ prefix = canonicalize_file_name (prefix);
46+
47+ module_dir = scm_gc_malloc_pointerless (strlen (prefix) + 50, "string");
48+ strcpy (module_dir, prefix);
920f2c42 49+ strcat (module_dir, "/share/guile/" SCM_EFFECTIVE_VERSION);
df1fab58
LC
50+
51+ ccache_dir = scm_gc_malloc_pointerless (strlen (prefix) + 50, "string");
52+ strcpy (ccache_dir, prefix);
920f2c42 53+ strcat (ccache_dir, "/lib/guile/" SCM_EFFECTIVE_VERSION "/ccache");
df1fab58 54+
0bd86510 55 env = scm_i_mirror_backslashes (getenv ("GUILE_SYSTEM_PATH"));
df1fab58
LC
56 if (env && strcmp (env, "") == 0)
57 /* special-case interpret system-path=="" as meaning no system path instead
eef44fea 58@@ -333,10 +360,7 @@ scm_init_load_path ()
df1fab58
LC
59 else if (env)
60 path = scm_parse_path (scm_from_locale_string (env), path);
61 else
eef44fea
JN
62- path = scm_list_4 (scm_from_locale_string (SCM_LIBRARY_DIR),
63- scm_from_locale_string (SCM_SITE_DIR),
64- scm_from_locale_string (SCM_GLOBAL_SITE_DIR),
65- scm_from_locale_string (SCM_PKGDATA_DIR));
b7f280ee
LC
66+ path = scm_list_1 (scm_from_locale_string (module_dir));
67
0bd86510 68 env = scm_i_mirror_backslashes (getenv ("GUILE_SYSTEM_COMPILED_PATH"));
b7f280ee 69 if (env && strcmp (env, "") == 0)
eef44fea 70@@ -346,8 +370,7 @@ scm_init_load_path ()
df1fab58
LC
71 cpath = scm_parse_path (scm_from_locale_string (env), cpath);
72 else
73 {
eef44fea
JN
74- cpath = scm_list_2 (scm_from_locale_string (SCM_CCACHE_DIR),
75- scm_from_locale_string (SCM_SITE_CCACHE_DIR));
b7f280ee 76+ cpath = scm_list_1 (scm_from_locale_string (ccache_dir));
df1fab58
LC
77 }
78
b7f280ee 79 #endif /* SCM_LIBRARY_DIR */
eef44fea
JN
80--
812.24.0
82