<?xml version="1.0"?>
<project name="PROJ bridge to Java" default="compile" basedir=".">

    <!-- *******************************************
             Set directory paths and versions.
         ******************************************* -->
    <property name="src"      value="."/>
    <property name="out"      value="out"/>
    <property name="classes"  value="${out}/classes"/>
    <property name="javadoc"  value="${out}/apidocs"/>
    <property name="module"   value="org.osgeo.proj"/>
    <property name="version"  value="3.0"/>             <!-- See "Versions" section in README.md -->

    <!-- *******************************************
             Compile (default target).
             Include generation of JNI header.
         ******************************************* -->
    <target name="compile">
        <mkdir dir="${out}"/>
        <mkdir dir="${classes}"/>
        <javac modulesourcepath="${src}" destdir="${classes}" encoding="UTF-8" nativeheaderdir="${src}"
               createMissingPackageInfoClass = "false"
               includeAntRuntime = "false">
            <compilerarg line="--module-version ${version}"/>
        </javac>

        <!-- Move the .h files generated by javac. -->
        <move todir="../src">
            <fileset dir="${src}/${module}">
                <include name="org_*.h"/>
            </fileset>
        </move>

        <jar destfile="${out}/proj.jar" basedir="${classes}/${module}" level="9" strict="fail">
            <manifest>
                <attribute name="Implementation-Title"   value="PROJ bridge to Java"/>
                <attribute name="Implementation-Version" value="${version}"/>
                <attribute name="Implementation-Vendor"  value="Proj.4 project"/>
                <attribute name="Implementation-URL"     value="https://proj.org/"/>
            </manifest>
        </jar>
    </target>

    <!-- **********************************************************
             Build and create documentation.
         ********************************************************** -->
    <target name="javadoc" depends="compile">
        <javadoc classpath="${classes}/${module}" destdir="${javadoc}"
                 encoding="UTF-8" noqualifier="all" windowtitle="PROJ bridge to Java" author="false" version="true"
                 link="http://www.geoapi.org/3.0/javadoc/" additionalparam="-html5">
          <sourcefiles>
            <fileset dir="${src}/${module}">
                <include name="org/**/*.java"/>
                <exclude name="module-info.java"/>
            </fileset>
          </sourcefiles>
        </javadoc>
    </target>

    <!-- *******************************************
             Clean up everything.
         ******************************************* -->
    <target name="clean">
        <delete dir="${out}"/>
    </target>

</project>
