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

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

There is a newer version: 2.1.0
Show 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.
https://github.com/kwhat/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 file="${dir.src}/native/jni/org_jnativehook_GlobalScreen.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. -->
		<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>


		<!-- Arm7 is not supported by Java... Yes, seriously. -->
		<fileset id="proc" dir="/proc">
			<patternset id="cpuinfo">
				<include name="cpuinfo" />
			</patternset>
		</fileset>
		<fileset id="arm7" dir="/proc">
			<patternset refid="cpuinfo" />
			<contains text="ARMv7" casesensitive="yes" />
		</fileset>

		<!-- Set the system arch name used for organizing native libraries -->
		<condition property="ant.build.native.arch" value="arm6">
			<and>
				<os arch="arm" />
				<resourcecount when="equal" count="0" refid="arm7" />
			</and>
		</condition>
		<condition property="ant.build.native.arch" value="arm7">
			<and>
				<os arch="arm" />
				<resourcecount when="greater" count="0" refid="arm7" />
			</and>
		</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="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-java" description="Compiles JNI source files.">
		<echo>Creating JNI Headers...</echo>
		<javah destdir="${dir.src}/native/jni" verbose="true">
			<class name="org.jnativehook.GlobalScreen" />
			<classpath refid="ant.project.class.path" />
		</javah>

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

		<!-- Guess what system specific libraries to use -->
		<condition property="ant.build.native.ld.libs" value="-framework ApplicationServices">
			<isset property="native.os.isDarwin" />
		</condition>
		<condition property="ant.build.native.ld.libs" value="-lmsvcrt -luser32 -lkernel32">
			<isset property="native.os.isWindows" />
		</condition>
		<property name="ant.build.native.ld.libs" value="-lX11 -lXt -lXtst" />

		<!-- Execute the native compiler on the source files. -->
		<echo>Compiling C source...</echo>
		<cc toolchain="${ant.build.native.toolchain}" jobs="${ant.build.native.jobs}" objdir="${dir.bin}/obj">
			<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="DEBUG" if="ant.build.debug"/>
			<define name="COREFOUNDATION" if="native.os.isDarwin" />
			<define name="IOKIT" if="native.os.isDarwin" />
			<define name="XKB" if="native.os.isX11" />
			<define name="XT" if="native.os.isX11" />
			<define name="_POSIX_C_SOURCE" value="200809L" if="native.os.isX11" />

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

			<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}/native">
				<include name="**/*.c" />
				<exclude name="osx/*.c" unless="native.os.isDarwin" />
				<exclude name="windows/*.c" unless="native.os.isWindows" />
				<exclude name="unix/*.c" unless="native.os.isX11" />
			</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/**/*.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="jar" 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="javadoc" description="Generates javadoc api documentation.">
		<echo level="info">Generating API Documenation...</echo>

		<!-- Delete any previous javadocs -->
		<mkdir dir="${dir.doc}"/>
		<delete includeemptydirs="true">
			<fileset dir="${dir.doc}" includes="**/*"/>
		</delete>

		<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/c_source/**"/>
				<exclude name="org/jnativehook/lib/**"/>
			</packageset>

			<doctitle><![CDATA[<h1>${project.name} 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,javadoc" 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="${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="native/**/*" />

				<exclude name="native/jni/org_jnativehook_GlobalScreen.h" />
			</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="*.properties" />
			</zipfileset>
		</zip>
	</target>

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy