Made LWJGLUtil.getLibraryPaths support multiple library names. Now AL.create on linux tries both libopenal.so and libopenal.so.0, which is the name of the system library

This commit is contained in:
Elias Naur 2006-11-20 20:07:29 +00:00
parent f62f11b437
commit 6abfeb4df2
4 changed files with 129 additions and 71 deletions

View File

@ -315,73 +315,68 @@ public class LWJGLUtil {
/** /**
* Locates the paths required by a library. * Locates the paths required by a library.
* *
* @param libNames List of library names to look for, in the form of Local Library name, Platform library name. * @param libName Local Library Name to search the classloader with ("openal").
* At least 6 names must be passed. 2 for each supported platform in the following order: Windows, Linux, MacOSX. * @param platform_lib_name The native library name ("libopenal.so")
* @param classloader The classloader to ask for library paths * @param classloader The classloader to ask for library paths
* @return Paths to located libraries, if any * @return Paths to located libraries, if any
*/ */
public static String[] getLibraryPaths(String[] libNames, ClassLoader classloader) throws LWJGLException { public static String[] getLibraryPaths(String libname, String platform_lib_name, ClassLoader classloader) {
return getLibraryPaths(libname, new String[]{platform_lib_name}, classloader);
}
/**
* Locates the paths required by a library.
*
* @param libName Local Library Name to search the classloader with ("openal").
* @param platform_lib_names The list of possible library names ("libopenal.so")
* @param classloader The classloader to ask for library paths
* @return Paths to located libraries, if any
*/
public static String[] getLibraryPaths(String libname, String[] platform_lib_names, ClassLoader classloader) {
// need to pass path of possible locations of library to native side // need to pass path of possible locations of library to native side
List possible_paths = new ArrayList(); List possible_paths = new ArrayList();
String libname;
String platform_lib_name;
switch (getPlatform()) {
case PLATFORM_WINDOWS:
libname = libNames[0];
platform_lib_name = libNames[1];
break;
case PLATFORM_LINUX:
libname = libNames[2];
platform_lib_name = libNames[3];
break;
case PLATFORM_MACOSX:
libname = libNames[4];
platform_lib_name = libNames[5];
break;
default:
throw new LWJGLException("Unknown platform: " + getPlatform());
}
String classloader_path = getPathFromClassLoader(libname, classloader); String classloader_path = getPathFromClassLoader(libname, classloader);
if (classloader_path != null) { if (classloader_path != null) {
log("getPathFromClassLoader: Path found: " + classloader_path); log("getPathFromClassLoader: Path found: " + classloader_path);
possible_paths.add(classloader_path); possible_paths.add(classloader_path);
} }
String lwjgl_classloader_path = getPathFromClassLoader("lwjgl", classloader); for (int i = 0; i < platform_lib_names.length; i++) {
if (lwjgl_classloader_path != null) { String platform_lib_name = platform_lib_names[i];
log("getPathFromClassLoader: Path found: " + lwjgl_classloader_path); String lwjgl_classloader_path = getPathFromClassLoader("lwjgl", classloader);
possible_paths.add(lwjgl_classloader_path.substring(0, lwjgl_classloader_path.lastIndexOf(File.separator)) if (lwjgl_classloader_path != null) {
+ File.separator + platform_lib_name); log("getPathFromClassLoader: Path found: " + lwjgl_classloader_path);
possible_paths.add(lwjgl_classloader_path.substring(0, lwjgl_classloader_path.lastIndexOf(File.separator))
+ File.separator + platform_lib_name);
}
// add Installer path
String alternative_path = getPrivilegedProperty("org.lwjgl.librarypath");
if (alternative_path != null) {
possible_paths.add(alternative_path + File.separator + platform_lib_name);
}
// Add all possible paths from java.library.path
String java_library_path = getPrivilegedProperty("java.library.path");
StringTokenizer st = new StringTokenizer(java_library_path, File.pathSeparator);
while (st.hasMoreTokens()) {
String path = st.nextToken();
possible_paths.add(path + File.separator + platform_lib_name);
}
//add current path
String current_dir = getPrivilegedProperty("user.dir");
possible_paths.add(current_dir + File.separator + platform_lib_name);
//add pure library (no path, let OS search)
possible_paths.add(platform_lib_name);
} }
// add Installer path
String alternative_path = getPrivilegedProperty("org.lwjgl.librarypath");
if (alternative_path != null) {
possible_paths.add(alternative_path + File.separator + platform_lib_name);
}
// Add all possible paths from java.library.path
String java_library_path = getPrivilegedProperty("java.library.path");
StringTokenizer st = new StringTokenizer(java_library_path, File.pathSeparator);
while (st.hasMoreTokens()) {
String path = st.nextToken();
possible_paths.add(path + File.separator + platform_lib_name);
}
//add current path
String current_dir = getPrivilegedProperty("user.dir");
possible_paths.add(current_dir + File.separator + platform_lib_name);
//add pure library (no path, let OS search)
possible_paths.add(platform_lib_name);
//create needed string array //create needed string array
String[] paths = new String[possible_paths.size()]; String[] paths = new String[possible_paths.size()];
possible_paths.toArray(paths); possible_paths.toArray(paths);
return paths; return paths;
} }

View File

@ -94,10 +94,25 @@ class ILNative {
private static native int getNativeLibraryVersion(); private static native int getNativeLibraryVersion();
static void createIL() throws LWJGLException { static void createIL() throws LWJGLException {
String[] illPaths = LWJGLUtil.getLibraryPaths(new String[]{ String libname;
"DevIL", "DevIL.dll", String platform_libname;
"IL", "libIL.so", switch (LWJGLUtil.getPlatform()) {
"IL", "libIL.dylib"}, IL.class.getClassLoader()); case LWJGLUtil.PLATFORM_WINDOWS:
libname = "DevIL";
platform_libname = "DevIL.dll";
break;
case LWJGLUtil.PLATFORM_LINUX:
libname = "IL";
platform_libname = "libIL.so";
break;
case LWJGLUtil.PLATFORM_MACOSX:
libname = "IL";
platform_libname = "libIL.dylib";
break;
default:
throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform());
}
String[] illPaths = LWJGLUtil.getLibraryPaths(libname, platform_libname, IL.class.getClassLoader());
ILNative.nCreateIL(illPaths); ILNative.nCreateIL(illPaths);
try { try {
@ -124,10 +139,22 @@ class ILNative {
static native void nDestroyILU(); static native void nDestroyILU();
static void createILU() throws LWJGLException { static void createILU() throws LWJGLException {
String[] iluPaths = LWJGLUtil.getLibraryPaths(new String[]{ String libname;
"ILU", "ILU.dll", switch (LWJGLUtil.getPlatform()) {
"ILU", "libILU.so", case LWJGLUtil.PLATFORM_WINDOWS:
"ILU", "libILU.dylib"}, ILU.class.getClassLoader()); libname = "ILU.dll";
break;
case LWJGLUtil.PLATFORM_LINUX:
libname = "libILU.so";
break;
case LWJGLUtil.PLATFORM_MACOSX:
libname = "libILU.dylib";
break;
default:
throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform());
}
String[] iluPaths = LWJGLUtil.getLibraryPaths("ILU", libname, ILU.class.getClassLoader());
ILNative.nCreateILU(iluPaths); ILNative.nCreateILU(iluPaths);
try { try {
@ -153,10 +180,21 @@ class ILNative {
static native void nDestroyILUT(); static native void nDestroyILUT();
static void createILUT() throws LWJGLException { static void createILUT() throws LWJGLException {
String[] ilutPaths = LWJGLUtil.getLibraryPaths(new String[]{ String libname;
"ILUT", "ILUT.dll", switch (LWJGLUtil.getPlatform()) {
"ILUT", "libILUT.so", case LWJGLUtil.PLATFORM_WINDOWS:
"ILUT", "libILUT.dylib"}, ILUT.class.getClassLoader()); libname = "ILUT.dll";
break;
case LWJGLUtil.PLATFORM_LINUX:
libname = "libILUT.so";
break;
case LWJGLUtil.PLATFORM_MACOSX:
libname = "libILUT.dylib";
break;
default:
throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform());
}
String[] ilutPaths = LWJGLUtil.getLibraryPaths("ILUT", libname, ILUT.class.getClassLoader());
ILNative.nCreateILUT(ilutPaths); ILNative.nCreateILUT(ilutPaths);
try { try {

View File

@ -263,11 +263,21 @@ public class FMOD {
} }
try { try {
String[] fmodPaths = LWJGLUtil.getLibraryPaths(new String[]{ String libname;
"fmod", "fmod.dll", switch (LWJGLUtil.getPlatform()) {
"fmod", "libfmod.so", case LWJGLUtil.PLATFORM_WINDOWS:
"fmod", "static-ignored"}, libname = "fmod.dll";
FMOD.class.getClassLoader()); break;
case LWJGLUtil.PLATFORM_LINUX:
libname = "libfmod.so";
break;
case LWJGLUtil.PLATFORM_MACOSX:
libname = "static-ignored";
break;
default:
throw new FMODException("Unknown platform: " + LWJGLUtil.getPlatform());
}
String[] fmodPaths = LWJGLUtil.getLibraryPaths("fmod", libname, FMOD.class.getClassLoader());
LWJGLUtil.log("Found " + fmodPaths.length + " FMOD paths"); LWJGLUtil.log("Found " + fmodPaths.length + " FMOD paths");
nCreate(fmodPaths); nCreate(fmodPaths);
created = true; created = true;

View File

@ -113,10 +113,25 @@ public final class AL {
if (created) if (created)
throw new IllegalStateException("Only one OpenAL context may be instantiated at any one time."); throw new IllegalStateException("Only one OpenAL context may be instantiated at any one time.");
String[] oalPaths = LWJGLUtil.getLibraryPaths(new String[]{ String libname;
"OpenAL32", "OpenAL32.dll", String[] library_names;
"openal", "libopenal.so", switch (LWJGLUtil.getPlatform()) {
"openal", "openal.dylib"}, AL.class.getClassLoader()); case LWJGLUtil.PLATFORM_WINDOWS:
libname = "OpenAL32";
library_names = new String[]{"OpenAL32.dll"};
break;
case LWJGLUtil.PLATFORM_LINUX:
libname = "openal";
library_names = new String[]{"libopenal.so", "libopenal.so.0"};
break;
case LWJGLUtil.PLATFORM_MACOSX:
libname = "openal";
library_names = new String[]{"openal.dylib"};
break;
default:
throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform());
}
String[] oalPaths = LWJGLUtil.getLibraryPaths(libname, library_names, AL.class.getClassLoader());
LWJGLUtil.log("Found " + oalPaths.length + " OpenAL paths"); LWJGLUtil.log("Found " + oalPaths.length + " OpenAL paths");
for (int i = 0; i < oalPaths.length; i++) { for (int i = 0; i < oalPaths.length; i++) {
try { try {