<project>

    <!-- Target machine and source language.
         There is a split between Java 8 and Java 9. This is a build file for
         Java 9 and up. Sorry.
    --> 
    <property name="targetJVM"  value="11" /> 
    <property name="sourceJava" value="11" /> 
    <!-- 'target' property is either OSX or standard 
	     'os' is OSX, Linux or Windows
	  -->
    
    <!-- Use environment to acquire JAPE version: too many differences in behaviour of
         shell+make between Linux and OS/X to do this by passing a -D parameter to ant.
    -->
    <property environment="environment"/> 
    <condition property="GUIVERSION" value="${environment.JAPEVERSION}" else="JAPE VERSION UNSPECIFIED">
     <isset property="environment.JAPEVERSION"/>
    </condition>

    <target name="clean">
        <delete quiet="true" dir="build/classes/${target}" />
        <delete quiet="true" dir="build/jre/${os}" />
        <delete quiet="true" file="src/base/uk/org/jape/Version.java" />
    </target>

    <target name="OSXcompile">
        <mkdir dir="build/classes"/>
        <mkdir dir="build/classes/OSX"/>
        <javac 
            source = "${sourceJava}"
            target = "${targetJVM}"
            deprecation="on"
            debug="on"
            debuglevel="source,lines"
            includeantruntime="false"
            sourcepath="."
            srcdir="src/base:src/OSX:src/module"
            destdir="build/classes/OSX"
        >
        </javac>
    </target>

    <target name="standardcompile" depends="version">
        <mkdir dir="build/classes"/>
        <mkdir dir="build/classes/standard"/>
        <javac 
            source = "${sourceJava}"
            target = "${targetJVM}"
            deprecation="on"
            debug="on"
            debuglevel="source,lines"
            sourcepath=""
            srcdir="src/base:src/standard:src/module"
            destdir="build/classes/standard"
        />
    </target>

    <target name="version">
	<delete quiet="true" file="build/classes/standard/uk/org/jape/Version.class"> </delete>
	<delete quiet="true" file="build/classes/standard/uk/org/jape/AboutBox.class"> </delete>
        <echo force="true" file="src/base/uk/org/jape/Version.java">
            package uk.org.jape; 
            public class Version { 
                static final String guiversion = "${GUIVERSION}"; 
            }
        </echo>
    </target>
    
    <target name="OSX.jar" depends="version,OSXcompile">
        <mkdir dir="build/jar/OSX"/>
        <jar destfile="build/jar/OSX/uk.org.jape.jar" 
             basedir="build/classes/OSX"
             includes = "**/*.class"
             update="yes"
             duplicate="fail"
             >
        </jar>
    </target>
    
    <target name="standard.jar" depends="version,standardcompile">
        <mkdir dir="build/jar/standard"/>
        <jar destfile="build/jar/standard/uk.org.jape.jar" 
             basedir="build/classes/standard"
             includes = "**/*.class"
             update="yes"
             duplicate="fail"
             >
        </jar>
    </target>
    
    <!-- no longer needed, I think
    <target name="run" depends="Jape.jar">
        <java jar="build/jar/standard/Jape.jar" fork="true"/>
    </target>
      -->

    <target name="jdepsclean">
        <delete file="src/module/uk.org.jape/module-info.java" />
        <delete file="build/classes/${target}/module-info.class" />
        <delete file="build/jar/${target}/uk.org.jape.jar" />
    </target>
    
    <target name="uk.org.jape.jar" depends="version,jdepsclean"
        description="Build a jre standalone-application">
        <antcall target="${target}.jar" />
        <exec executable="jdeps" failifexecutionfails="true">
            <arg value="--generate-module-info" />
            <arg value="src/module" />
            <arg value="build/jar/${target}/uk.org.jape.jar" />
        </exec>   
        <antcall target="${target}.jar" />
        <!-- <OSXjar/>
        <delete file="build/Jape.jmod"/>
        <delete dir="build/jre"/>
        <jmod destfile="build/Jape.jmod" classpath="../java_GUI/build/classes/OSX" mainclass="uk.org.jape.Jape"/>
        <link destDir="build/jre" modulepath="build/Jape.jmod" modules="uk.org.jape">
            <launcher name="jape" module="uk.org.jape" mainClass="uk.org.jape.Jape" />
        </link> -->
    </target>

    <target name="jre" description="Build a minimal jre">
        <mkdir dir="build/jmod"/>
        <mkdir dir="build/jmod/${target}"/>
        <mkdir dir="build/jre"/>
        <mkdir dir="build/jre/${os}"/>
        <delete file="build/jmod/${target}/Jape.jmod"/>
        <delete dir="build/jre/${os}/jre"/>
        <jmod destfile="build/jmod/${target}/Jape.jmod" classpath="build/jar/${target}/uk.org.jape.jar" mainclass="uk.org.jape.Jape"/>
        <!-- ant link is java jlink -->
        <!-- force inclusion of jdk.accessibility, to get Access Bridge. This is mad, but blame Oracle. On startup, if the user has
             activated jabswitch, it looks for Access Bridge to implement Tool Tips on Windows, and that's in jdk.accessibility.
             Thanks to StackOverflow for the fix, which is third answer in this:
               https://stackoverflow.com/questions/15260989/exception-in-thread-main-java-awt-awterror-assistive-technology-not-found
         -->
        <link destDir="build/jre/${os}/jre" modulepath="build/jmod/${target}" modules="uk.org.jape,jdk.accessibility" includeManPages="false" includeHeaders="false">
        </link>
    </target>
    

</project>







