view lib/mod/build_mod.xml @ 33:3d86f0391168

Work on improving the build system.
author David Barts <davidb@stashtea.com>
date Fri, 24 Apr 2020 19:45:57 -0700
parents
children
line wrap: on
line source

<?xml version="1.0" encoding="UTF-8"?>
<project name="mod" default="help" basedir=".">
  <!-- import all environment variables as env.* -->
  <property environment="env"/>

  <!-- ensure required environment variables are set -->
  <macrodef name="env-require">
    <attribute name="name"/>
    <sequential>
      <fail message="Environment variable @{name} not set!">
        <condition>
          <not><isset property="env.@{name}"/></not>
        </condition>
      </fail>
    </sequential>
  </macrodef>
  <env-require name="JRE_HOME"/>

  <!-- load launch4j (Windows app builder) -->
  <!-- load m-o-d (Linux Gnome app builder) -->

  <!-- cribbed from https://stackoverflow.com/questions/7129672/uppercase-lowercase-capitalize-an-ant-property -->
  <scriptdef language="javascript" name="toLowerCase">
    <attribute name="value" />
    <attribute name="target" />
    <![CDATA[
      project.setProperty( attributes.get( "target" ),
                           attributes.get( "value" ).toLowerCase() );
    ]]>
  </scriptdef>

  <!-- Define the properties used by the build -->
  <property name="app.name"      value="${ant.project.name}"/>
  <toLowerCase target="lc.app.name" value="${app.name}"/>
  <property name="jar.name"      value="${basedir}/${lc.app.name}.jar"/>
  <property name="src.home"      value="${basedir}/src"/>
  <property name="work.home"     value="${basedir}/work"/>

  <!-- help message -->
  <target name="help">
    <echo>You can use the following targets:</echo>
    <echo> </echo>
    <echo>  help    : (default) Prints this message </echo>
    <echo>  clean   : Deletes work directories</echo>
    <echo>  compile : Compiles source into class files</echo>
    <echo>  jar     : Make JAR file.</echo>
    <echo> </echo>
    <echo>For example, to clean, compile, and package all at once, run:</echo>
    <echo>prompt> ant -f build_mod.xml all </echo>
  </target>

  <!-- do everything -->
  <target name="all" depends="clean,jar"
          description="Clean work dirs, compile, make JAR."/>

  <!-- clean old cruft out of our way -->
  <target name="clean"
          description="Delete old work and dist directories.">
    <delete dir="${work.home}"/>
  </target>

  <!-- make new dist and work trees -->
  <target name="mkdirs" description="Create working dirs">
    <mkdir dir="${work.home}"/>
  </target>

  <!-- compile *.java to *.class -->
  <target name="compile" depends="mkdirs"
          description="Compile Java sources to ${work.home}">
    <javac srcdir="${src.home}" destdir="${work.home}" debug="true"
           includeAntRuntime="true">
    </javac>
  </target>

  <!-- make .jar file -->
  <target name="jar" depends="compile" description="Create JAR file.">
    <jar destfile="${jar.name}">
      <fileset dir="${work.home}"/>
    </jar>
  </target>

</project>