All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ativehook.2.1.0.source-code.build.xml Maven / Gradle / Ivy

The newest version!
<?xml version="1.0" encoding="UTF-8"?>

<!--
JNativeHook: Global keyboard and mouse hooking for Java.
Copyright (C) 2006-2017 Alexander Barker.  All Rights Received.
http://code.google.com/p/jnativehook/

JNativeHook is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

JNativeHook is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->

<project name="jnativehook" default="all" basedir=".">
	<!-- Project Settings -->
	<property file="build.num" />
	<tstamp>
		<format property="ant.build.revision" pattern="yyyyMMdd" />
	</tstamp>

	<property name="ant.project.vendor" value="Alexander Barker ([email protected])" />
	<property name="ant.project.version" value="${ant.build.major}.${ant.build.minor}.${ant.build.revision}" />

	<property environment="env" />

	<!-- Path Settings -->
	<property name="dir.src"		value="${basedir}/src" />
	<property name="dir.doc"		value="${basedir}/doc" />
	<property name="dir.dist"		value="${basedir}/dist" />
	<property name="dir.lib"		value="${basedir}/lib" />
	<property name="dir.jar"		value="${basedir}/jar" />
	<property name="dir.bin"		value="${basedir}/bin" />

	<!-- Class Path Settings -->
	<!-- NOTE Gentoo requires `CLASSPATH="$(java-config -p hamcrest-core-1.3,ant-junit,junit-4)" ant test` -->
	<path id="ant.project.class.path">
		<pathelement location="${dir.bin}/class/java" />
		<pathelement location="${dir.bin}/class/test" />

		<fileset dir="${basedir}">
			<include name="*.jar" />
		</fileset>

		<pathelement location="${dir.lib}" />
		<pathelement path="${java.class.path}" />
	</path>


	<target name="clean" description="Removes generated bytecode and object files.">
		<echo>Cleaning build structure...</echo>

		<delete includeEmptyDirs="true" verbose="true" failonerror="false">
			<fileset dir="${dir.bin}" includes="**/*" />
		</delete>
	</target>


	<target name="mostlyclean" depends="clean" description="Removes all items except previously built libs.">
		<echo>Cleaning all build related items...</echo>

		<delete includeEmptyDirs="true" verbose="true" failonerror="false">
			<fileset file="${basedir}/build.properties" />

			<fileset dir="${dir.dist}" />
			<fileset dir="${dir.doc}" />
			<fileset dir="${dir.jar}" />

			<fileset dir="${dir.src}/libuiohook" casesensitive="yes">
				<include name="autom4te.cache" />
				<include name="config" />

				<include name="include/*" />
				<exclude name="include/uiohook.h"/>

				<include name="m4/*" />
				<exclude name="m4/ax_pthread.m4"/>

				<include name="pc/*" />
				<exclude name="pc/uiohook.pc.in" />

				<include name="Makefile" />
				<include name="Makefile.in" />
				<include name="aclocal.m4" />
				<include name="config.log" />
				<include name="config.status" />
				<include name="configure" />
			</fileset>

			<fileset file="${dir.src}/jni/include/org_jnativehook_GlobalScreen.h" />
			<fileset file="${dir.src}/jni/include/org_jnativehook_GlobalScreen_EventDispatchTask.h" />
			<fileset file="${dir.src}/jni/include/org_jnativehook_GlobalScreen_NativeHookThread.h" />
		</delete>
	</target>


	<target name="distclean" depends="mostlyclean" description="Removes all items generated by the build system.">
		<echo>Cleaning all build related items...</echo>

		<delete includeEmptyDirs="true" verbose="true" failonerror="false">
			<fileset dir="${dir.lib}" />
		</delete>
	</target>


	<target name="init" description="Initialize local build environment.">
		<echo>Initializing local build environment...</echo>
		<mkdir dir="${dir.bin}" />

		<fail message="Could not determine ${ant.project.name} version.  Please check the build.num file.">
			<condition>
				<not>
					<and>
						<isset property="ant.build.major" />
						<isset property="ant.build.minor" />
						<isset property="ant.build.revision" />
					</and>
				</not>
			</condition>
		</fail>

		<property file="build.properties" />

		<!-- Try to locate the include folder for java headers -->
		<condition property="ant.build.javac.include" value="${env.JDK_HOME}/include">
			<available file="${env.JDK_HOME}/include" type="dir" />
		</condition>
		<condition property="ant.build.javac.include" value="${env.JAVA_HOME}/include">
			<available file="${env.JAVA_HOME}/include" type="dir" />
		</condition>
		<condition property="ant.build.javac.include" value="${java.home}/include">
			<available file="${java.home}/include" type="dir" />
		</condition>
		<condition property="ant.build.javac.include" value="${java.home}/../include">
			<available file="${java.home}/../include" type="dir" />
		</condition>
		<condition property="ant.build.javac.include" value="${java.home}/../Headers">
			<available file="${java.home}/../Headers" type="dir" />
		</condition>
		<condition property="ant.build.javac.include" value="/System/Library/Frameworks/JavaVM.framework/Headers">
			<available file="/System/Library/Frameworks/JavaVM.framework/Headers" type="dir" />
		</condition>
		<condition property="ant.build.javac.include" value="${java.home}/Headers">
			<available file="${java.home}${file.separator}Headers" type="dir" />
		</condition>

		<fail message="Could not determine ant.build.javac.include.  Please set your JDK_HOME / JAVA_HOME environment variable or manually set the ant.build.javac.include property to the location of your java header files.">
			<condition>
				<not>
					<or>
						<isset property="ant.build.javac.include" />
						<available file="${ant.build.javac.include}" type="dir" />
					</or>
				</not>
			</condition>
		</fail>


		<!-- Define the JNI Tasks provided by classpathref. -->
		<typedef resource="org/jnitasks/antlib.xml" classpathref="ant.project.class.path" onerror="failall" />


		<!-- Preform target checks. -->
		<fileset dir="${dir.src}/libuiohook" id="src-libuiohook" />
		<pathconvert refid="src-libuiohook" property="project.check.libuiohook.download" setonempty="false" />
		<available file="${dir.src}/libuiohook/configure" property="project.check.libuiohook.bootstrap" />
		<available file="${dir.bin}/libuiohook/Makefile" property="project.check.libuiohook.configure" />
		<available file="${dir.doc}/" property="project.check.javadoc" />


		<!-- Set the operating system name used for organizing native libraries -->
		<condition property="ant.build.native.os" value="freebsd">
			<os family="unix" name="FreeBSD" />
		</condition>
		<condition property="ant.build.native.os" value="openbsd">
			<os family="unix" name="OpenBSD" />
		</condition>
		<condition property="ant.build.native.os" value="darwin">
			<and>
				<os family="mac" />
				<os family="unix" />
			</and>
		</condition>
		<condition property="ant.build.native.os" value="solaris">
			<or>
				<os family="unix" name="Solaris" />
				<os family="unix" name="SunOS" />
			</or>
		</condition>
		<condition property="ant.build.native.os" value="linux">
			<os family="unix" name="Linux" />
		</condition>
		<condition property="ant.build.native.os" value="windows">
			<os family="winnt" />
		</condition>


		<!-- Set the system arch name used for organizing native libraries -->
		<condition property="ant.build.native.arch" value="arm">
			<os arch="arm" />
		</condition>
		<condition property="ant.build.native.arch" value="ppc">
			<or>
				<os arch="ppc" />
				<os arch="PowerPC" />
			</or>
		</condition>
		<condition property="ant.build.native.arch" value="ppc64">
			<or>
				<os arch="ppc64" />
				<os arch="PowerPC64" />
			</or>
		</condition>
		<!-- TODO Testing Needed
		<condition property="native.arch" value="sparc">
			<os arch="sparc" />
		</condition>
		-->
		<condition property="ant.build.native.arch" value="x86">
			<or>
				<os arch="x86" />
				<os arch="i386" />
				<os arch="i486" />
				<os arch="i586" />
				<os arch="i686" />
			</or>
		</condition>
		<condition property="ant.build.native.arch" value="x86_64">
			<or>
				<os arch="x86-64" />
				<os arch="x86_64" />
				<os arch="amd64" />
				<os arch="k8" />
			</or>
		</condition>
		<property name="ant.build.native.arch" value="${os.arch}" />


		<!-- Figure out the platform we are building for. -->
		<condition property="native.os.isDarwin" value="true">
			<equals arg1="${ant.build.native.os}" arg2="darwin" />
		</condition>
		<condition property="native.os.isX11" value="true">
			<or>
				<equals arg1="${ant.build.native.os}" arg2="freebsd" />
				<equals arg1="${ant.build.native.os}" arg2="openbsd" />
				<equals arg1="${ant.build.native.os}" arg2="solaris" />
				<equals arg1="${ant.build.native.os}" arg2="linux" />
			</or>
		</condition>
		<condition property="native.os.isWindows" value="true">
			<equals arg1="${ant.build.native.os}" arg2="windows" />
		</condition>


		<!-- Set system specific toolchain. -->
		<condition property="ant.build.native.toolchain" value="clang">
			<isset property="native.os.isDarwin" />
		</condition>
		<property name="ant.build.native.toolchain" value="gcc" />

		<!-- Set parallel jobs. -->
		<property name="ant.build.native.jobs" value="auto" />

		<!-- Set default compiler and linker flags. -->
		<condition property="ant.build.native.cflags" value="-O1 -g -pipe" else="-O2 -pipe">
			<istrue value="${ant.build.debug}" />
		</condition>
		<property name="ant.build.native.ldflags" value="" />

		<!-- Set default javac options. -->
		<property name="ant.build.debug" value="false" />
		<property name="ant.build.javac.compiler" value="modern" />
		<property name="ant.build.javac.source" value="${ant.java.version}" />
		<property name="ant.build.javac.target" value="${ant.java.version}" />
		<property name="ant.build.javac.args" value="" />

		<!-- Set system specific library name. -->
		<condition property="ant.build.native.executable" value="libJNativeHook.dylib">
			<isset property="native.os.isDarwin" />
		</condition>
		<condition property="ant.build.native.executable" value="JNativeHook.dll">
			<isset property="native.os.isWindows" />
		</condition>
		<property name="ant.build.native.executable" value="libJNativeHook.so" />


		<!-- Print the relevant Ant properties for logging. -->
		<echo level="info">Project:            ${ant.project.name} ${ant.project.version}</echo>
		<echo level="info">Debug:              ${ant.build.debug}</echo>

		<echo level="info">Java Compiler:      ${ant.build.javac.compiler}</echo>
		<echo level="info">Java Source:        ${ant.build.javac.source}</echo>
		<echo level="info">Java Target:        ${ant.build.javac.target}</echo>
		<echo level="info">Java Include:       ${ant.build.javac.include}</echo>
		<echo level="info">Java Args:          ${ant.build.javac.args}</echo>

		<echo level="info">Native Lib:         ${ant.build.native.executable}</echo>
		<echo level="info">Native OS:          ${ant.build.native.os}</echo>
		<echo level="info">Native Arch:        ${ant.build.native.arch}</echo>
		<echo level="info">Native Toolchain:   ${ant.build.native.toolchain}</echo>
		<echo level="info">Native CFLAGS:      ${ant.build.native.cflags}</echo>
		<echo level="info">Native LDFLAGS:     ${ant.build.native.ldflags}</echo>

		<!-- Create property file for the descovered values -->
		<propertyfile file="build.properties" comment="auto-generated by ant configure">
			<entry key="ant.build.debug"			value="${ant.build.debug}" />

			<entry key="ant.build.javac.compiler"		value="${ant.build.javac.compiler}" />
			<entry key="ant.build.javac.source"			value="${ant.build.javac.source}" />
			<entry key="ant.build.javac.target"			value="${ant.build.javac.target}" />
			<entry key="ant.build.javac.include"		value="${ant.build.javac.include}" />
			<entry key="ant.build.javac.args"			value="${ant.build.javac.args}" />

			<entry key="ant.build.native.toolchain"		value="${ant.build.native.toolchain}" />
			<entry key="ant.build.native.jobs"			value="${ant.build.native.jobs}" />
			<entry key="ant.build.native.cflags"		value="${ant.build.native.cflags}" />
			<entry key="ant.build.native.ldflags"		value="${ant.build.native.ldflags}" />
		</propertyfile>
	</target>


	<target name="download-libuiohook" depends="init" unless="project.check.libuiohook.download" description="Download the native library source code.">
		<echo>Downloading libUIOHook source...</echo>
		<mkdir dir="${dir.src}/libuiohook" />

		<get src="https://github.com/kwhat/libuiohook/archive/master.zip" dest="${dir.bin}/libuiohook-master.zip" verbose="true" />

		<unzip src="${dir.bin}/libuiohook-master.zip" dest="${dir.src}/libuiohook">
			<mapper type="glob" from="libuiohook-master/*" to="*" />
		</unzip>
	</target>


	<target name="bootstrap-libuiohook" depends="download-libuiohook" unless="project.check.libuiohook.bootstrap" description="Initialize the native library build system.">
		<echo>Bootstrapping libUIOHook...</echo>

		<autoreconf dir="${dir.src}/libuiohook" force="true" install="true">
			<include path="/opt/local/share/aclocal" if="native.os.isDarwin" />
		</autoreconf>
	</target>


	<target name="configure-libuiohook" depends="bootstrap-libuiohook" unless="project.check.libuiohook.configure" description="Configure platform dependent features for native library.">
		<echo>Configuring libUIOHook source...</echo>
		<mkdir dir="${dir.bin}/libuiohook" />

		<configure toolchain="${ant.build.native.toolchain}" dir="${dir.bin}/libuiohook" script="${dir.src}/libuiohook/configure" prefix="${dir.bin}" lib="${dir.bin}/lib">
			<env key="CFLAGS" value="${ant.build.native.cflags}" />
			<env key="LDFLAGS" value="${ant.build.native.ldflags}" />

			<enable if="ant.build.debug">debug</enable>
			<enable>quiet</enable>
			<enable>static</enable>
			<disable>shared</disable>

			<with>pic</with>
		</configure>
	</target>


	<target name="compile-libuiohook" depends="configure-libuiohook" description="Compile the native library.">
		<echo>Compiling libUIOHook source...</echo>
		<make dir="${dir.bin}/libuiohook" jobs="${ant.build.native.jobs}" target="install" />
	</target>


	<target name="compile-java" depends="init" description="Compiles Java source files.">
		<echo>Compiling Java source...</echo>
		<mkdir dir="${dir.bin}/class/java" />

		<javac
			destdir="${dir.bin}/class/java"
			debug="${ant.build.debug}"
			debuglevel="lines,vars,source"
			optimize="true"
			deprecation="false"
			includeantruntime="false"
			listfiles="true"
			verbose="false"
		>
			<compilerarg line="${ant.build.javac.args}"/>

			<src path="${dir.src}/java" />

			<classpath refid="ant.project.class.path" />
		</javac>
	</target>


	<target name="compile-jni" depends="compile-libuiohook,compile-java" description="Compiles JNI source files.">
		<echo>Creating JNI Headers...</echo>
		<javah destdir="${dir.src}/jni/include" verbose="true">
			<class name="org.jnativehook.GlobalScreen" />
			<classpath refid="ant.project.class.path" />
		</javah>


		<!-- Call pkg-config to determine what libraries to link against. -->
		<pkgconfig libs="true" libraries="uiohook" outputproperty="ant.build.native.ld.libs">
			<dirset dir="${dir.bin}">
				<include name="lib/pkgconfig"/>
				<include name="bin/pkgconfig"/>
			</dirset>
		</pkgconfig>


		<echo>Compiling C source...</echo>
		<!-- Create required directories for compiling. -->
		<mkdir dir="${dir.bin}/obj/jni" />

		<!-- Execute the native compiler on the source files. -->
		<cc toolchain="${ant.build.native.toolchain}" jobs="${ant.build.native.jobs}" objdir="${dir.bin}/obj/jni">
			<arg value="-Wall -Wextra -Wno-unused-parameter" />
			<arg value="-std=c99" />
			<arg value="-fPIC" unless="native.os.isWindows" />
			<arg value="${ant.build.native.cflags}" />

			<define name="USE_DEBUG" if="ant.build.debug"/>

			<include path="${dir.bin}/include" />
			<include path="${dir.src}/jni/include" />

			<include path="${ant.build.javac.include}" />
			<include path="${ant.build.javac.include}/win32" if="native.os.isWindows" />
			<include path="${ant.build.javac.include}/${ant.build.native.os}" unless="native.os.isWindows" />

			<fileset dir="${dir.src}/jni">
				<include name="**/*.c" />
			</fileset>
		</cc>


		<echo>Linking C objects...</echo>
		<!-- Create required directory for linking. -->
		<mkdir dir="${dir.lib}/${ant.build.native.os}/${ant.build.native.arch}" />

		<!-- Execute the native linker on the object files. -->
		<ld toolchain="${ant.build.native.toolchain}" outfile="${dir.lib}/${ant.build.native.os}/${ant.build.native.arch}/${ant.build.native.executable}">
			<!-- weak linker options for darwin: -Wl,-flat_namespace,-undefined,dynamic_lookup -->
			<arg value="-dynamiclib" if="native.os.isDarwin" />
			<arg value="-shared" unless="native.os.isDarwin" />

			<arg value="-static-libgcc" if="native.os.isWindows" />
			<arg value="${ant.build.native.ldflags}" />

			<fileset dir="${dir.bin}">
				<include name="obj/jni/**/*.o" />
			</fileset>

			<!-- Linking order matters and libraries should come after obj files. -->
			<arg value="${ant.build.native.ld.libs}" />
		</ld>
	</target>


	<target name="compile" depends="compile-java,compile-jni" description="Compiles both Java and C source files.">
	</target>


	<target name="test" depends="compile" description="Compile and perform JUnit tests.">
		<echo>Compiling JUnit source...</echo>
		<mkdir dir="${dir.bin}/class/test" />

		<javac
			destdir="${dir.bin}/class/test"
			debug="${ant.build.debug}"
			debuglevel="lines,vars,source"
			optimize="true"
			deprecation="false"
			includeantruntime="false"
			listfiles="true"
			verbose="false"
		>
			<compilerarg line="${ant.build.javac.args}"/>
			<compilerarg value="-Xlint:unchecked" />

			<src path="${dir.src}/test" />

			<classpath refid="ant.project.class.path" />
		</javac>

		<echo>Performing JUnit tests...</echo>
		<junit fork="true" printsummary="true" haltonerror="true">
			<jvmarg value="-Djava.library.path=${dir.lib}/${ant.build.native.os}/${ant.build.native.arch}" />

			<classpath refid="ant.project.class.path" />

			<formatter type="brief" usefile="false" />
			<!-- test name="org.jnativehook.GlobalScreenTest" /-->

			<!-- todir="${reports.tests}" -->
			<batchtest>
				<fileset dir="${dir.src}/test">
					<include name="**/*Test.java"/>
				</fileset>
			</batchtest>
		</junit>
	</target>


	<target name="jar" depends="javadoc" description="Creates the jar library.">
		<echo>Copying libs...</echo>
		<mkdir dir="${dir.bin}/class/java/org/jnativehook/lib" />
		<copy overwrite="true" todir="${dir.bin}/class/java/org/jnativehook/lib">
			<fileset dir="${dir.lib}" includes="**/*" />
		</copy>

		<echo>Creating jar files...</echo>
		<mkdir dir="${dir.jar}" />
		<jar jarfile="${dir.jar}/${ant.project.name}-${ant.project.version}.jar" basedir="${dir.bin}/class/java" update="true" compress="true" level="9">
			<include name="org/jnativehook/**" />

			<manifest>
				<attribute name="Main-Class" value="org.jnativehook.example.NativeHookDemo" />
				<section name="org/jnativehook">
					<attribute name="Specification-Title" value="${ant.project.name} Library" />
					<attribute name="Specification-Version" value="${ant.build.major}.${ant.build.minor}" />
					<attribute name="Specification-Vendor" value="${ant.project.vendor}" />

					<attribute name="Implementation-Title" value="org.jnativehook" />
					<attribute name="Implementation-Version" value="${ant.build.revision}" />
					<attribute name="Implementation-Vendor" value="${ant.project.vendor}" />
				</section>
			</manifest>
		</jar>
	</target>


	<target name="run" depends="compile" description="Execute the bundled example.">
		<java classname="org.jnativehook.example.NativeHookDemo" fork="true" failonerror="true">
			<jvmarg value="-Djava.library.path=${dir.lib}/${ant.build.native.os}/${ant.build.native.arch}" />
			<classpath>
				<pathelement location="${dir.jar}/${ant.project.name}-${ant.project.version}.jar" />
				<pathelement path="${dir.bin}/class/java" />
				<pathelement path="${java.class.path}" />
			</classpath>
		</java>
	</target>


	<target name="javadoc" unless="project.check.javadoc" description="Generates javadoc api documentation.">
		<echo level="info">Generating API Documentation...</echo>
		<mkdir dir="${dir.doc}" />

		<javadoc destdir="${dir.doc}" windowtitle="${ant.project.name}" author="true" version="true" use="true">
			<packageset dir="${dir.src}/java" defaultexcludes="yes">
				<include name="org/jnativehook/**" />
				<exclude name="org/jnativehook/example/**" />
			</packageset>

			<doctitle><![CDATA[<h1>JNativeHook-${ant.build.major}.${ant.build.minor} API Documentation</h1>]]></doctitle>
			<bottom><![CDATA[<i>Copyright &#169; 2006-2017 ${project.vendor}. All Rights Received.</i>]]></bottom>

			<link href="http://docs.oracle.com/javase/7/docs/api/" />
		</javadoc>
	</target>


	<target name="package" depends="jar" description="Creates zip files for distribution.">
		<!-- Copy Files To Dist Locations -->
		<echo>Creating Distribution Archive...</echo>
		<mkdir dir="${dir.dist}" />

		<zip destfile="${dir.dist}/${ant.project.name}-${ant.project.version}.zip" level="9">
			<zipfileset dir="targets" prefix="${ant.project.name}/targets">
				<include name="**/*.properties" />
			</zipfileset>

			<zipfileset dir="${dir.doc}" prefix="${ant.project.name}/doc">
				<include name="**/*" />
			</zipfileset>

			<zipfileset dir="${basedir}/wiki" prefix="${ant.project.name}/wiki">
				<include name="**/*" />
			</zipfileset>

			<zipfileset dir="${dir.jar}" prefix="${ant.project.name}/jar">
				<include name="${ant.project.name}-${ant.project.version}.jar" />
			</zipfileset>

			<zipfileset dir="${dir.src}" prefix="${ant.project.name}/src">
				<include name="java/**/*" />
				<include name="jni/**/*" />
				<include name="test/**/*" />

				<exclude name="jni/include/org_jnativehook_GlobalScreen.h" />
				<exclude name="jni/include/org_jnativehook_GlobalScreen_EventDispatchTask.h" />
				<exclude name="jni/include/org_jnativehook_GlobalScreen_NativeHookThread.h" />
			</zipfileset>

			<zipfileset dir="${dir.src}/libuiohook" prefix="${ant.project.name}/src/libuiohook">
				<include name="include/uiohook.h" />
				<include name="m4/ax_*.m4" />
				<include name="man/*" />
				<include name="pc/uiohook.pc.in" />
				<include name="src/**/*" />
				<include name="test/**/*" />

				<include name="AUTHORS" />
				<include name="bootstrap.sh" />
				<include name="*.am" />
				<include name="*.md" />
				<include name="*.ac" />
			</zipfileset>

			<zipfileset dir="${basedir}" prefix="${ant.project.name}">
				<include name="build.num" />
				<include name="build.xml" />
				<include name="cross.build.xml" />
				<include name="AUTHORS" />
				<include name="*.md" />

				<exclude name="build.properties" />
			</zipfileset>
		</zip>
	</target>


	<target name="all" depends="compile,jar" description="Compile all source files and create the jar library.">
	</target>
</project>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy