[pl] Unify java path search

Petr Pisar ppisar at fedoraproject.org
Fri Sep 30 08:49:33 UTC 2011


commit 2a0970d03774bc29db155d01e3aa836e584907cd
Author: Petr Písař <ppisar at redhat.com>
Date:   Fri Sep 30 10:49:00 2011 +0200

    Unify java path search

 JavaConfig.java |  107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 pl.spec         |   59 ++++++++++++++++++------------
 2 files changed, 143 insertions(+), 23 deletions(-)
---
diff --git a/JavaConfig.java b/JavaConfig.java
new file mode 100644
index 0000000..2ef5ce8
--- /dev/null
+++ b/JavaConfig.java
@@ -0,0 +1,107 @@
+/* JavaConfig - tool for getting paths for current java environment.
+ * © 2011  Petr Písař <ppisar at redhat.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+class JavaConfig {
+  private static String output = "";
+
+
+  /*
+   * Append text to output with proper padding or terminates if text is null.
+   * @param text String to append.
+   */
+  private static void concatenate(String text) {
+    if (text == null) {
+      System.exit(2);
+    }
+    output = (output.equals("") ? ""  : output + " " ) + text;
+  }
+
+
+  /*
+   * Show usage message and terminates program with given @exit_code.
+   * @param exit_code code to return
+   * */
+  private static void usage(int exitCode) {
+    System.out.print(
+        "JavaConfig [OPTIONS]\n" +
+        "  --home         Output path to Java home\n" +
+        "  --libs-only-L  Output -L linker flags\n"
+    );
+    System.exit(exitCode);
+  }
+
+
+  /*
+   * @Return path to Java home or null in case of error.
+   */
+  public static String home() {
+    return System.getProperty("java.home");
+  }
+
+
+  /*
+   * @Return formated libary search path as -L compiler flag,
+   * null if error occured.
+   * */
+  public static String libsOnlyL() {
+    String value;
+    String paths[];
+   
+    if (null == (value = System.getProperty("java.library.path"))) {
+      return null;
+    }
+
+    paths = value.split(":");
+
+    for (int i = 0; i < paths.length; i++) {
+      if (paths[i].equals("")) {
+        continue;
+      }
+      
+      if (i == 0) {
+        value = "-L" + paths[i];
+      } else {
+        value = value + " -L" + paths[i];
+      }
+    }
+
+    return value;
+  }
+
+
+  /*
+   * Entry point to this class.
+   */
+  public static void main(String argv[]) {
+    if (argv.length < 1) {
+      usage(1);
+    }
+
+    for (int i = 0; i < argv.length; i++) {
+      if (argv[i].equals("--home")) {
+          concatenate(home());
+      } else if (argv[i].equals("--libs-only-L")) {
+          concatenate(libsOnlyL());
+      } else {
+          usage(1);
+      }
+    }
+
+    System.out.println(output);
+    System.exit(0);
+  }
+}
diff --git a/pl.spec b/pl.spec
index 6323418..1fd9f92 100644
--- a/pl.spec
+++ b/pl.spec
@@ -1,12 +1,13 @@
 %define with_java 1
 %define separate_xpce 0
 
+# Require openjdk 1.6 until bug #740762 becomes resolved.
 %define jdkvershort 1.6.0
 %define jdkverlong %{jdkvershort}.0
 
 Name:       pl
 Version:    5.10.5
-Release:    3%{?dist}
+Release:    4%{?dist}
 
 Summary:    SWI-Prolog - Edinburgh compatible Prolog compiler
 
@@ -18,11 +19,13 @@ Group:      Development/Languages
 #library/COPYING                GPLv2 with SWI-Prolog extra clause
 #library/unicode/blocks.pl      UCD
 #packages/http/examples/calc.pl Public Domain
-License:    Artistic and LGPLv2+ and LGPLv2 and GPLv2 and GPLv2+ and UCD and Public Domain
+#External: JavaConfig.java      GPLv3+
+License:    Artistic and LGPLv2+ and LGPLv2 and GPLv2 and GPLv2+ and UCD and Public Domain and GPLv3+
 URL:        http://www.swi-prolog.org
 Source:     http://www.swi-prolog.org/download/stable/src/%{name}-%{version}.tar.gz
 Source1:    http://www.swi-prolog.org/download/stable/doc/SWI-Prolog-%{version}.pdf
 Source2:    http://www.swi-prolog.org/download/xpce/doc/userguide/userguide.html.tgz
+Source3:    JavaConfig.java
 Patch1:     %{name}-5.10.5-jpl-configure.patch
 Patch2:     %{name}-5.10.5-man-files.patch
 Patch3:     %{name}-5.10.2-jni.patch
@@ -156,6 +159,9 @@ cd packages/xpce
    tar -xzf %{SOURCE2}
    mv UserGuide xpce-UserGuide
 )
+(
+    cp %{SOURCE3} .
+)
 
 # Adjustments to take into account the new location of JNI stuff
 sed --in-place=.jni2 -e 's#LIBDIR#%{_libdir}#g' packages/jpl/jpl.pl
@@ -164,26 +170,30 @@ sed --in-place=.jni2 -e 's#LIBDIR#%{_libdir}#g' packages/jpl/src/java/jpl/fli/Pr
 
 %build
 %if %{with_java}
-export JAVA_HOME=/usr/lib/jvm/java-%{jdkvershort}-openjdk-%{jdkverlong}.%{_arch}
-%ifarch x86_64
-export JAVA_LIB=$JAVA_HOME/jre/lib/amd64
-%else
-%ifarch sparcv9
-export JAVA_HOME=/usr/lib/jvm/java-%{jdkvershort}-openjdk-%{jdkverlong}
-export JAVA_LIB=$JAVA_HOME/jre/lib/sparc
-%else
-%ifarch sparc64
-export JAVA_LIB=$JAVA_HOME/jre/lib/sparcv9
-%else
-%ifarch %{arm}
-export JAVA_HOME=/usr/lib/jvm/java-%{jdkvershort}-openjdk-%{jdkverlong}
-export JAVA_LIB=$JAVA_HOME/jre/lib/arm
-%else
-export JAVA_LIB=$JAVA_HOME/jre/lib/%{_arch}
-%endif
-%endif
-%endif
-%endif
+LC_CTYPE=en_US.UTF-8 javac JavaConfig.java
+JAVA_HOME=$(java JavaConfig --home)
+JAVA_LIBS=$(java JavaConfig --libs-only-L)
+
+#export JAVA_HOME=/usr/lib/jvm/java-%{jdkvershort}-openjdk-%{jdkverlong}.%{_arch}
+#%%ifarch x86_64
+#export JAVA_LIB=$JAVA_HOME/jre/lib/amd64
+#%%else
+#%%ifarch sparcv9
+#export JAVA_HOME=/usr/lib/jvm/java-%{jdkvershort}-openjdk-%{jdkverlong}
+#%export JAVA_LIB=$JAVA_HOME/jre/lib/sparc
+#%%else
+#%%ifarch sparc64
+#export JAVA_LIB=$JAVA_HOME/jre/lib/sparcv9
+#%%else
+#%%ifarch %{arm}
+#export JAVA_HOME=/usr/lib/jvm/java-%{jdkvershort}-openjdk-%{jdkverlong}
+#export JAVA_LIB=$JAVA_HOME/jre/lib/arm
+#%%else
+#export JAVA_LIB=$JAVA_HOME/jre/lib/%{_arch}
+#%%endif
+#%%endif
+#%%endif
+#%%endif
 %else
 # Processed by packages/configure
 export DISABLE_PKGS="jpl"
@@ -196,7 +206,7 @@ make COFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing"
 # Build SWI packages
 pushd packages
 %configure LDFLAGS="-Wl,--enable-new-dtags"
-make COFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing" JAVALIBS="-L$JAVA_LIB/server -L$JAVA_LIB -ljava -lverify -ljvm"
+make COFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing" JAVALIBS="${JAVA_LIBS} -ljava -lverify -ljvm"
 popd
 
 
@@ -320,6 +330,9 @@ rm -rf $RPM_BUILD_ROOT
 
 
 %changelog
+* Tue Sep 27 2011 Petr Pisar <ppisar at redhat.com> - 5.10.5-4
+- Unify java path search (bug #740897)
+
 * Fri Sep 23 2011 Petr Pisar <ppisar at redhat.com> - 5.10.5-3
 - Correct Java paths on ARM (thanks to David A. Marlin)
 


More information about the scm-commits mailing list