<?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-c-runtime" basedir="." default="help">
    <description>Etch-to-C runtime binding implementation</description>
    <property name="Etch.basedir" location="${basedir}/../.." />
    <import file="${Etch.basedir}/build-support/etch.includes.xml" />

    <!-- Static properties of the sub-project -->
    <property name="proj"                 location="${Etch.basedir}/binding-c/runtime/c" />
    <property name="target"               location="${proj}/target" />
    <property name="testResultsDirectory" location="${target}/test-results" />
    
    <!-- INIT TARGET -->
    <!-- Modify this target to define project specific properties that can only be set at runtime -->
    <target name="do-init" >
        <mkdir dir="${target}" />
        <mkdir dir="${testResultsDirectory}" />
    </target>

    <!-- CLEAN TARGET -->
    <target name="do-clean">
        <delete dir="${target}" />
    </target>

    <!-- BUILD TARGET -->
    <target name="do-build-info" unless="USE.cmake">
        <echo message="**********************************" />
        <echo message="binding-c build will not be done." />
        <echo message="**********************************" />
    </target>
    
    <target name="do-build-generate-sources" if="USE.cmake">
        <mkdir dir="${Etch.dist}/binding-c" />
        <!-- package up etch-java-runtime src -->
        <zip destfile="${Etch.dist}/binding-c/${etch-c-runtime-src.zip}">
            <fileset dir="${proj}">
                <exclude name="target/" />
                <exclude name="doc/" />
                <exclude name="**/.svn" />
            </fileset>
        </zip>
    </target>

    <target name="do-build-main" if="USE.cmake">

        <!-- CMake configuration -->
        <exec dir="${basedir}/c/target" executable="cmake" failonerror="true">
            <arg value="-DETCH_EXTERNAL_DEPENDS:PATH=${env.ETCH_EXTERNAL_DEPENDS}"/>
            <arg value="${basedir}/c"/>
        </exec>
        
        <!-- run the build -->
        <exec dir="${basedir}/c/target" executable="cmake" failonerror="true">
            <arg line="--build . --config Debug"/>
        </exec>
    </target>

    <target name="do-build" depends="do-build-info,do-build-generate-sources,do-build-main" if="USE.cmake">

        <mkdir dir="${Etch.dist}/binding-c/bin" />
        <mkdir dir="${Etch.dist}/binding-c/include" />
        <mkdir dir="${Etch.dist}/binding-c/lib" />

        <!-- copy etch library to dist folder -->
        <copy todir="${Etch.dist}/binding-c/include">
            <fileset dir="${proj}/include">
                <exclude name="**/.svn" />
            </fileset>
        </copy>

        <copy todir="${Etch.dist}/binding-c/lib" flatten="true">
            <fileset dir="${target}/src/main">
                <include name="debug/etch.lib" />
                <include name="debug/etch.pdb" />
                <include name="Debug/etch.lib" />
                <include name="Debug/etch.pdb" />
                <include name="libetch.a" />
            </fileset>
        </copy>

        <!-- copy apr library to dist folder -->
        <copy todir="${Etch.dist}/binding-c/extern/apr">
            <fileset dir="${env.ETCH_EXTERNAL_DEPENDS}/apr/1.4.8">
            </fileset>
        </copy>
    </target>

    <!-- TEST TARGET -->
    <target name="do-test">
    </target>

    <!-- POSTBUILD TARGET -->
    <target name="do-postbuild">
    </target>

    <target name="do-publish" if="build.tests.fail">
        <!-- Set flag file if any tests failed -->
        <touch file="${Etch.runtime.tests.fail}"/>
    </target>

</project>
