Mac OS X: Made Makefile compile a fat binary under 10.4 as default, and added Makefile.legacy for 10.3 compiles. Made OpenAL try to load the builtin OpenAL framework (available on 10.4) if loading openal.dylib fails

This commit is contained in:
Elias Naur 2006-01-16 15:15:38 +00:00
parent e636ab9671
commit c7f671d062
3 changed files with 83 additions and 20 deletions

View File

@ -59,7 +59,10 @@ static void* handleOAL;
#include <mach-o/dyld.h>
#include <stdlib.h>
#include <string.h>
static const struct mach_header* handleOAL;
#include <CoreFoundation/CoreFoundation.h>
static const struct mach_header* handleOAL = NULL;
static CFBundleRef openal_bundle = NULL;
#endif
typedef ALvoid* (ALAPIENTRY *alGetProcAddressPROC)( ALubyte* fname );
@ -80,15 +83,23 @@ static void *NativeGetFunctionPointer(const char *function) {
#endif
#ifdef _MACOSX
char *mac_symbol_name = (char *)malloc((strlen(function) + 2)*sizeof(char));
void *address = NULL;
if (mac_symbol_name == NULL)
return NULL;
mac_symbol_name[0] = '_';
strcpy(&(mac_symbol_name[1]), function);
NSSymbol symbol = NSLookupSymbolInImage(handleOAL, mac_symbol_name, NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
if (handleOAL != NULL) {
NSSymbol symbol = NSLookupSymbolInImage(handleOAL, mac_symbol_name, NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
if (symbol != NULL) {
address = NSAddressOfSymbol(symbol);
}
} else if (openal_bundle != NULL) {
CFStringRef cf_function = CFStringCreateWithCString(NULL, function, kCFStringEncodingUTF8);
address = CFBundleGetFunctionPointerForName(openal_bundle, cf_function);
CFRelease(cf_function);
}
free(mac_symbol_name);
if (symbol == NULL)
return NULL;
return NSAddressOfSymbol(symbol);
return address;
#endif
}
@ -106,7 +117,25 @@ static void* extal_GetProcAddress(const char* function) {
return p;
}
static void tryLoadLibrary(JNIEnv *env, jstring path) {
#ifdef _MACOSX
static CFBundleRef tryLoadFramework(JNIEnv *env) {
CFStringRef framework_path = CFSTR("/System/Library/Frameworks/OpenAL.framework");
if (framework_path == NULL) {
printfDebugJava(env, "Failed to allocate string");
return NULL;
}
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, framework_path, kCFURLPOSIXPathStyle, TRUE);
if (url == NULL) {
printfDebugJava(env, "Failed to allocate URL");
return NULL;
}
CFBundleRef openal_bundle = CFBundleCreate(NULL, url);
CFRelease(url);
return openal_bundle;
}
#endif
static bool tryLoadLibrary(JNIEnv *env, jstring path) {
#ifdef _WIN32
char *path_str = GetStringNativeChars(env, path);
printfDebugJava(env, "Testing '%s'", path_str);
@ -115,6 +144,7 @@ static void tryLoadLibrary(JNIEnv *env, jstring path) {
printfDebugJava(env, "Found OpenAL at '%s'", path_str);
}
free(path_str);
return handleOAL != NULL;
#endif
#ifdef _X11
char *path_str = GetStringNativeChars(env, path);
@ -124,6 +154,7 @@ static void tryLoadLibrary(JNIEnv *env, jstring path) {
printfDebugJava(env, "Found OpenAL at '%s'", path_str);
}
free(path_str);
return handleOAL != NULL;
#endif
#ifdef _MACOSX
const char *path_str = (*env)->GetStringUTFChars(env, path, NULL);
@ -133,6 +164,10 @@ static void tryLoadLibrary(JNIEnv *env, jstring path) {
printfDebugJava(env, "Found OpenAL at '%s'", path_str);
}
(*env)->ReleaseStringUTFChars(env, path, path_str);
openal_bundle = tryLoadFramework(env);
if (openal_bundle != NULL)
printfDebugJava(env, "Found OpenAL Bundle");
return handleOAL != NULL || openal_bundle != NULL;
#endif
}
@ -146,8 +181,7 @@ static bool LoadOpenAL(JNIEnv *env, jobjectArray oalPaths) {
for(i=0;i<pathcount;i++) {
path = (jstring) (*env)->GetObjectArrayElement(env, oalPaths, i);
tryLoadLibrary(env, path);
if (handleOAL != NULL) {
if (tryLoadLibrary(env, path)) {
return true;
}
}
@ -169,7 +203,10 @@ static void UnLoadOpenAL() {
}
#endif
#ifdef _MACOSX
// Cannot remove the image
if (openal_bundle != NULL) {
CFRelease(openal_bundle);
openal_bundle = NULL;
}
#endif
}

View File

@ -1,17 +1,14 @@
CC=gcc
LINKER=gcc
# This makefile builds a 'fat' library that is _only_ compatible with 10.4 and later
CC=gcc-4.0
LINKER=gcc-4.0
STRIP=strip
# Replace SDK_ROOT and ARCHS with the following to enable universal binary build
#SDK_ROOT=/Developer/SDKs/MacOSX10.4u.sdk
#ARCHS=-arch i386 -arch ppc
SDK_ROOT=/Developer/SDKs/MacOSX10.3.9.sdk
ARCHS=
#CFLAGS_LINK=-isysroot $(SDK_ROOT) -Wl,-syslibroot,$(SDK_ROOT) $(ARCHS) -exported_symbols_list lwjgl.symbols -dynamiclib -Wall
SDK_ROOT=/Developer/SDKs/MacOSX10.4u.sdk
ARCHS=-arch i386 -arch ppc
CFLAGS_LINK=-isysroot $(SDK_ROOT) -Wl,-syslibroot,$(SDK_ROOT) $(ARCHS) -exported_symbols_list lwjgl.symbols -dynamiclib -Wall
SYMBOL_FILE=lwjgl.symbols
CFLAGS_LINK=-exported_symbols_list lwjgl.symbols -dynamiclib -Wall
FRAMEWORKS=-framework Foundation -framework AppKit -framework JavaVM -framework Carbon
#CFLAGS_O=-isysroot $(SDK_ROOT) $(ARCHS) -fPIC -O2 -D_MACOSX -Wall -c -I${AL}/include -I../common -I$(SDK_ROOT)/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers
CFLAGS_O=-fPIC -O2 -D_MACOSX -Wall -c -I${AL}/include -I../common -I$(SDK_ROOT)/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers
CFLAGS_O=-isysroot $(SDK_ROOT) $(ARCHS) -fPIC -O2 -D_MACOSX -Wall -c -I$(SDK_ROOT)/System/Library/Frameworks/OpenAL.framework/Versions/A/Headers -I../common -I$(SDK_ROOT)/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers
SRC=$(wildcard *.m) $(wildcard *.c) $(wildcard ../common/*.c) $(wildcard ../generated/*.c)
OBJECTS=$(subst .m,.o, $(subst .c,.o,$(SRC)))
LIBRARY=liblwjgl.jnilib

View File

@ -0,0 +1,29 @@
# Use this makefile to build for Mac OS X 10.3 and earlier
CC=gcc-3.0
LINKER=gcc-3.0
STRIP=strip
ARCHS=
SYMBOL_FILE=lwjgl.symbols
CFLAGS_LINK=-exported_symbols_list lwjgl.symbols -dynamiclib -Wall
FRAMEWORKS=-framework Foundation -framework AppKit -framework JavaVM -framework Carbon
CFLAGS_O=-fPIC -O2 -D_MACOSX -Wall -c -I${AL}/include -I../common -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers
SRC=$(wildcard *.m) $(wildcard *.c) $(wildcard ../common/*.c) $(wildcard ../generated/*.c)
OBJECTS=$(subst .m,.o, $(subst .c,.o,$(SRC)))
LIBRARY=liblwjgl-legacy.jnilib
$(LIBRARY): $(OBJECTS) $(SYMBOL_FILE)
$(LINKER) $(CFLAGS_LINK) -o $@ $(OBJECTS) $(FRAMEWORKS)
$(STRIP) -S -X $@
$(SYMBOL_FILE): $(OBJECTS)
nm -g $(OBJECTS) | grep "Java_" | cut -d ' ' -f3 | cut -c 1- > $(SYMBOL_FILE)
.m.o:
$(CC) $(CFLAGS_O) $< -o $@
.c.o:
$(CC) $(CFLAGS_O) $< -o $@
clean:
rm -f $(OBJECTS) $(LIBRARY)