From 36f1d3206e905f66c31c53bd387df02aa5084103 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Thu, 20 Sep 2007 10:13:41 -0600 Subject: [PATCH] The proper extension for Mac JNI libraries is .jnilib. Hard-coded constants have been factored to common locations. Furthermore, the LD_LIBRARY_PATH environment variable is DYLD_LIBRARY_PATH on Mac OS X. --- classpath/java-lang.cpp | 10 ++++++++-- makefile | 6 ++++-- src/common.h | 6 ++++++ src/system.cpp | 10 ++-------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index f6ba9524c6..a550d048df 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -6,6 +6,12 @@ #include "jni.h" #include "jni-util.h" +#ifdef __APPLE__ +#define SO_SUFFIX ".jnilib" +#else +#define SO_SUFFIX ".so" +#endif + #undef JNIEXPORT #define JNIEXPORT __attribute__ ((visibility("default"))) @@ -54,9 +60,9 @@ Java_java_lang_System_doMapLibraryName(JNIEnv* e, jclass, jstring name) const char* chars = e->GetStringUTFChars(name, 0); if (chars) { unsigned nameLength = strlen(chars); - unsigned size = nameLength + 7; + unsigned size = nameLength + 3 + sizeof(SO_SUFFIX); char buffer[size]; - snprintf(buffer, size, "lib%s.so", chars); + snprintf(buffer, size, "lib%s" SO_SUFFIX, chars); r = e->NewStringUTF(buffer); e->ReleaseStringUTFChars(name, chars); diff --git a/makefile b/makefile index 02ee0cb687..416f3218a7 100644 --- a/makefile +++ b/makefile @@ -13,12 +13,14 @@ ifeq ($(platform),Darwin) rdynamic = thread-cflags = shared = -dynamiclib - so-extension = dylib + so-extension = jnilib + ld-library-path = DYLD_LIBRARY_PATH else rdynamic = -rdynamic thread-cflags = -pthread shared = -shared so-extension = so + ld-library-path = LD_LIBRARY_PATH endif mode = debug @@ -154,7 +156,7 @@ $(input): $(classpath-objects) .PHONY: run run: $(executable) $(input) - LD_LIBRARY_PATH=$(bld) $(<) $(args) + $(ld-library-path)=$(bld) $(<) $(args) .PHONY: debug debug: $(executable) $(input) diff --git a/src/common.h b/src/common.h index 64f012d8be..a379403efb 100644 --- a/src/common.h +++ b/src/common.h @@ -25,6 +25,12 @@ #error "Unsupported architecture" #endif +#ifdef __APPLE__ +#define SO_SUFFIX ".jnilib" +#else +#define SO_SUFFIX ".so" +#endif + #define NO_RETURN __attribute__((noreturn)) #define LIKELY(v) __builtin_expect((v) != 0, true) diff --git a/src/system.cpp b/src/system.cpp index 5ede163711..e1d7338d40 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -597,15 +597,9 @@ class MySystem: public System { void* p; unsigned nameLength = (name ? strlen(name) : 0); if (mapName) { -#ifdef __APPLE__ - unsigned size = nameLength + 10; + unsigned size = nameLength + 3 + sizeof(SO_SUFFIX); char buffer[size]; - snprintf(buffer, size, "lib%s.dylib", name); -#else - unsigned size = nameLength + 7; - char buffer[size]; - snprintf(buffer, size, "lib%s.so", name); -#endif + snprintf(buffer, size, "lib%s" SO_SUFFIX, name); p = dlopen(buffer, RTLD_LAZY); } else { p = dlopen(name, RTLD_LAZY);