diff --git a/configure.ac b/configure.ac index 3c73795..da96b82 100644 --- a/configure.ac +++ b/configure.ac @@ -378,6 +378,14 @@ fi AC_SUBST(classlib) +dnl On Darwin, the OpenJDK class library's native libraries (e.g. libjava) +dnl reference libjvm via @rpath/libjvm.dylib. Set our install name to match +dnl so that dyld resolves the dependency. +if test "$classlib" = openjdk -a "$host_os" = darwin; then + LIBJVM_EXTRA_LDFLAGS="-Wl,-install_name,@rpath/libjvm.dylib" +fi +AC_SUBST(LIBJVM_EXTRA_LDFLAGS) + case "$with_java_runtime_library" in gnuclasspath | openjdk6 ) AC_DEFINE([SHARED_CHAR_BUFFERS],1, diff --git a/src/Makefile.am b/src/Makefile.am index 1cf2e87..d62ddf2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -42,7 +42,7 @@ libjvm_la_SOURCES = jamvm_LDADD = libcore.la libjvm_la_LIBADD = libcore.la -libjvm_la_LDFLAGS = -avoid-version +libjvm_la_LDFLAGS = -avoid-version @LIBJVM_EXTRA_LDFLAGS@ libcore_la_LIBADD = interp/libinterp.la os/@os@/@arch@/libnative.la \ os/@os@/libos.la classlib/@classlib@/libclasslib.la diff --git a/src/classlib/openjdk/dll.c b/src/classlib/openjdk/dll.c index 1d9cc9c..5d42dff 100644 --- a/src/classlib/openjdk/dll.c +++ b/src/classlib/openjdk/dll.c @@ -43,9 +43,18 @@ int classlibInitialiseDll() { char *classlibDefaultBootDllPath() { char *java_home = getJavaHome(); + + /* On most platforms, native libraries are in lib//. + On Darwin, they are directly in lib/. */ +#ifdef __APPLE__ + char *dll_path = sysMalloc(strlen(java_home) + sizeof("/lib")); + + return strcat(strcpy(dll_path, java_home), "/lib"); +#else char *dll_path = sysMalloc(strlen(java_home) + sizeof("/lib/"OS_ARCH)); return strcat(strcpy(dll_path, java_home), "/lib/"OS_ARCH); +#endif } void *classlibLookupLoadedDlls(char *name, Object *loader) { diff --git a/src/classlib/openjdk/properties.c b/src/classlib/openjdk/properties.c index 2391e61..dc7a1f8 100644 --- a/src/classlib/openjdk/properties.c +++ b/src/classlib/openjdk/properties.c @@ -27,10 +27,19 @@ char *classlibDefaultJavaHome() { int count = 0; char *home; - while(pntr > path && count < 4) + /* Derive java.home from the location of libjvm. + Default (most platforms): /lib///libjvm.so + Darwin (no arch subdir): /lib//libjvm.dylib */ +#ifdef __APPLE__ + int n_sep = 3; +#else + int n_sep = 4; +#endif + + while(pntr > path && count < n_sep) count += *--pntr == '/'; - if(count != 4) { + if(count != n_sep) { printf("Error: JVM path malformed. Aborting VM.\n"); exitVM(1); } diff --git a/src/properties.c b/src/properties.c index b453d7b..a7b11fc 100644 --- a/src/properties.c +++ b/src/properties.c @@ -25,6 +25,10 @@ #include #include +#ifdef __APPLE__ +#include +#endif + #include "jam.h" #include "symbol.h" #include "hash.h" @@ -161,7 +165,11 @@ void setOSProperties(Object *properties) { uname(&info); setProperty(properties, "os.arch", OS_ARCH); +#if defined(__APPLE__) && !TARGET_OS_IPHONE + setProperty(properties, "os.name", "Mac OS X"); +#else setProperty(properties, "os.name", info.sysname); +#endif setProperty(properties, "os.version", info.release); }