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:
parent
f62f11b437
commit
6abfeb4df2
|
@ -315,73 +315,68 @@ public class LWJGLUtil {
|
|||
/**
|
||||
* 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.
|
||||
* At least 6 names must be passed. 2 for each supported platform in the following order: Windows, Linux, MacOSX.
|
||||
* @param libName Local Library Name to search the classloader with ("openal").
|
||||
* @param platform_lib_name The native library name ("libopenal.so")
|
||||
* @param classloader The classloader to ask for library paths
|
||||
* @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
|
||||
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);
|
||||
if (classloader_path != null) {
|
||||
log("getPathFromClassLoader: Path found: " + classloader_path);
|
||||
possible_paths.add(classloader_path);
|
||||
}
|
||||
|
||||
String lwjgl_classloader_path = getPathFromClassLoader("lwjgl", classloader);
|
||||
if (lwjgl_classloader_path != null) {
|
||||
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);
|
||||
for (int i = 0; i < platform_lib_names.length; i++) {
|
||||
String platform_lib_name = platform_lib_names[i];
|
||||
String lwjgl_classloader_path = getPathFromClassLoader("lwjgl", classloader);
|
||||
if (lwjgl_classloader_path != null) {
|
||||
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
|
||||
String[] paths = new String[possible_paths.size()];
|
||||
possible_paths.toArray(paths);
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
|
|
|
@ -94,10 +94,25 @@ class ILNative {
|
|||
private static native int getNativeLibraryVersion();
|
||||
|
||||
static void createIL() throws LWJGLException {
|
||||
String[] illPaths = LWJGLUtil.getLibraryPaths(new String[]{
|
||||
"DevIL", "DevIL.dll",
|
||||
"IL", "libIL.so",
|
||||
"IL", "libIL.dylib"}, IL.class.getClassLoader());
|
||||
String libname;
|
||||
String platform_libname;
|
||||
switch (LWJGLUtil.getPlatform()) {
|
||||
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);
|
||||
|
||||
try {
|
||||
|
@ -124,10 +139,22 @@ class ILNative {
|
|||
static native void nDestroyILU();
|
||||
|
||||
static void createILU() throws LWJGLException {
|
||||
String[] iluPaths = LWJGLUtil.getLibraryPaths(new String[]{
|
||||
"ILU", "ILU.dll",
|
||||
"ILU", "libILU.so",
|
||||
"ILU", "libILU.dylib"}, ILU.class.getClassLoader());
|
||||
String libname;
|
||||
switch (LWJGLUtil.getPlatform()) {
|
||||
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||
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);
|
||||
|
||||
try {
|
||||
|
@ -153,10 +180,21 @@ class ILNative {
|
|||
static native void nDestroyILUT();
|
||||
|
||||
static void createILUT() throws LWJGLException {
|
||||
String[] ilutPaths = LWJGLUtil.getLibraryPaths(new String[]{
|
||||
"ILUT", "ILUT.dll",
|
||||
"ILUT", "libILUT.so",
|
||||
"ILUT", "libILUT.dylib"}, ILUT.class.getClassLoader());
|
||||
String libname;
|
||||
switch (LWJGLUtil.getPlatform()) {
|
||||
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||
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);
|
||||
|
||||
try {
|
||||
|
|
|
@ -263,11 +263,21 @@ public class FMOD {
|
|||
}
|
||||
|
||||
try {
|
||||
String[] fmodPaths = LWJGLUtil.getLibraryPaths(new String[]{
|
||||
"fmod", "fmod.dll",
|
||||
"fmod", "libfmod.so",
|
||||
"fmod", "static-ignored"},
|
||||
FMOD.class.getClassLoader());
|
||||
String libname;
|
||||
switch (LWJGLUtil.getPlatform()) {
|
||||
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||
libname = "fmod.dll";
|
||||
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");
|
||||
nCreate(fmodPaths);
|
||||
created = true;
|
||||
|
|
|
@ -113,10 +113,25 @@ public final class AL {
|
|||
|
||||
if (created)
|
||||
throw new IllegalStateException("Only one OpenAL context may be instantiated at any one time.");
|
||||
String[] oalPaths = LWJGLUtil.getLibraryPaths(new String[]{
|
||||
"OpenAL32", "OpenAL32.dll",
|
||||
"openal", "libopenal.so",
|
||||
"openal", "openal.dylib"}, AL.class.getClassLoader());
|
||||
String libname;
|
||||
String[] library_names;
|
||||
switch (LWJGLUtil.getPlatform()) {
|
||||
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");
|
||||
for (int i = 0; i < oalPaths.length; i++) {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue