<?xml version="1.0"?>

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

  <!-- =================================================================== -->
  <!-- INIT                                                                -->
  <!-- =================================================================== -->
  <target name="init">  

    <!-- Variables -->
    <property name="name"           value="SoundSPI" />    
    <property name="year"           value="2015" />
    
    <!-- JClic is currently targeted to JVM 1.6 -->
    <property name="ant.build.javac.source" value="1.6"/>
    <property name="ant.build.javac.target" value="1.6"/>    

    <property name="build.dir"      location="build" />
    <property name="apidoc.dir"     location="apidoc" />
    
    <property name="debug"          value="on" />    
    <property name="deprecation"    value="on" />    
    <property name="optimize"       value="on" />    

   <patternset id="serialized" >
        <include name="**/*.ser"/>
    </patternset>
    <patternset id="spi.services" >
        <include name="META-INF/services/javax.sound.sampled.spi.*"/>
        <include name="META-INF/services/javax.sound.midi.spi.*"/>
    </patternset> 

    <echo message="---------------------"/>
    <echo message="SoundSPI build"/>
    <echo message="---------------------"/>
    
    <!-- Create dirs -->
    <mkdir dir="${build.dir}"/>

  </target>

  <!-- =================================================================== -->
  <!-- MAIN                                                                -->
  <!-- =================================================================== -->
  <target name="all" 
          depends="soundspi" 
          description="Build everything.">

    <echo message="*** SoundSPI successfully compiled!"/>

  </target>

  <!-- =================================================================== -->
  <!-- CLEAN                                                               -->
  <!-- =================================================================== -->
  <target name="clean" 
          depends="init" 
          description="Clean build dir">
    <delete dir="${build.dir}" />
    <echo message="*** Build dir cleared!"/>
  </target>
  
  <!-- =================================================================== -->
  <!-- JAVADOC                                                             -->
  <!-- =================================================================== -->
  <target name="javadoc" 
          depends="all" 
          description="JDom JavaDoc">
    <delete dir="${apidoc.dir}" />
    <mkdir dir="${apidoc.dir}"/>
    <javadoc packagenames="*" 
             destdir="${apidoc.dir}" 
             author="true" 
             version="true" 
             use="true" 
             splitindex="true" 
             noindex="false" 
             windowtitle="${name} API" 
             doctitle="${name}">
             <sourcepath>
               <pathelement location="javalayer/src"/>
               <pathelement location="jorbis/src"/>
               <pathelement location="MpegAudioSPI/src"/>
               <pathelement location="tritonus/src"/>
             </sourcepath>
             <classpath />
             <link href="http://docs.oracle.com/javase/1.5.0/docs/api/" />
    </javadoc>
  </target>

  <!-- =================================================================== -->
  <!-- SOUNDSPI                                                            -->
  <!-- =================================================================== -->
  <target name="soundspi" 
          depends="init">
    <mkdir dir="${build.dir}/soundspi"/>
    <javac destdir="${build.dir}/soundspi" 
           debug="${debug}" 
           deprecation="${deprecation}"
           source="${ant.build.javac.source}"
           target="${ant.build.javac.target}"
           includeAntRuntime="false"
           optimize="${optimize}">
           <src path="javalayer/src" />
           <src path="jorbis/src" />
           <src path="MpegAudioSPI/src" />
           <src path="tritonus/src" />
    </javac>
    <copy todir="${build.dir}/soundspi">
        <fileset dir="javalayer/src">
            <patternset refid="serialized" />
        </fileset>            
        <fileset dir="catalog">
            <patternset refid="spi.services" />
        </fileset>            
    </copy>
    <jar jarfile="${build.dir}/soundspi.jar" 
         basedir="${build.dir}/soundspi" />
  </target>

</project>
