<project name="j3dvrml" default="jar" basedir=".">

    <!-- ここから環境設定 -->
    <!--
    環境変数から値を取得して設定するようにしている。 
    処理される環境変数は以下の物だが、指定しなければデフォルトの値が使われる。
    * ACEROLA3D_JARDIR_PATH
        - Acerola3D関係のJARファイルを読み込む場所(java3d,joal,joalmixer,joglも含む)
        - デフォルトは${basedir}/lib/acerola3d/
    * ACEROLA3D_LIBRARY_PATH
        - Acerola3D関係のネイティブライブラリを読み込む場所(java3d,joal,joalmixer,joglも含む)
        - デフォルトは${basedir}/lib/acerola3d/
    * J3D_REND
        - Java3Dのレンダリングに使うエンジンの指定(jogl,ogl,d3dなどが指定可能)
        - デフォルトはプラットフォーム依存
    * J3D_AUDIODEVICE
        - Java3Dのオーディオミキサーのクラス名の指定(以下のような物)
            + org.jdesktop.j3d.audioengines.joal.JOALMixer
            + com.sun.j3d.audioengines.javasound.JavaSoundMixer
            + com.sun.j3d.audioengines.headspace.HeadspaceMixer
            + jp.sourceforge.acerola3d.sound.JOALMixer2
        - デフォルトはcom.sun.j3d.audioengines.javasound.JavaSoundMixer
    -->

    <property environment="env"/>
    <!-- Acerola3D関係のJARファイルを読み込む場所の設定 -->
    <condition property="my.acerola3d.jardir.path" value="${env.ACEROLA3D_JARDIR_PATH}">
        <isset property="env.ACEROLA3D_JARDIR_PATH"/>
    </condition>
    <condition property="my.acerola3d.jardir.path" value="${basedir}/lib/acerola3d/">
        <not><isset property="my.acerola3d.jardir.path"/></not>
    </condition>
    <!-- Acerola3D関係のネイティブライブラリを読み込む場所の設定 -->
    <condition property="my.acerola3d.library.path" value="-Djava.library.path=${env.ACEROLA3D_LIBRARY_PATH}">
        <isset property="env.ACEROLA3D_LIBRARY_PATH"/>
    </condition>
    <condition property="my.acerola3d.library.path" value="-Djava.library.path=${basedir}/lib/acerola3d/">
        <not><isset property="my.acerola3d.library.path"/></not>
    </condition>
    <!-- Java3Dのレンダリングに使うエンジンの指定 -->
    <condition property="my.j3d.rend" value="-Dj3d.rend=${env.J3D_REND}">
        <isset property="env.J3D_REND"/>
    </condition>
    <condition property="my.j3d.rend" value="-Dj3d.dummy=dummy">
        <not><isset property="my.j3d.rend"/></not>
    </condition>
    <!-- Java3Dのオーディオミキサーのクラス名の指定 -->
    <condition property="my.j3d.audiodevice" value="-Dj3d.audiodevice=${env.J3D_AUDIODEVICE}">
        <isset property="env.J3D_AUDIODEVICE"/>
    </condition>
    <condition property="my.j3d.audiodevice" value="-Dj3d.audiodevice=com.sun.j3d.audioengines.javasound.JavaSoundMixer">
        <not><isset property="my.j3d.audiodevice"/></not>
    </condition>

    <!-- 環境設定、ここまで -->

    <path id="compile.class.path">
        <fileset dir="${my.acerola3d.jardir.path}">
            <include name="*.jar"/>
        </fileset>
    </path>

    <path id="exec.class.path">
        <fileset dir="${my.acerola3d.jardir.path}">
            <include name="*.jar"/>
        </fileset>
        <pathelement location="release/j3dvrml.jar"/>
    </path>

    <target name="compile">
        <mkdir dir="build"/>
        <copy todir="build/jp/sourceforge/acerola3d/j3dvrml/resources">
            <fileset dir="src/jp/sourceforge/acerola3d/j3dvrml/resources"/>
        </copy>
        <javac srcdir="src" destdir="build" encoding="utf-8" debug="on">
            <classpath refid="compile.class.path"/>
            <!--
            <compilerarg value="-Xlint:unchecked" />
            -->
        </javac>
    </target>

    <target name="jar" depends="compile">
        <java classname="BuildTime">
            <arg value="build/buildTime.txt"/> 
            <classpath>
                <pathelement location="build"/>
            </classpath>
        </java>
        <jar jarfile="release/j3dvrml.jar" basedir="build"
             manifest="release/Manifest"/>
    </target>

    <target name="clean">
        <delete dir="build"/>
        <delete file="release/j3dvrml.jar"/>
        <delete>
            <fileset dir="." includes="**/gaha"/>
        </delete>
        <delete>
            <fileset dir="." includes="**/*~" defaultexcludes="no"/>
        </delete>
    </target>

    <target name="exec" depends="jar">
        <java classname="jp.sourceforge.acerola3d.j3dvrml.J3DVrml" fork="true">
            <classpath refid="exec.class.path"/>
            <jvmarg value="${my.acerola3d.library.path}"/>
            <jvmarg value="${my.j3d.rend}"/>
            <jvmarg value="${my.j3d.audiodevice}"/>
        </java>
    </target>

    <target name="version-input" unless="version">
    	<echo>*****************************</echo>
    	<echo>Please specify the version...</echo>
    	<echo>*****************************</echo>
    	<input message="input package version:" addproperty="version"/>
    </target>

	<target name="linux-bin-package" depends="version-input,jar">
    	<tstamp><format property="my.today" pattern="yyyy,MM/dd"/></tstamp>
    	<copy file="release/j3dvrml.jar" todir="release/j3dvrml_Linux"/> 
    	<copy file="release/j3dvrml_Linux_README.txt"
              tofile="release/j3dvrml_Linux/README.txt"
              encoding="UTF8"
    		  overwrite="true">
            <filterset>
                <filter token="date" value="${my.today}"/>
                <filter token="version" value="Version:${version}"/>
            </filterset>
    	</copy>
        <copy todir="release/j3dvrml_Linux/acerola3d">
        	<fileset dir="lib/Acerola3D_Libraries_Linux/acerola3d"/>
    	</copy>
        <copy todir="release/j3dvrml_Linux/licensing">
        	<fileset dir="lib/Acerola3D_Libraries_Linux/licensing"/>
    	</copy>
    	<concat destfile="release/j3dvrml_Linux/licensing/acerola3d-license.txt">
    		<filelist dir="lib/Acerola3D_Libraries_Linux" files="COPYRIGHT,COPYING.LESSER,COPYING"/>
        </concat>
    	<copy file="COPYING" todir="release/j3dvrml_Linux/"/>
    	<copy file="COPYING.LESSER" todir="release/j3dvrml_Linux/"/>
      	<copy file="COPYRIGHT" todir="release/j3dvrml_Linux/"/>
        <tar destfile="../j3dvrml_Linux-${version}.tar.gz" compression="gzip">
            <tarfileset dir="release" mode="755">
                <include name="j3dvrml_Linux/j3dvrml"/>
            </tarfileset>
            <tarfileset dir="release">
                <include name="j3dvrml_Linux/**"/>
                <exclude name="j3dvrml_Linux/j3dvrml"/>
            </tarfileset>
        </tar>
    	<delete file="release/j3dvrml_Linux/j3dvrml.jar"/>
    	<delete file="release/j3dvrml_Linux/README.txt"/>
    	<delete file="release/j3dvrml_Linux/COPYING"/>
    	<delete file="release/j3dvrml_Linux/COPYING.LESSER"/>
       	<delete file="release/j3dvrml_Linux/COPYRIGHT"/>
    	<delete includeEmptyDirs="true" >
    	    <fileset dir="release/j3dvrml_Linux/acerola3d" />
        </delete>
    	<delete includeEmptyDirs="true" >
    	    <fileset dir="release/j3dvrml_Linux/licensing" />
        </delete>
    </target>

    <target name="mac-bin-package" depends="version-input,jar">
    	<tstamp><format property="my.today" pattern="yyyy,MM/dd"/></tstamp>
    	<copy file="release/j3dvrml.jar" todir="release/j3dvrml_MacOSX/j3dvrml.app/Contents/Resources/Java/"/>
    	<copy file="release/j3dvrml_MacOSX_README.txt"
              tofile="release/j3dvrml_MacOSX/README.txt"
              encoding="SJIS"
    		  overwrite="true">
            <filterset>
                <filter token="date" value="${my.today}"/>
                <filter token="version" value="Version:${version}"/>
            </filterset>
    	</copy>
        <copy todir="release/j3dvrml_MacOSX/j3dvrml.app/Contents/Resources/Java/">
        	<fileset dir="lib/Acerola3D_Libraries_MacOSX/acerola3d"/>
    	</copy>
        <copy todir="release/j3dvrml_MacOSX/licensing">
        	<fileset dir="lib/Acerola3D_Libraries_MacOSX/licensing"/>
    	</copy>
    	<concat destfile="release/j3dvrml_MacOSX/licensing/acerola3d-license.txt">
    		<filelist dir="lib/Acerola3D_Libraries_MacOSX" files="COPYRIGHT,COPYING.LESSER,COPYING"/>
        </concat>
    	<copy file="COPYING" todir="release/j3dvrml_MacOSX/"/>
    	<copy file="COPYING.LESSER" todir="release/j3dvrml_MacOSX/"/>
      	<copy file="COPYRIGHT" todir="release/j3dvrml_MacOSX/"/>
    	<exec dir="release" executable="chmod" os="Mac OS X">
    		<arg value="755"/>
    		<arg value="j3dvrml_MacOSX/j3dvrml.app/Contents/MacOS/JavaApplicationStub"/>
       	</exec>
    	<exec dir="release/j3dvrml_MacOSX" executable="ln" os="Mac OS X">
    		<arg value="-s"/>
    		<arg path="/Applications"/>
    		<arg value="."/>
       	</exec>
    	<exec dir="release" executable="hdiutil" os="Mac OS X">
    		<arg value="create"/>
    		<arg value="-srcfolder"/>
       		<arg value="j3dvrml_MacOSX"/>
	    	<arg value="-fs"/>
	    	<arg value="HFS+"/>
    		<arg value="-volname"/>
    		<arg value="j3dvrml_MacOSX"/>
    		<arg value="../../j3dvrml_MacOSX-${version}.dmg"/>
       	</exec>
    	<exec dir="release/j3dvrml_MacOSX" executable="rm" os="Mac OS X">
    		<arg value="Applications"/>
       	</exec>
        <delete>
            <fileset dir="release/j3dvrml_MacOSX/j3dvrml.app/Contents/Resources/Java/">
                <include name="*"/>
            </fileset>
        </delete>
    	<delete file="release/j3dvrml_MacOSX/README.txt"/>
    	<delete file="release/j3dvrml_MacOSX/COPYING"/>
    	<delete file="release/j3dvrml_MacOSX/COPYING.LESSER"/>
       	<delete file="release/j3dvrml_MacOSX/COPYRIGHT"/>
    	<delete includeEmptyDirs="true" >
    	    <fileset dir="release/j3dvrml_MacOSX/licensing" />
        </delete>
    </target>

    <target name="win-bin-package" depends="version-input,jar">
    	<tstamp><format property="my.today" pattern="yyyy,MM/dd"/></tstamp>
    	<copy file="release/j3dvrml.jar" todir="release/j3dvrml_Windows"/> 
    	<copy file="release/j3dvrml_Windows_README.txt"
              tofile="release/j3dvrml_Windows/README.txt"
              encoding="SJIS"
    		  overwrite="true">
            <filterset>
                <filter token="date" value="${my.today}"/>
                <filter token="version" value="Version:${version}"/>
            </filterset>
    	</copy>
        <copy todir="release/j3dvrml_Windows/acerola3d">
        	<fileset dir="lib/Acerola3D_Libraries_Windows/acerola3d"/>
    	</copy>
        <copy todir="release/j3dvrml_Windows/licensing">
        	<fileset dir="lib/Acerola3D_Libraries_Windows/licensing"/>
    	</copy>
    	<concat destfile="release/j3dvrml_Windows/licensing/acerola3d-license.txt">
    		<filelist dir="lib/Acerola3D_Libraries_Windows" files="COPYRIGHT,COPYING.LESSER,COPYING"/>
        </concat>
    	<copy file="COPYING" todir="release/j3dvrml_Windows/"/>
    	<copy file="COPYING.LESSER" todir="release/j3dvrml_Windows/"/>
      	<copy file="COPYRIGHT" todir="release/j3dvrml_Windows/"/>
        <zip destfile="../j3dvrml_Windows-${version}.zip">
            <zipfileset dir="release">
                <include name="j3dvrml_Windows/**"/>
            </zipfileset>
        </zip>
    	<delete file="release/j3dvrml_Windows/j3dvrml.jar"/>
    	<delete file="release/j3dvrml_Windows/README.txt"/>
    	<delete file="release/j3dvrml_Windows/COPYING"/>
    	<delete file="release/j3dvrml_Windows/COPYING.LESSER"/>
       	<delete file="release/j3dvrml_Windows/COPYRIGHT"/>
    	<delete includeEmptyDirs="true" >
    	    <fileset dir="release/j3dvrml_Windows/acerola3d" />
        </delete>
    	<delete includeEmptyDirs="true" >
    	    <fileset dir="release/j3dvrml_Windows/licensing" />
        </delete>
    </target>

	<target name="src-package" depends="version-input,clean">
        <tar destfile="../j3dvrml-src-${version}.tar.gz" compression="gzip">
        	<tarfileset dir="..">
        		<include name="j3dvrml/**/*"/>
        		<exclude name="j3dvrml/lib/**/*"/>
        		<exclude name="j3dvrml/build/**/*"/>
        	</tarfileset>
        	<tarfileset dir="..">
        		<include name="j3dvrml/lib/memo.txt"/>
        	</tarfileset>
        </tar>
    </target>

</project>
