<?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. -->

<!-- ====================================================================== 
     build-native-source    
     Compile the native source into component shared libs.
     ====================================================================== -->
<project name="build-native-source" default="default" basedir="..">
    <description>
		Compile the native source into component shared libs.
    </description>

    <!-- import common properties -->
    <import file="${basedir}/make/properties.xml" />
    <import file="${basedir}/make/depends.xml" />

    <property name="hy.hdk" location="deploy" />
    <property name="hy.jdk" location="${hy.hdk}/jdk" />
    <property name="depends.build" location="depends/build" />
    <property name="depends.oss" location="depends/oss" />
    <property name="depends.libs" location="depends/libs/${hy.platform}" />
    <property name="depends.files" location="depends/files" />
    <property name="native.lib.target" location="${hy.hdk}/lib" />

    <!-- ================================= 
          target: default              
         ================================= -->
    <target name="default" 
        description="Compile the native source into component shared libs." 
        depends="clean, build" />


    <!-- ================================= 
          target: build
         ================================= -->
    <target name="build"
        depends="overlay-oss, copy-includes, layout, make-all" />


    <!-- ================================= 
          target: clean              
         ================================= -->
    <target name="clean"
        depends="make-clean, clean-includes, clean-overlay-oss, clean-layout" />


    <!-- This target invokes make on the all target to compile all natives -->
    <target name="make-all" depends="copy-makefile-includes">
    	
    	<!-- These module targets take care of building and copying
             their shared libs -->
    	<ant dir="modules/portlib" antfile="build.xml" target="build-native" />
        <ant dir="modules/luni" antfile="build.xml" target="build-native-core" />
    	<ant dir="modules/archive" antfile="build.xml" target="build-native" />
    	<ant dir="modules/auth" antfile="build.xml" target="build-native" />
    	<ant dir="modules/text" antfile="build.xml" target="build-native" />
    	<ant dir="modules/prefs" antfile="build.xml" target="build-native" />
    	<ant dir="modules/luni" antfile="build.xml" target="build-native-secondary" />
        <ant dir="modules/nio" antfile="build.xml" target="build-native" />    	
        <ant dir="modules/misc" antfile="build.xml" target="build-native" />    	
        <ant dir="modules/awt" antfile="build.xml" target="build-native" />    	
        <ant dir="modules/security" antfile="build.xml" target="build-native" />    	
        <ant dir="modules/instrument" antfile="build.xml" target="build-native" />    	
        <ant dir="modules/imageio" antfile="build.xml" target="build-native" />    	
        <ant dir="modules/print" antfile="build.xml" target="build-native" />    	
    </target>


    <!-- ================================= 
          target: make-clean              
         ================================= -->
    <target name="make-clean"
        depends="copy-makefile-includes,-make-clean,clean-makefile-includes" />

    <target name="-make-clean">
        <ant dir="modules/portlib" antfile="build.xml" target="clean-native" />
    	<ant dir="modules/auth" antfile="build.xml" target="clean-native" />
    	<ant dir="modules/archive" antfile="build.xml" target="clean-native" />
       	<ant dir="modules/text" antfile="build.xml" target="clean-native" />
    	<ant dir="modules/prefs" antfile="build.xml" target="clean-native" />
    	<ant dir="modules/luni" antfile="build.xml" target="clean-native" />
    	<ant dir="modules/nio" antfile="build.xml" target="clean-native" />
    	<ant dir="modules/misc" antfile="build.xml" target="clean-native" />
    	<ant dir="modules/awt" antfile="build.xml" target="clean-native" />
    	<ant dir="modules/security" antfile="build.xml" target="clean-native" />
    	<ant dir="modules/instrument" antfile="build.xml" target="clean-native" />
        <ant dir="modules/imageio" antfile="build.xml" target="clean-native" />    	
        <ant dir="modules/print" antfile="build.xml" target="clean-native" />    	
    	<delete dir="${native.lib.target}" />
    </target>


    <!-- ================================= 
          target: layout              
         ================================= -->
    <target name="layout" depends="layout.windows"
        description="Construct the correct directory structure for native binaries">

    	<!-- Create the target directory structure -->
        <mkdir dir="${hy.jdk}/jre/bin" />
        <mkdir dir="${hy.jdk}/include" />
    	<mkdir dir="${native.lib.target}"/>

    	<!-- NLS catalog files -->
        <copy todir="${hy.jdk}/jre/bin" overwrite="yes">
            <fileset dir="${depends.files}">
                <include name="harmony*.properties" />
            </fileset>
        </copy>

        <!-- Copy across dependency shared libs -->
        <copy todir="${hy.jdk}/jre/bin" overwrite="yes">
            <fileset dir="${depends.libs}" includes="*${shlib.suffix}*" />
        </copy>

    </target>

    <target name="layout.windows" if="is.windows" depends="-select-win-deps-x86_64,-select-win-deps-x86">
        <!-- workaround until msdll is moved. -->
        <copy file="${msvcr.dll}" todir="${hy.jdk}/jre/bin" overwrite="yes" />
    </target>

    <!-- ================================= 
          target: clean-layout              
         ================================= -->
    <target name="clean-layout">
        <delete includeemptydirs="true" failonerror="false">
            <fileset dir="${hy.jdk}">
                <include name="**/bin/java${exe.suffix}" />
                <include name="**/bin/javaw${exe.suffix}" />
                <include name="**/bin/*${shlib.suffix}*" />
            	<include name="**/bin/harmony*.properties" />
            </fileset>
        </delete>
    </target>


    <!-- ================================= 
          target: overlay-oss              
         ================================= -->
    <condition property="iculib.zip"
        value="${depends.oss}/icu4c-3.4-harmony-windows.x86_64.zip"
        else="${depends.oss}/icu4c-3.4-harmony.zip">
        <and>
            <isset property="is.windows"/>
            <isset property="is.x86_64"/>
        </and>
    </condition>

    <target name="overlay-oss">
        <ant dir="modules/luni" antfile="build.xml"
             target="overlay-oss" />

    	<ant dir="modules/archive" antfile="build.xml" 
	     target="overlay-oss" />        
    	
        <mkdir dir="${hy.hdk}/include/icu4c/unicode" />
        <unzip src="${iculib.zip}" dest="${hy.hdk}/include/icu4c/unicode" />
        <chmod dir="${hy.hdk}/include/icu4c/unicode" perm="ugo+r" />
        <copy file="${hy.hdk}/include/icu4c/unicode/icuuc.lib" todir="${native.lib.target}" overwrite="yes"/>
    </target>

    <!-- ================================= 
          target: copy-includes              
         ================================= -->
    <target name="copy-includes" >
	<!-- Call copy-native-includes targets to copy across
	     global includes to deploy/includes/harmony -->
    	<ant dir="modules/archive" antfile="build.xml"
             target="copy-native-includes" />
    	<ant dir="modules/luni" antfile="build.xml" 
    	     target="copy-native-includes" />
        <ant dir="modules/portlib" antfile="build.xml"
             target="copy-native-includes" />

    </target>
	
    <!-- ================================= 
          target: clean-includes              
         ================================= -->
    <target name="clean-includes" >
	<!-- Call clean.native.includes targets to delete global
   	     includes under deploy/includes/harmony -->
        
    	<ant dir="modules/archive" antfile="build.xml" 
    	     target="clean-native-includes" />
    	<ant dir="modules/luni" antfile="build.xml" 
    	     target="clean-native-includes" />
        <ant dir="modules/portlib" antfile="build.xml"
             target="clean-native-includes" />
        <!-- delete the deploy/include and deploy/jdk/include directories -->
        <delete dir="${hy.hdk}/include" />
        <delete dir="${hy.hdk}/jdk/include" />
    </target>

    <!-- ================================= 
          target: copy-makefile-includes              
         ================================= -->
    <target name="copy-makefile-includes">
	<!-- copy generic defines and rules for each platform into a shared
	     place -->
	<mkdir dir="${hy.hdk}/build/make" />
	<copy todir="${hy.hdk}/build/make" overwrite="yes">
            <fileset dir="${depends.build}">
                <include name="**" />
            </fileset>
        </copy>
    </target>
	
    <!-- ================================= 
          target: clean-makefile-includes              
         ================================= -->
    <target name="clean-makefile-includes">
	<!-- delete generic defines and rules -->
	<delete dir="${hy.hdk}/build/make" />
    </target>

    <!-- ================================= 
          target: clean-overlay-oss              
         ================================= -->
    <target name="clean-overlay-oss">
        <ant dir="modules/luni" antfile="build.xml" 
             target="clean-overlay-oss" />
     	<ant dir="modules/archive" antfile="build.xml" 
    	     target="clean-overlay-oss" />
	<delete dir="${hy.hdk}/include/icu4c" quiet="true" />     
    </target>

</project>
