-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.xml
293 lines (267 loc) · 10.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
<?xml version="1.0" encoding="UTF-8"?>
<project name="jav8" default="dist" basedir=".">
<property environment="env"/>
<property name="project.name" value="jav8"/>
<property name="project.version" value="0.4"/>
<property name="project.mode" value="release" />
<property name="src.dir" value="${basedir}/src" />
<property name="docs.dir" value="${basedir}/docs" />
<property name="test.dir" value="${basedir}/test" />
<property name="out.dir" value="${basedir}/build" />
<property name="classes.dir" value="${out.dir}/classes" />
<property name="test.classes.dir" value="${out.dir}/test-classes" />
<property name="test.report.dir" value="${out.dir}/test-report" />
<property name="obj.dir" value="${out.dir}/objs" />
<property name="bin.dir" value="${out.dir}/bin/${project.mode}" />
<property name="jni.dir" value="${basedir}/jni" />
<property name="dist.dir" value="${basedir}/dist" />
<property name="lib.dir" value="${basedir}/lib" />
<property name="junit4.path" value="${lib.dir}/junit-4.9b3.jar" />
<property file="build.properties" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${lib.dir}/ant-contrib-1.0b3.jar" />
</classpath>
</taskdef>
<taskdef resource="cpptasks.tasks">
<classpath>
<pathelement location="${lib.dir}/cpptasks-1.0b5.jar" />
</classpath>
</taskdef>
<condition property="is_win">
<os family="windows" />
</condition>
<condition property="is_unix">
<os family="unix" />
</condition>
<condition property="is_osx">
<or>
<os name="Mac OS X" />
<os name="darwin" />
</or>
</condition>
<condition property="is_x64">
<equals arg1="${os.arch}" arg2="amd64"/>
</condition>
<condition property="is_debug">
<equals arg1="${project.mode}" arg2="debug"/>
</condition>
<if>
<istrue value="${is_win}"/>
<then>
<property name="os.family" value="win"/>
</then>
<else>
<property name="os.family" value="linux"/>
</else>
</if>
<condition property="cc.compiler" value="msvc" else="gcc">
<istrue value="${is_win}"/>
</condition>
<condition property="link.incremental">
<istrue value="${is_win}"/>
</condition>
<condition property="link.static_runtime" value="static" else="dynamic">
<isfalse value="${is_x64}"/>
</condition>
<condition property="lib.v8" value="v8_g" else="v8">
<istrue value="${is_debug}"/>
</condition>
<condition property="cc.compiler" value="msvc" else="gcc">
<istrue value="${is_win}"/>
</condition>
<condition property="link.incremental">
<istrue value="${is_win}"/>
</condition>
<condition property="link.static_runtime">
<isfalse value="${is_x64}"/>
</condition>
<if>
<equals arg1="${is_osx}" arg2="true" />
<then>
<property name="jar.file" value="${dist.dir}/${project.name}-jsr223-${os.name}-${os.arch}-${project.version}.jar" />
</then>
<else>
<property name="jar.file" value="${dist.dir}/${project.name}-jsr223-${os.family}-${os.arch}-${project.version}.jar" />
</else>
</if>
<path id="build.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="clean">
<delete dir="${out.dir}" />
<delete dir="${docs.dir}" />
</target>
<target name="prepare">
<mkdir dir="${classes.dir}"/>
<mkdir dir="${bin.dir}" />
</target>
<target name="compile" depends="prepare">
<javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
<classpath refid="build.classpath"/>
<include name="**/*.java"/>
</javac>
<copy todir="${classes.dir}/META-INF">
<fileset dir="${src.dir}/META-INF" />
</copy>
</target>
<target name="docs" depends="compile">
<mkdir dir="${docs.dir}"/>
<javadoc packagenames="lu.flier" sourcepath="${src.dir}" destdir="${docs.dir}">
<fileset dir="${src.dir}">
<include name="**" />
<exclude name="META-INF/**" />
</fileset>
</javadoc>
</target>
<target name="jni" depends="compile">
<echo>Generating JNI header ...</echo>
<mkdir dir="${jni.dir}"/>
<javah classpath="${classes.dir}" outputfile="${jni.dir}/jav8.h">
<class name="lu.flier.script.ManagedV8Object"/>
<class name="lu.flier.script.V8ScriptEngineFactory"/>
<class name="lu.flier.script.V8ScriptEngine"/>
<class name="lu.flier.script.V8CompiledScript"/>
<class name="lu.flier.script.V8Context"/>
<class name="lu.flier.script.V8Object"/>
<class name="lu.flier.script.V8Array"/>
<class name="lu.flier.script.V8Function"/>
</javah>
<echo>Building JNI library with ${project.mode} mode ...</echo>
<cc name="${cc.compiler}"
objdir="${bin.dir}" outfile="${project.name}"
runtime="${link.static_runtime}" link="static" outtype="shared"
multithreaded="true" optimize="speed" incremental="${link.incremental}"
debug="${is_debug}" exceptions="true" rtti="true">
<fileset dir="${jni.dir}" includes="*.cpp"/>
<compilerarg value="-DWIN32" if="is_win"/>
<compilerarg value="/GL" if="is_win"/>
<compilerarg value="/EHsc" if="is_win"/>
<compilerarg value="-fPIC" if="is_x64"/>
<linkerarg value="/INCREMENTAL" if="is_win"/>
<linkerarg value="-fPIC" if="is_x64"/>
<includepath>
<path>
<pathelement path="${env.JAVA_HOME}/include"/>
<pathelement path="${env.JAVA_HOME}/include/win32"/>
<pathelement path="${env.JAVA_HOME}/include/linux"/>
<pathelement path="${env.JAVA_HOME}/include/darwin"/>
<pathelement path="/System/Library/Frameworks/JavaVM.framework/Headers/"/>
<pathelement path="${env.V8_HOME}"/>
<pathelement path="${env.V8_HOME}/include"/>
</path>
</includepath>
<libset libs="winmm,ws2_32" if="is_win"/>
<libset libs="stdc++" if="is_unix"/>
<libset dir="${env.V8_HOME}" libs="${lib.v8}"/>
</cc>
<!--
Core Java APIs and the Java Runtime on Mac OS X
http://developer.apple.com/library/mac/#documentation/java/conceptual/java14development/05-corejavaapis/corejavaapis.html
-->
<if>
<equals arg1="${is_osx}" arg2="true" />
<then>
<echo>rename lib${project.name}.so to lib${project.name}.dylib for Mac OSX</echo>
<move file="lib${project.name}.so" tofile="lib${project.name}.dylib" overwrite="yes" failonerror="no"/>
</then>
</if>
<copy todir="${classes.dir}">
<fileset dir="${out.dir}" file="*.dll"/>
<fileset dir="${out.dir}" file="*.pdb"/>
<fileset dir="${out.dir}" file="*.so"/>
<fileset dir="${out.dir}" file="*.dylib"/>
</copy>
</target>
<target name="jar" depends="jni">
<mkdir dir="${dist.dir}"/>
<jar destfile="${jar.file}" basedir="${classes.dir}">
<include name="**/*.class"/>
<include name="**/*.dll"/>
<include name="**/*.so"/>
<include name="**/*.dylib"/>
<include name="META-INF/**"/>
</jar>
</target>
<target name="test" depends="jar">
<mkdir dir="${test.classes.dir}"/>
<mkdir dir="${test.report.dir}"/>
<javac srcdir="${test.dir}" destdir="${test.classes.dir}"
includeantruntime="false" classpath="${junit4.path};${jar.file}">
<include name="**/*.java"/>
</javac>
<junit printsummary="yes" haltonfailure="yes" fork="yes">
<jvmarg value="-Djava.library.path=${basedir}" />
<formatter type="plain" usefile="false" />
<formatter type="xml"/>
<test name="lu.flier.script.V8ScriptEngineTest" todir="${test.report.dir}" />
<classpath>
<pathelement location="${jar.file}" />
<pathelement location="${test.classes.dir}" />
<pathelement location="${junit4.path}" />
<pathelement path="${java.class.path}" />
</classpath>
</junit>
</target>
<target name="dist" depends="test, docs">
<tar destfile="${dist.dir}/jav8-${project.version}-apidocs.tar.gz" basedir="${docs.dir}" compression="gzip"/>
<tar destfile="${dist.dir}/jav8-${project.version}-src.tar.gz" compression="gzip">
<tarfileset dir="${basedir}">
<include name="build.xml"/>
<include name="build.properties"/>
<include name=".classpath"/>
<include name=".project"/>
<include name="jav8.sln"/>
<include name="src/**/*.java"/>
<include name="src/META-INF/**/*"/>
<include name="jni/*.h"/>
<include name="jni/*.cpp"/>
<include name="jni/jav8.vcxproj*"/>
<include name="test/**/*.java"/>
<include name="lib/*.jar"/>
</tarfileset>
</tar>
</target>
<target name="pause">
<echo>Press Enter to continue ...</echo>
<input/>
</target>
<target name="gdb" if="is_unix">
<property name="gdb.classpath" value="${jar.file}:${test.classes.dir}:${junit4.path}:${java.class.path}" />
<property name="gdb.test.runner" value="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" />
<property name="gdb.test.cases" value="lu.flier.script.V8ScriptEngineTest" />
<property name="gdb.args" value="-Djava.library.path=${basedir} -classpath ${gdb.classpath} ${gdb.test.runner} ${gdb.test.cases}" />
<echo file="gdb.cmds" append="false">set args ${gdb.args}</echo>
<echo>gdb java -x gdb.cmds</echo>
</target>
<target name="jdb">
<!--
jdb - The Java Debugger
http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/jdb.html
$>ant jdb
...
[junit] Listening for transport dt_socket at address: <port>
...
$>jdb -connect com.sun.jdi.SocketAttach:port=<port>
-->
<junit printsummary="yes" haltonfailure="yes" fork="yes">
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xnoagent"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y"/>
<jvmarg value="-verbose:jni"/>
<jvmarg value="-Djava.compiler=none"/>
<jvmarg value="-Djava.library.path=${basedir}" />
<formatter type="plain" usefile="flase" />
<formatter type="xml"/>
<test name="lu.flier.script.V8ScriptEngineTest" todir="${test.report.dir}" />
<classpath>
<pathelement location="${jar.file}" />
<pathelement location="${test.classes.dir}" />
<pathelement location="${junit4.path}" />
<pathelement path="${java.class.path}" />
</classpath>
</junit>
</target>
</project>