From 7cc4bb2a8bcc4c16b6a12826abbd874bf38f9dc1 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 8 Apr 2010 02:22:12 +0200 Subject: http://jogamp.org/bugzilla/show_bug.cgi?id=393 Fixed junit test: test1 - Create seperate native libraries to reflect a real world example: test1 - the library to bind to (no more declaring __stdcall @nn functions) BindingTest1p1 - the dynamic fixed linkage binding test1p1, references dynamic library test1 at linktime. BindingTest1p2 - the dynamic runtime linkage binding test1p2, loads dynamic library test1 at runtime. Generic: - gluegen-cpptasks-base.xml - target 'gluegen.cpptasks.detect.os' Set new property 'system.env.library.path' DYLD_LIBRARY_PATH (macosx) LD_LIBRARY_PATH (unix) PATH (windows) - target 'gluegen.cpptasks.striplibs' Strips the symbols out of the native libraries in case c.compiler.debug is false. Maybe configured with the properties: c.strip.tool, c.strip.args - Using system.env.library.path in junit call to find the test1 library in case of runtime linkage and lookup (test1p2). - Use gluegen.cpptasks.striplibs for all native libs .. - Added macosx32 in analogy to macosx64, both defaults to true now - com.jogamp.common.os.WindowsDynamicLinkerImpl:lookupSymbol() - Added lookup for __stdcall @nn (stepping alignment 4, max-args: 12) in case no undecorated __cdecl symbol is found. Fixed Windows platform: - Use proper path.seperator on Windows. - test1.dll needs proper soname inside for fixed linkage (test1p1) hence the output name must be test1.dll, not libtest1.so +++ http://jogamp.org/bugzilla/show_bug.cgi?id=394 Fix MacOsX platform: The commit of cpptasks.jar, git hash 129e783741d91e9ee5cd7da5d5c962c32ec96b0b, broke the universal binary build on MacOSX. The above change used cpptasks-1.05b with a few patches in regards to crosscompilation, but missed one, which accepts the '-arch' argument for GccLinker undecorated. The new cpptasks.jar is vanilla 1.05b + cpptasks-1.0b5-darwin-patch.diff, the latter a more refined one. This version accepts the '-arch' argument undecorated on the darwin platform. +++ --- make/build-junit.xml | 103 ++++++++++++++------- make/build.xml | 22 +++-- make/gluegen-cpptasks-base.xml | 100 +++++++++++++++----- make/gluegen-cpptasks.xml | 3 +- make/gluegen-properties.xml | 20 ++-- make/gluegen.properties | 46 +++++---- make/lib/CppTasksGCCNamespaceHack.jar | Bin 7810 -> 0 bytes ...-mbien-129e783741d91e9ee5cd7da5d5c962c32ec96b0b | Bin 0 -> 7810 bytes make/lib/cpptasks-1.0b5-darwin-patch.diff | 39 ++++++++ make/lib/cpptasks-1.0b5.zip | Bin 0 -> 2221439 bytes ...c91f003551542c2aab62dd8ef89a7894c7e50689.tar.gz | Bin 0 -> 7743 bytes make/lib/cpptasks-patch.tar.gz | Bin 7743 -> 0 bytes make/lib/cpptasks.jar | Bin 363963 -> 364113 bytes ...-mbien-129e783741d91e9ee5cd7da5d5c962c32ec96b0b | Bin 0 -> 363963 bytes ...r-orig-c91f003551542c2aab62dd8ef89a7894c7e50689 | Bin 0 -> 345356 bytes make/make.gluegen.all.macosx.sh | 2 +- make/make.gluegen.all.win32.bat | 17 ++++ .../jogamp/common/os/WindowsDynamicLinkerImpl.java | 28 +++++- .../test/junit/generation/Test1p1JavaEmitter.java | 4 +- .../generation/Test1p2ProcAddressEmitter.java | 6 +- .../jogamp/gluegen/test/junit/generation/test1.c | 44 ++++----- .../jogamp/gluegen/test/junit/generation/test1.h | 20 +++- test/junit/com/sun/gluegen/BasicTest.java | 5 +- 23 files changed, 338 insertions(+), 121 deletions(-) delete mode 100644 make/lib/CppTasksGCCNamespaceHack.jar create mode 100644 make/lib/CppTasksGCCNamespaceHack.jar-mbien-129e783741d91e9ee5cd7da5d5c962c32ec96b0b create mode 100644 make/lib/cpptasks-1.0b5-darwin-patch.diff create mode 100644 make/lib/cpptasks-1.0b5.zip create mode 100644 make/lib/cpptasks-patch-orig-c91f003551542c2aab62dd8ef89a7894c7e50689.tar.gz delete mode 100644 make/lib/cpptasks-patch.tar.gz create mode 100644 make/lib/cpptasks.jar-mbien-129e783741d91e9ee5cd7da5d5c962c32ec96b0b create mode 100755 make/lib/cpptasks.jar-orig-c91f003551542c2aab62dd8ef89a7894c7e50689 create mode 100644 make/make.gluegen.all.win32.bat diff --git a/make/build-junit.xml b/make/build-junit.xml index f1f3b6f..2da5997 100644 --- a/make/build-junit.xml +++ b/make/build-junit.xml @@ -121,10 +121,8 @@ - - - - + @@ -172,33 +170,30 @@ - - - - - - - - - - - - - + + + + + + + - - + + - - + @@ -221,7 +216,12 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + - + linker.cfg.id="linker.test1.fixed.cfg.id"/> + + + + + + + + + + + + - + linker.cfg.id="linker.test1.runtime.cfg.id"/> + + + + + + @@ -341,10 +344,7 @@ - - - - + @@ -352,8 +352,8 @@ + + + + + @@ -572,7 +577,7 @@ - + @@ -583,7 +588,8 @@ - + + diff --git a/make/gluegen-cpptasks-base.xml b/make/gluegen-cpptasks-base.xml index 9eedcd1..5375306 100755 --- a/make/gluegen-cpptasks-base.xml +++ b/make/gluegen-cpptasks-base.xml @@ -24,7 +24,6 @@ - isLinuxX86 - isOSX - isOSXPPC - - isOSXUniversal (if macosxfat=true) - isSolaris - isSolaris32Bit - isSolarisAMD64 @@ -116,21 +115,37 @@ --> - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -265,6 +280,7 @@ + @@ -347,6 +363,26 @@ + + + + + + + + + + + + + + + + + - - @@ -473,12 +506,14 @@ - + + - + + @@ -561,8 +596,8 @@ - - + + @@ -611,13 +646,15 @@ - + + - + + - + - + @@ -647,10 +684,11 @@ + - - + + @@ -781,6 +819,24 @@ + + + + + + + + + + + + + + + - + + diff --git a/make/gluegen-properties.xml b/make/gluegen-properties.xml index 19483bb..2afc533 100755 --- a/make/gluegen-properties.xml +++ b/make/gluegen-properties.xml @@ -11,14 +11,22 @@ - c.compiler.debug: - set to "true" if debug version of the compiled - C code is desired. + - + - MacOsX libraries can be universal / fat binaries. + - The following switches enables/disables a target platform. + - If non of them is enabled, the default + - compiler target platform is used for a thin binary. + - - macosppc: - - set to "true" if ppc universal / fat binaries are desired - - on Mac OS X. Requires support for cross-compilation from the - - underlying C compiler. Note: Unsupported on Snow Leopard! + - set to "true" for ppc support, + - default is 'false' + - Note: Unsupported on Snow Leopard! + - macosx32: + - set to "false" to disable x86 32-bit support, + - default is 'true' - macosx64: - - set to "true" if 64-bit universal / fat binaries are desired - - on Mac OS X. Requires support for cross-compilation from the - - underlying C compiler. + - set to "false" to disable x86 64-bit support, + - default is 'true' - --> diff --git a/make/gluegen.properties b/make/gluegen.properties index 8d667b4..2f319bc 100755 --- a/make/gluegen.properties +++ b/make/gluegen.properties @@ -13,13 +13,13 @@ # including the name of the jar # # Windows -antlr.jar=C:/Users/kbr/ANTLR/antlr-2.7.2/antlr.jar -# Linux -# antlr.jar=/home/kbr/antlr-2.7.2/antlr.jar +antlr.jar=C:/JOGL/lib/antlr-2.7.2.jar +# Linux / Solaris / .. +# antlr.jar=/home/sven/projects/JOGL/lib/antlr-2.7.7.jar # Mac OS X -# antlr.jar=/Users/kbr/antlr-2.7.2/antlr.jar -# Solaris -# antlr.jar=/export/kbr/ANTLR/antlr-2.7.2/antlr.jar +# antlr.jar=/JOGL/lib/antlr-2.7.2.jar + +junit.jar=/home/sven/projects/JOGL/lib/junit-4.5.jar # If you are building the native code for the GlueGen run-time library # on Windows and have the Microsoft Visual C++ compilers installed, @@ -28,19 +28,27 @@ antlr.jar=C:/Users/kbr/ANTLR/antlr-2.7.2/antlr.jar # "mingw". # win32.c.compiler=vc6 -# If you are building on a Mac OS X system supporting -# cross-compilation and want to generate fat binaries containing -# x86_64 code, uncomment the property below -# macosx64=true - -# If you are building on a Mac OS X system supporting -# cross-compilation and want to generate fat binaries containing -# ppc code, uncomment the property below. -# Note: Unsupported on Snow Leopard! +# MacOsX libraries can be universal / fat binaries. +# The following switches enables/disables a target platform. +# If non of them is enabled, the default +# compiler target platform is used for a thin binary. +# +# macosppc: +# set to "true" for ppc support, +# default is 'false' +# Note: Unsupported on Snow Leopard! # macosppc=true +# +# macosx32: +# set to "false" to disable x86 32-bit support, +# default is 'true' +# macosx32=false +# +# macosx64: +# set to "false" to disable x86 64-bit support, +# default is 'true' +# macosx64=false +# -# isX11 is selected for a platform where: !isWindows && !isOSX. -# To avoid X11 related builds you need to set 'noX11' to true. -# noX11=true -#user.compiler.import="${user.home}/gluegen.compiler.xml" +#gluegen-cpptasks.file="${user.home}/gluegen-cpptasks-linux-32bit.xml" diff --git a/make/lib/CppTasksGCCNamespaceHack.jar b/make/lib/CppTasksGCCNamespaceHack.jar deleted file mode 100644 index c31779e..0000000 Binary files a/make/lib/CppTasksGCCNamespaceHack.jar and /dev/null differ diff --git a/make/lib/CppTasksGCCNamespaceHack.jar-mbien-129e783741d91e9ee5cd7da5d5c962c32ec96b0b b/make/lib/CppTasksGCCNamespaceHack.jar-mbien-129e783741d91e9ee5cd7da5d5c962c32ec96b0b new file mode 100644 index 0000000..c31779e Binary files /dev/null and b/make/lib/CppTasksGCCNamespaceHack.jar-mbien-129e783741d91e9ee5cd7da5d5c962c32ec96b0b differ diff --git a/make/lib/cpptasks-1.0b5-darwin-patch.diff b/make/lib/cpptasks-1.0b5-darwin-patch.diff new file mode 100644 index 0000000..1544fcc --- /dev/null +++ b/make/lib/cpptasks-1.0b5-darwin-patch.diff @@ -0,0 +1,39 @@ +diff -Nur cpptasks-1.0b5/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java cpptasks-1.0b5-patched-01/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java +--- cpptasks-1.0b5/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java 2008-04-02 19:26:44.000000000 +0200 ++++ cpptasks-1.0b5-patched-01/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java 2010-04-07 22:16:03.330794801 +0200 +@@ -17,6 +17,8 @@ + package net.sf.antcontrib.cpptasks.gcc; + import java.io.File; + import java.util.Vector; ++import java.util.HashSet; ++import java.util.Arrays; + + import net.sf.antcontrib.cpptasks.CUtil; + import net.sf.antcontrib.cpptasks.compiler.LinkType; +@@ -36,6 +38,7 @@ + "-dynamiclib", "-nostartfiles", "-nostdlib", "-prebind", "-s", + "-static", "-shared", "-symbolic", "-Xlinker", + "--export-all-symbols", "-static-libgcc",}; ++ private static String[] darwinLinkerOptions = new String[]{"-arch", }; + private static final GccLinker dllLinker = new GccLinker("gcc", objFiles, + discardFiles, "lib", ".so", false, new GccLinker("gcc", objFiles, + discardFiles, "lib", ".so", true, null)); +@@ -97,12 +100,13 @@ + break; + default : + boolean known = false; +- for (int i = 0; i < linkerOptions.length; i++) { +- if (linkerOptions[i].equals(arg)) { +- known = true; +- break; +- } ++ HashSet allLinkerOptions = new HashSet(); ++ allLinkerOptions.addAll(Arrays.asList(linkerOptions)); ++ if (isDarwin()) { ++ allLinkerOptions.addAll(Arrays.asList(darwinLinkerOptions)); + } ++ known = allLinkerOptions.contains(arg); ++ + if (!known) { + buf.setLength(0); + buf.append("-Wl,"); diff --git a/make/lib/cpptasks-1.0b5.zip b/make/lib/cpptasks-1.0b5.zip new file mode 100644 index 0000000..21f8c07 Binary files /dev/null and b/make/lib/cpptasks-1.0b5.zip differ diff --git a/make/lib/cpptasks-patch-orig-c91f003551542c2aab62dd8ef89a7894c7e50689.tar.gz b/make/lib/cpptasks-patch-orig-c91f003551542c2aab62dd8ef89a7894c7e50689.tar.gz new file mode 100644 index 0000000..22f1cde Binary files /dev/null and b/make/lib/cpptasks-patch-orig-c91f003551542c2aab62dd8ef89a7894c7e50689.tar.gz differ diff --git a/make/lib/cpptasks-patch.tar.gz b/make/lib/cpptasks-patch.tar.gz deleted file mode 100644 index 22f1cde..0000000 Binary files a/make/lib/cpptasks-patch.tar.gz and /dev/null differ diff --git a/make/lib/cpptasks.jar b/make/lib/cpptasks.jar index dec6c13..f1bf393 100644 Binary files a/make/lib/cpptasks.jar and b/make/lib/cpptasks.jar differ diff --git a/make/lib/cpptasks.jar-mbien-129e783741d91e9ee5cd7da5d5c962c32ec96b0b b/make/lib/cpptasks.jar-mbien-129e783741d91e9ee5cd7da5d5c962c32ec96b0b new file mode 100644 index 0000000..dec6c13 Binary files /dev/null and b/make/lib/cpptasks.jar-mbien-129e783741d91e9ee5cd7da5d5c962c32ec96b0b differ diff --git a/make/lib/cpptasks.jar-orig-c91f003551542c2aab62dd8ef89a7894c7e50689 b/make/lib/cpptasks.jar-orig-c91f003551542c2aab62dd8ef89a7894c7e50689 new file mode 100755 index 0000000..005691c Binary files /dev/null and b/make/lib/cpptasks.jar-orig-c91f003551542c2aab62dd8ef89a7894c7e50689 differ diff --git a/make/make.gluegen.all.macosx.sh b/make/make.gluegen.all.macosx.sh index 3086733..1078cec 100644 --- a/make/make.gluegen.all.macosx.sh +++ b/make/make.gluegen.all.macosx.sh @@ -8,4 +8,4 @@ fi ant -v \ -Drootrel.build=build-macosx \ - $* 2>&1 | tee make.gluegen.all.macosx-x86.log + $* 2>&1 | tee make.gluegen.all.macosx.log diff --git a/make/make.gluegen.all.win32.bat b/make/make.gluegen.all.win32.bat new file mode 100644 index 0000000..2c97baf --- /dev/null +++ b/make/make.gluegen.all.win32.bat @@ -0,0 +1,17 @@ +set THISDIR="C:\JOGL" + +set J2RE_HOME=c:\jre1.6.0_19 +set JAVA_HOME=c:\jdk1.6.0_19 +set ANT_PATH=C:\apache-ant-1.7.1 + +set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw\bin;%PATH% + +set LIB_GEN=%THISDIR%\lib +set CLASSPATH=.;%THISDIR%\build-win32\classes +REM -Dc.compiler.debug=true +REM -DuseOpenMAX=true +REM -DuseKD=true +REM -Djogl.cg=1 -D-Dwindows.cg.lib=C:\Cg-2.2 + +ant -Drootrel.build=build-win32 %1 %2 %3 %4 %5 %6 %7 %8 %9 > make.gluegen.all.win32.log 2>&1 + diff --git a/src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java b/src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java index f5a3312..2858f74 100755 --- a/src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java +++ b/src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java @@ -2,9 +2,20 @@ package com.jogamp.common.os; +import java.security.*; public class WindowsDynamicLinkerImpl implements DynamicLinker { + private static boolean DEBUG; + + static { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + DEBUG = (System.getProperty("gluegen.debug.NativeLibrary") != null); + return null; + } + }); + } /** Interface to C language function:
BOOL FreeLibrary(HANDLE hLibModule); */ private static native int FreeLibrary(long hLibModule); @@ -36,7 +47,22 @@ public class WindowsDynamicLinkerImpl implements DynamicLinker { } public long lookupSymbol(long libraryHandle, String symbolName) { - return GetProcAddressA(libraryHandle, symbolName); + String _symbolName = symbolName; + long addr = GetProcAddressA(libraryHandle, _symbolName); + if(0==addr) { + // __stdcall hack: try some @nn decorations, + // the leading '_' must not be added (same with cdecl) + final int argAlignment=4; // 4 byte alignment of each argument + final int maxArguments=12; // experience .. + for(int arg=0; 0==addr && arg<=maxArguments; arg++) { + _symbolName = symbolName+"@"+(arg*argAlignment); + addr = GetProcAddressA(libraryHandle, _symbolName); + } + } + if(DEBUG) { + System.err.println("WindowsDynamicLinkerImpl.lookupSymbol(0x"+Long.toHexString(libraryHandle)+", "+symbolName+") -> "+_symbolName+", 0x"+Long.toHexString(addr)); + } + return addr; } public void closeLibrary(long libraryHandle) { diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java index 6320f92..7e8ef49 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java @@ -65,8 +65,8 @@ public class Test1p1JavaEmitter extends BaseTest1 { */ @Test public void chapter01TestLoadLibrary() throws Exception { - String nativesPath = testOutput + "/build/natives"; - System.load(nativesPath + "/libtest1p1.so"); + //System.loadLibrary("test1"); + System.loadLibrary("BindingTest1p1"); } /** diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java index 83f20d1..2d2cca3 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java @@ -69,9 +69,9 @@ public class Test1p2ProcAddressEmitter extends BaseTest1 { */ @Test public void chapter01TestLoadLibrary() throws Exception { - System.loadLibrary("test1p2"); - dynamicLookupHelper = NativeLibrary.open("test1p2", getClass().getClassLoader(), true); - Assert.assertNotNull("NativeLibrary.open(test1p2) failed", dynamicLookupHelper); + System.loadLibrary("BindingTest1p2"); + dynamicLookupHelper = NativeLibrary.open("test1", getClass().getClassLoader(), true); + Assert.assertNotNull("NativeLibrary.open(test1) failed", dynamicLookupHelper); BindingTest1p2Impl.resetProcAddressTable(dynamicLookupHelper); } diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c index f654467..d74cfc6 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c @@ -1,14 +1,16 @@ +#define __MYAPI_EXPORT_ 1 #include "test1.h" + #include #include #include #include -foo nopTest() { +MYAPI foo MYAPIENTRY nopTest() { return 42; } -int32_t arrayTestInt32(int64_t context, int32_t * array) { +MYAPI int32_t MYAPIENTRY arrayTestInt32(int64_t context, int32_t * array) { int32_t r=0; int i; assert(NULL!=array); @@ -20,7 +22,7 @@ int32_t arrayTestInt32(int64_t context, int32_t * array) { return r+context; } -int64_t arrayTestInt64(int64_t context, int64_t * array) { +MYAPI int64_t MYAPIENTRY arrayTestInt64(int64_t context, int64_t * array) { int64_t r=0; int i; assert(NULL!=array); @@ -32,7 +34,7 @@ int64_t arrayTestInt64(int64_t context, int64_t * array) { return r+context; } -foo * arrayTestFoo2( foo * array ) { +MYAPI foo * MYAPIENTRY arrayTestFoo2( foo * array ) { int i; foo * result = calloc(ARRAY_SIZE, sizeof(foo)); assert(NULL!=array); @@ -43,7 +45,7 @@ foo * arrayTestFoo2( foo * array ) { return result; } -foo * * arrayTestFoo3ArrayToPtrPtr(foo * array) { +MYAPI foo * * MYAPIENTRY arrayTestFoo3ArrayToPtrPtr(foo * array) { int j; foo * * result = calloc(ARRAY_SIZE, sizeof(foo *)); for(j=0; j clazz = Class.forName("test.BindingTest"); -- cgit v1.2.3