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.
4 diff --git a/libguile/load.c b/libguile/load.c
12 #include <sys/types.h>
15 @@ -334,6 +335,32 @@ scm_init_load_path ()
18 #ifdef SCM_LIBRARY_DIR
19 + char *program, *bin_dir, *prefix, *module_dir, *ccache_dir;
21 + /* Determine the source and compiled module directories at run-time,
22 + relative to the executable's location.
24 + Note: Use /proc/self/exe instead of argv[0] because the latter is
25 + not necessarily an absolute, nor a valid file name. */
27 + program = scm_gc_malloc_pointerless (256, "string");
28 + readlink ("/proc/self/exe", program, 256);
30 + bin_dir = dirname (strdupa (program));
32 + prefix = scm_gc_malloc_pointerless (strlen (bin_dir) + 4, "string");
33 + strcpy (prefix, bin_dir);
34 + strcat (prefix, "/..");
35 + prefix = canonicalize_file_name (prefix);
37 + module_dir = scm_gc_malloc_pointerless (strlen (prefix) + 50, "string");
38 + strcpy (module_dir, prefix);
39 + strcat (module_dir, "/share/guile/" SCM_EFFECTIVE_VERSION);
41 + ccache_dir = scm_gc_malloc_pointerless (strlen (prefix) + 50, "string");
42 + strcpy (ccache_dir, prefix);
43 + strcat (ccache_dir, "/lib/guile/" SCM_EFFECTIVE_VERSION "/ccache");
45 env = scm_i_mirror_backslashes (getenv ("GUILE_SYSTEM_PATH"));
46 if (env && strcmp (env, "") == 0)
47 /* special-case interpret system-path=="" as meaning no system path instead
48 @@ -342,10 +369,7 @@ scm_init_load_path ()
50 path = scm_parse_path (scm_from_locale_string (env), path);
52 - path = scm_list_4 (scm_from_utf8_string (SCM_LIBRARY_DIR),
53 - scm_from_utf8_string (SCM_SITE_DIR),
54 - scm_from_utf8_string (SCM_GLOBAL_SITE_DIR),
55 - scm_from_utf8_string (SCM_PKGDATA_DIR));
56 + path = scm_list_1 (scm_from_locale_string (module_dir));
58 env = scm_i_mirror_backslashes (getenv ("GUILE_SYSTEM_COMPILED_PATH"));
59 if (env && strcmp (env, "") == 0)
60 @@ -355,8 +379,7 @@ scm_init_load_path ()
61 cpath = scm_parse_path (scm_from_locale_string (env), cpath);
64 - cpath = scm_list_2 (scm_from_utf8_string (SCM_CCACHE_DIR),
65 - scm_from_utf8_string (SCM_SITE_CCACHE_DIR));
66 + cpath = scm_list_1 (scm_from_locale_string (ccache_dir));
69 #endif /* SCM_LIBRARY_DIR */