From f917c96d82f871b1fb85b3d2310dc0da35c92cf6 Mon Sep 17 00:00:00 2001
From: "Viral B. Shah" <viral@mayin.org>
Date: Mon, 28 May 2012 00:06:04 +0530
Subject: [PATCH] Use relative paths for locating libraries. Update the path
 lookup in jl_load.

---
 Make.inc       | 4 ++--
 Makefile       | 2 +-
 src/builtins.c | 2 +-
 src/dlload.c   | 4 ++--
 src/init.c     | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/Make.inc b/Make.inc
index fcba213bfb86f..4a7cbbb93fe79 100644
--- a/Make.inc
+++ b/Make.inc
@@ -170,7 +170,7 @@ endif
 ifeq ($(OS), Linux)
 INSTALL_NAME_CMD = true -ignore
 SHLIB_EXT = so
-RPATH = -Wl,-rpath,'$$ORIGIN/usr/lib'
+RPATH = -Wl,-rpath,'$$ORIGIN/../lib'
 RPATH_ORIGIN = -Wl,-rpath,'$$ORIGIN'
 OSLIBS += -ldl -lrt -Wl,--export-dynamic -Wl,--version-script=$(JULIAHOME)/src/julia.expmap -Wl,--no-whole-archive $(LIBUNWIND)
 WHOLE_ARCHIVE = -Wl,--whole-archive
@@ -180,7 +180,7 @@ endif
 ifeq ($(OS), FreeBSD)
 INSTALL_NAME_CMD = true -ignore
 SHLIB_EXT = so
-RPATH = -Wl,-rpath,'$$ORIGIN/usr/lib' -Wl,-z,origin
+RPATH = -Wl,-rpath,'$$ORIGIN/../lib' -Wl,-z,origin
 RPATH_ORIGIN = -Wl,-rpath,'$$ORIGIN' -Wl,-z,origin
 WHOLE_ARCHIVE = -Wl,--whole-archive
 NO_WHOLE_ARCHIVE = -Wl,--no-whole-archive
diff --git a/Makefile b/Makefile
index b0137f3af703a..d6db81c0eebfe 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ sys.ji: VERSION sys0.ji base/*.jl
 	$(QUIET_JULIA) cd base && ../julia `test -f ../sys.ji && echo stage1.jl || echo -J sys0.ji stage1.jl`
 
 install: release
-	install -d $(DESTDIR)$(PREFIX)/julia/usr/lib
+	install -d $(DESTDIR)$(PREFIX)/julia/usr/lib/julia
 	install -d $(DESTDIR)$(PREFIX)/julia/usr/sbin
 	install -d $(DESTDIR)$(PREFIX)/julia/usr/etc
 	install -d $(DESTDIR)$(PREFIX)/julia/base
diff --git a/src/builtins.c b/src/builtins.c
index c0ea7d01381c3..26c8140eda36c 100644
--- a/src/builtins.c
+++ b/src/builtins.c
@@ -516,7 +516,7 @@ char *jl_find_file_in_path(const char *fname)
     int fid = open (fpath, O_RDONLY);
     // try adding julia home
     if (fid == -1 && julia_home && fname[0] != '/') {
-        if (-1 != asprintf(&fpath, "%s/%s", julia_home, fname))
+        if (-1 != asprintf(&fpath, "%s/../lib/julia/%s", julia_home, fname))
             fid = open (fpath, O_RDONLY);
     }
     if (fid == -1) {
diff --git a/src/dlload.c b/src/dlload.c
index be3c2eaf6cf9a..4255c9b57eede 100644
--- a/src/dlload.c
+++ b/src/dlload.c
@@ -71,9 +71,9 @@ uv_lib_t *jl_load_dynamic_library(char *fname)
         handle->handle = NULL;
         if (modname[0] != '/') {
             if (julia_home) {
-                /* try julia_home/usr/lib */
+                /* try julia_home/../lib */
                 strncpy(path, julia_home, PATHBUF-1);
-                strncat(path, "/usr/lib/", PATHBUF-1-strlen(path));
+                strncat(path, "/../lib/", PATHBUF-1-strlen(path));
                 strncat(path, modname, PATHBUF-1-strlen(path));
                 strncat(path, ext, PATHBUF-1-strlen(path));
                 error = uv_dlopen(path, handle);
diff --git a/src/init.c b/src/init.c
index 4e2245690913f..6471a7140d879 100644
--- a/src/init.c
+++ b/src/init.c
@@ -128,7 +128,7 @@ void julia_init(char *imageFile)
         jl_current_module = jl_core_module;
         jl_init_intrinsic_functions();
         jl_init_primitives();
-        jl_load("src/boot.jl");
+        jl_load("../../../src/boot.jl");
         jl_get_builtin_hooks();
         jl_boot_file_loaded = 1;
         jl_init_box_caches();