|
From: Elias N. <eli...@us...> - 2006-01-16 20:37:40
|
Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv764/src/java/org/lwjgl Modified Files: DefaultSysImplementation.java LWJGLUtil.java MacOSXSysImplementation.java Sys.java SysImplementation.java Log Message: Mac OS X: Added loading of a legacy native lwjgl library to support applications that need to run on Mac OS X 10.2, 10.3 and 10.4, including intel mac versions. NOTE: Intel support from the universal build is not tested, since I don\'t have acces to an intel mac. Index: SysImplementation.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/SysImplementation.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- SysImplementation.java 18 Jan 2005 20:22:45 -0000 1.1 +++ SysImplementation.java 16 Jan 2006 20:37:28 -0000 1.2 @@ -42,6 +42,12 @@ */ interface SysImplementation { /** + * Return an array of possible library names. later names + * tried last. + */ + public String[] getNativeLibraryNames(); + + /** * Return the version of the native library */ public String getNativeLibraryVersion(); Index: LWJGLUtil.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/LWJGLUtil.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- LWJGLUtil.java 21 Oct 2005 18:52:45 -0000 1.8 +++ LWJGLUtil.java 16 Jan 2006 20:37:28 -0000 1.9 @@ -421,4 +421,28 @@ System.err.println(msg); } } + + /** + * Method to determine if the current system is running a version of + * Mac OS X better than the given version. This is only useful for Mac OS X + * specific code and will not work for any other platform. + */ + public static boolean isMacOSXEqualsOrBetterThan(int major_required, int minor_required) { + String os_version = System.getProperty("os.version"); + StringTokenizer version_tokenizer = new StringTokenizer(os_version, "."); + int major; + int minor; + try { + String major_str = version_tokenizer.nextToken(); + String minor_str = version_tokenizer.nextToken(); + major = Integer.parseInt(major_str); + minor = Integer.parseInt(minor_str); + } catch (Exception e) { + LWJGLUtil.log("Exception occurred while trying to determine OS version: " + e); + // Best guess, no + return false; + } + return major > major_required || (major == major_required && minor >= minor_required); + } + } Index: MacOSXSysImplementation.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/MacOSXSysImplementation.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- MacOSXSysImplementation.java 30 May 2005 16:21:03 -0000 1.3 +++ MacOSXSysImplementation.java 16 Jan 2006 20:37:28 -0000 1.4 @@ -43,6 +43,37 @@ * @version $Revision$ */ class MacOSXSysImplementation extends J2SESysImplementation { + public String[] getNativeLibraryNames() { + /* If we're on 10.4, fine, we'll just try the default library name. For + * earlier versions of Mac OS X, try the legacy library first. + * + * Having a kludge like this is unfortunate, but necessary for the following reasons: + * 1. We need two libraries to support Mac OS X 10.2, 10.3 and 10.4. We could + * cover 10.2, 10.3 and 10.4 with one gcc 3 compiled library, but then we + * loose intel mac support. Instead, we'll distribute two versions of the lwjgl + * native library, the default and a legacy one. + * 2. The default library will be universal ('fat') with both intel and powerpc support + * compiled in. This requires gcc 4, and makes the library unusable on Mac OS X 10.3 + * and earlier (actually 10.3.9 has the required gcc 4 libraries, but we'll ignore that). + * We could still choose to load the default library first, and the legacy one later, + * but a bug in the Mac OS X java implementation forces a java program to exit + * if the loaded library has a missing dependency (The correct behaviour is to throw + * an UnsatisfiedLinkError, like on linux and windows). + * 3. If the LWJGL program is launched with an intelligent ClassLoader, this issue can be avoided + * altogether, and the legacy library naming can be avoided too. For example, when + * using webstart, one can supply two nativelib references, one for Mac OS X 10.4 + * (the default library), and one for earlier Mac OS X (the legacy library). This is the + * preferred way to deploy the libraries. The legacy naming is for the users that don't want to + * mess around with libraries and classloaders. They can simply supply make sure that lwjgl.jar + * is in the classpath and that both the default library and the legacy library is in the native + * library path (java.library.path). + */ + if (LWJGLUtil.isMacOSXEqualsOrBetterThan(10, 4)) + return super.getNativeLibraryNames(); + else + return new String[]{LIBRARY_NAME + "-legacy", LIBRARY_NAME}; + } + public boolean openURL(String url) { try { Method openURL_method = (Method)AccessController.doPrivileged(new PrivilegedExceptionAction() { Index: Sys.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/Sys.java,v retrieving revision 1.90 retrieving revision 1.91 diff -u -d -r1.90 -r1.91 --- Sys.java 19 Dec 2005 10:57:22 -0000 1.90 +++ Sys.java 16 Jan 2006 20:37:28 -0000 1.91 @@ -54,20 +54,31 @@ /** Current version of library */ private static final String VERSION = "0.99"; - /** The native library name */ - private static final String LIBRARY_NAME = "lwjgl"; - /** The implementation instance to delegate platform specific behavior to */ private final static SysImplementation implementation; - static { - implementation = createImplementation(); + private static void loadLibrary(final String name) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { - System.loadLibrary(LIBRARY_NAME); + System.loadLibrary(name); return null; } }); + } + + static { + implementation = createImplementation(); + String[] library_names = implementation.getNativeLibraryNames(); + UnsatisfiedLinkError last_load_error = null; + for (int i = 0; i < library_names.length; i++) { + try { + loadLibrary(library_names[i]); + } catch (UnsatisfiedLinkError e) { + last_load_error = e; + } + } + if (last_load_error != null) + throw last_load_error; String native_version = implementation.getNativeLibraryVersion(); if (!native_version.equals(getVersion())) throw new LinkageError("Version mismatch: jar version is '" + getVersion() + Index: DefaultSysImplementation.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/DefaultSysImplementation.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- DefaultSysImplementation.java 20 Jan 2005 22:51:27 -0000 1.2 +++ DefaultSysImplementation.java 16 Jan 2006 20:37:28 -0000 1.3 @@ -39,6 +39,13 @@ * @version $Revision$ */ abstract class DefaultSysImplementation implements SysImplementation { + /** The native library name */ + protected static final String LIBRARY_NAME = "lwjgl"; + + public String[] getNativeLibraryNames() { + return new String[]{LIBRARY_NAME}; + } + public native String getNativeLibraryVersion(); public native void setDebug(boolean debug); |