<?xml version="1.0" encoding="UTF-8"?>
<project name="JNA" default="default" basedir="." 
         xmlns:artifact="antlib:org.apache.maven.artifact.ant"
         xmlns:if="ant:if"
         xmlns:unless="ant:unless">
  <description>Builds and tests JNA</description>

  <!-- Default build compiles all platform-independent stuff as well
       as the JNI bits for the current platform, using the arch model
       of the current Java VM to determine whether 32- or 64-bit
       binaries are built (ANT_OPTS=-d32/-d64 to switch on platforms that
       support it).

       Cross-compile by specifying -Dos.prefix={name-arch} to ant
       (cross-compile currently only configured/tested on android targets)

       Use ANT_OPTS=-D-native=true to build native parts, or directly
         invoke the native or test targets
       Use ANT_OPTS=-Dheadless to run tests headless
       Use ANT_OPTS=-Drelease to stage a final, non-snapshot version
    -->

  <!--
  Conventions (since ant can't easily specify arbitrary file dependencies):
  The uptodate property for a given target TARGET is "-TARGET"; the actual
  target to generate the uptodate property is named ":TARGET".

  Properties (except for uptodate properties) separate words by dots, targets
  by dashes.
  -->

  <!-- global properties -->
  <!-- (all build-related props should go in -dynamic-properties) -->
  <import file="common.xml" />
  <property name="jar" value="${name}.jar"/>
  <property name="aar" value="${name}.aar"/>
  <property name="minjar" value="${name}-min.jar"/>
  <property name="testjar" value="${name}-test.jar"/>
  <property name="testjar2" value="${name}-test2.jar"/>
  <property name="testjar3" value="${name}-test3.jar"/>
  <property name="jar-jpms" value="${name}-jpms.jar"/>
  <property name="debug" value="true"/>
  <property name="debug.native" value="false"/>
  <property name="cflags_extra.native" value=""/>
  <property name="dynlink.native" value="false"/>
  <property name="native" location="native"/>
  <property name="src" location="src"/>
  <property name="platform.src" location="contrib/platform/src"/>
  <property name="contrib" location="contrib"/>
  <property name="dist" location="dist"/>
  <property name="lib.native" location="lib/native"/>
  <property name="test.src" location="test"/>
  <property name="doc" location="doc"/>
  <property name="javadoc" location="${doc}/javadoc"/>
  <property name="stylesheet" location="${javadoc}/doc/css/javadoc.css"/>

  <condition property="tests.exclude-patterns" value="**/VarArgsTest.java,**/AnnotatedLibraryTest.java,**/WebStartTest.java,**/PointerBufferTest.java,**/HeadlessLoadLibraryTest.java,**/StructureBufferFieldTest.java,**/PerformanceTest.java,**/*BufferArgumentsMarshalTest.java" else="**/wince/*.java,**/WebStartTest.java">
    <equals arg1="${os.prefix}" arg2="w32ce-arm"/>
  </condition>
  <property name="dist-jar" value="${dist}/${jar}"/>
  <property name="dist-aar" value="${dist}/${aar}"/>
  <property name="dist-jar-jpms" value="${dist}/${jar-jpms}"/>

  <!-- Maven -->
  <!-- define Maven coordinates -->
  <property name="groupId" value="net.java.dev.jna" />
  <property name="artifactId" value="jna" />

  <property name="maven-javadoc-jar" value="${dist}/${artifactId}-${jna.version}-javadoc.jar" />
  <property name="maven-sources-jar" value="${dist}/${artifactId}-${jna.version}-sources.jar" />

  <property name="platform-jar" value="${dist}/jna-platform.jar"/>
  <property name="platform-javadoc-jar" value="${dist}/platform-${jna.version}-javadoc.jar" />
  <property name="platform-sources-jar" value="${dist}/platform-${jna.version}-sources.jar" />
  <property name="platform-jpms-jar" value="${dist}/jna-platform-jpms.jar" />

  <!-- defined maven snapshots and staging repository id and url -->
  <property name="maven-snapshots-repository-id" value="oss.sonatype.org" />
  <property name="maven-snapshots-repository-url" value="https://oss.sonatype.org/content/repositories/snapshots/" />
  <property name="maven-staging-repository-id" value="oss.sonatype.org" />
  <property name="maven-staging-repository-url" value="https://oss.sonatype.org/service/local/staging/deploy/maven2/" />

  <!-- Miscellaneous -->
  <property name="build" value="build"/>
  <property name="build.compiler.emacs" value="true"/>

  <property name="pom-base" value="pom-jna.xml" />
  <property name="pom-platform-base" value="pom-jna-platform.xml" />
  <property name="pom-jpms-base" value="pom-jna-jpms.xml" />
  <property name="pom-platform-jpms-base" value="pom-jna-platform-jpms.xml" />

  <property name="pom" value="${build}/pom-jna.xml" />
  <property name="pom-platform" value="${build}/pom-jna-platform.xml" />
  <property name="pom-jpms" value="${build}/pom-jna-jpms.xml" />
  <property name="pom-platform-jpms" value="${build}/pom-jna-platform-jpms.xml" />

  <target name="default" depends="test" description="Build and Test."/>

  <target name="init" depends="-setup"/>
  <target name="compile-test-single" depends="compile-tests"/>
  <target name="compile-single" depends="compile"/>

  <!-- Prepare additional ant task -->

  <target name="-prepare-anttools">
      <subant antfile="build-ant-tools.xml" buildpath="${basedir}"></subant>
      <taskdef name="BuildArmSoftFloatDetector" classname="com.sun.jna.BuildArmSoftFloatDetector" classpath="${build}/ant-tools:$lib/asm-8.0.1.jar" />
      <taskdef name="CalcAndroidVersion" classname="com.sun.jna.ant.CalcAndroidVersion" classpath="${build}/ant-tools:lib/asm-8.0.1.jar" />
      <taskdef name="ModuleGenerator" classname="com.sun.jna.ant.ModuleGenerator" classpath="${build}/ant-tools:lib/asm-8.0.1.jar" />
  </target>

  <target name="-dynamic-properties" depends="-prepare-anttools">

    <condition property="-native" value="true">
      <not><isset property="build-native"/></not>
    </condition>
    <condition property="jni.valid" value="true">
      <isset property="-native"/>
    </condition>

    <copy file="${pom-base}" tofile="${pom}" />
    <copy file="${pom-platform-base}" tofile="${pom-platform}" />
    <copy file="${pom-jpms-base}" tofile="${pom-jpms}" />
    <copy file="${pom-platform-jpms-base}" tofile="${pom-platform-jpms}" />

    <replaceregexp match="(&lt;version&gt;).*(&lt;/version&gt;)"
                   replace="\1${jna.version}\2"
                   flags="g"
                   file="${pom}"/>

    <replaceregexp match="(&lt;version&gt;).*(&lt;/version&gt;)"
                   replace="\1${jna.version}\2"
                   flags="g"
                   file="${pom-platform}"/>

    <replaceregexp match="(&lt;version&gt;).*(&lt;/version&gt;)"
                   replace="\1${jna.version}\2"
                   flags="g"
                   file="${pom-jpms}"/>

    <replaceregexp match="(&lt;version&gt;).*(&lt;/version&gt;)"
                 replace="\1${jna.version}\2"
                 flags="g"
                 file="${pom-platform-jpms}"/>

    <condition property="jar.omitted" value="**/*jnidispatch*" else="jnilib-included">
      <isset property="omit-jnilib"/>
    </condition>

    <property name="classes" location="${build}/classes"/>
    <property name="eclipse.classes" location="build.eclipse/classes"/>
    <property name="test.classes" location="${build}/test-classes"/>
    <property name="reports" value="${build}/reports"/>

    <CalcAndroidVersion
        major="${jna.major}"
        minor="${jna.minor}"
        revision="${jna.revision}"
        releaseProperty="release"
        targetProperty="android.versionCode"
    />
    <BuildArmSoftFloatDetector targetProperty="build.isArmSoftFloat"/>

    <fail unless="os.prefix" message="OS/arch not supported (${os.name}/${jre.arch}), edit build.xml and native/Makefile to add it."/>
    <!-- Keep all natives separate -->
    <condition property="jdk.home" value="${java.home}">
      <available file="${java.home}/include"/>
    </condition>
    <condition property="jdk.home" value="${java.home}/..">
      <available file="${java.home}/../include"/>
    </condition>
    <condition property="jdk.home" value="/System/Library/Frameworks/JavaVM.framework/Home">
      <available file="/System/Library/Frameworks/JavaVM.framework/Headers"/>
    </condition>
    <fail unless="jdk.home" message="Can't find JNI headers (java.home=${java.home})"/>
    <property name="libarch" value="${os.arch}"/>
    <condition property="libjsig"
               value="${java.home}/lib/${libarch}/libjsig.so" else="">
      <available file="${java.home}/lib/${libarch}/libjsig.so"/>
    </condition>
    <condition property="ld.preload.name" value="LD_PRELOAD" else="IGNORE">
      <not><equals arg1="${libjsig}" arg2=""/></not>
    </condition>
    <property name="native.jar" value="${os.prefix}.jar"/>
    <property name="build.native" location="${build}/${native.subdir}"/>
    <property name="build.headers" location="${build}/headers"/>
    <property name="build.aar" location="${build}/aar"/>
    <property name="md5.file" location="${build.headers}/jni.checksum"/>
    <property name="jni.info" location="${build.headers}/jni.properties"/>

    <mkdir dir="${build}"/>
    <mkdir dir="${build.native}"/>
    <mkdir dir="${build.headers}"/>
    <mkdir dir="${classes}"/>
    <mkdir dir="${test.classes}"/>
    <mkdir dir="${reports}"/>
    <mkdir dir="${doc}"/>
    <mkdir dir="${build.aar}"/>

    <echo>Java version ${java.version}, compatibility: ${javac.release}, ant: ${ant.java.version}</echo>
    <echo>JNA version ${jna.version}, native ${jni.version}, android ${android.versionCode}</echo>
    <echo>${java.vm.name} (${java.vm.vendor}, ${java.vm.version})</echo>
    <echo>java.home=${java.home}</echo>
    <echo>java.library.path=${java.library.path}</echo>
    <echo>os.prefix=${os.prefix}</echo>
    <echo>os.name=${build.os.name}</echo>
    <echo>os.arch=${build.os.arch} (${build.os.endianess})</echo>
    <echo>build=${build}</echo>
    <echo>build.native=${build.native}</echo>
    <echo>build.headers=${build.headers}</echo>
    <echo>build.aar=${build.aar}</echo>

  </target>

  <target name="-setup" depends="-dynamic-properties">
    <path id="compile-test.path">
      <path id="test.libs">
        <fileset dir="lib">
          <include name="junit.jar"/>
          <include name="hamcrest-core-1.3.jar"/>
        </fileset>
        <fileset dir="lib/test"/>
        <pathelement path="${classes}"/>
      </path>
    </path>
    <path id="compile.path"/>
    <path id="src.path">
      <pathelement location="${src}"/>
    </path>
    <path id="test.runpath">
      <pathelement path="${build}/${jar}"/>
      <pathelement path="${test.classes}"/>
      <pathelement path="${build}/${testjar}"/>
      <pathelement path="lib/clover.jar"/>
      <path refid="test.libs"/>
    </path>
  </target>

  <target name="compile" depends="-setup"
          description="Compile all Java source">

    <delete dir="${build}/jna-src" />
    <mkdir dir="${build}/jna-src/com/sun/jna" />

    <copy file="src/com/sun/jna/Version.java" todir="${build}/jna-src/com/sun/jna" />

    <replaceregexp match='VERSION = ".*";'
                   replace='VERSION = "${jna.version}";'
                   file="${build}/jna-src/com/sun/jna/Version.java"/>
    <replaceregexp match='VERSION_NATIVE = ".*";'
                   replace='VERSION_NATIVE = "${jni.version}";'
                   file="${build}/jna-src/com/sun/jna/Version.java"/>

    <javac release="${javac.release}"
           destdir="${classes}"
           includeantruntime="false"
           deprecation="on"
           debug="${debug}"
           encoding="UTF-8"
           nativeheaderdir="${build.headers}">
      <src location="${build}/jna-src/com/sun/jna" />
    </javac>
    <javac release="${javac.release}"
           destdir="${classes}"
           includeantruntime="false"
           deprecation="on" 
           debug="${debug}"
           encoding="UTF-8"
           nativeheaderdir="${build.headers}">
      <src refid="src.path"/>
      <exclude name="com/sun/jna/Version.java" />
    </javac>
  </target>

  <target name=":jar">
    <uptodate property="-jar" targetfile="${build}/${jar}">
      <srcfiles dir="${classes}">
        <patternset id="jar-compiled">
          <include name="com/sun/jna/*"/>
          <include name="com/sun/jna/**/*"/>
        </patternset>
      </srcfiles>
    </uptodate>
  </target>
  <target name="jar" depends="-setup,native,:jar" unless="-jar"
          description="Build primary jar">
    <!-- Bundle native components with primary jar to facilitate
         easy distribution to common platforms.
      -->
  <macrodef name="build-manifest">
      <attribute name="target" />
      <attribute name="module-info" default="false" />
      <sequential>
          <manifest file="@{target}" mode="replace">
              <attribute name="Main-Class" value="com.sun.jna.Native"/>
              <attribute name="Manifest-Version" value="1.0"/>
              <attribute name="Implementation-Title" value="${impl.title}"/>
              <attribute name="Implementation-Vendor" value="${vendor}"/>
              <attribute name="Implementation-Version" value="${impl.version}"/>
              <attribute name="Specification-Title" value="${spec.title}"/>
              <attribute name="Specification-Vendor" value="${spec.vendor}"/>
              <attribute name="Specification-Version" value="${spec.version}"/>
              <!--
                OSGi Bundle attributes
                See http://www.osgi.org/Specifications/Reference
              -->
              <attribute name="Bundle-Category" value="jni"/>
              <attribute name="Bundle-ManifestVersion" value="2"/>
              <attribute name="Bundle-Name" value="jna"/>
              <attribute name="Bundle-Description" value="JNA Library"/>
              <attribute name="Bundle-SymbolicName" value="com.sun.jna"/>
              <attribute name="Bundle-Version" value="${jna.major}.${jna.minor}.${jna.revision}"/>
              <attribute name="Bundle-RequiredExecutionEnvironment" value="JavaSE-1.6"/>
              <attribute name="Bundle-Vendor" value="${vendor}"/>
              <attribute name="Bundle-ActivationPolicy" value="lazy"/>
              <!--
              The full "Export-Package" statement can be generated by invoking
              create-export-package-metadata-pom.sh in the main folder. This is
              necessary if the exported packages change. Then the list in the
              shell script needs to be updated as well.
              -->
              <attribute name="Export-Package" value="
com.sun.jna;version=&quot;${osgi.version}&quot;,
com.sun.jna.ptr;version=&quot;${osgi.version}&quot;;uses:=&quot;com.sun.jna&quot;,
com.sun.jna.win32;version=&quot;${osgi.version}&quot;;uses:=&quot;com.sun.jna&quot;
"/>
              <!-- Note that no terminal "*" is included in this list,
                 which will force failure on unsupported platforms.
              -->
              <attribute name="Bundle-NativeCode"
                         value="
com/sun/jna/win32-x86/jnidispatch.dll;
processor=x86;osname=win32,
com/sun/jna/win32-x86-64/jnidispatch.dll;
processor=x86-64;osname=win32,
com/sun/jna/win32-aarch64/jnidispatch.dll;
processor=aarch64;osname=win32,
com/sun/jna/win32-x86/jnidispatch.dll;
processor=x86;osname=win,
com/sun/jna/win32-x86-64/jnidispatch.dll;
processor=x86-64;osname=win,
com/sun/jna/win32-aarch64/jnidispatch.dll;
processor=aarch64;osname=win,
com/sun/jna/w32ce-arm/jnidispatch.dll;
processor=arm;osname=wince,

com/sun/jna/sunos-x86/libjnidispatch.so;
processor=x86;osname=sunos,
com/sun/jna/sunos-x86-64/libjnidispatch.so;
processor=x86-64;osname=sunos,
com/sun/jna/sunos-sparc/libjnidispatch.so;
processor=sparc;osname=sunos,
com/sun/jna/sunos-sparcv9/libjnidispatch.so;
processor=sparcv9;osname=sunos,

com/sun/jna/aix-ppc/libjnidispatch.a;
processor=ppc;osname=aix,
com/sun/jna/aix-ppc64/libjnidispatch.a;
processor=ppc64;osname=aix,

com/sun/jna/linux-ppc/libjnidispatch.so;
processor=ppc;osname=linux,
com/sun/jna/linux-ppc64/libjnidispatch.so;
processor=ppc64;osname=linux,
com/sun/jna/linux-ppc64le/libjnidispatch.so;
processor=ppc64le;osname=linux,
com/sun/jna/linux-x86/libjnidispatch.so;
processor=x86;osname=linux,
com/sun/jna/linux-x86-64/libjnidispatch.so;
processor=x86-64;osname=linux,
com/sun/jna/linux-arm/libjnidispatch.so;
processor=arm;osname=linux,
com/sun/jna/linux-arm/libjnidispatch.so;
processor=arm_le;osname=linux,
com/sun/jna/linux-armel/libjnidispatch.so;
processor=armel;osname=linux,
com/sun/jna/linux-aarch64/libjnidispatch.so;
processor=aarch64;osname=linux,
com/sun/jna/linux-ia64/libjnidispatch.so;
processor=ia64;osname=linux,
com/sun/jna/linux-sparcv9/libjnidispatch.so;
processor=sparcv9;osname=linux,
com/sun/jna/linux-mips64el/libjnidispatch.so;
processor=mips64el;osname=linux,
com/sun/jna/linux-s390x/libjnidispatch.so;
processor=S390x;osname=linux,
com/sun/jna/linux-loongarch64/libjnidispatch.so;
processor=loongarch64;osname=linux,
com/sun/jna/linux-riscv64/libjnidispatch.so;
processor=riscv64;osname=linux,

com/sun/jna/dragonflybsd-x86-64/libjnidispatch.so;
processor=x86-64;osname=dragonflybsd,

com/sun/jna/freebsd-x86/libjnidispatch.so;
processor=x86;osname=freebsd,
com/sun/jna/freebsd-x86-64/libjnidispatch.so;
processor=x86-64;osname=freebsd,
com/sun/jna/freebsd-aarch64/libjnidispatch.so;
processor=aarch64;osname=freebsd,

com/sun/jna/openbsd-x86/libjnidispatch.so;
processor=x86;osname=openbsd,
com/sun/jna/openbsd-x86-64/libjnidispatch.so;
processor=x86-64;osname=openbsd,

com/sun/jna/darwin-ppc/libjnidispatch.jnilib;
osname=macosx;processor=ppc,
com/sun/jna/darwin-ppc64/libjnidispatch.jnilib;
osname=macosx;processor=ppc64,
com/sun/jna/darwin-x86/libjnidispatch.jnilib;
osname=macosx;processor=x86,
com/sun/jna/darwin-x86-64/libjnidispatch.jnilib;
osname=macosx;processor=x86-64,
com/sun/jna/darwin-aarch64/libjnidispatch.jnilib;
osname=macosx;processor=aarch64
"/>
          </manifest>
          <manifest file="@{target}" mode="update" if:true="@{module-info}">
              <attribute name="Multi-Release" value="true"/>
          </manifest>
          <manifest file="@{target}" mode="update" unless:true="@{module-info}">
              <attribute name="Automatic-Module-Name" value="com.sun.jna"/>
          </manifest>
      </sequential>
  </macrodef>
    <delete dir="${build}/manifest"/>
    <mkdir dir="${build}/manifest"/>
    <build-manifest target="${build}/manifest/module.mf" module-info="true"/>
    <build-manifest target="${build}/manifest/automatic.mf" module-info="false"/>
    <ModuleGenerator
        targetFile="${build}/manifest/module-info.class"
        name="com.sun.jna"
        version="${jna.major}.${jna.minor}.${jna.revision}"
        open="false"
    >
        <exports package="com.sun.jna" />
        <exports package="com.sun.jna.ptr" />
        <exports package="com.sun.jna.win32" />
        <exports package="com.sun.jna.internal" to="com.sun.jna.platform"/>
        <requires module="java.logging" />
        <requires module="java.desktop" />
    </ModuleGenerator>
    <jar jarfile="${build}/${jar}" duplicate="preserve" createUnicodeExtraFields="never" encoding="UTF-8" manifest="${build}/manifest/automatic.mf">
      <fileset dir="${classes}" excludes="${jar.omitted}">
        <patternset refid="jar-compiled"/>
      </fileset>
      <zipfileset src="${lib.native}/win32-x86.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/win32-x86"/>
      <zipfileset src="${lib.native}/aix-ppc.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/aix-ppc"/>
      <zipfileset src="${lib.native}/aix-ppc64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/aix-ppc64"/>
      <zipfileset src="${lib.native}/darwin-ppc.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/darwin-ppc"/>
      <zipfileset src="${lib.native}/darwin-ppc64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/darwin-ppc64"/>
      <zipfileset src="${lib.native}/darwin-x86.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/darwin-x86"/>
      <zipfileset src="${lib.native}/darwin-x86-64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/darwin-x86-64"/>
      <zipfileset src="${lib.native}/darwin-aarch64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/darwin-aarch64"/>
      <zipfileset src="${lib.native}/linux-x86.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-x86"/>
      <zipfileset src="${lib.native}/linux-x86-64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-x86-64"/>
      <zipfileset src="${lib.native}/linux-arm.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-arm"/>
      <zipfileset src="${lib.native}/linux-armel.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-armel"/>
      <zipfileset src="${lib.native}/linux-aarch64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-aarch64"/>
      <zipfileset src="${lib.native}/linux-ia64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-ia64"/>
      <zipfileset src="${lib.native}/linux-ppc.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-ppc"/>
      <zipfileset src="${lib.native}/linux-ppc64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-ppc64"/>
      <zipfileset src="${lib.native}/linux-ppc64le.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-ppc64le"/>
      <zipfileset src="${lib.native}/linux-sparcv9.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-sparcv9"/>
      <zipfileset src="${lib.native}/linux-mips64el.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-mips64el"/>
      <zipfileset src="${lib.native}/linux-loongarch64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-loongarch64"/>
      <zipfileset src="${lib.native}/linux-s390x.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-s390x"/>
      <zipfileset src="${lib.native}/linux-riscv64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/linux-riscv64"/>
      <zipfileset src="${lib.native}/sunos-x86.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/sunos-x86"/>
      <zipfileset src="${lib.native}/sunos-x86-64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/sunos-x86-64"/>
      <zipfileset src="${lib.native}/sunos-sparc.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/sunos-sparc"/>
      <zipfileset src="${lib.native}/sunos-sparcv9.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/sunos-sparcv9"/>
      <zipfileset src="${lib.native}/dragonflybsd-x86-64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/dragonflybsd-x86-64"/>
      <zipfileset src="${lib.native}/freebsd-x86.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/freebsd-x86"/>
      <zipfileset src="${lib.native}/freebsd-x86-64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/freebsd-x86-64"/>
      <zipfileset src="${lib.native}/freebsd-aarch64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/freebsd-aarch64"/>
      <zipfileset src="${lib.native}/openbsd-x86.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/openbsd-x86"/>
      <zipfileset src="${lib.native}/openbsd-x86-64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/openbsd-x86-64"/>
      <zipfileset src="${lib.native}/win32-x86-64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/win32-x86-64"/>
      <zipfileset src="${lib.native}/win32-aarch64.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/win32-aarch64"/>
      <zipfileset src="${lib.native}/w32ce-arm.jar"
                  includes="*jnidispatch*"
                  prefix="com/sun/jna/w32ce-arm"/>
      <zipfileset dir="."
                  includes="LICENSE,LGPL2.1,AL2.0"
                  prefix="META-INF"/>
    </jar>
    <zip zipfile="${build}/${minjar}">
      <zipfileset src="${build}/${jar}" excludes="**/*jnidispatch*"/>
    </zip>
    <jar jarfile="${build}/jna-jpms.jar" duplicate="preserve" createUnicodeExtraFields="never" encoding="UTF-8" manifest="${build}/manifest/module.mf">
      <zipfileset src="${build}/${jar}" excludes="META-INF/MANIFEST.mf"/>
      <zipfileset dir="${build}/manifest/" includes="module-info.class" prefix="META-INF/versions/9"/>
    </jar>
  </target>

  <target name="aar" depends="jar" description="Build Android Archive">
    <!-- Dummy entries in R.txt and the string resources are needed or a grails
         build using this library will fail (tested with Android Studio 2.2.3 -->
    <mkdir dir="${build.aar}/res/values" />
    <echo file="${build.aar}/res/values/values.xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <string name="jna_library_appname">JNA bindings</string>
</resources>
    ]]></echo>
    <echo file="${build.aar}/R.txt">int string jna_library_appname 0x7f050021
</echo>
    <echo file="${build.aar}/AndroidManifest.xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sun.jna"
    android:versionCode="]]>${android.versionCode}<![CDATA["
    android:versionName="]]>${jna.version}<![CDATA[" >

    <uses-sdk android:targetSdkVersion="25" />
</manifest> 
    ]]></echo>
    <zip zipfile="${build}/${aar}">
        <mappedresources>
          <fileset file="${build}/${minjar}"/>
          <globmapper from="*" to="classes.jar"/>
        </mappedresources>
        <zipfileset src="${lib.native}/android-aarch64.jar"
                  includes="*jnidispatch*"
                  prefix="jni/arm64-v8a"/>
        <zipfileset src="${lib.native}/android-arm.jar"
                  includes="*jnidispatch*"
                  prefix="jni/armeabi"/>
        <zipfileset src="${lib.native}/android-armv7.jar"
                  includes="*jnidispatch*"
                  prefix="jni/armeabi-v7a"/>
        <zipfileset src="${lib.native}/android-mips.jar"
                  includes="*jnidispatch*"
                  prefix="jni/mips"/>
        <zipfileset src="${lib.native}/android-mips64.jar"
                  includes="*jnidispatch*"
                  prefix="jni/mips64"/>
        <zipfileset src="${lib.native}/android-x86-64.jar"
                  includes="*jnidispatch*"
                  prefix="jni/x86_64"/>
        <zipfileset src="${lib.native}/android-x86.jar"
                  includes="*jnidispatch*"
                  prefix="jni/x86"/>
        <fileset dir="${build.aar}"/>
    </zip>
  </target>

  <target name="platform-jar" depends="jar">
    <subant target="jar" failonerror="true">
      <fileset dir="${contrib}" includes="platform/build.xml" />
    </subant>
    <!-- Sources package as required by maven -->
    <zip zipfile="${platform-sources-jar}">
      <zipfileset dir="${contrib}/platform/src" />
    </zip>
  </target>

  <target name="contrib-jars" depends="platform-jar" description="Build contrib jars">
    <subant target="jar" failonerror="true">
      <property name="file.reference.jna.build" location="${build}"/>
      <property name="file.reference.jna.jar" location="${build}/${jar}"/>
      <property name="libs.junit.classpath" refid="test.libs"/>
      <property name="javac.source" value="${javac.release}" />
      <property name="javac.target" value="${javac.release}" />
      <property name="javac.release" value="${javac.release}" />
      <fileset dir="${contrib}" includes="*/build.xml" excludes="platform/build.xml"/>
    </subant>
  </target>

  <target name="idea-jar" depends="jar" description="Build Intellij Idea convenience jar">
    <jar destfile="${dist}/idea-dispatch.jar" createUnicodeExtraFields="never" encoding="UTF-8">
      <zipfileset src="${dist-jar}" excludes="**/*.class"/>
    </jar>
  </target>

  <target name="javah" depends="compile" unless="-native">
    <condition property="grep" value="/usr/sfw/bin/ggrep">
      <os name="SunOS"/>
    </condition>
    <condition property="grep" value="ggrep">
      <os name="OpenBSD"/>
    </condition>
    <property name="grep" value="grep"/>
    <condition property="grep.required" value="false" else="true">
      <os name="AIX"/>
    </condition>
    <!-- args are based on GNU grep, other versions may differ -->
    <apply dir="${build.headers}" executable="${grep}" parallel="true"
           failonerror="${grep.required}" relative="true" output="${md5.file}"
           error="${md5.file}.error">
      <arg value="-A"/>
      <arg value="1"/>
      <arg value="JNIEXPORT"/>
      <fileset dir="${build.headers}" includes="*.h"/>
    </apply>
    <apply dir="${build.headers}" executable="${grep}" parallel="true"
           failonerror="${grep.required}" relative="true" output="${md5.file}"
           error="${md5.file}.error" append="true">
      <arg value="#define"/>
      <fileset dir="${build.headers}" includes="*.h"/>
    </apply>
    <!-- Clean up gcj javah output to match that of Sun's javah -->
    <fixcrlf file="${md5.file}" eol="unix"/>
    <replaceregexp match="^((.*\.h):JNIEXPORT[^(]+)( +\(.*)"
                   replace="\1&#xa;\2- \3&#xa;--"
		   byline="true"
                   file="${md5.file}"/>
    <replaceregexp match="(JNIEnv *\*) *env"
                   replace="\1"
		   byline="true"
                   file="${md5.file}"/>
    <replaceregexp match="&#xa;--&#xa;.*\.h-$"
                   replace=""
		   flags="m"
                   file="${md5.file}"/>
    <checksum property="md5" file="${md5.file}" />
    <propertyfile file="${jni.info}">
        <entry key="checksum" value="${md5}" />
        <entry key="version" value="${jni.version}" />
    </propertyfile>
    <condition property="jni.valid" value="true">
      <or>
        <os name="AIX"/>
        <equals arg1="${jni.md5}" arg2="${md5}" trim="true"/>
        <equals arg1="${jni.md5}" arg2=""/>
      </or>
    </condition>
  </target>

  <!-- Invalidate native libraries when native API changes -->
  <target name="-native-api-check" depends="javah" unless="jni.valid">
    <echo>Invalidating native code, new checksum is ${md5}</echo>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/darwin-ppc.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/darwin-ppc64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/darwin-x86.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/darwin-x86-64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/darwin-aarch64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/win32-x86.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/win32-x86-64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/win32-aarch64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/w32ce-arm.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-x86.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-x86-64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-arm.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-armel.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-aarch64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-ia64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-ppc.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-ppc64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-ppc64le.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-sparcv9.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-mips64el.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-loongarch64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-s390x.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-riscv64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/dragonflybsd-x86-64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/freebsd-x86.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/freebsd-x86-64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/freebsd-aarch64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/openbsd-x86.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/openbsd-x86-64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/sunos-x86.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/sunos-x86-64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/sunos-sparc.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/sunos-sparcv9.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/android-arm.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/android-armv7.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/android-aarch64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/android-x86.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/android-x86-64.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/android-mips.jar" overwrite="true"/>
    <copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/android-mips64.jar" overwrite="true"/>
    <delete failOnError="false" includeEmptyDirs="true">
      <fileset dir="${build.native}" includes="*.o,*jnidispatch*"/>
    </delete>
    <fail>API for native code has changed, or javah output is inconsistent.  Re-run this build after checking ${md5.file} or updating jni.version and jni.md5 in build.xml</fail>
  </target>

  <target name=":rsrc">
    <condition property="-rsrc">
      <and>
        <not><equals arg1="${build.os.family}" arg2="windows"/></not>
        <not><equals arg1="${os.prefix}" arg2="w32ce-arm"/></not>
      </and>
    </condition>
  </target>
  <target name="rsrc" depends="-setup,:rsrc" unless="-rsrc"
          description="Generate w32 DLL version resource information">
    <property name="rsrc" location="${build.native}/jnidispatch.rc"/>
    <copy todir="${build.native}" file="${native}/jnidispatch.rc"/>
    <replaceregexp match="FILEVERSION.*"
                   replace="FILEVERSION ${jni.major},${jni.minor},${jni.revision},${jni.build}"
                   preserveLastModified="true"
                   file="${rsrc}" byline="true"/>
    <replaceregexp match="PRODUCTVERSION.*"
                   replace="PRODUCTVERSION ${jna.major},${jna.minor},${jna.revision},${jna.build}"
                   preserveLastModified="true"
                   file="${rsrc}" byline="true"/>
    <replaceregexp match="FileVersion.*"
                   replace="FileVersion&quot;,&quot;${jni.version}&quot;"
                   preserveLastModified="true"
                   file="${rsrc}" byline="true"/>
    <replaceregexp match="Full Version.*"
                   replace="Full Version&quot;,&quot;${jni.version} b${jni.build}&quot;"
                   preserveLastModified="true"
                   file="${rsrc}" byline="true"/>
    <replaceregexp match="ProductVersion.*"
                   replace="ProductVersion&quot;,&quot;${spec.version}&quot;"
                   preserveLastModified="true"
                   file="${rsrc}" byline="true"/>
    <replaceregexp match="(Copyright.*-)2..."
                   replace="\1${year}"
                   preserveLastModified="true"
                   file="${rsrc}" byline="true"/>
  </target>

  <target name="-prepare-native" depends="-setup,rsrc">
    <property name="comment" value="# auto-generated by ant"/>
    <condition property="make.OS" value="OS=w32ce">
      <equals arg1="${os.prefix}" arg2="w32ce-arm"/>
    </condition>
    <condition property="make.OS" value="OS=android">
      <matches pattern="^android-" string="${os.prefix}"/>
    </condition>
    <property name="make.OS" value="IGNORE="/>
    <!-- Ensure Makefile ARCH property properly set for darwin -->
    <condition property="ARCH" value="aarch64">
        <equals arg1="${os.prefix}" arg2="darwin-aarch64"/>
    </condition>
    <condition property="ARCH" value="i386">
        <equals arg1="${os.prefix}" arg2="darwin-x86"/>
    </condition>
    <condition property="ARCH" value="x86-64">
        <equals arg1="${os.prefix}" arg2="darwin-x86-64"/>
    </condition>
    <condition property="ARCH" value="ppc">
        <equals arg1="${os.prefix}" arg2="darwin-ppc"/>
    </condition>
    <condition property="ARCH" value="ppc64">
        <equals arg1="${os.prefix}" arg2="darwin-ppc64"/>
    </condition>
    <condition property="ARCH" value="arm">
      <equals arg1="${os.prefix}" arg2="w32ce-arm"/>
    </condition>
    <condition property="ARCH" value="arm">
      <equals arg1="${os.prefix}" arg2="android-arm"/>
    </condition>
    <condition property="ARCH" value="armv7">
      <equals arg1="${os.prefix}" arg2="android-armv7"/>
    </condition>
    <condition property="ARCH" value="aarch64">
      <matches string="${os.prefix}" pattern="-aarch64$"/>
    </condition>
    <condition property="ARCH" value="x86">
      <equals arg1="${os.prefix}" arg2="android-x86"/>
    </condition>
    <condition property="ARCH" value="x86-64">
      <equals arg1="${os.prefix}" arg2="android-x86-64"/>
    </condition>
    <condition property="ARCH" value="mips">
      <equals arg1="${os.prefix}" arg2="android-mips"/>
    </condition>
    <condition property="ARCH" value="mips64">
      <equals arg1="${os.prefix}" arg2="android-mips64"/>
    </condition>
    <condition property="ARCH" value="ppc">
      <equals arg1="${os.prefix}" arg2="aix-ppc"/>
    </condition>
    <condition property="ARCH" value="ppc64">
      <equals arg1="${os.prefix}" arg2="aix-ppc64"/>
    </condition>
    <condition property="ARCH" value="riscv64">
      <matches string="${os.prefix}" pattern="-riscv64$"/>
    </condition>
    <!-- ensure ARCH is set properly for 64-bit capable platforms -->
    <!-- use ANT_OPTS=-d64/-d32 to build 64-bit/32-bit if not the platform default -->
    <property name="ARCH" value="${build.os.arch}"/>
    <condition property="make.USE_MSVC" value="USE_MSVC=${USE_MSVC}" else="IGNORE=">
      <isset property="USE_MSVC"/>
    </condition>
    <condition property="make.CC" value="CC=${CC}" else="IGNORE=">
      <isset property="CC"/>
    </condition>
    <condition property="make.ARCH" value="ARCH=${ARCH}" else="IGNORE=">
      <isset property="ARCH"/>
    </condition>
    <condition property="make.SDKROOT" value="SDKROOT=${SDKROOT}">
      <isset property="SDKROOT"/>
    </condition>
    <!-- If not manually provided, detect the SDKROOT in various locations:
         - Modern build environments ("MacOSX.sdk", no version):
           /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

         - macOS 10.8 and older:
           /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX(version).sdk

         - Prior versions:
           /Developer/SDKs/MacOSX(version).sdk
    -->
    <condition property="make.SDKROOT" value="SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk">
      <and>
        <matches string="${os.prefix}" pattern="^darwin-"/>
        <available file="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"/>
      </and>
    </condition>
    <condition property="sdk-parent" value="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs">
      <and>
        <matches string="${os.prefix}" pattern="^darwin-"/>
        <available file="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs"/>
      </and>
    </condition>
    <condition property="sdk-parent" value="/Developer/SDKs">
      <and>
        <matches string="${os.prefix}" pattern="^darwin-"/>
        <available file="/Developer/SDKs"/>
      </and>
    </condition>
    <!-- Multiple SDKs is common; find the most recent (sort -V requires 10.12+) -->
    <exec executable="sh" dir="${sdk-parent}" outputproperty="sdk-latest" if:set="darwin.build" unless:set="make.SDKROOT">
      <arg value="-c"/>
      <arg line="&quot;ls -d MacOSX10.*.sdk | sort -t &quot;.&quot; -k2 -n | tail -1&quot;"/>
    </exec>
    <condition property="make.SDKROOT" value="SDKROOT=${sdk-parent}/${sdk-latest}" else="IGNORE=">
      <isset property="sdk-latest"/>
    </condition>

    <!-- Windows' drive letters and spaces in absolute paths wreak havoc on
         make -->
    <condition property="make.BUILD" value="BUILD=../${build}/${native.subdir}" else="BUILD=${build.native}">
      <equals arg1="${build.os.family}" arg2="windows"/>
    </condition>
    <condition property="make.PATH" value="PATH=/opt/csw/bin:/usr/sfw/bin:/usr/bin:/usr/ccs/bin" else="IGNORE=">
      <equals arg1="${build.os.name}" arg2="SunOS"/>
    </condition>
    <condition property="make" value="/usr/sfw/bin/gmake">
      <and>
        <equals arg1="${build.os.name}" arg2="SunOS"/>
        <available file="/usr/sfw/bin/gmake"/>
      </and>
    </condition>
    <condition property="make" value="gmake">
      <or>
        <equals arg1="${build.os.name}" arg2="DragonFlyBSD"/>
        <equals arg1="${build.os.name}" arg2="FreeBSD"/>
        <equals arg1="${build.os.name}" arg2="OpenBSD"/>
        <equals arg1="${build.os.name}" arg2="NetBSD"/>
        <equals arg1="${build.os.name}" arg2="SunOS"/>
        <equals arg1="${build.os.name}" arg2="AIX"/>
      </or>
    </condition>
    <!-- Allow explicit override of make variables -->
    <condition property="make.OPTS" value="${EXTRA_MAKE_OPTS}" else="IGNORE=">
      <isset property="EXTRA_MAKE_OPTS"/>
    </condition>
    <!-- Native resource path within jna.jar -->
    <property name="native.path" value="com/sun/jna/${resource.prefix}"/>

    <!-- Default make program -->
    <property name="make" value="make"/>
  </target>

  <target name="native-build-package" depends="javah,-native-api-check,-prepare-native">
    <echo file="${build}/build.sh">#!/bin/sh
cwd=$(pwd)
if [ -z "$JAVA_HOME" ]; then
    echo "Please make sure JAVA_HOME is set"
    exit 1
fi
cd native
${make}\
 JAVA_HOME=$JAVA_HOME\
 JAVAH=$cwd/headers\
 DEBUG=${debug.native}\
 CFLAGS_EXTRA=${cflags_extra.native}\
 DYNAMIC_LIBFFI=${dynlink.native}\
 ${make.CC}\
 ${make.USE_MSVC}\
 BUILD=../build\
 ${make.SDKROOT}\
 ${make.ARCH}\
 ${make.PATH}\
 ${make.OS}\
 ${make.OPTS}\
 JNA_JNI_VERSION=${jni.version}\
 CHECKSUM=${jni.md5}
cd ..
cd build
zip ../${os.prefix}.jar libjnidispatch.so jnidispatch.dll libjnidispatch.a
cd ..
    </echo>
    <jar jarfile="${build}/${os.prefix}.jar" createUnicodeExtraFields="never" encoding="UTF-8">
      <manifest>
        <attribute name="Implementation-Version" value="${jni.version} b${jni.build}"/>
        <attribute name="Specification-Version" value="${jni.version}"/>
      </manifest>
    </jar>
    <zip destfile="${build}/build-package-${os.prefix}-${jni.version}.zip">
        <zipfileset dir="native" 
                    prefix="build-package-${os.prefix}-${jni.version}/native"
            >
            <!-- Exclude generated files from the ZIP -->
            <exclude name="libffi/autom4te.cache/**" />
            <exclude name="libffi/Makefile.in" />
            <exclude name="libffi/aclocal.m4" />
            <exclude name="libffi/compile" />
            <exclude name="libffi/config.guess" />
            <exclude name="libffi/config.sub" />
            <exclude name="libffi/configure" />
            <exclude name="libffi/depcomp" />
            <exclude name="libffi/fficonfig.h.in" />
            <exclude name="libffi/install-sh" />
            <exclude name="libffi/ltmain.sh" />
            <exclude name="libffi/mdate-sh" />
            <exclude name="libffi/missing" />
        </zipfileset>
        <zipfileset dir="${build}" includes="${os.prefix}.jar" prefix="build-package-${os.prefix}-${jni.version}"/>
        <zipfileset dir="${build}" includes="build.sh" prefix="build-package-${os.prefix}-${jni.version}"/>
        <zipfileset dir="build/headers" prefix="build-package-${os.prefix}-${jni.version}/headers" />
    </zip>
  </target>

  <target name="native" depends="-enable-native,javah,-native-api-check,-prepare-native" unless="-native"
          description="Build native libraries.  Use 'ant -DCC=xxx' to build using a compiler other than gcc">
    <exec executable="${make}" dir="${native}" failonerror="true">
      <arg value="JAVA_HOME=${jdk.home}"/>
      <arg value="JAVAH=${build.headers}"/>
      <arg value="DEBUG=${debug.native}"/>
      <arg value="CFLAGS_EXTRA=${cflags_extra.native}"/>
      <arg value="DYNAMIC_LIBFFI=${dynlink.native}"/>
      <arg value="${make.CC}"/>
      <arg value="${make.USE_MSVC}"/>
      <arg value="${make.BUILD}"/>
      <arg value="${make.SDKROOT}"/>
      <arg value="${make.ARCH}"/>
      <arg value="${make.PATH}"/>
      <arg value="${make.OS}"/>
      <arg line="${make.OPTS}"/>
      <arg value="JNA_JNI_VERSION=${jni.version}"/>
      <arg value="CHECKSUM=${jni.md5}"/>
    </exec>
    <mkdir dir="${classes}/${native.path}"/>
    <copy todir="${classes}/${native.path}">
      <fileset dir="${build.native}"
               includes="jnidispatch.dll,libjnidispatch.*"/>
    </copy>
    <mkdir dir="${eclipse.classes}/${native.path}"/>
    <copy todir="${eclipse.classes}/${native.path}"
          failonerror="false">
      <fileset dir="${build.native}"
               includes="jnidispatch.dll,libjnidispatch.*"/>
    </copy>
    <!-- For web start, native libraries may be provided in the root of -->
    <!-- an included jar file -->
    <jar jarfile="${build}/${native.jar}" createUnicodeExtraFields="never" encoding="UTF-8">
      <fileset dir="${build.native}" includes="jnidispatch.dll,libjnidispatch.*"/>
      <manifest>
        <attribute name="Implementation-Version" value="${jni.version} b${jni.build}"/>
        <attribute name="Specification-Version" value="${jni.version}"/>
      </manifest>
    </jar>
    <copy todir="${lib.native}">
      <fileset dir="${build}" includes="${native.jar}"/>
    </copy>
  </target>

  <target name="compile-some-tests" depends="compile,jar"
          description="Compile test code which does not have additional native
                       dependencies">
    <javac classpathref="compile-test.path"
           release="${javac.release}"
           includeantruntime="false"
           includes="**/StructureFieldOrderInspector.java"
           destdir="${test.classes}"
           deprecation="on" 
           debug="${debug}"
           encoding="UTF-8"
    >
      <src path="${test.src}"/>
    </javac>
  </target>

  <target name="compile-tests" depends="compile,native,jar"
  	description="Compile all test code">
    <javac classpathref="compile-test.path"
           release="${javac.release}"
           destdir="${test.classes}"
           includeantruntime="false"
           excludes="${tests.exclude-patterns}"
           deprecation="on" 
           debug="${debug}"
           encoding="UTF-8"
    >
      <src path="${test.src}"/>
      <exclude name="${tests.exclude}"/>
    </javac>
    <!-- Embed testlib-jar at root and at default resource path -->
    <mkdir dir="${test.classes}/${resource.prefix}"/>
    <copy todir="${test.classes}">
      <fileset dir="${build.native}">
        <include name="*testlib-jar*"/>
      </fileset>
    </copy>
    <copy todir="${test.classes}/${resource.prefix}">
      <fileset dir="${build.native}">
        <include name="*testlib-jar*"/>
      </fileset>
    </copy>
    <copy todir="${test.classes}">
        <fileset dir="${test.src}">
            <include name="**/data/**" />
        </fileset>
    </copy>
    <!-- Create a jar for easy movement of tests, and jar load test -->
    <jar jarfile="${build}/${testjar}" createUnicodeExtraFields="never" encoding="UTF-8">
      <fileset dir="${test.classes}">
        <patternset refid="jar-compiled"/>
        <include name="**/*testlib-jar*"/>
        <include name="**/data/**" />
      </fileset>
      <manifest>
        <attribute name="permissions" value="all-permissions"/>
      </manifest>
    </jar>

    <!--
        Create test case for darwin - darwin supports two paths: darwin-$arch
        and darwin.

        - The jna-test2.jar is the artifact, that contains the native library
          in darwin-$arch
        - The jna-test3.jar is the artifact, that contains the native library
          in darwin
    -->

    <delete>
        <fileset dir="${test.classes}">
            <include name="*testlib-jar*"/>
        </fileset>
    </delete>

    <jar jarfile="${build}/${testjar2}" createUnicodeExtraFields="never" encoding="UTF-8">
      <fileset dir="${test.classes}">
        <include name="**/*testlib-jar*"/>
      </fileset>
    </jar>

    <condition property="resource.secondary-prefix" value="darwin">
        <matches pattern="^darwin.*" string="${resource.prefix}"/>
    </condition>
    <property name="resource.secondary-prefix" value="${resource.prefix}" />

    <move file="${test.classes}/${resource.prefix}" tofile="${test.classes}/${resource.secondary-prefix}" />

    <jar jarfile="${build}/${testjar3}" createUnicodeExtraFields="never" encoding="UTF-8">
      <fileset dir="${test.classes}">
        <include name="**/*testlib-jar*"/>
      </fileset>
    </jar>

    <!-- Ensure jar-based library is unavailable on FS-based class path -->
    <delete>
      <fileset dir="${build}">
        <include name="**/*testlib-jar*"/>
      </fileset>
    </delete>
    <mkdir dir="${build}/jws"/>
    <copy todir="${build}/jws" file="${build}/${jar}"/>
    <copy todir="${build}/jws" file="${build}/${testjar}"/>
    <copy todir="${build}/jws" file="lib/junit.jar"/>
    <copy todir="${build}/jws" file="lib/clover.jar"/>
    <jar jarfile="${build}/jws/jnidispatch.jar" createUnicodeExtraFields="never" encoding="UTF-8">
      <fileset dir="${build.native}" includes="*jnidispatch.*"/>
    </jar>
    <!-- To allow JNLP tests to run, import the JNA testing certificate as a CA -->
    <!-- keytool -exportcert -file jna.csr -keystore jna.keystore -alias jna -->
    <!-- javaws -viewer (security tab, import CSR as CA-->
    <!--
    <signjar alias="jna" keystore="jna.keystore" storepass="jnadev" lazy="true">
      <fileset dir="${build}/jws" includes="${jar},${testjar},junit.jar,jnidispatch.jar,clover.jar"/>
    </signjar>
    -->
  </target>

  <target name="android-test-setup" depends="compile-tests"
          description="Configure tests for running on an Android emulator">
    <!-- 'shared' should be the path to a folder mounted as the mobile
         device/simulator storage card. -->
    <property name="shared" value="shared"/>
  </target>

  <target name="wince-test-setup" depends="compile-tests"
          description="Configure tests for running on the WM emulator">
    <!-- 'shared' should be the path to a folder mounted as the mobile
         device/simulator storage card. -->
    <property name="shared" value="shared"/>
    <!-- w32ce arm testing -->
    <jar jarfile="${shared}/test.jar" createUnicodeExtraFields="never" encoding="UTF-8">
      <zipfileset src="${build}/${jar}"/>
      <zipfileset src="${build}/${testjar}"/>
    </jar>
    <copy todir="${shared}" file="${build}/${jar}"/>
    <copy todir="${shared}" file="${build.native}/jnidispatch.dll"/>
    <copy todir="${shared}" file="${build.native}/testlib.dll"/>
    <copy todir="${shared}" file="${build.native}/testlib2.dll"/>
    <copy todir="${shared}" file="${build.native}/test-path.dll"/>
    <copy todir="${shared}" file="${build.native}/testlib-truncated"/>
    <copy todir="${shared}" file="w32ce-test.lnk"/>
    <chmod file="${shared}/*.dll" perm="+x"/>
  </target>

  <target name="-enable-native" unless="-native">
    <property name="build-native" value="true"/>
  </target>

  <!-- When running tests from an IDE, be sure to set jna.library.path -->
  <!-- to where the test library (testlib) is found.                   -->
  <target name="test" depends="-enable-native,jar,compile-tests" unless="cross-compile"
          description="Run all unit tests">

    <property name="test.fork" value="yes"/>
    <property name="test.forkmode" value="perTest"/>

    <condition property="test.jdwp" value="-Xrunjdwp:transport=dt_socket,address=${test.debugport},server=y,suspend=y">
        <isset property="test.debugport" />
    </condition>

    <property name="reports.junit" location="${reports}/junit/${os.prefix}"/>
    <property name="results.junit" location="${build}/junit-results/${os.prefix}"/>
    <mkdir dir="${results.junit}"/>
    <echo>Saving test results in ${results.junit}</echo>
    <property name="tests.stdcall" value="**/win32/*StdCallTest.java"/>
    <condition property="tests.platform" value="**/win32/**/*Test.java">
      <os family="windows"/>
    </condition>
    <condition property="tests.exclude" value="${tests.stdcall}">
      <and><os family="windows"/><not><os arch="x86"/></not></and>
    </condition>
    <condition property="tests.platform" value="**/mac/**/*Test.java">
      <os family="mac"/>
    </condition>
    <condition property="tests.platform" value="**/unix/**/*Test.java">
      <and>
        <os family="unix"/>
        <not><os family="mac"/></not>
      </and>
    </condition>
    <property name="tests.platform" value=""/>
    <property name="tests.include" value="com/sun/jna/*Test.java com/sun/jna/different_package/*Test.java"/>
    <property name="tests.exclude" value=""/>
    <property name="tests.exclude-patterns" value=""/>
    <condition property="java.awt.headless" value="true">
      <isset property="headless"/>
    </condition>
    <propertyset id="headless">
      <propertyref prefix="java.awt.headless"/>
    </propertyset>
    <junit fork="${test.fork}" forkmode="${test.forkmode}" failureproperty="testfailure" tempdir="${build}">
      <jvmarg if:set="test.jdwp" value="${test.jdwp}" />
      <!-- optionally run headless -->
      <syspropertyset refid="headless"/>
      <!-- avoid VM conflicts with JNA protected mode -->
      <env key="${ld.preload.name}" file="${libjsig}"/>
      <env key="LC_MESSAGES" value="C" />
      <sysproperty key="jna.library.path" file="${build.native}"/>
      <!-- Ignore any system install of JNA -->
      <sysproperty key="jna.nosys" value="true"/>
      <sysproperty key="jna.builddir" file="${build}"/>
      <sysproperty key="jna.nativedir" file="${build.native}"/>
      <classpath><path refid="test.runpath"/></classpath>
      <formatter type="brief" usefile="false"/>
      <formatter type="xml"/>
      <batchtest todir="${results.junit}">
        <fileset dir="${test.src}" excludes="${tests.exclude-patterns}">
          <patternset includes="${tests.include}"/>
          <include name="${tests.platform}"/>
          <exclude name="${tests.exclude}"/>
        </fileset>
      </batchtest>
    </junit>
    <junitreport todir="${results.junit}">
      <fileset dir="${results.junit}">
        <include name="TEST-*.xml"/>
      </fileset>
      <report todir="${reports.junit}"/>
    </junitreport>
    <echo>View test report in file://${reports.junit}/index.html</echo>
    <fail if="testfailure" unless="clover">One or more tests failed</fail>
  </target>

  <target name="test-platform" depends="compile-some-tests,platform-jar"
          description="Run platform-specific tests">
    <subant target="test" failonerror="true">
      <property name="javac.release" value="${javac.release}"/>
      <fileset dir="${contrib}" includes="platform/build.xml"/>
    </subant>
  </target>

  <target name="with.clover" description="Enable code coverage for tests">
    <taskdef resource="cloverlib.xml" classpath="lib/clover.jar"/>
    <property name="clover" value="true"/>
    <property name="build" value="build.clover"/>
    <clover-setup/>
  </target>

  <target name="clover" depends="with.clover,test"
          description="Generate test code coverage reports">
    <property name="reports.clover" value="${reports}/clover"/>
    <mkdir dir="${reports.clover}"/>
    <clover-report>
      <current outfile="${reports.clover}" title="clover">
        <fileset dir="." includes="**/*.java" />
        <testresults dir="${results.junit}" includes="TEST-*.xml"/>
        <format type="html"/>
      </current>
    </clover-report>
    <echo>Reports generated in ${reports.clover}</echo>
  </target>

  <target name="javadoc" depends="-setup">
    <path id="javadoc.src.path">
      <path refid="src.path"/>
      <pathelement location="${platform.src}"/>
    </path>
    <path id="javadoc.compile.path">
      <path refid="compile.path"/>
      <pathelement location="${classes}"/>
    </path>
    <property name="header"
              value="&lt;b&gt;JNA API&lt;/&gt;&lt;font size=&quot;-1&quot;&gt; ${jna.version}&lt;/font&gt;"/>
    <property name="footer"
              value="&lt;center&gt;&lt;i&gt;${copyright}&lt;/i&gt;&lt;/center&gt;"/>

    <mkdir dir="${javadoc}"/>
    <condition property="javadoc.opts" value="-Xdoclint:none" else="">
      <not><matches pattern="^1.[0-7]$" string="${ant.java.version}"/></not>
    </condition>
    <javadoc package="true"
             windowtitle="JNA API"
             encoding="UTF-8"
             sourcepathref="javadoc.src.path"
             classpathref="javadoc.compile.path"
             maxmemory="256m"
             packagenames="com.sun.jna,com.sun.jna.ptr,com.sun.jna.types,com.sun.jna.platform,com.sun.jna.platform.win32"
             overview="${src}/com/sun/jna/overview.html"
             additionalparam="${javadoc.opts}"
             destdir="${javadoc}">
      <!-- stylesheetfile="${stylesheet}" -->
      <doctitle>JNA API Documentation</doctitle>
      <header>${header}</header>
      <bottom>${footer}</bottom>
      <link href="http://download.oracle.com/javase/${javac.release}/docs/api/"/>

      <packageset dir="${src}" defaultexcludes="yes">
        <patternset>
          <include name="com/sun/jna/**/*"/>
        </patternset>
      </packageset>
      <packageset dir="${platform.src}" defaultexcludes="yes">
        <patternset>
          <include name="com/sun/jna/platform/**/*"/>
        </patternset>
      </packageset>

      <group title="Java Native Access" packages="com.sun.jna,com.sun.jna.ptr,com.sun.jna.types,com.sun.jna.win32"/>
      <group title="Platform Utilities" packages="com.sun.jna.platform,com.sun.jna.platform.dnd"/>
      <group title="Platform Specific" packages="com.sun.jna.platform.*"/>

      <arg value="-notimestamp"/>
    </javadoc>
    <jar jarfile="${platform-javadoc-jar}" createUnicodeExtraFields="never" encoding="UTF-8">
      <fileset dir="${javadoc}" />
    </jar>
  </target>

  <target name="dist" depends="jar,aar,javadoc,contrib-jars,compile-tests,native"
          description="Build distribution files">
    <copy todir="${dist}" force="true" overwrite="true">
      <fileset dir="${build}" includes="${jar},${minjar},${aar},${jar-jpms}"/>
      <fileset dir="${contrib}/platform/dist" includes="jna-platform.jar,jna-platform-jpms.jar"/>
      <fileset dir="${lib.native}">
        <include name="*.jar"/>
        <exclude name="out-of-date.jar"/>
      </fileset>
    </copy>
    <copy todir="${dist}/jnacontrib" flatten="true">
      <fileset dir="${contrib}">
	<include name="**/build/demo-*.jar" />
      </fileset>
    </copy>
    <jar jarfile="${maven-javadoc-jar}" createUnicodeExtraFields="never" encoding="UTF-8">
        <fileset dir="${javadoc}" />
    </jar>

    <zip zipfile="${dist}/doc.zip">
      <zipfileset dir="${javadoc}" prefix="javadoc"/>
    </zip>
    <!-- Javadoc -->
    <!-- JNA sources only, for use in Linux build from source/shared libffi -->
    <zip zipfile="${dist}/src.zip">
      <zipfileset dir="." includes="build.xml,${pom},LICENSE,LGPL2.1,AL2.0"/>
      <zipfileset dir="${src}" includes="**/*.java" prefix="src"/>
      <zipfileset dir="${test.src}" includes="**/*.java" prefix="test"/>
      <zipfileset dir="${native}" excludes="libffi,libffi/**/*,build,build/**/*" prefix="native"/>
      <zipfileset dir="${contrib}/platform" includes="**/*.java" prefix="contrib/platform"/>
    </zip>
    <!-- Full sources required to build and test everything -->
    <zip zipfile="${dist}/src-full.zip">
      <zipfileset src="${dist}/src.zip"/>
      <zipfileset dir="lib" includes="junit.jar,clover.jar" prefix="lib"/>
      <zipfileset dir="." includes=".classpath,.project"/>
      <zipfileset dir="${native}" includes="libffi,libffi/**/*" prefix="native"/>
    </zip>
    <!-- Sources package as required by maven -->
    <zip zipfile="${maven-sources-jar}">
      <zipfileset dir="${src}" />
    </zip>
  </target>

  <target name="clean" depends="-dynamic-properties">
    <delete failOnError="false" includeEmptyDirs="true">
      <fileset dir="${build}"/>
    </delete>
    <delete quiet="true" includeEmptyDirs="true">
      <fileset dir=".clover"/>
      <fileset dir="build.clover" />
      <fileset dir="${javadoc}"/>
      <fileset dir="." includes="*~,**/*~,build.number,native/libffi/configure"/>
    </delete>
    <subant target="clean" failonerror="true">
      <fileset dir="${contrib}" includes="*/build.xml"/>
    </subant>
  </target>

  <target name="install" depends="dist" description="Install jna and jna-platform artifacts into local maven repository">
    <exec executable="mvn" searchpath="true" failonerror="true" failifexecutionfails="true" logError="true">
      <arg value="org.apache.maven.plugins:maven-install-plugin:2.5:install-file"/>
      <arg value="-DpomFile=${pom}"/>
      <arg value="-Dfile=${dist-jar}"/>
      <arg value="-Dsources=${maven-sources-jar}"/>
      <arg value="-Djavadoc=${maven-javadoc-jar}"/>
    </exec>

    <exec executable="mvn" searchpath="true" failonerror="true" failifexecutionfails="true" logError="true">
      <arg value="org.apache.maven.plugins:maven-install-plugin:2.5:install-file"/>
      <arg value="-DpomFile=${pom}"/>
      <arg value="-Dfile=${dist-aar}"/>
      <arg value="-Dpackaging=aar"/>
    </exec>

    <exec executable="mvn" searchpath="true" failonerror="true" failifexecutionfails="true" logError="true">
      <arg value="org.apache.maven.plugins:maven-install-plugin:2.5:install-file"/>
      <arg value="-DpomFile=${pom-jpms}"/>
      <arg value="-Dfile=${dist-jar-jpms}"/>
      <arg value="-Dsources=${maven-sources-jar}"/>
      <arg value="-Djavadoc=${maven-javadoc-jar}"/>
    </exec>

    <exec executable="mvn" searchpath="true" failonerror="true" failifexecutionfails="true" logError="true">
      <arg value="org.apache.maven.plugins:maven-install-plugin:2.5:install-file"/>
      <arg value="-DpomFile=${pom-platform}"/>
      <arg value="-Dfile=${platform-jar}"/>
      <arg value="-Dsources=${platform-sources-jar}"/>
      <arg value="-Djavadoc=${platform-javadoc-jar}"/>
    </exec>

    <exec executable="mvn" searchpath="true" failonerror="true" failifexecutionfails="true" logError="true">
      <arg value="org.apache.maven.plugins:maven-install-plugin:2.5:install-file"/>
      <arg value="-DpomFile=${pom-platform-jpms}"/>
      <arg value="-Dfile=${platform-jpms-jar}"/>
      <arg value="-Dsources=${platform-sources-jar}"/>
      <arg value="-Djavadoc=${platform-javadoc-jar}"/>
    </exec>
  </target>

  <!-- NOTE: The 'deploy' target works only if the version (jna.version in build.xml) ends in '-SNAPSHOT'. -->
  <target name="deploy" depends="dist" description="deploy snapshot version to Maven snapshot repository">
    <exec executable="mvn" searchpath="true" failonerror="true" failifexecutionfails="true" logError="true">
      <arg value="org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file"/>
      <arg value="-Durl=${maven-snapshots-repository-url}"/>
      <arg value="-DrepositoryId=${maven-snapshots-repository-id}"/>
      <arg value="-DpomFile=${pom}"/>
      <arg value="-Dfile=${dist-jar}"/>
      <arg value="-Dfiles=${maven-sources-jar},${maven-javadoc-jar},${dist-aar}"/>
      <arg value="-Dtypes=jar,jar,aar"/>
      <arg value="-Dclassifiers=sources,javadoc,"/>
    </exec>

    <exec executable="mvn" searchpath="true" failonerror="true" failifexecutionfails="true" logError="true">
      <arg value="org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file"/>
      <arg value="-Durl=${maven-snapshots-repository-url}"/>
      <arg value="-DrepositoryId=${maven-snapshots-repository-id}"/>
      <arg value="-DpomFile=${pom-platform}"/>
      <arg value="-Dfile=${platform-jar}"/>
      <arg value="-Dfiles=${platform-sources-jar},${platform-javadoc-jar}"/>
      <arg value="-Dtypes=jar,jar"/>
      <arg value="-Dclassifiers=sources,javadoc"/>
    </exec>

    <exec executable="mvn" searchpath="true" failonerror="true" failifexecutionfails="true" logError="true">
      <arg value="org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file"/>
      <arg value="-Durl=${maven-snapshots-repository-url}"/>
      <arg value="-DrepositoryId=${maven-snapshots-repository-id}"/>
      <arg value="-DpomFile=${pom-jpms}"/>
      <arg value="-Dfile=${dist-jar-jpms}"/>
      <arg value="-Dfiles=${maven-sources-jar},${maven-javadoc-jar}"/>
      <arg value="-Dtypes=jar,jar"/>
      <arg value="-Dclassifiers=sources,javadoc"/>
    </exec>

    <exec executable="mvn" searchpath="true" failonerror="true" failifexecutionfails="true" logError="true">
      <arg value="org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file"/>
      <arg value="-Durl=${maven-snapshots-repository-url}"/>
      <arg value="-DrepositoryId=${maven-snapshots-repository-id}"/>
      <arg value="-DpomFile=${pom-platform-jpms}"/>
      <arg value="-Dfile=${platform-jpms-jar}"/>
      <arg value="-Dfiles=${platform-sources-jar},${platform-javadoc-jar}"/>
      <arg value="-Dtypes=jar,jar"/>
      <arg value="-Dclassifiers=sources,javadoc"/>
    </exec>
  </target>


  <property name="version-maven-gpg-plugin" value="1.4"/>

  <target name="stage" depends="dist" description="deploy release version to Maven staging repository">
    <!-- sign and deploy the jna,  artifact -->
    <exec executable="mvn" searchpath="true" failonerror="true" failifexecutionfails="true" logError="true">
      <arg value="org.apache.maven.plugins:maven-gpg-plugin:${version-maven-gpg-plugin}:sign-and-deploy-file"/>
      <arg value="-Durl=${maven-staging-repository-url}"/>
      <arg value="-DrepositoryId=${maven-staging-repository-id}"/>
      <arg value="-DpomFile=${pom}"/>
      <arg value="-Dfile=${dist-jar}"/>
      <arg value="-Dfiles=${maven-sources-jar},${maven-javadoc-jar},${dist-aar}"/>
      <arg value="-Dclassifiers=sources,javadoc,"/>
      <arg value="-Dtypes=jar,jar,aar"/>
      <arg value="-Dgpg.useagent=true"/>
    </exec>

    <!-- sign and deploy the platform artifact -->
    <exec executable="mvn" searchpath="true" failonerror="true" failifexecutionfails="true" logError="true">
      <arg value="org.apache.maven.plugins:maven-gpg-plugin:${version-maven-gpg-plugin}:sign-and-deploy-file"/>
      <arg value="-Durl=${maven-staging-repository-url}"/>
      <arg value="-DrepositoryId=${maven-staging-repository-id}"/>
      <arg value="-DpomFile=${pom-platform}"/>
      <arg value="-Dfile=${platform-jar}"/>
      <arg value="-Dfiles=${platform-sources-jar},${platform-javadoc-jar}"/>
      <arg value="-Dclassifiers=sources,javadoc"/>
      <arg value="-Dtypes=jar,jar"/>
      <arg value="-Dgpg.useagent=true"/>
    </exec>

    <!-- sign and deploy the jna,  artifact -->
    <exec executable="mvn" searchpath="true" failonerror="true" failifexecutionfails="true" logError="true">
      <arg value="org.apache.maven.plugins:maven-gpg-plugin:${version-maven-gpg-plugin}:sign-and-deploy-file"/>
      <arg value="-Durl=${maven-staging-repository-url}"/>
      <arg value="-DrepositoryId=${maven-staging-repository-id}"/>
      <arg value="-DpomFile=${pom-jpms}"/>
      <arg value="-Dfile=${dist-jar-jpms}"/>
      <arg value="-Dfiles=${maven-sources-jar},${maven-javadoc-jar}"/>
      <arg value="-Dtypes=jar,jar"/>
      <arg value="-Dclassifiers=sources,javadoc"/>
      <arg value="-Dgpg.useagent=true"/>
    </exec>

    <!-- sign and deploy the platform artifact -->
    <exec executable="mvn" searchpath="true" failonerror="true" failifexecutionfails="true" logError="true">
      <arg value="org.apache.maven.plugins:maven-gpg-plugin:${version-maven-gpg-plugin}:sign-and-deploy-file"/>
      <arg value="-Durl=${maven-staging-repository-url}"/>
      <arg value="-DrepositoryId=${maven-staging-repository-id}"/>
      <arg value="-DpomFile=${pom-platform-jpms}"/>
      <arg value="-Dfile=${platform-jpms-jar}"/>
      <arg value="-Dfiles=${platform-sources-jar},${platform-javadoc-jar}"/>
      <arg value="-Dtypes=jar,jar"/>
      <arg value="-Dclassifiers=sources,javadoc"/>
      <arg value="-Dgpg.useagent=true"/>
    </exec>
  </target>

  <target name="checkstyle">
      <taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties"
               classpath="lib/checkstyle-8.17-all.jar"/>
      <checkstyle config="checkstyle.xml">
          <fileset dir="." includes="**/*.java"/>
      </checkstyle>
  </target>
</project>
