Commit | Line | Data |
---|---|---|
3ba23f05 MB |
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 | diff --git a/libguile/load.c b/libguile/load.c | |
5 | --- a/libguile/load.c | |
6 | +++ b/libguile/load.c | |
7 | @@ -27,6 +27,7 @@ | |
8 | #include <stat-time.h> | |
9 | #include <string.h> | |
10 | #include <stdio.h> | |
11 | +#include <libgen.h> | |
12 | #include <sys/types.h> | |
13 | #include <sys/stat.h> | |
14 | #include <unistd.h> | |
15 | @@ -334,6 +335,32 @@ scm_init_load_path () | |
16 | SCM cpath = SCM_EOL; | |
17 | ||
18 | #ifdef SCM_LIBRARY_DIR | |
19 | + char *program, *bin_dir, *prefix, *module_dir, *ccache_dir; | |
20 | + | |
21 | + /* Determine the source and compiled module directories at run-time, | |
22 | + relative to the executable's location. | |
23 | + | |
24 | + Note: Use /proc/self/exe instead of argv[0] because the latter is | |
25 | + not necessarily an absolute, nor a valid file name. */ | |
26 | + | |
27 | + program = scm_gc_malloc_pointerless (256, "string"); | |
28 | + readlink ("/proc/self/exe", program, 256); | |
29 | + | |
30 | + bin_dir = dirname (strdupa (program)); | |
31 | + | |
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); | |
36 | + | |
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); | |
40 | + | |
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"); | |
44 | + | |
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 () | |
49 | else if (env) | |
50 | path = scm_parse_path (scm_from_locale_string (env), path); | |
51 | else | |
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)); | |
57 | ||
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); | |
62 | else | |
63 | { | |
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)); | |
67 | } | |
68 | ||
69 | #endif /* SCM_LIBRARY_DIR */ |