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