<?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="idl" xmlns:if="ant:if" xmlns:unless="ant:unless">

    <dirname property="idl.basedir" file="${ant.file.idl}"/>

    <!-- global properties -->
    <property file="${idl.basedir}/../../ant.properties"/>



    <property name="idl.build.dir" location="${build.base.dir}/idl"/>
    <property name="idl.urd.build.dir" location="${idl.build.dir}/urd"/>
    <property name="idl.rdb.build.dir" location="${idl.build.dir}/rdb"/>
    <property name="idl.classes.build.dir" location="${idl.build.dir}/classes"/>
    <property name="idl.javamaker.flag" location="${idl.build.dir}/idl.javamaker.flag"/>

    <target name="idl" depends="idl-check,idl-javamaker"/>

    <target name="idl-check">
        <local name="idl.files.exist"/>
        <condition property="idl.files.exist">
            <resourcecount refid="idl.files" when="greater" count="0"/>
        </condition>

        <local name="idl.files.union"/>
        <union id="idl.files.union" if:set="idl.files.exist">
            <filelist refid="idl.files"/>
        </union>
        <uptodate property="idl.uptodate" targetfile="${idl.javamaker.flag}" if:set="idl.files.exist">
            <srcresources refid="idl.files.union"/>
        </uptodate>
        <property name="idl.uptodate" value="true" unless:set="idl.files.exist"/>
    </target>

    <target name="idl-javamaker" depends="idl-regmerge" unless="idl.uptodate">
        <mkdir dir="${idl.classes.build.dir}"/>
        <exec executable="${OUTDIR}/bin/javamaker" failonerror="true">
            <env key="LD_LIBRARY_PATH" value="${OUTDIR}/lib"/>
            <env key="DYLD_LIBRARY_PATH" value="${OUTDIR}/lib"/>
            <arg value="-O${idl.classes.build.dir}"/>
            <arg value="-BUCR"/>
            <arg value="-nD"/>
            <arg value="${idl.rdb.build.dir}/registry.rdb"/>
            <arg value="-X${OUTDIR}/bin/types.rdb"/>
        </exec>
        <touch file="${idl.javamaker.flag}"/>
    </target>

    <target name="idl-regmerge" depends="idl-idlc" unless="idl.uptodate">
        <mkdir dir="${idl.rdb.build.dir}"/>
        <delete file="${idl.rdb.build.dir}/registry.rdb"/>
        <apply executable="${OUTDIR}/bin/regmerge" failonerror="true">
            <env key="LD_LIBRARY_PATH" value="${OUTDIR}/lib"/>
            <env key="DYLD_LIBRARY_PATH" value="${OUTDIR}/lib"/>
            <arg value="${idl.rdb.build.dir}/registry.rdb"/>
            <arg value="/UCR"/>
            <fileset dir="${idl.urd.build.dir}" includes="**/*.urd"/>
        </apply>
    </target>

    <target name="idl-idlc" unless="idl.uptodate">
        <mkdir dir="${idl.urd.build.dir}"/>
        <apply executable="${OUTDIR}/bin/idlc" failonerror="true">
            <env key="LD_LIBRARY_PATH" value="${OUTDIR}/lib"/>
            <env key="DYLD_LIBRARY_PATH" value="${OUTDIR}/lib"/>
            <arg value="-I${OUTDIR}/idl"/>
            <arg value="-O"/>
            <arg value="${idl.urd.build.dir}"/>
            <arg value="-verbose"/>
            <arg value="-cid"/>
            <arg value="-we"/>
            <filelist refid="idl.files"/>
        </apply>
    </target>

</project>

