<?xml version="1.0" ?>

<!--

  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

-->

<project name="createjs" default="main" basedir=".">
    
    <property name="ROYALE_HOME" value="${basedir}/.." />
    
    <condition property="ROYALE_COMPILER_HOME" value="${env.ROYALE_COMPILER_HOME}">
        <and>
            <not>
                <isset property="ROYALE_COMPILER_HOME" />
            </not>
            <available file="${env.ROYALE_COMPILER_HOME}/lib/compiler-mxmlc.jar" type="file" />
        </and>
    </condition>
    
    <condition property="ROYALE_COMPILER_HOME" value="${ROYALE_HOME}/../royale-compiler/compiler">
        <and>
            <not>
                <isset property="ROYALE_COMPILER_HOME" />
            </not>
            <available file="${ROYALE_HOME}/../royale-compiler/compiler/lib/compiler-mxmlc.jar" type="file" />
        </and>
    </condition>
    
    <condition property="ROYALE_COMPILER_HOME" value="${ROYALE_HOME}">
        <and>
            <not>
                <isset property="ROYALE_COMPILER_HOME" />
            </not>
            <available file="${ROYALE_HOME}/lib/compiler-mxmlc.jar" type="file" />
        </and>
    </condition>
    
    <condition property="ROYALE_TRANSPILER_HOME" value="${env.ROYALE_TRANSPILER_HOME}">
        <and>
            <not>
                <isset property="ROYALE_TRANSPILER_HOME" />
            </not>
            <available file="${env.ROYALE_TRANSPILER_HOME}/lib/jsc.jar" type="file" />
        </and>
    </condition>
    
    <condition property="ROYALE_TRANSPILER_HOME" value="${ROYALE_HOME}/js">
        <and>
            <not>
                <isset property="ROYALE_TRANSPILER_HOME" />
            </not>
            <available file="${ROYALE_HOME}/js/lib/jsc.jar" type="file" />
        </and>
    </condition>
    
    <condition property="ROYALE_TRANSPILER_HOME" value="${ROYALE_HOME}/../royale-compiler/compiler-jx">
        <and>
            <not>
                <isset property="ROYALE_TRANSPILER_HOME" />
            </not>
            <available file="${ROYALE_HOME}/../royale-compiler/compiler-jx/lib/jsc.jar" type="file" />
        </and>
    </condition>
    
    <tstamp>
        <format property="royale.swc-date" pattern="MM/dd/yy HH:mm Z"/>
    </tstamp>
    <echo>swc-date is ${royale.swc-date}</echo>

    <target name="main" depends="externc, compc" />
    
    <target name="download" >
        <mkdir dir="${basedir}/target/downloads" />
        <get src="https://github.com/CreateJS/EaselJS/archive/${createjs.version}.zip"
            dest="${basedir}/target/downloads/easel-${createjs.version}.zip" skipexisting="true" ignoreerrors="true"/>
        <antcall target="get-from-cache-if-needed" >
            <param name="srcFile" value="easel-${createjs.version}.zip" />
            <param name="destFile" value="easel-${createjs.version}.zip" />
            <param name="destDir" value="${basedir}/target/downloads" />
        </antcall>
        <antcall target="fail-if-not-found" >
            <param name="destFile" value="easel-${createjs.version}.zip" />
            <param name="destDir" value="${basedir}/target/downloads" />
        </antcall>
    </target>
    
    <target name="download_tween" >
        <mkdir dir="${basedir}/target/downloads" />
        <get src="https://github.com/CreateJS/TweenJS/archive/${tweenjs.version}.zip"
            dest="${basedir}/target/downloads/tween-${tweenjs.version}.zip" skipexisting="true" ignoreerrors="true"/>
        <antcall target="get-from-cache-if-needed" >
            <param name="srcFile" value="tween-${tweenjs.version}.zip" />
            <param name="destFile" value="tween-${tweenjs.version}.zip" />
            <param name="destDir" value="${basedir}/target/downloads" />
        </antcall>
        <antcall target="fail-if-not-found" >
            <param name="destFile" value="tween-${tweenjs.version}.zip" />
            <param name="destDir" value="${basedir}/target/downloads" />
        </antcall>
    </target>

    <!-- createjs files have certain patterns that fool our compilers.
     we process each file to make it look a bit more like what we expect -->
    <!-- this target requires mac/linux -->
    <target name="make_patch" depends="download, download_tween, expandzip, expandzip_tween">
        <antcall target="preprocessfile" >
            <param name="file" value="createjs/events/Event.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="createjs/events/EventDispatcher.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="createjs/utils/extend.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="createjs/utils/indexOf.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="createjs/utils/promote.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="createjs/utils/Ticker.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/Bitmap.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/BitmapText.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/Container.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/DisplayObject.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/DOMElement.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/Graphics.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/MovieClip.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/Shadow.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/Shape.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/Sprite.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/SpriteContainer.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/SpriteSheet.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/SpriteStage.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/Stage.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/display/Text.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="folder" value="EaselJS-${createjs.version}" />
            <param name="file" value="easeljs/events/MouseEvent.js" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/filters/AlphaMapFilter.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/filters/AlphaMaskFilter.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/filters/BlurFilter.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/filters/ColorFilter.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/filters/ColorMatrix.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/filters/ColorMatrixFilter.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/filters/Filter.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/geom/DisplayProps.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/geom/Matrix2D.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/geom/Point.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/geom/Rectangle.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/ui/ButtonHelper.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/ui/Touch.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/utils/SpriteSheetBuilder.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/utils/SpriteSheetUtils.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="easeljs/utils/UID.js" />
            <param name="folder" value="EaselJS-${createjs.version}" />
        </antcall>
        <antcall target="preprocessGraphics" />
        <antcall target="preprocessMouseEvent" />
        <antcall target="preprocessMovieClip" />
        <antcall target="preprocessTicker" />
        <antcall target="rename.in.jsdoc" />
        <!-- TweenJS -->
        <antcall target="preprocessfile" >
            <param name="file" value="tweenjs/CSSPlugin.js" />
            <param name="folder" value="TweenJS-${tweenjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="tweenjs/Ease.js" />
            <param name="folder" value="TweenJS-${tweenjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="tweenjs/MotionGuidePlugin.js" />
            <param name="folder" value="TweenJS-${tweenjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="tweenjs/SamplePlugin.js" />
            <param name="folder" value="TweenJS-${tweenjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="tweenjs/Timeline.js" />
            <param name="folder" value="TweenJS-${tweenjs.version}" />
        </antcall>
        <antcall target="preprocessfile" >
            <param name="file" value="tweenjs/Tween.js" />
            <param name="folder" value="TweenJS-${tweenjs.version}" />
        </antcall>
        <antcall target="preprocessEase" />
        <antcall target="preprocessTween" />
        <antcall target="preprocessTicker" />
        <antcall target="preprocessIndexOf" />
        <antcall target="externc_jsroot" />
        <antcall target="diff" />
    </target>
    
    <target name="diff" >
        <mkdir dir="${basedir}/target/reference" />
        <delete dir="${basedir}/target/reference/EaselJS-${createjs.version}" />
        <unzip src="${basedir}/target/downloads/easel-${createjs.version}.zip"
            dest="${basedir}/target/reference">
        </unzip>
        <mkdir dir="${basedir}/target/reference" />
        <delete dir="${basedir}/target/reference/TweenJS-${tweenjs.version}" />
        <unzip src="${basedir}/target/downloads/tween-${tweenjs.version}.zip"
            dest="${basedir}/target/reference">
        </unzip>
        <delete dir="${basedir}/src/main/patch" />
        <mkdir dir="${basedir}/src/main/patch" />
        <exec executable="git" output="${basedir}/src/main/patch/easeljs.temp.patch" >
            <arg value="diff"/>
            <arg value="--no-index"/>
            <arg value="--"/>
            <arg value="${basedir}/target/reference/EaselJS-${createjs.version}"/>
            <arg value="${basedir}/target/downloads/EaselJS-${createjs.version}"/>
        </exec>
        <exec executable="git" output="${basedir}/src/main/patch/tweenjs.temp.patch" >
            <arg value="diff"/>
            <arg value="--no-index"/>
            <arg value="--"/>
            <arg value="${basedir}/target/reference/TweenJS-${tweenjs.version}"/>
            <arg value="${basedir}/target/downloads/TweenJS-${tweenjs.version}"/>
        </exec>
        <replace file="${basedir}/src/main/patch/easeljs.temp.patch" token="target/reference" value="target/downloads" />
        <replace file="${basedir}/src/main/patch/easeljs.temp.patch" token="${basedir}/target/downloads" value="/createjs/target/downloads" />
        <replace file="${basedir}/src/main/patch/tweenjs.temp.patch" token="target/reference" value="target/downloads" />
        <replace file="${basedir}/src/main/patch/tweenjs.temp.patch" token="${basedir}/target/downloads" value="/createjs/target/downloads" />
        <concat destfile="${basedir}/src/main/patch/tweenjs.patch" >
            <header filtering="no" trimleading="yes">
                Generated from Ant script
            </header>
            <filelist dir="${basedir}/src/main/patch" files="tweenjs.temp.patch"/>
        </concat>
        <concat destfile="${basedir}/src/main/patch/easeljs.patch" >
            <header filtering="no" trimleading="yes">
                Generated from Ant script
            </header>
            <filelist dir="${basedir}/src/main/patch" files="easeljs.temp.patch"/>
        </concat>
        <delete file="${basedir}/src/main/patch/easeljs.temp.patch" />
        <delete file="${basedir}/src/main/patch/tweenjs.temp.patch" />
    </target>
    
    <target name="preprocess" depends="expandzip, expandzip_tween">
        <exec executable="git" dir="${basedir}/..">
            <arg value="apply"/>
            <arg value="--ignore-whitespace"/>
            <arg value="--whitespace=nowarn"/>
            <arg value="${basedir}/src/main/patch/easeljs.patch"/>
        </exec>
        <exec executable="git" dir="${basedir}/..">
            <arg value="apply"/>
            <arg value="--ignore-whitespace"/>
            <arg value="--whitespace=nowarn"/>
            <arg value="${basedir}/src/main/patch/tweenjs.patch"/>
        </exec>
    </target>
    
    <target name="expandzip">
        <mkdir dir="${basedir}/target/downloads" />
        <delete dir="${basedir}/target/downloads/EaselJS-${createjs.version}" />
        <unzip src="${basedir}/target/downloads/easel-${createjs.version}.zip"
            dest="${basedir}/target/downloads">
        </unzip>
    </target>
    
    <target name="expandzip_tween">
        <mkdir dir="${basedir}/target/downloads" />
        <delete dir="${basedir}/target/downloads/TweenJS-${tweenjs.version}" />
        <unzip src="${basedir}/target/downloads/tween-${tweenjs.version}.zip"
            dest="${basedir}/target/downloads">
        </unzip>
    </target>
    
    <target name="preprocessfile" >
        <basename property="file.base" file="${file}" suffix=".js"/>
        <echo>file.base is ${file.base}</echo>
        <replace file="${basedir}/target/downloads/${folder}/src/${file}" token="this.createjs = this.createjs||{};" value="" />
        <replace file="${basedir}/target/downloads/${folder}/src/${file}" token="this.createjs = this.createjs || {};" value="" />
        <replace file="${basedir}/target/downloads/${folder}/src/${file}" token="(function() {" value="" />
        <replace file="${basedir}/target/downloads/${folder}/src/${file}" token="(function () {" value="" />
        <replace file="${basedir}/target/downloads/${folder}/src/${file}" token="setTimeout " value="setTimeout(function() {" />
        <replace file="${basedir}/target/downloads/${folder}/src/${file}" token="}());" value="" />
        <replace file="${basedir}/target/downloads/${folder}/src/${file}" token="})();" value="" />
        <replace file="${basedir}/target/downloads/${folder}/src/${file}" token="@param [time] {Number}" value="@param {Number} time" />
        <replace file="${basedir}/target/downloads/${folder}/src/${file}" token="function ${file.base}(" value="createjs.${file.base} = function(" />
        <replace file="${basedir}/target/downloads/${folder}/src/${file}" token="@param data" value="@param {Object} data" />
        <replace file="${basedir}/target/downloads/${folder}/src/${file}" token="@param ratio" value="@param {Number} ratio" />
        <replace file="${basedir}/target/downloads/${folder}/src/${file}" token="@param target" value="@param {Object} target" />
        <replace file="${basedir}/target/downloads/${folder}/src/${file}" token="{any}" value="{Object}" />
        <replaceregexp file="${basedir}/target/downloads/${folder}/src/${file}" match="\s&quot;use strict&quot;;" replace="" />
        <replaceregexp file="${basedir}/target/downloads/${folder}/src/${file}" match="\screatejs.${file.base} = .*;" replace="" />
        <replaceregexp file="${basedir}/target/downloads/${folder}/src/${file}" match="var p = createjs.extend.*;" replace="" />
        <replaceregexp file="${basedir}/target/downloads/${folder}/src/${file}" match="var p = ${file.base}.prototype;" replace="" />
        <replaceregexp file="${basedir}/target/downloads/${folder}/src/${file}" match="var s = ${file.base};" replace="" />
        <replaceregexp file="${basedir}/target/downloads/${folder}/src/${file}" match="\sp\." replace="${file.base}.prototype." flags="g"/>
        <replaceregexp file="${basedir}/target/downloads/${folder}/src/${file}" match="\ss\." replace="${file.base}." flags="g"/>
        <replaceregexp file="${basedir}/target/downloads/${folder}/src/${file}" match="${file.base}\." replace="createjs.${file.base}." flags="g"/>
        <replaceregexp file="${basedir}/target/downloads/${folder}/src/${file}" match="\stry [{]\s*Object.defineProperties[(]p, [{]\s*(.*):\s(.*)[}] catch [(]e[)] [{][}]"
            replace="createjs.${file.base}.prototype.\1;" flags="gs" />
        <replaceregexp file="${basedir}/target/downloads/${folder}/src/${file}" match="\s@extends\s(.*)" replace=" @extends createjs.\1" />
    </target>
    
    <target name="preprocessTween">
    	<replaceregexp file="${basedir}/target/downloads/TweenJS-${tweenjs.version}/src/tweenjs/Tween.js" match="@constructor" replace="@static" flags="gs" />
    	<replaceregexp file="${basedir}/target/downloads/TweenJS-${tweenjs.version}/src/tweenjs/Tween.js" match="@static" replace="@constructor" />
    </target>
    
    <target name="preprocessEase">
        <replaceregexp file="${basedir}/target/downloads/TweenJS-${tweenjs.version}/src/tweenjs/Ease.js" match="@static" replace="@constructor" />
    </target>
    
    <target name="preprocessTicker">
        <replaceregexp file="${basedir}/target/downloads/EaselJS-${createjs.version}/src/createjs/utils/Ticker.js" match="@static" replace="@constructor" />
        <replace file="${basedir}/target/downloads/EaselJS-${createjs.version}/src/createjs/utils/Ticker.js" token="createjs.Ticker.addEventListener = function()" value="createjs.Ticker.addEventListener = function(type, handler)" />
    </target>
    
    <target name="preprocessGraphics" >
        <replaceregexp file="${basedir}/target/downloads/EaselJS-${createjs.version}/src/easeljs/display/Graphics.js" match="\s[(]G\..*function[(]ctx[)] [{].*[}];" replace="" flags="gs" />
    </target>
    <target name="preprocessMouseEvent" >
        <replaceregexp file="${basedir}/target/downloads/EaselJS-${createjs.version}/src/easeljs/events/MouseEvent.js" match="createjs.MouseEvent.prototype.localX:.*isTouch;" replace="" flags="gs" />
    </target>
    <target name="preprocessMovieClip" >
        <replaceregexp file="${basedir}/target/downloads/EaselJS-${createjs.version}/src/easeljs/display/MovieClip.js" match="createjs.MovieClip.prototype.labels:.*currentLabel;" replace="" flags="gs" />
    </target>
    <target name="preprocessIndexOf" >
        <replace file="${basedir}/target/downloads/EaselJS-${createjs.version}/src/createjs/utils/indexOf.js" token="@param searchElement Element" value="@param {Object} searchElement Element" />
    </target>
    
    <target name="rename.in.jsdoc" >
        <replace dir="${basedir}/target/downloads/EaselJS-${createjs.version}/src" >
            <include name="**/*.js"/>
            <replacefilter token="ColorMatrix|" value="createjs.ColorMatrix|" />
            <replacefilter token="Container|" value="createjs.Container|" />
            <replacefilter token="DisplayObject|" value="createjs.DisplayObject|" />
            <replacefilter token="DisplayProps|" value="createjs.DisplayProps|" />
            <replacefilter token="Filter|" value="createjs.Filter|" />
            <replacefilter token="Graphics|" value="createjs.Graphics|" />
            <replacefilter token="Matrix2D|" value="createjs.Matrix2D|" />
            <replacefilter token="MovieClip|" value="createjs.MovieClip|" />
            <replacefilter token="Point|" value="createjs.Point|" />
            <replacefilter token="Rectangle|" value="createjs.Rectangle|" />
            <replacefilter token="Shadow|" value="createjs.Shadow|" />
            <replacefilter token="SpriteSheet|" value="createjs.SpriteSheet|" />
            <replacefilter token="Stage|" value="createjs.Stage|" />
            <replacefilter token="ColorMatrix}" value="createjs.ColorMatrix}" />
            <replacefilter token="Container}" value="createjs.Container}" />
            <replacefilter token="DisplayObject}" value="createjs.DisplayObject}" />
            <replacefilter token="DisplayProps}" value="createjs.DisplayProps}" />
            <replacefilter token="Filter}" value="createjs.Filter}" />
            <replacefilter token="Graphics}" value="createjs.Graphics}" />
            <replacefilter token="Matrix2D}" value="createjs.Matrix2D}" />
            <replacefilter token="MovieClip}" value="createjs.MovieClip}" />
            <replacefilter token="Point}" value="createjs.Point}" />
            <replacefilter token="Rectangle}" value="createjs.Rectangle}" />
            <replacefilter token="Shadow}" value="createjs.Shadow}" />
            <replacefilter token="SpriteSheet}" value="createjs.SpriteSheet}" />
            <replacefilter token="Stage}" value="createjs.Stage}" />
            <replacefilter token="Point |" value="createjs.Point|" />
            <replacefilter token="{String}" value="{string}" />
        </replace>
    </target>
    
    <target name="externc_jsroot" >
        <!-- this step removes function bodies and otherwise makes the files
             look like typical GCC externs files that GCC expects -->
        <delete dir="${basedir}/target/generated-sources/externs" />
        <java jar="${ROYALE_TRANSPILER_HOME}/lib/externc.jar" fork="true"
            failonerror="false">
            <arg value="+royalelib=externs" />
            <arg value="-debug" />
            <arg value="-js-root=${basedir}/target/generated-sources/externs" />
            <arg value="-load-config=${basedir}/src/main/config/externc-config.xml" />
        </java>
        <!-- copy the externc jsroot output back on top of the original files.
             That way the build can just patch the original files and then flatten them
             into a folder -->
        <copy todir="${basedir}/target/downloads/EaselJS-${createjs.version}/src/easeljs/filters" overwrite="true">
            <fileset dir="${basedir}/target/generated-sources/externs">
                <include name="*Filter.js" />
                <include name="ColorMatrix.js" />
            </fileset >
        </copy>
        <copy todir="${basedir}/target/downloads/EaselJS-${createjs.version}/src/easeljs/display" overwrite="true">
            <fileset dir="${basedir}/target/generated-sources/externs">
                <include name="Bitmap.js" />
                <include name="BitmapText.js" />
                <include name="Container.js" />
                <include name="DisplayObject.js" />
                <include name="DOMElement.js" />
                <include name="Graphics.js" />
                <include name="MovieClip.js" />
                <include name="Shadow.js" />
                <include name="Shape.js" />
                <include name="Sprite.js" />
                <include name="SpriteContainer.js" />
                <include name="SpriteSheet.js" />
                <include name="SpriteStage.js" />
                <include name="Stage.js" />
                <include name="Text.js" />
            </fileset >
        </copy>
        <copy todir="${basedir}/target/downloads/EaselJS-${createjs.version}/src/easeljs/ui" overwrite="true">
            <fileset dir="${basedir}/target/generated-sources/externs">
                <include name="ButtonHelper.js" />
            </fileset >
        </copy>
        <copy todir="${basedir}/target/downloads/EaselJS-${createjs.version}/src/easeljs/geom" overwrite="true">
            <fileset dir="${basedir}/target/generated-sources/externs">
                <include name="DisplayProps.js" />
                <include name="Matrix2D.js" />
                <include name="Point.js" />
                <include name="Rectangle.js" />
            </fileset >
        </copy>
        <copy todir="${basedir}/target/downloads/TweenJS-${tweenjs.version}/src/tweenjs" overwrite="true">
            <fileset dir="${basedir}/target/generated-sources/externs">
                <include name="Ease.js" />
                <include name="Tween.js" />
                <include name="Timeline.js" />
            </fileset >
        </copy>
        <copy todir="${basedir}/target/downloads/EaselJS-${createjs.version}/src/createjs/events" overwrite="true">
            <fileset dir="${basedir}/target/generated-sources/externs">
                <include name="Event.js" />
                <include name="EventDispatcher.js" />
            </fileset >
        </copy>
        <copy todir="${basedir}/target/downloads/EaselJS-${createjs.version}/src/easeljs/events" overwrite="true">
            <fileset dir="${basedir}/target/generated-sources/externs">
                <include name="MouseEvent.js" />
            </fileset >
        </copy>
        <copy todir="${basedir}/target/downloads/EaselJS-${createjs.version}/src/easeljs/utils" overwrite="true">
            <fileset dir="${basedir}/target/generated-sources/externs">
                <include name="SpriteSheetBuilder.js" />
            </fileset >
        </copy>
        <copy todir="${basedir}/target/downloads/EaselJS-${createjs.version}/src/createjs/utils" overwrite="true">
            <fileset dir="${basedir}/target/generated-sources/externs">
                <include name="Ticker.js" />
            </fileset >
        </copy>
    </target>
    
    <target name="externc" >
        <delete dir="${basedir}/target/generated-sources/externs" />
        <java jar="${ROYALE_TRANSPILER_HOME}/lib/externc.jar" fork="true"
            failonerror="true">
            <arg value="+royalelib=externs" />
            <arg value="-debug" />
            <arg value="-load-config=${basedir}/src/main/config/externc-config.xml" />
        </java>
    </target>
    
    <target name="postprocess" >
    </target>
    
    <target name="compc" >
        <copy file="${basedir}/src/main/config/compile-as-config.xml"
        todir="${basedir}/target" />
        <java jar="${ROYALE_TRANSPILER_HOME}/lib/compc.jar" fork="true"
            failonerror="true">
            <arg value="+royalelib=externs/frameworks" />
            <arg value="-targets=SWF" />
            <arg value="-external-library-path+=${basedir}/../js/target/js.swc" />
            <arg value="-load-config=${basedir}/target/compile-as-config.xml" />
            <arg line="-metadata.date=&quot;${royale.swc-date}&quot;" />
            <arg line="-metadata.dateFormat=&quot;MM/dd/yy HH:mm Z&quot;" />
            <arg value="-output=${basedir}/target/createjs.swc" />
        </java>
    </target>
    
    <target name="clean">
        <delete failonerror="false" includeEmptyDirs="true" >
            <fileset dir="${basedir}/target">
                <include name="**/**"/>
                <exclude name="EaselJS-${createjs-version}/**"/>
            </fileset>
        </delete>
    </target>
    
    <target name="wipe">
        <delete dir="${basedir}/target" />
    </target>

    <target name="fail-if-not-found">
        <fail message="${destDir}/${destFile} could not be downloaded or found in cache">
            <condition>
                <not>
                    <available file="${destDir}/${destFile}" />
                </not>
            </condition>
        </fail>
    </target>

    <target name="double-check-file" >
        <echo>${env.ROYALE_DOWNLOAD_CACHE}</echo>
        <condition property="still-no-file" value="true">
            <and>
                <not>
                    <available file="${destDir}/${destFile}" />
                </not>
                <isset property="env.ROYALE_DOWNLOAD_CACHE" />
            </and>
        </condition>
        <echo>Need file: ${still_no_file}</echo>
    </target>
    <target name="get-from-cache-if-needed" depends="double-check-file" if="still-no-file">
        <copy file="${env.ROYALE_DOWNLOAD_CACHE}/${srcFile}" tofile="${destDir}/${destFile}" />
    </target>
</project>
