This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: RFA: set LD_LIBRARY_PATH
- From: Thomas Fitzsimmons <fitzsim at redhat dot com>
- To: java-patches at gcc dot gnu dot org
- Date: Thu, 01 Sep 2005 21:08:24 -0400
- Subject: Patch: RFA: set LD_LIBRARY_PATH
Hi,
Sun's JRE includes $JAVA_HOME/lib/<arch> in its LD_LIBRARY_PATH so that
users don't need to specify LD_LIBRARY_PATH manually. This patch makes
libgcj do the same when the --with-java-home configure option is
specified.
OK for mainline?
Tom
2005-09-01 Thomas Fitzsimmons <fitzsim@redhat.com>
PR libgcj/21741
* configure.ac (JAVA_HOME_SET): Define when --with-java-home is
specified.
* configure: Regenerate.
* gnu/classpath/natSystemProperties.cc (insertSystemProperties)
[JAVA_HOME_SET]: Prepend JAVA_HOME/lib/arch to LD_LIBRARY_PATH.
Set java.library.path to value of LD_LIBRARY_PATH if it is set.
* include/config.h.in: Regenerate.
Index: configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/libjava/configure.ac,v
retrieving revision 1.38
diff -u -r1.38 configure.ac
--- configure.ac 24 Aug 2005 05:54:22 -0000 1.38
+++ configure.ac 2 Sep 2005 00:39:30 -0000
@@ -379,7 +379,10 @@
AC_ARG_WITH(java-home,
AS_HELP_STRING([--with-java-home=DIRECTORY],
[value of java.home system property]),
- [JAVA_HOME="${withval}"], [JAVA_HOME=""])
+ [JAVA_HOME="${withval}"
+ AC_DEFINE(JAVA_HOME_SET, 1,
+ [Define if you're setting java.home])],
+ [JAVA_HOME=""])
AM_CONDITIONAL(JAVA_HOME_SET, test ! -z "$JAVA_HOME")
AC_SUBST(JAVA_HOME)
Index: include/config.h.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/config.h.in,v
retrieving revision 1.61
diff -u -r1.61 config.h.in
--- include/config.h.in 18 May 2005 02:03:48 -0000 1.61
+++ include/config.h.in 2 Sep 2005 00:39:31 -0000
@@ -357,6 +357,9 @@
/* Define if you want a bytecode interpreter. */
#undef INTERPRETER
+/* Define if you're setting java.home */
+#undef JAVA_HOME_SET
+
/* API compatibility version string */
#undef JV_API_VERSION
Index: gnu/classpath/natSystemProperties.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/classpath/natSystemProperties.cc,v
retrieving revision 1.1
diff -u -r1.1 natSystemProperties.cc
--- gnu/classpath/natSystemProperties.cc 25 Apr 2005 19:48:34 -0000 1.1
+++ gnu/classpath/natSystemProperties.cc 2 Sep 2005 00:55:23 -0000
@@ -336,6 +336,54 @@
// Allow platform specific settings and overrides.
_Jv_platform_initProperties (newprops);
+ // Set LD_LIBRARY_PATH
+#ifdef JAVA_HOME_SET
+#ifdef HAVE_UNAME
+ char *libpath = NULL;
+ char *newpath = NULL;
+ ::java::lang::String *archstr;
+ char *arch;
+ jsize archtotal;
+ int newlen = 0;
+
+ archstr = newprops->getProperty(JvNewStringLatin1("os.arch"));
+ arch = (char *) _Jv_Malloc (JvGetStringUTFLength (archstr) + 1);
+ archtotal = JvGetStringUTFRegion (archstr, 0, archstr->length(), arch);
+ arch[archtotal] = '\0';
+ newlen += archstr->length();
+
+ libpath = getenv ("LD_LIBRARY_PATH");
+
+ if (libpath && libpath[0] != '\0')
+ {
+ newlen += strlen (libpath);
+ // for the separating ':'
+ newlen += 1;
+ }
+
+ newlen += sizeof (JAVA_HOME) - 1;
+ newlen += sizeof ("/lib/") - 1;
+
+ newpath = (char *) _Jv_Malloc (newlen + 1);
+
+ if (newpath != NULL)
+ {
+ if (libpath && libpath[0] != '\0')
+ snprintf (newpath, newlen + 1,
+ "%s%s%s%s%s", JAVA_HOME, "/lib/", arch, ":", libpath);
+ else
+ snprintf (newpath, newlen + 1, "%s%s%s", JAVA_HOME, "/lib/", arch);
+ }
+
+ // LD_LIBRARY_PATH must be set before lt_dlinit() so that libltdl
+ // searches JAVA_HOME for dependencies of dlopened libraries.
+ setenv ("LD_LIBRARY_PATH", newpath, 1);
+
+ _Jv_Free (arch);
+ _Jv_Free (newpath);
+#endif /* HAVE_UNAME */
+#endif /* JAVA_HOME_SET */
+
// If java.library.path is set, tell libltdl so we search the new
// directories as well. FIXME: does this work properly on Windows?
::java::lang::String *path = newprops->getProperty(JvNewStringLatin1("java.library.path"));
@@ -350,9 +398,12 @@
else
{
// Set a value for user code to see.
- // FIXME: JDK sets this to the actual path used, including
- // LD_LIBRARY_PATH, etc.
- SET ("java.library.path", "");
+ char *libpath = getenv ("LD_LIBRARY_PATH");
+ if (libpath)
+ newprops->put(JvNewStringLatin1 ("java.library.path"),
+ JvNewStringLatin1 (libpath));
+ else
+ SET ("java.library.path", "");
}
// If java.class.path is still not set then set it according to the