<?xml version="1.0" encoding="utf-8" ?>
<!--
 * 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="etch" default="debug" basedir=".">
    <description>Master build script for Etch</description>
    <property name="Etch.basedir" location="${basedir}" />
    <import file="build-support/etch.common.xml" />

    <!-- standard, supported targets -->
    <target name="Debug"         depends="debug" />
    <target name="Release"       depends="release" />
    <target name="Clean"         depends="clean" />
    <target name="debug"         depends="init-debug,component-all,post-debug"   />
    <target name="release"       depends="init-release,component-all,post-release" />
    <target name="clean"         depends="init-clean,component-all,post-clean" />
    <target name="realclean"     depends="clean,extra-clean" />
    <target name="maven-install" depends="init-maven,release" />

    <!-- Execute a clean, then 'debug' build -->
    <target name="rebuild-debug">
        <ant target="clean" />
        <ant target="debug" />
    </target>

    <!-- Execute a clean, then 'release' build -->
    <target name="rebuild-release">
        <ant target="clean" />
        <ant target="release" />
    </target>

    <!-- Execute a clean, then 'release' and then maven snapshot install (e.g. like running 'mvn clean install') -->
    <target name="rebuild-maven-install">
        <ant target="clean" />
        <ant target="maven-install" />
    </target>

    <!-- framework targets, do not call these directly -->

    <target name="init-maven" >
        <property name="DO.maven.install" value="true" />
    </target>

    <target name="validate-dependencies" >
        <tstamp />
        <build_component dir="build-support" target="check-all" script="dependencies" />
        
        <echo message="Workspace: ${Etch.basedir}" />
        <echo message="SVN Revision: ${Etch.runtime.revisionNumber}" />
        <echo message="Version: ${Etch.property.majorVersion}.${Etch.property.minorVersion}" />
        <echo message="BuildKey: ${Etch.runtime.buildKey}" />
        <echo message="BuildNumber: ${Etch.runtime.buildNumber}" />
        <echo message="LogDir: ${Etch.logDirectory}" />
        <echo message="InstallDir: ${Etch.installerDirectory}" />
        <mkdir dir="${Etch.logDirectory}" />
    </target>

    <target name="init-debug" depends="validate-dependencies,do-clover-init" >
        <property name="Etch.build.target" value="Debug" />
        <property name="Etch.javac.debug" value="on" />
        <property name="Etch.javac.optimize" value="off" />
    </target>

    <target name="post-debug" depends="do-clover-report">
    </target>

    <target name="init-release" depends="validate-dependencies,do-clover-init">
        <!-- For now, keep debug-symbols and no-optimize, even for release builds -->
        <property name="Etch.build.target" value="Release" />
        <property name="Etch.javac.debug"  value="on" />
        <property name="Etch.javac.optimize" value="off" />
        <!--
        <property name="Etch.javac.debug"  value="off" />
        <property name="Etch.javac.optimize" value="on" />
        -->
    </target>
    
    <target name="post-release" depends="do-clover-report">
    </target>

    <target name="do-clover-init" >
    </target>
        
    <target name="do-clover-report" if="Clover.enabled" >
        <!-- Generate Coverage Report -->
        <mkdir dir="${Clover.coverage}" />
        
        <clover-merge initString="${Clover.db}">
            <cloverDbSet dir="${Clover.db.path}">
                <include name="**/clover.db" />
            </cloverDbSet>
        </clover-merge>
        
        <!-- TODO: implement a toggle for the PDF report -->
        <!-- <clover-pdf-report initstring="${Clover.db}" outfile="${Clover.coverage}/coverage.pdf" />  -->
        
        <clover-report initstring="${Clover.db}" >
            <current alwaysReport="true" outfile="${Clover.coverage}/coverage.xml">
                <format type="xml"/>
            </current>
        </clover-report>

        <!-- Clean Clover DB -->
        <!-- <clover-clean initstring="${Clover.db}" keepdb="false" /> -->
    </target>


    <target name="init-clean" depends="validate-dependencies">
        <property name="Etch.build.target" value="Clean" />
    </target>

    <target name="post-clean" >
        <echo message="Executing clean" />
        <delete quiet="true" dir="${Etch.target}" />
    </target>

    <target name="extra-clean">
        <!-- remove files that were overwritten by the filtered copy -->
        <!--
        <delete file="compiler/src/main/java/org/apache/etch/compiler/Version.java" />
        <delete file="binding-java/compiler/src/main/java/org/apache/etch/bindings/java/compiler/CompilerVersion.java" />
        <delete file="binding-xml/compiler/src/main/java/org/apache/etch/bindings/xml/compiler/CompilerVersion.java" />
        <delete file="binding-csharp/compiler/src/main/java/org/apache/etch/bindings/csharp/compiler/CompilerVersion.java" />
        <delete file="binding-c/compiler/src/main/java/org/apache/etch/bindings/c/compiler/CompilerVersion.java" />
        <delete file="binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/CompilerVersion.java" />
        <delete file="binding-csharp/runtime/src/main/csharp/Properties/AssemblyInfo.cs" />
        -->
    </target>    

    <!-- Component targets; Add to this set -->
    <target name="component-all" depends="component-core, component-plugins, component-bindings, component-bindings-experimental, component-examples, component-tests, component-bundles" />

    <target name="component-core" >
        <!-- Core -->
        <build_component dir="util" />
        <build_component dir="compiler" />
    </target>

    <target name="component-plugins" >
        <!-- IDE/tool plugins -->
        <build_component dir="plugins/ant" />
    </target>

    <target name="component-bindings">
        <!-- Bindings -->
        <build_component dir="binding-xml" />
        <build_component dir="binding-java" />
        <build_component dir="binding-csharp" />
        <build_component dir="binding-c" />
    </target>

    <target name="component-bindings-experimental" if="include.experimental">
        <!-- Experimental Bindings -->
        <build_component dir="binding-cpp" />
        <build_component dir="binding-go" />
    </target>

    <target name="component-examples" unless="build.skip.examples">
        <!-- Examples -->
        <build_component dir="examples" />
    </target>

    <target name="component-tests" unless="build.skip.tests">
          <build_component dir="tests" />
    </target>

    <target name="component-bundles">
        <!-- Installer/zip Bundles -->
        <build_component dir="installers" />
    </target>
</project>
