build.xml 10.2 KB
Newer Older
1
<project name="javartm" basedir="." default="jar">
2 3 4 5 6 7 8 9 10

	<!-- Support for lower-casing a string.
		See http://stackoverflow.com/questions/7129672/uppercase-lowercase-capitalize-an-ant-property -->
	<scriptdef language="javascript" name="tolower">
		<attribute name="string"/><attribute name="toproperty"/>
		project.setProperty(attributes.get("toproperty"), attributes.get("string").toLowerCase());
	</scriptdef>
	<tolower string="${os.name}" toproperty="os.name.lower"/>

11 12 13
	<!-- Set timestamp -->
	<tstamp/>

14
	<!-- Project properties -->
Ivo Anjo's avatar
Ivo Anjo committed
15 16 17 18 19 20 21
	<property name="src.dir" value="src"/>
	<property name="java.src.dir" value="${src.dir}/java"/>
	<property name="c.src.dir" value="${src.dir}/c"/>

	<property name="build.dir" value="build"/>
	<property name="classes.dir" value="${build.dir}/classes"/>
	<property name="jni.dir" value="${build.dir}/jni"/>
22 23
	<property name="jnioutput.dir" value="${jni.dir}/javartm"/>
	<property name="jnilib.file" value="${jnioutput.dir}/javartm"/>
Ivo Anjo's avatar
Ivo Anjo committed
24 25 26

	<property name="jars.dir" value="lib"/>
	<property name="dist.dir" location="dist"/>
Ivo Anjo's avatar
Ivo Anjo committed
27
	<property name="dist.version" value="0.3-beta${DSTAMP}"/>
28 29

	<property name="jar.file" value="${dist.dir}/javartm-${dist.version}-${os.name.lower}-${os.arch}.jar"/>
30
	<property name="jarfat.file" value="${dist.dir}/javartm-fat-${dist.version}-${os.name.lower}-${os.arch}.jar"/>
31
	<property name="src-dist.file" value="${dist.dir}/javartm-${dist.version}-src.zip"/>
Ivo Anjo's avatar
Ivo Anjo committed
32

33 34 35 36 37 38 39 40 41 42 43 44 45 46
	<property name="antjars.dir" value="antlib"/>
	<property name="ant-contrib.file" value="${antjars.dir}/ant-contrib-1.0b5-SNAPSHOT.jar"/>
	<property name="ant-cpptasks.file" value="${antjars.dir}/ant-contrib-cpptasks-1.0~b5.jar"/>

	<!-- import ant-contrib -->
	<taskdef resource="net/sf/antcontrib/antlib.xml">
		<classpath><pathelement location="${ant-contrib.file}"/></classpath>
	</taskdef>

	<!-- import ant-cpptasks -->
	<taskdef resource="cpptasks.tasks">
		<classpath><pathelement location="${ant-cpptasks.file}"/></classpath>
	</taskdef>

47 48 49 50 51
	<!-- platform conditions, used for conditional includes -->
	<condition property="isLinux">
		<os name="Linux"/>
	</condition>

Ivo Anjo's avatar
Ivo Anjo committed
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
	<path id="jars-classpath">
		<fileset dir="${jars.dir}" >
			<include name="*.jar"/>
		</fileset>
	</path>

	<target name="clean">
		<delete dir="${build.dir}"/>
		<delete dir="${dist.dir}"/>
	</target>

	<target name="java-compile">
		<mkdir dir="${classes.dir}"/>
		<javac includeantruntime="false" srcdir="${java.src.dir}" destdir="${classes.dir}" debug="true" deprecation="true" debuglevel="lines,vars,source">
			<compilerarg value="-Xlint:unchecked"/>
			<classpath>
				<path refid="jars-classpath"/>
			</classpath>
		</javac>
	</target>

	<target name="jni-headers" depends="java-compile">
		<mkdir dir="${jni.dir}"/>
		<javah destdir="${jni.dir}">
			<classpath>
				<path path="${classes.dir}"/>
			</classpath>
			<class name="javartm.Transaction"/>
80
			<class name="javartm.CheckRtmSupport"/>
Ivo Anjo's avatar
Ivo Anjo committed
81 82 83
		</javah>
	</target>

84
	<target name="jni-compile-libcheckrtmsupport" depends="jni-headers">
85
		<mkdir dir="${jnioutput.dir}"/>
86
		<cc outtype="shared" subsystem="console" objdir="${jni.dir}" outfile="${jnioutput.dir}/checkrtmsupport">
87 88 89
			<compilerarg value="-Wall"/>
			<compilerarg value="-O2"/>
			<compilerarg value="-std=c99"/>
90
			<fileset dir="${c.src.dir}" includes="**/CheckRtmSupport.c"/>
91 92 93 94
			<includepath>
				<path path="${java.home}/../include"/>
				<path path="${jni.dir}"/>
			</includepath>
95 96 97
			<includepath if="isLinux">
				<path path="${java.home}/../include/linux"/>
			</includepath>
98 99 100 101 102 103 104 105 106 107 108 109 110 111
		</cc>
	</target>

	<target name="jni-compile-libjavartm-dummy" depends="jni-headers">
		<mkdir dir="${jnioutput.dir}"/>
		<cc outtype="shared" subsystem="console" objdir="${jni.dir}" outfile="${jnioutput.dir}/javartm-dummy">
			<compilerarg value="-Wall"/>
			<compilerarg value="-O2"/>
			<compilerarg value="-std=c99"/>
			<fileset dir="${c.src.dir}" includes="**/Transaction-dummy.c"/>
			<includepath>
				<path path="${java.home}/../include"/>
				<path path="${jni.dir}"/>
			</includepath>
112 113 114
			<includepath if="isLinux">
				<path path="${java.home}/../include/linux"/>
			</includepath>
115 116 117 118
		</cc>
	</target>

	<target name="jni-compile-libjavartm" depends="jni-headers">
119
		<mkdir dir="${jnioutput.dir}"/>
120 121 122 123 124 125 126 127 128 129 130 131
		<trycatch>
			<try>
				<!-- Try first to compile with gcc rtm intrinsics -->
				<cc outtype="shared" subsystem="console" objdir="${jni.dir}" outfile="${jnilib.file}">
					<compilerarg value="-Wall"/>
					<compilerarg value="-O2"/>
					<compilerarg value="-std=c99"/>
					<compilerarg value="-mrtm"/>
					<!-- we are going to be running on haswell at least, so why not take advantage of it -->
					<compilerarg value="-march=core-avx2"/>
					<fileset dir="${c.src.dir}"
						includes="**/*.c"
132
						excludes="**/CheckRtmSupport.c **/Transaction-dummy.c"/>
133 134 135 136
					<includepath>
						<path path="${java.home}/../include"/>
						<path path="${jni.dir}"/>
					</includepath>
137 138 139
					<includepath if="isLinux">
						<path path="${java.home}/../include/linux"/>
					</includepath>
140 141 142 143
				</cc>
			</try>
			<catch>
				<echo>Compile failed possibly due to -mrtm error, falling back to built-in rtm instrinsics</echo>
144
				<fail>FIXME: Built-in rtm instrinsics currently broken, sorry</fail>
145 146 147 148 149 150 151 152 153 154 155 156 157 158
				<trycatch>
					<try>
						<cc outtype="shared" subsystem="console" objdir="${jni.dir}" outfile="${jnilib.file}">
							<compilerarg value="-Wall"/>
							<compilerarg value="-std=gnu99"/>
							<compilerarg value="-O2"/>
							<!--
							-march=core-avx-i is a bit less recent than -march=core-avx2, for older compilers;
							see also http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html
							-->
							<compilerarg value="-march=core-avx-i"/>
							<defineset define="JAVARTM_RTM_INTRINSICS"/>
							<fileset dir="${c.src.dir}"
								includes="**/*.c"
159
								excludes="**/CheckRtmSupport.c **/Transaction-dummy.c"/>
160 161 162 163
							<includepath>
								<path path="${java.home}/../include"/>
								<path path="${jni.dir}"/>
							</includepath>
164 165 166
							<includepath if="isLinux">
								<path path="${java.home}/../include/linux"/>
							</includepath>
167 168 169 170 171 172 173 174 175 176 177
						</cc>
					</try>
					<catch>
						<echo>Compile failed possibly due to -march settings error, final try without explicit -march</echo>
						<cc outtype="shared" subsystem="console" objdir="${jni.dir}" outfile="${jnilib.file}">
							<compilerarg value="-Wall"/>
							<compilerarg value="-std=gnu99"/>
							<compilerarg value="-O2"/>
							<defineset define="JAVARTM_RTM_INTRINSICS"/>
							<fileset dir="${c.src.dir}"
								includes="**/*.c"
178
								excludes="**/CheckRtmSupport.c **/Transaction-dummy.c"/>
179 180 181 182
							<includepath>
								<path path="${java.home}/../include"/>
								<path path="${jni.dir}"/>
							</includepath>
183 184 185
							<includepath if="isLinux">
								<path path="${java.home}/../include/linux"/>
							</includepath>
186 187 188 189 190
						</cc>
					</catch>
				</trycatch>
			</catch>
		</trycatch>
191 192
	</target>

193
	<target name="jni-compile" depends="jni-compile-libcheckrtmsupport,jni-compile-libjavartm-dummy,jni-compile-libjavartm"/>
194

195
	<target name="build" depends="clean,java-compile,jni-compile" description="Builds javartm (java and native resources)"/>
Ivo Anjo's avatar
Ivo Anjo committed
196

197
	<target name="jar" depends="build" description="Generates the javartm jar">
Ivo Anjo's avatar
Ivo Anjo committed
198
		<mkdir dir="${dist.dir}"/>
199 200 201 202 203 204 205 206 207 208
		<jar destfile="${jar.file}">
			<manifest>
				<!-- Who is building this jar? -->
				<attribute name="Built-By" value="${user.name}"/>
				<!-- Information about the program itself -->
				<attribute name="Implementation-Vendor" value="javartm project"/>
				<attribute name="Implementation-Title" value="javartm"/>
				<attribute name="Implementation-Version" value="${dist.version}"/>
			</manifest>

209
			<fileset dir="${classes.dir}" excludes="**/*Test*.class"/>
210 211 212
			<fileset dir="${jni.dir}" includes="**/*.so"/>
		</jar>
	</target>
Ivo Anjo's avatar
Ivo Anjo committed
213

214
	<target name="fat-jar" depends="jar" description="Generates a fat javartm jar including all dependencies">
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
		<jar destfile="${jarfat.file}">
			<manifest>
				<!-- Who is building this jar? -->
				<attribute name="Built-By" value="${user.name}"/>
				<!-- Information about the program itself -->
				<attribute name="Implementation-Vendor" value="javartm project"/>
				<attribute name="Implementation-Title" value="javartm"/>
				<attribute name="Implementation-Version" value="${dist.version}"/>
			</manifest>

			<archives>
				<zips>
					<fileset dir="${jars.dir}" includes="**/*.jar"/>
					<fileset dir="${dist.dir}" includes="${jar.filename}"/>
				</zips>
			</archives>
		</jar>
	</target>

234
       <!-- Targets for running tests -->
235
	<target name="test-rtm" description="Runs RTM tests (requires hardware *WITH* RTM support)">
236 237 238 239 240 241 242 243 244 245 246 247 248 249
		<junit printsummary="yes" haltonfailure="yes">
			<formatter type="plain" usefile="false"/>
			<classpath>
				<path refid="jars-classpath"/>
				<path path="${classes.dir}"/>
			</classpath>
			<batchtest fork="yes">
				<fileset dir="${java.src.dir}">
					<include name="**/rtm/*Test*.java"/>
				</fileset>
			</batchtest>
		</junit>
	</target>

250
	<target name="test-nortm" description="Runs no-RTM tests (requires hardware *WITHOUT* RTM support)">
251 252 253 254 255 256 257 258 259 260 261 262 263 264
		<junit printsummary="yes" haltonfailure="yes">
			<formatter type="plain" usefile="false"/>
			<classpath>
				<path refid="jars-classpath"/>
				<path path="${classes.dir}"/>
			</classpath>
			<batchtest fork="yes">
				<fileset dir="${java.src.dir}">
					<include name="**/nortm/*Test*.java"/>
				</fileset>
			</batchtest>
		</junit>
	</target>

265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
	<!-- Other targets -->
	<target name="src-dist" depends="clean" description="Builds a source distribution">
		<mkdir dir="${dist.dir}"/>
		<zip destfile="${src-dist.file}">
			<fileset dir="./">
				<exclude name="build/**"/>
				<exclude name="dist/**"/>
				<exclude name="sde-*.txt"/>
				<exclude name="hs_err_pid*.txt"/>
				<exclude name="pin-log.txt"/>
				<exclude name=".git/**"/>
			</fileset>
		</zip>
	</target>

280 281 282 283 284 285 286
	<target name="mvn-local-install" depends="jar" description="Deploys the javartm jar to local maven repository">
		<!-- TODO: Better alternative would be using https://maven.apache.org/ant-tasks/index.html -->
		<exec executable="mvn">
			<arg line="install:install-file -Dfile=${jar.file} -Dversion=${dist.version} -DgroupId=javartm -DartifactId=javartm -Dpackaging=jar"/>
		</exec>
	</target>

Ivo Anjo's avatar
Ivo Anjo committed
287
	<!-- aliases -->
288 289
	<target name="main" depends="build"/>
	<target name="compile" depends="build"/>
Ivo Anjo's avatar
Ivo Anjo committed
290
	<target name="clean-all" depends="clean"/>
291
	<target name="dist" depends="jar"/>
Ivo Anjo's avatar
Ivo Anjo committed
292
</project>