diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/Makefile.am | 17 | ||||
-rw-r--r-- | tools/toolwrapper.c | 40 |
2 files changed, 40 insertions, 17 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index 2c1ceacce..b6bc4fbe2 100755 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -22,62 +22,47 @@ bin_SCRIPTS = bin_PROGRAMS = gappletviewer gjarsigner gkeytool \ gjar gnative2ascii gserialver $(javah) -#if FOUND_GCJ -#LIBJVM = -lgcj -#else -if FOUND_CACAO -LIBJVM = -ljvm -else -LIBJVM = -endif -#endif AM_CPPFLAGS = -Wall \ -I$(top_srcdir)/include \ + -DLIBJVM="\"$(libdir)/libjvm\"" \ -DTOOLS_ZIP="\"$(TOOLSdir)/$(TOOLS_ZIP)\"" gappletviewer_SOURCES = toolwrapper.c gappletviewer_CFLAGS = \ -DTOOLPACKAGE="\"appletviewer\"" \ -DTOOLNAME="\"gappletviewer\"" -gappletviewer_LDFLAGS = -L$(libdir) $(LIBJVM) gjarsigner_SOURCES = toolwrapper.c gjarsigner_CFLAGS = \ -DTOOLPACKAGE="\"jarsigner\"" \ -DTOOLNAME="\"gjarsigner\"" -gjarsigner_LDFLAGS = -L$(libdir) $(LIBJVM) gkeytool_SOURCES = toolwrapper.c gkeytool_CFLAGS = \ -DTOOLPACKAGE="\"keytool\"" \ -DTOOLNAME="\"gkeytool\"" -gkeytool_LDFLAGS = -L$(libdir) $(LIBJVM) gjar_SOURCES = toolwrapper.c gjar_CFLAGS = \ -DTOOLPACKAGE="\"jar\"" \ -DTOOLNAME="\"gjar\"" -gjar_LDFLAGS = -L$(libdir) $(LIBJVM) gnative2ascii_SOURCES = toolwrapper.c gnative2ascii_CFLAGS = \ -DTOOLPACKAGE="\"native2ascii\"" \ -DTOOLNAME="\"gnative2ascii\"" -gnative2ascii_LDFLAGS = -L$(libdir) $(LIBJVM) gserialver_SOURCES = toolwrapper.c gserialver_CFLAGS = \ -DTOOLPACKAGE="\"serialver\"" \ -DTOOLNAME="\"gserialver\"" -gserialver_LDFLAGS = -L$(libdir) $(LIBJVM) if USE_ASM gjavah_SOURCES = toolwrapper.c gjavah_CFLAGS = \ -DTOOLPACKAGE="\"javah\"" \ -DTOOLNAME="\"gjavah\"" -gjavah_LDFLAGS = -L$(libdir) $(LIBJVM) endif else diff --git a/tools/toolwrapper.c b/tools/toolwrapper.c index 9ad14ac6d..9f4720ab9 100644 --- a/tools/toolwrapper.c +++ b/tools/toolwrapper.c @@ -37,6 +37,7 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include <jni.h> +#include <ltdl.h> #include <string.h> #include <stdlib.h> #include "config.h" @@ -51,6 +52,9 @@ union env_union JNIEnv *jni_env; }; +/* Typedef for JNI_CreateJavaVM dlopen call. */ +typedef jint createVM (JavaVM **, void **, void *); + int main (int argc, const char** argv) { @@ -68,6 +72,10 @@ main (int argc, const char** argv) int non_vm_argc; int i; int classpath_found = 0; + /* Variables for JNI_CreateJavaVM dlopen call. */ + lt_dlhandle libjvm_handle = NULL; + createVM* libjvm_create = NULL; + int libjvm_error = 0; env = NULL; jvm = NULL; @@ -152,7 +160,27 @@ main (int argc, const char** argv) vm_args.version = JNI_VERSION_1_2; vm_args.ignoreUnrecognized = JNI_TRUE; - result = JNI_CreateJavaVM (&jvm, &tmp.void_env, &vm_args); + /* dlopen libjvm.so */ + libjvm_error = lt_dlinit (); + if (libjvm_error) + { + fprintf (stderr, TOOLNAME ": lt_dlinit failed.\n"); + goto destroy; + } + + libjvm_handle = lt_dlopenext (LIBJVM); + if (!libjvm_handle) + { + fprintf (stderr, TOOLNAME ": failed to open " LIBJVM "\n"); + goto destroy; + } + libjvm_create = (createVM*) lt_dlsym (libjvm_handle, "JNI_CreateJavaVM"); + if (!libjvm_create) + { + fprintf (stderr, TOOLNAME ": failed to load JNI_CreateJavaVM symbol from " LIBJVM "\n"); + goto destroy; + } + result = (*libjvm_create) (&jvm, &tmp.void_env, &vm_args); if (result < 0) { @@ -216,5 +244,15 @@ main (int argc, const char** argv) (*jvm)->DestroyJavaVM (jvm); } + /* libltdl cleanup */ + if (libjvm_handle) + { + if (lt_dlclose (libjvm_handle) != 0) + fprintf (stderr, TOOLNAME ": failed to close " LIBJVM "\n"); + } + + if (lt_dlexit () != 0) + fprintf (stderr, TOOLNAME ": lt_dlexit failed.\n"); + return 1; } |