-
Notifications
You must be signed in to change notification settings - Fork 78
/
build.xml
445 lines (394 loc) · 16.1 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<?xml version="1.0" encoding="UTF-8"?>
<project name="jffi" default="jar" basedir=".">
<description>Builds, tests, and runs the project jffi.</description>
<path id="classpath.test">
<pathelement location="lib/junit_4/junit-4.11.jar"/>
<pathelement location="lib/junit_4/hamcrest-core-1.3.jar"/>
</path>
<target name="clean-java" depends="-init">
<delete dir="${build.dir}/classes"/>
<delete dir="${build.dir}/java"/>
<delete dir="${build.test.dir}"/>
<delete dir="${dist.dir}"/>
</target>
<target name="clean" depends="-init">
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
</target>
<target name="jar" depends="-init,-pre-jar,-do-jar,-post-jar"/>
<target name="build-native" depends="-init, -build-platform-jar, -assemble-final-jar"/>
<target name="-pre-init">
<property name="run.jvmargs" value="-Djffi.library.path=build/jni -Djffi.boot.library.path=build/jni"/>
</target>
<target name="-init-vars">
<property name="src.dir" location="src/main/java"/>
<property name="src.test.dir" location="src/test/java"/>
<property name="build.dir" location="build"/>
<property name="dist.dir" location="dist"/>
<property name="build.classes.dir" location="${build.dir}/classes"/>
<property name="build.test.dir" location="${build.dir}/test"/>
<property name="dist.jar" value="${dist.dir}/jffi.jar"/>
<property name="complete.jar" value="${dist.dir}/jffi-complete.jar"/>
<property name="build.native.dir" location="${build.dir}/jni"/>
<property name="src.native.dir" location="jni"/>
<property name="ant.build.javac.target" value="8"/>
<property name="ant.build.javac.source" value="8"/>
<property name="ant.build.javac.includeantruntime" value="false"/>
<property name="test.fork" value="yes"/>
<property name="test.fork.mode" value="once"/>
<mkdir dir="${build.native.dir}"/>
<!-- normalize the various os.arch naming conventions -->
<condition property="platform.cpu" value="i386">
<or>
<os arch="i386"/>
<os arch="x86"/>
</or>
</condition>
<condition property="platform.cpu" value="x86_64">
<or>
<os arch="amd64"/>
<os arch="x86_64"/>
</or>
</condition>
<condition property="platform.cpu" value="ppc">
<or>
<os arch="ppc"/>
<os arch="powerpc"/>
</or>
</condition>
<condition property="platform.cpu" value="ppc64">
<or>
<os arch="ppc64"/>
<os arch="powerpc64"/>
</or>
</condition>
<condition property="platform.cpu" value="aarch64">
<or>
<os arch="aarch64"/>
</or>
</condition>
<condition property="platform.cpu" value="loongarch64">
<or>
<os arch="loongarch64"/>
</or>
</condition>
<condition property="platform.cpu" value="mipsel">
<or>
<os arch="mipsel"/>
</or>
</condition>
<condition property="platform.cpu" value="mips64">
<or>
<os arch="mips64"/>
</or>
</condition>
<condition property="platform.cpu" value="mips64el">
<or>
<os arch="mips64el"/>
</or>
</condition>
<condition property="platform.os" value="Windows">
<os family="Windows"/>
</condition>
<!-- default to os.arch for the cpu -->
<condition property="platform.cpu" value="${os.arch}">
<not><isset property="platform.cpu"/></not>
</condition>
<condition property="platform.os" value="${os.name}">
<not><isset property="platform.os"/></not>
</condition>
<condition property="platform" value="Darwin">
<os family="Mac"/>
</condition>
<condition property="platform" value="${platform.cpu}-${platform.os}">
<not><isset property="platform"/></not>
</condition>
<condition property="native.jar" value="${build.dir}/native.jar">
<not><isset property="native.jar"/></not>
</condition>
<condition property="make.exe" value="gmake">
<or>
<os name="FreeBSD"/>
<os name="OpenBSD"/>
<os name="DragonFlyBSD"/>
<os name="AIX"/>
<os name="HP-UX"/>
</or>
</condition>
<condition property="make.exe" value="/usr/sfw/bin/gmake">
<os name="SunOS"/>
</condition>
<condition property="make.exe" value="make">
<not><isset property="make.exe"/></not>
</condition>
</target>
<target name="-init" depends="-pre-init,-init-vars,-post-init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build.dir}"/>
</target>
<import file="version.xml"/>
<target name="-pre-jar"/>
<target name="-post-init" depends="-init-vars"/>
<target name="-pre-compile" depends="-init"/>
<target name="-post-compile" depends="-build-native-library"/>
<target name="-pre-compile-test" depends="-init"/>
<target name="-post-compile-test" depends="-build-native-testlib"/>
<target name="-post-jar" depends="-assemble-final-jar"/>
<target name="-do-compile" depends="-init">
<mkdir dir="${build.classes.dir}"/>
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src.dir}" destdir="${build.classes.dir}" includeantruntime="false"/>
</target>
<target name="-compile-java" depends="-do-compile"/>
<target name="compile" depends="-init,-pre-compile,-do-compile,-post-compile">
</target>
<target name="-do-jar" depends="-init,compile">
<mkdir dir="${dist.dir}"/>
<jar destfile="${dist.jar}" basedir="${build.classes.dir}" compress="true"/>
</target>
<target name="test" depends="compile,-compile-test">
<mkdir dir="${build.test.dir}/results"/>
<echo>test with jni libraries from sources</echo>
<junit fork="${test.fork}" forkMode="${test.fork.mode}" printsummary="withOutAndErr" haltonfailure="true">
<env key="LC_ALL" value="C"/>
<classpath>
<pathelement location="${build.classes.dir}"/>
<pathelement location="${build.test.dir}/classes"/>
<pathelement location="lib/junit_4/junit-4.11.jar"/>
<pathelement location="lib/junit_4/hamcrest-core-1.3.jar"/>
</classpath>
<sysproperty key="java.library.path" value="${build.native.dir}"/>
<formatter type="plain" /> <!-- to file -->
<batchtest todir="${build.test.dir}/results">
<fileset dir="${src.test.dir}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
<echo>test with unpack of jni library</echo>
<junit fork="${test.fork}" forkMode="${test.fork.mode}" printsummary="withOutAndErr" haltonfailure="true">
<env key="LC_ALL" value="C"/>
<classpath>
<pathelement location="${build.classes.dir}"/>
<pathelement location="${build.test.dir}/classes"/>
<fileset dir="archive" includes="*.jar"/>
<pathelement location="lib/junit_4/junit-4.11.jar"/>
<pathelement location="lib/junit_4/hamcrest-core-1.3.jar"/>
</classpath>
<formatter type="plain" /> <!-- to file -->
<batchtest todir="${build.test.dir}/results">
<fileset dir="${src.test.dir}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
<echo>test with unpack of jni library to specific locatiohn</echo>
<junit fork="${test.fork}" forkMode="${test.fork.mode}" printsummary="withOutAndErr" haltonfailure="true">
<env key="LC_ALL" value="C"/>
<classpath>
<pathelement location="${build.classes.dir}"/>
<pathelement location="${build.test.dir}/classes"/>
<fileset dir="archive" includes="*.jar"/>
<pathelement location="lib/junit_4/junit-4.11.jar"/>
<pathelement location="lib/junit_4/hamcrest-core-1.3.jar"/>
</classpath>
<sysproperty key="jffi.extract.name" value=""/>
<formatter type="plain" /> <!-- to file -->
<batchtest todir="${build.test.dir}/results">
<fileset dir="${src.test.dir}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="ensure-test-name" unless="test">
<fail message="You must run this target with -Dtest=TestName"/>
</target>
<target name="runtest" description="Runs the test you specify on the command
line with -Dtest=" depends="compile, -compile-test, ensure-test-name">
<junit printsummary="withOutAndErr" fork="${test.fork}" forkMode="${test.fork.mode}">
<classpath>
<pathelement location="${build.classes.dir}"/>
<pathelement location="${build.test.dir}/classes"/>
<pathelement location="lib/junit_4/junit-4.11.jar"/>
<pathelement location="lib/junit_4/hamcrest-core-1.3.jar"/>
</classpath>
<sysproperty key="java.library.path" value="${build.native.dir}"/>
<formatter type="plain" usefile="false"/>
<batchtest>
<fileset dir="${src.test.dir}">
<include name="**/${test}.java"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="-compile-test" depends="-pre-compile-test,-do-compile-test,-post-compile-test"/>
<target name="-do-compile-test" depends="-init">
<mkdir dir="${build.test.dir}/classes"/>
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src.test.dir}" destdir="${build.test.dir}/classes" includeantruntime="false" classpathref="classpath.test">
<classpath>
<pathelement location="${build.classes.dir}"/>
<pathelement location="lib/junit_4/junit-4.11.jar"/>
<pathelement location="lib/junit_4/hamcrest-core-1.3.jar"/>
</classpath>
</javac>
</target>
<target name="cross-win32" depends="-init, -generate-native-headers">
<mkdir dir="${build.native.dir}"/>
<exec executable="${make.exe}" failonerror="true">
<arg value="JAVA_HOME=${java.home}"/>
<arg value="OS=cross-mingw32"/>
<arg value="SRC_DIR=${src.native.dir}"/>
<arg value="JNI_DIR=${src.native.dir}"/>
<arg value="BUILD_DIR=${build.native.dir}"/>
<arg value="VERSION=${jffi.version.major}.${jffi.version.minor}"/>
<arg value="CPU=i386"/>
<arg value="-f"/>
<arg value="jni/GNUmakefile"/>
</exec>
<exec executable="i686-w64-mingw32-strip" failonerror="true">
<arg value="--strip-debug"/> <!-- Strip debug symbols only -->
<arg value="${build.native.dir}/jffi-${jffi.version.major}.${jffi.version.minor}.dll"/>
</exec>
<mkdir dir="${dist.dir}"/>
<zip destfile="${dist.dir}/jffi-i386-Windows.jar" level="9">
<zipfileset prefix="jni/i386-Windows" dir="${build.native.dir}">
<include name="jffi*.dll"/>
</zipfileset>
</zip>
</target>
<target name="cross-win64" depends="-init, -generate-native-headers">
<mkdir dir="${build.native.dir}"/>
<exec executable="${make.exe}" failonerror="true">
<arg value="JAVA_HOME=${java.home}"/>
<arg value="OS=cross-win64"/>
<arg value="SRC_DIR=${src.native.dir}"/>
<arg value="JNI_DIR=${src.native.dir}"/>
<arg value="BUILD_DIR=${build.native.dir}"/>
<arg value="VERSION=${jffi.version.major}.${jffi.version.minor}"/>
<arg value="CPU=x86_64"/>
<arg value="-f"/>
<arg value="jni/GNUmakefile"/>
</exec>
<exec executable="x86_64-w64-mingw32-strip" failonerror="true">
<arg value="--strip-debug"/> <!-- Strip debug symbols only -->
<arg value="${build.native.dir}/jffi-${jffi.version.major}.${jffi.version.minor}.dll"/>
</exec>
<mkdir dir="${dist.dir}"/>
<zip destfile="${dist.dir}/jffi-x86_64-Windows.jar" level="9">
<zipfileset prefix="jni/x86_64-Windows" dir="${build.native.dir}">
<include name="jffi*.dll"/>
</zipfileset>
</zip>
</target>
<target name="-generate-version" depends="-init,-init-vars,-generate-version-source">
<javac target="${ant.build.javac.target}" destdir="${build.classes.dir}" srcdir="${build.dir}/java" includeantruntime="false"/>
</target>
<target name="-generate-native-headers" depends="-init-vars,-generate-version,-compile-java">
<mkdir dir="${build.native.dir}"/>
<mkdir dir="${build.classes.dir}"/>
<javac destdir="${build.native.dir}" nativeheaderdir="${build.native.dir}">
<src path="${src.dir}"/>
<src path="${build.dir}/java"/>
<include name="com/kenai/jffi/Foreign.java"/>
<include name="com/kenai/jffi/ObjectBuffer.java"/>
<include name="com/kenai/jffi/Version.java"/>
</javac>
<!--
<exec executable="javah" failonerror="true">
<arg line="-d ${build.native.dir}"/>
<arg line="-classpath ${build.classes.dir}"/>
<arg line="com.kenai.jffi.Foreign"/>
<arg line="com.kenai.jffi.ObjectBuffer"/>
</exec>
-->
</target>
<target name="-build-native-library" depends="-init-vars, -generate-native-headers, -generate-version">
<mkdir dir="${build.native.dir}"/>
<exec executable="cygpath" outputproperty="jni.GNUmakefile" osfamily="Windows">
<arg value="-u"/>
<arg value="${src.native.dir}/GNUmakefile"/>
</exec>
<exec executable="cygpath" outputproperty="jni.src.dir" osfamily="Windows">
<arg value="-u"/>
<arg value="${src.native.dir}"/>
</exec>
<exec executable="cygpath" outputproperty="jni.build.dir" osfamily="Windows">
<arg value="-u"/>
<arg value="${build.native.dir}"/>
</exec>
<exec executable="cygpath" outputproperty="jni.java.home" osfamily="Windows">
<arg value="-u"/>
<arg value="${java.home}"/>
</exec>
<condition property="jni.GNUmakefile" value="${src.native.dir}/GNUmakefile">
<not><isset property="jni.GNUmakefile"/></not>
</condition>
<condition property="jni.src.dir" value="${src.native.dir}">
<not><isset property="jni.src.dir"/></not>
</condition>
<condition property="jni.build.dir" value="${build.native.dir}">
<not><isset property="jni.build.dir"/></not>
</condition>
<condition property="jni.java.home" value="${java.home}">
<not><isset property="jni.java.home"/></not>
</condition>
<exec executable="${make.exe}" failonerror="true">
<arg value="JAVA_HOME=${jni.java.home}"/>
<arg value="SRC_DIR=${jni.src.dir}"/>
<arg value="JNI_DIR=${jni.src.dir}"/>
<arg value="BUILD_DIR=${jni.build.dir}"/>
<arg value="CPU=${platform.cpu}"/>
<arg value="VERSION=${jffi.version.major}.${jffi.version.minor}"/>
<arg value="USE_SYSTEM_LIBFFI=${use.system.libffi}"/>
<!-- <arg value="USE_SYSTEM_LIBFFI=0"/> -->
<arg value="-f"/>
<arg value="${jni.GNUmakefile}"/>
</exec>
</target>
<target name="-build-native-testlib" depends="-init-vars">
<mkdir dir="${build.native.dir}"/>
<exec executable="${make.exe}" failonerror="true">
<arg value="JAVA_HOME=${java.home}"/>
<arg value="BUILD_DIR=${build.dir}"/>
<arg value="CPU=${platform.cpu}"/>
<arg value="-f"/>
<arg value="libtest/GNUmakefile"/>
</exec>
</target>
<target name="-build-platform-jar" depends="-init-vars, -build-native-library">
<echo message="platform=${platform}"/>
<zip destfile="${dist.dir}/jffi-${platform}.jar" level="9">
<zipfileset prefix="jni/${platform}" dir="${build.native.dir}">
<include name="jffi*.dll"/>
<include name="libjffi*.so"/>
<include name="libjffi*.jnilib"/>
<include name="libjffi*.dylib"/>
<include name="libjffi*.a"/>
</zipfileset>
</zip>
</target>
<target name="-assemble-final-jar" depends="-init-vars, -assemble-native-jar">
<jar jarfile="${complete.jar}" index="true" update="true" duplicate="preserve"
filesetmanifest="skip">
<zipfileset src="${dist.jar}"/>
<zipfileset src="${native.jar}"/>
<manifest>
<attribute name="Main-Class" value="com.kenai.jffi.Main"/>
</manifest>
</jar>
</target>
<target name="-assemble-native-jar" depends="-init-vars, -build-platform-jar">
<jar jarfile="${native.jar}" index="true" update="true" duplicate="preserve"
filesetmanifest="skip">
<zipgroupfileset dir="archive" includes="jffi-*.jar"/>
<zipfileset src="${dist.dir}/jffi-${platform}.jar"/>
</jar>
</target>
<target name="archive-platform-jar" depends="-build-platform-jar">
<copy file="${dist.dir}/jffi-${platform}.jar" todir="archive" flatten="true"/>
</target>
</project>