0.7.13.5
[sbcl.git] / src / runtime / runtime.c
index 55f4d50..087efc4 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <libgen.h>
 #include <sys/types.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include "save.h"
 #include "lispregs.h"
 
+#include "genesis/static-symbols.h"
+#include "genesis/symbol.h"
+
+
 #ifdef irix
 #include <string.h>
 #include "interr.h"
@@ -271,15 +276,33 @@ main(int argc, char *argv[], char *envp[])
            core = copied_existing_filename_or_null(lookhere);
            free(lookhere);
        } else {
-           core = copied_existing_filename_or_null("/usr/lib/sbcl.core");
+           putenv("SBCL_HOME=/usr/local/lib/sbcl/");
+           core = copied_existing_filename_or_null("/usr/local/lib/sbcl/sbcl.core");
            if (!core) {
+               putenv("SBCL_HOME=/usr/lib/sbcl/");
                core =
-                   copied_existing_filename_or_null("/usr/local/lib/sbcl.core");
+                   copied_existing_filename_or_null("/usr/lib/sbcl/sbcl.core");
            }
        }
        if (!core) {
            lose("can't find core file");
        }
+    } else {
+       /* If a core was specified and SBCL_HOME is unset, set it */
+       char *sbcl_home = getenv("SBCL_HOME");
+       if (!sbcl_home) {
+           char *envstring, *copied_core, *dir;
+           char *stem = "SBCL_HOME=";
+           copied_core = copied_string(core);
+           dir = dirname(copied_core);
+           envstring = (char *) calloc(strlen(stem) +
+                                       strlen(dir) + 
+                                       1,
+                                       sizeof(char));
+           sprintf(envstring, "%s%s", stem, dir);
+           putenv(envstring);
+           free(copied_core);
+       }
     }
 
     if (!noinform) {