Commit | Line | Data |
---|---|---|
df1fab58 LC |
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 | ||
df1fab58 LC |
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" | |
0bd86510 MW |
13 | #include "libguile/alist.h" |
14 | @@ -325,6 +326,32 @@ | |
df1fab58 LC |
15 | SCM cpath = SCM_EOL; |
16 | ||
17 | #ifdef SCM_LIBRARY_DIR | |
b7f280ee | 18 | + char *program, *bin_dir, *prefix, *module_dir, *ccache_dir; |
df1fab58 LC |
19 | + |
20 | + /* Determine the source and compiled module directories at run-time, | |
b7f280ee | 21 | + relative to the executable's location. |
df1fab58 | 22 | + |
b7f280ee LC |
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)); | |
df1fab58 LC |
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/2.0"); | |
39 | + | |
40 | + ccache_dir = scm_gc_malloc_pointerless (strlen (prefix) + 50, "string"); | |
41 | + strcpy (ccache_dir, prefix); | |
42 | + strcat (ccache_dir, "/lib/guile/2.0/ccache"); | |
43 | + | |
0bd86510 | 44 | env = scm_i_mirror_backslashes (getenv ("GUILE_SYSTEM_PATH")); |
df1fab58 LC |
45 | if (env && strcmp (env, "") == 0) |
46 | /* special-case interpret system-path=="" as meaning no system path instead | |
0bd86510 | 47 | @@ -333,10 +360,7 @@ |
df1fab58 LC |
48 | else if (env) |
49 | path = scm_parse_path (scm_from_locale_string (env), path); | |
50 | else | |
51 | - path = scm_list_4 (scm_from_locale_string (SCM_LIBRARY_DIR), | |
b7f280ee LC |
52 | - scm_from_locale_string (SCM_SITE_DIR), |
53 | - scm_from_locale_string (SCM_GLOBAL_SITE_DIR), | |
54 | - scm_from_locale_string (SCM_PKGDATA_DIR)); | |
55 | + path = scm_list_1 (scm_from_locale_string (module_dir)); | |
56 | ||
0bd86510 | 57 | env = scm_i_mirror_backslashes (getenv ("GUILE_SYSTEM_COMPILED_PATH")); |
b7f280ee | 58 | if (env && strcmp (env, "") == 0) |
0bd86510 | 59 | @@ -346,8 +370,7 @@ |
df1fab58 LC |
60 | cpath = scm_parse_path (scm_from_locale_string (env), cpath); |
61 | else | |
62 | { | |
63 | - cpath = scm_list_2 (scm_from_locale_string (SCM_CCACHE_DIR), | |
b7f280ee LC |
64 | - scm_from_locale_string (SCM_SITE_CCACHE_DIR)); |
65 | + cpath = scm_list_1 (scm_from_locale_string (ccache_dir)); | |
df1fab58 LC |
66 | } |
67 | ||
b7f280ee | 68 | #endif /* SCM_LIBRARY_DIR */ |