<project name="linux" default="jar">

  <tstamp/>

  <!--===== Properties =====================================================-->

  <property name="common-dir" value="../lightcrafts"/>

  <!-- The default maxmemory for the run* targets. -->
  <property name="maxmemory" value="512m"/>

  <exec executable="cat" vmlauncher="true" failonerror="true"
        outputproperty="app-version">
    <arg value="${common-dir}/version.txt"/>
  </exec>

  <property name="JVMARG" value=""/>

  <!--===== Application build ==============================================-->

  <condition property="MAKE" value="make">
    <not>
      <or>
        <os name="freebsd"/>
        <os name="SunOS"/>
      </or>
    </not>
  </condition>
  <condition property="MAKE" value="gmake">
    <or>
      <os name="freebsd"/>
      <os name="SunOS"/>
    </or>
  </condition>

  <target name="common">
    <ant dir="${common-dir}" target="jar"/>
    <exec executable="${MAKE}" dir="products" failonerror="true"
          vmlauncher="true">
      <arg value="-j"/>
    </exec>
  </target>

  <target name="javac" depends="common">
    <mkdir dir="build"/>
    <mkdir dir="javah"/>
    <javac destdir="build" includeantruntime="false" debug="true"
           release="11" nativeheaderdir="javah">
      <src path="src"/>
      <classpath>
        <fileset dir="${common-dir}/products">
          <include name="*.jar"/>
        </fileset>
        <fileset dir="/usr">
          <include name="share/java*/**/*.jar"/>
          <include name="local/share/java/classes/*.jar"/>
          <include name="jdk/packages/lib/ext/*.jar"/>
        </fileset>
      </classpath>
    </javac>
  </target>

  <target name="jni">
    <exec executable="${MAKE}" dir="jnisrc" failonerror="true" vmlauncher="true"/>
  </target>

  <target name="locales">
    <copy todir="build">
      <fileset dir="locale" excludes=".git"/>
    </copy>
  </target>

  <target name="help">
    <ant dir="help" target="build"/>
  </target>

  <target name="build" depends="javac, jni, locales, help"/>

  <!--===== Make the jar files =============================================-->

  <target name="jar" depends="build">
    <delete file="products/lightcrafts-linux.jar"/>
    <jar jarfile="products/lightcrafts-linux.jar">
      <fileset dir="build"/>
      <manifest>
        <attribute name="Built-By" value="${user.name}"/>
        <attribute name="Implementation-Vendor" value="Light Crafts, Inc."/>
        <attribute name="Implementation-Version"
                   value="${app-version} ${TODAY}"/>
      </manifest>
    </jar>
  </target>

  <!--===== Run the application ============================================-->

  <target name="run">
    <java classname="com.lightcrafts.platform.linux.LinuxLauncher"
          dir="products" failonerror="true" fork="true"
          maxmemory="${maxmemory}">
      <jvmarg line="${JVMARG}"/>
      <classpath>
        <fileset dir="products">
          <include name="*.jar"/>
        </fileset>
        <fileset dir="/usr">
          <include name="share/java*/**/*.jar"/>
          <include name="local/share/java/classes/*.jar"/>
          <include name="jdk/packages/lib/ext/*.jar"/>
        </fileset>
      </classpath>
      <env key="LD_LIBRARY_PATH" value="."/>
      <sysproperty key="java.library.path" value="."/>
      <sysproperty key="lightcrafts.debug" value="1"/>
    </java>
  </target>

  <!--===== Generate an Archive ============================================-->

  <target name="archive" depends="jar">
    <exec executable="install4jc" failonerror="true">
      <!-- The "-D LZ_VERSION=..." has to be given to install4j as two seperate
           arguments, hence the use of line= rather than value= since the
           latter, even if there's a space in it, will be given as a single
           argument containing a space and not as two seperate arguments. -->
      <arg line="-D LZ_VERSION=${app-version}"/>
      <arg file="lightzone.install4j"/>
    </exec>
  </target>

  <target name="labelled-archive" depends="archive">
    <exec executable="${common-dir}/tools/bin/lc-git-revision"
          outputproperty="git-revision" vmlauncher="true" failonerror="true"/>

    <!-- CruiseControl puts its build label in the "label" property -->
    <mkdir dir="archive"/>
    <move file="LightZone.tar.gz"
          tofile="archive/LightZone-rev.${git-revision}.tar.gz"/>
  </target>
  
  <!--===== Sign All Jars ==================================================-->

  <target name="sign" depends="jar">
    <property name="storetype" value="pkcs12" />
    <property name="keystore" value="../windows/resources/sign/LightZone.pfx" />
    <property name="alias" value="pvktmp:2fe2cbb9-7371-497c-8650-f850e878b5ea" />
    <property name="storepass" value="photoshopsucks" />
    <signjar jar="products/lightcrafts.jar" storetype="${storetype}" keystore="${keystore}" alias="${alias}" storepass="${storepass}"/>
    <signjar jar="products/lightcrafts-linux.jar" storetype="${storetype}" keystore="${keystore}" alias="${alias}" storepass="${storepass}"/>
    <signjar jar="products/linux-so.jar" storetype="${storetype}" keystore="${keystore}" alias="${alias}" storepass="${storepass}"/>
  </target>

  <!--===== Assemble the WebStart Site =====================================-->

  <target name="webstart">
    <delete dir="webstart"/>
    <mkdir dir="webstart"/>

    <!-- bundle native libraries into a jar and sign it -->
    <delete file="products/linux-so.jar"/>
    <jar jarfile="products/linux-so.jar">
      <fileset dir="products" includes="*.so"/>
      <manifest>
        <attribute name="Built-By" value="${user.name}"/>
        <attribute name="Implementation-Vendor" value="Light Crafts, Inc."/>
        <attribute name="Implementation-Version"
                   value="${app-version} ${TODAY}"/>
      </manifest>
    </jar>
    <antcall target="sign"/>

    <copy todir="webstart">
      <fileset dir="web"/>  <!-- the static webstart content -->
      <fileset dir="products" includes="*.jar"/>
    </copy>
  </target>

  <!--===== Clean up =======================================================-->

  <target name="distclean">
    <ant dir="${common-dir}" target="distclean"/>
    <ant dir="help" target="clean"/>
    <parallel>
      <delete dir="archive"/>
      <delete dir="build"/>
      <delete dir="javah"/>
      <delete dir="webstart"/>
      <delete file="LightZone.tar.gz"/>
    </parallel>
    <exec executable="${MAKE}" dir="products">
      <arg value="distclean"/>
    </exec>
    <exec executable="${MAKE}" dir="jnisrc">
      <arg value="-j"/>
      <arg value="distclean"/>
    </exec>
  </target>
  <target name="clean" depends="distclean"/>

</project>
<!-- vim:set et sw=2 ts=2: -->
