gnu: hidapi: Fix 'license'.
[jackhill/guix/guix.git] / gnu / packages / patches / guile-relocatable.patch
CommitLineData
df1fab58
LC
1This patch changes Guile to use a default search path relative to the
2location of the `guile' binary, allowing it to be relocated.
3
4diff --git a/libguile/load.c b/libguile/load.c
b7f280ee 5index af2ca45..19dd338 100644
df1fab58
LC
6--- a/libguile/load.c
7+++ b/libguile/load.c
8@@ -26,6 +26,7 @@
9
10 #include <string.h>
11 #include <stdio.h>
12+#include <libgen.h>
13
14 #include "libguile/_scm.h"
15 #include "libguile/private-gc.h" /* scm_getenv_int */
b7f280ee 16@@ -255,6 +256,32 @@ scm_init_load_path ()
df1fab58
LC
17 SCM cpath = SCM_EOL;
18
19 #ifdef SCM_LIBRARY_DIR
b7f280ee 20+ char *program, *bin_dir, *prefix, *module_dir, *ccache_dir;
df1fab58
LC
21+
22+ /* Determine the source and compiled module directories at run-time,
b7f280ee 23+ relative to the executable's location.
df1fab58 24+
b7f280ee
LC
25+ Note: Use /proc/self/exe instead of argv[0] because the latter is
26+ not necessarily an absolute, nor a valid file name. */
27+
28+ program = scm_gc_malloc_pointerless (256, "string");
29+ readlink ("/proc/self/exe", program, 256);
30+
31+ bin_dir = dirname (strdupa (program));
df1fab58
LC
32+
33+ prefix = scm_gc_malloc_pointerless (strlen (bin_dir) + 4, "string");
34+ strcpy (prefix, bin_dir);
35+ strcat (prefix, "/..");
36+ prefix = canonicalize_file_name (prefix);
37+
38+ module_dir = scm_gc_malloc_pointerless (strlen (prefix) + 50, "string");
39+ strcpy (module_dir, prefix);
40+ strcat (module_dir, "/share/guile/2.0");
41+
42+ ccache_dir = scm_gc_malloc_pointerless (strlen (prefix) + 50, "string");
43+ strcpy (ccache_dir, prefix);
44+ strcat (ccache_dir, "/lib/guile/2.0/ccache");
45+
46 env = getenv ("GUILE_SYSTEM_PATH");
47 if (env && strcmp (env, "") == 0)
48 /* special-case interpret system-path=="" as meaning no system path instead
b7f280ee 49@@ -263,10 +290,7 @@ scm_init_load_path ()
df1fab58
LC
50 else if (env)
51 path = scm_parse_path (scm_from_locale_string (env), path);
52 else
53- path = scm_list_4 (scm_from_locale_string (SCM_LIBRARY_DIR),
b7f280ee
LC
54- scm_from_locale_string (SCM_SITE_DIR),
55- scm_from_locale_string (SCM_GLOBAL_SITE_DIR),
56- scm_from_locale_string (SCM_PKGDATA_DIR));
57+ path = scm_list_1 (scm_from_locale_string (module_dir));
58
59 env = getenv ("GUILE_SYSTEM_COMPILED_PATH");
60 if (env && strcmp (env, "") == 0)
61@@ -276,8 +300,7 @@ scm_init_load_path ()
df1fab58
LC
62 cpath = scm_parse_path (scm_from_locale_string (env), cpath);
63 else
64 {
65- cpath = scm_list_2 (scm_from_locale_string (SCM_CCACHE_DIR),
b7f280ee
LC
66- scm_from_locale_string (SCM_SITE_CCACHE_DIR));
67+ cpath = scm_list_1 (scm_from_locale_string (ccache_dir));
df1fab58
LC
68 }
69
b7f280ee 70 #endif /* SCM_LIBRARY_DIR */