<?xml version="1.0"?>

<project name="plasma" default="build">
  
  <property name="projName" value="plasma"/> <!-- base part of output bin name -->
  <property name="src.dir" location="."/> 
  <property name="include.dir" location="../include"/>
  <property file="${include.dir}/build.props"/> <!-- needs to define ACME_BIN_DIR -->

  <property name="build.dir" value="${src.dir}/build"/>
  
  <property name="ACME_TOOL" location="${ACME_BIN_DIR}/acme"/>
  
  <property name="ASM_SETTINGS" value="-f plain"/>
  
  <target name="all">
    <antcall target="clean"/>
    <antcall target="build"/>
  </target>
  
  <target name="clean">
    <delete failonerror="false" dir="${build.dir}"/>
    <delete>
      <fileset dir="." includes="gen_*.pl?"/>
    </delete>
  </target>
  
  <target name="build">

    <!-- Create build directory -->
    <mkdir dir="${build.dir}"/>

    <!-- Translate the PLASMA code to ACME assembly code-->
    <apply executable="../../../tools/PLASMA/src/plasm" dir="${src.dir}" 
           relative="true" parallel="false" failonerror="true" verbose="true"
           addsourcefile="false">
      <fileset dir="${src.dir}" includes="*.pla" excludes="heaptest*,playtype*"/>
      <arg value="-AMW"/>
      <redirector logError="yes">
        <!-- redirect STDIN; fileset collects relative to its dir, but we need -->
        <!-- relative to basedir -->
        <inputmapper type="glob" from="*" to="${src.dir}/*"/>
        <!-- redirect STDOUT to file in dest-dir -->
        <outputmapper id="out" type="glob" from="*.pla" to="${build.dir}/*.a"/>
      </redirector>
    </apply>

    <!-- Assemble the ACME code -->
    <apply executable="acme" dir="${build.dir}" 
           relative="true" parallel="false" failonerror="true" verbose="true">
      <fileset dir="${build.dir}" includes="*.a"/>
      <mapper type="glob" from="*.a" to="*.b"/>
      <arg line="--setpc 4096"/>
      <arg value="-o"/>
      <targetfile/>
      <srcfile/>
    </apply>

  </target>
</project>
