@@ -16,50 +16,53 @@ See the License for the specific language governing permissions and
16
16
limitations under the License.
17
17
18
18
19
- By default, we build a JNI library (.jar and .so files) that is statically
20
- linked against the GS1 Syntax Engine.
19
+ This solution builds a JNI library (.jar and .so files) that wraps the GS1
20
+ Syntax Engine.
21
21
22
22
It is sufficient to place the built libgs1encoders.{jar,so} files into
23
23
accessible locations, then at runtime:
24
24
25
25
- Add the .jar file into the classpath.
26
26
- Add the directory containing the .so file into java.library.path.
27
27
28
+ -->
28
29
29
- Alternatively, you can build a JNI library that is dynamically linked against
30
- the GS1 Syntax Engine with:
30
+ <project name =" gs1encoders" default =" all" basedir =" ." xmlns : if =" ant:if" xmlns : unless =" ant:unless" >
31
31
32
- ant -Dlink_to_shared_lib=true
32
+ <description >
33
+ Java binding for GS1 Syntax Engine.
34
+ </description >
33
35
34
- This assumes that the GS1 Syntax Engine will be made available as a shared
35
- library pre-installed on any system to which projects using this JNI library
36
- are deployed.
36
+ < condition property = " no_strip " value = " true " >
37
+ < os family = " mac " />
38
+ </ condition >
37
39
38
- In addition to setting the classpath and java.library.path as above, when
39
- linking to a shared library instance of the GS1 Syntax Engine that is not
40
- installed in the system's regular library location, it is necessary to include
41
- the actual location in the dynamic linker's search path. For example by setting
42
- the environment variables:
40
+ <condition property =" dyn_lib_suffix" value =" dylib" else =" so" >
41
+ <os family =" mac" />
42
+ </condition >
43
43
44
- - LD_LIBRARY_PATH (Linux)
45
- - DYLD_LIBRARY_PATH (MacOS)
44
+ <condition property =" os.family" value =" darwin" else =" linux" >
45
+ <os family =" mac" />
46
+ </condition >
46
47
47
- -->
48
+ <condition property =" ldargs" value =" " else =" -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--no-as-needed" >
49
+ <os family =" mac" />
50
+ </condition >
48
51
49
- <project name =" gs1encoders" default =" all" basedir =" ." xmlns : if =" ant:if" xmlns : unless =" ant:unless" >
52
+ <condition property =" ldwholearchive" value =" " else =" -Wl,--whole-archive" >
53
+ <os family =" mac" />
54
+ </condition >
50
55
51
- <description >
52
- Java binding for GS1 Syntax Engine.
53
- </description >
56
+ <condition property = " ldnowholearchive " value = " " else = " -Wl,--no-whole-archive " >
57
+ < os family = " mac " />
58
+ </condition >
54
59
55
60
<property name =" src" location =" ." />
56
61
<property name =" build" location =" build" />
57
62
<property name =" classes" location =" ${ build } /classes" />
58
63
<property name =" jar" location =" libgs1encoders.jar" />
59
-
60
64
<property name =" wrapfile" location =" gs1encoders_wrap.c" />
61
- <property name =" sofile" location =" libgs1encoders.so" />
62
-
65
+ <property name =" sofile" location =" libgs1encoders.${ dyn_lib_suffix } " />
63
66
<property name =" clib" location =" ../c-lib" />
64
67
65
68
<target name =" init" >
@@ -68,17 +71,15 @@ the environment variables:
68
71
</target >
69
72
70
73
<target name =" cc" >
71
- <exec executable =" gcc " failonerror =" true" >
74
+ <exec executable =" cc " failonerror =" true" >
72
75
<arg line =" -fPIC -O2 -g -Werror" />
73
76
<arg line =" -I${ clib } " />
74
77
<arg line =" -I${ java.home } /../include" />
75
- <arg line =" -I${ java.home } /../include/linux " />
78
+ <arg line =" -I${ java.home } /../include/${ os.family } " />
76
79
<arg line =" -I${ java.home } /include" />
77
- <arg line =" -I${ java.home } /include/linux" />
78
- <arg line =" -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--no-as-needed" />
79
- <arg line =" -Wl,--whole-archive -Wl,-Bstatic" unless : set =" link_to_shared_lib" />
80
- <arg line =" -L${ clib } /build -lgs1encoders" />
81
- <arg line =" -Wl,--no-whole-archive -Wl,-Bdynamic" unless : set =" link_to_shared_lib" />
80
+ <arg line =" -I${ java.home } /include/${ os.family } " />
81
+ <arg line =" ${ ldargs } " />
82
+ <arg line =" ${ ldwholearchive } ${ clib } /build/libgs1encoders.a ${ ldnowholearchive } " />
82
83
<arg line =" -shared" />
83
84
<arg line =" -o ${ sofile } " />
84
85
<arg line =" ${ wrapfile } " />
@@ -116,13 +117,11 @@ the environment variables:
116
117
<javac includes =" Example.java" srcdir =" ${ src } " destdir =" ${ src } " includeantruntime =" false" classpath =" .:${ jar } " >
117
118
<compilerarg value =" -Werror" />
118
119
</javac >
119
- <echo unless : set =" link_to_shared_lib" >To run: java -Djava.library.path=${ src } -classpath ${ src } :${ jar } Example</echo >
120
- <echo if : set =" link_to_shared_lib" >To run: LD_LIBRARY_PATH=${ clib } /build:$LD_LIBRARY_PATH java -Djava.library.path=${ src } -classpath ${ src } :${ jar } Example</echo >
120
+ <echo >To run: java -Djava.library.path=${ src } -classpath ${ src } :${ jar } Example</echo >
121
121
</target >
122
122
123
123
<target name =" test" depends =" example" >
124
124
<java classname =" Example" failonerror =" true" classpath =" ${ src } :${ jar } " fork =" true" >
125
- <env key =" LD_LIBRARY_PATH" value =" ${ clib } /build:$LD_LIBRARY_PATH" if : set =" link_to_shared_lib" />
126
125
<sysproperty key =" java.library.path" path =" ${ src } " />
127
126
<arg value =" --version" />
128
127
</java >
0 commit comments