<!-- Ant build script for ProGuard. -->

<project name    = "proguard"
         default = "all"
         basedir = "..">

  <property file = "build/build.properties"/>
  <property name = "src"     value = "src"/>
  <property name = "classes" value = "classes"/>
  <property name = "lib"     value = "lib"/>

  <property name = "gradle.jar1" value = "${gradle.home}/lib/plugins/gradle-plugins-2.1.jar"/>
  <property name = "gradle.jar2" value = "${gradle.home}/lib/gradle-base-services-2.1.jar"/>
  <property name = "gradle.jar3" value = "${gradle.home}/lib/gradle-base-services-groovy-2.1.jar"/>
  <property name = "gradle.jar4" value = "${gradle.home}/lib/gradle-core-2.1.jar"/>
  <property name = "gradle.jar5" value = "${gradle.home}/lib/groovy-all-2.3.6.jar"/>
  <property name = "wtk.jar"     value = "${wtk.home}/wtklib/kenv.zip"/>

  <target name = "all"     depends = "basic,options"/>
  <target name = "basic"   depends = "proguard,proguardgui,retrace"/>
  <target name = "options" depends = "anttask,wtkplugin"/>

  <target name = "proguard" depends = "classes,lib">
    <javac nowarn            = "true"
           deprecation       = "false"
           includeantruntime = "false"
           srcdir            = "${src}"
           destdir           = "${classes}"
           includes          = "proguard/ProGuard.java">
      <compilerarg value = "-Xlint:none"/>
    </javac>

    <copy todir = "${classes}">
      <fileset dir = "${src}">
        <include name = "proguard/*.properties"/>
        <include name = "proguard/*.png"/>
        <include name = "proguard/*.gif"/>
        <include name = "proguard/*.pro"/>
      </fileset>
    </copy>

    <jar jarfile  = "${lib}/proguard.jar"
         manifest = "${src}/proguard/MANIFEST.MF"
         basedir  = "${classes}"
         includes = "proguard/**"/>
  </target>

  <target name = "proguardgui" depends = "proguard">
    <javac nowarn            = "true"
           deprecation       = "false"
           includeantruntime = "false"
           srcdir            = "${src}"
           destdir           = "${classes}"
           includes          = "proguard/gui/ProGuardGUI.java">
      <compilerarg value = "-Xlint:none"/>
    </javac>

    <copy todir = "${classes}">
      <fileset dir = "${src}">
        <include name = "proguard/gui/*.properties"/>
        <include name = "proguard/gui/*.png"/>
        <include name = "proguard/gui/*.gif"/>
        <include name = "proguard/gui/*.pro"/>
      </fileset>
    </copy>

    <jar jarfile  = "${lib}/proguardgui.jar"
         manifest = "${src}/proguard/gui/MANIFEST.MF"
         basedir  = "${classes}"
         includes = "proguard/gui/**"/>
  </target>

  <target name = "retrace" depends = "classes,lib">
    <javac nowarn            = "true"
           deprecation       = "false"
           includeantruntime = "false"
           srcdir            = "${src}"
           destdir           = "${classes}"
           includes          = "proguard/retrace/ReTrace.java">
      <compilerarg value = "-Xlint:none"/>
    </javac>

    <copy todir = "${classes}">
      <fileset dir = "${src}">
        <include name = "proguard/retrace/*.properties"/>
        <include name = "proguard/retrace/*.png"/>
        <include name = "proguard/retrace/*.gif"/>
        <include name = "proguard/retrace/*.pro"/>
      </fileset>
    </copy>

    <jar jarfile  = "${lib}/retrace.jar"
         manifest = "${src}/proguard/retrace/MANIFEST.MF"
         basedir  = "${classes}"
         includes = "proguard/retrace/**"/>
  </target>

  <target name = "anttask" depends = "proguard">
    <javac nowarn            = "true"
           deprecation       = "false"
           includeantruntime = "true"
           srcdir            = "${src}"
           destdir           = "${classes}"
           includes          = "proguard/ant/ProGuardTask.java">
      <compilerarg value = "-Xlint:none"/>
    </javac>

    <copy todir = "${classes}">
      <fileset dir = "${src}">
        <include name = "proguard/ant/*.properties"/>
        <include name = "proguard/ant/*.png"/>
        <include name = "proguard/ant/*.gif"/>
        <include name = "proguard/ant/*.pro"/>
      </fileset>
    </copy>

    <jar jarfile  = "${lib}/proguard.jar"
         update   = "true"
         basedir  = "${classes}"
         includes = "proguard/ant/**"/>
  </target>

  <target name = "gradletask" depends = "proguard">
    <fail message="Please set the value of the property gradle.home in the file build.properties, if you want to build the optional ProGuard Gradle task.">
      <condition>
        <not>
          <and>
            <available file="${gradle.jar1}"/>
            <available file="${gradle.jar2}"/>
            <available file="${gradle.jar3}"/>
            <available file="${gradle.jar4}"/>
            <available file="${gradle.jar5}"/>
          </and>
        </not>
      </condition>
    </fail>

    <javac nowarn            = "true"
           deprecation       = "false"
           includeantruntime = "false"
           srcdir            = "${src}"
           destdir           = "${classes}"
           includes          = "proguard/gradle/ProGuardTask.java">
      <compilerarg value = "-Xlint:none"/>
      <classpath>
        <path location="${gradle.jar1}"/>
        <path location="${gradle.jar2}"/>
        <path location="${gradle.jar3}"/>
        <path location="${gradle.jar4}"/>
        <path location="${gradle.jar5}"/>
      </classpath>
    </javac>

    <copy todir = "${classes}">
      <fileset dir = "${src}">
        <include name = "proguard/gradle/*.properties"/>
        <include name = "proguard/gradle/*.png"/>
        <include name = "proguard/gradle/*.gif"/>
        <include name = "proguard/gradle/*.pro"/>
      </fileset>
    </copy>

    <jar jarfile  = "${lib}/proguard.jar"
         update   = "true"
         basedir  = "${classes}"
         includes = "proguard/gradle/**"/>
  </target>

  <target name = "wtkplugin" depends = "proguard">
    <fail message="Please set the value of the property wtk.home in the file build.properties, if you want to build the optional ProGuard WTK plugin.">
      <condition>
        <not>
          <available file="${wtk.jar}"/>
        </not>
      </condition>
    </fail>

    <javac nowarn            = "true"
           deprecation       = "false"
           includeantruntime = "false"
           classpath         = "${wtk.jar}"
           srcdir            = "${src}"
           destdir           = "${classes}"
           includes          = "proguard/wtk/ProGuardObfuscator.java">
      <compilerarg value = "-Xlint:none"/>
    </javac>

    <copy todir = "${classes}">
      <fileset dir = "${src}">
        <include name = "proguard/wtk/*.properties"/>
        <include name = "proguard/wtk/*.png"/>
        <include name = "proguard/wtk/*.gif"/>
        <include name = "proguard/wtk/*.pro"/>
      </fileset>
    </copy>

    <jar jarfile  = "${lib}/proguard.jar"
         update   = "true"
         basedir  = "${classes}"
         includes = "proguard/wtk/**"/>
  </target>

  <target name = "classes">
    <mkdir dir = "${classes}"/>
  </target>

  <target name = "lib">
    <mkdir dir = "${lib}"/>
  </target>

  <target name = "clean">
    <delete>
      <fileset dir = "${classes}"/>
      <fileset dir = "${lib}"/>
    </delete>
  </target>
</project>