<!-- 
  Copyright IBM Corp. 2015, 2015 All Rights Reserved
  Copyright (c) 2010-2016 OpenStack Foundation
  Licensed 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>
    <property name="jarname" value="SBusJavaFacade.jar"/>
    <property name="libdir" value="/usr/local/lib/storlets/java"/>
    <property environment="env"/>
    <property name="env.STORLETS_JDK_VERSION" value="11"/>

    <target name="clean">
        <delete dir="bin" />
        <delete file="org_openstack_storlet_sbus_SBusJNI.h"/>
    </target>

    <target name="java">
        <mkdir dir="bin" />
        <javac
            srcdir="src/main"
            destdir="bin"
            classpath="../dependencies/json-simple-1.1.1.jar"
            includeantruntime="false"
            nativeheaderdir='.'>
            <compilerarg value="-Xlint"/>
        </javac>
    </target>

    <target name="so" depends="java">
        <exec dir="." executable="gcc">
            <arg line="-shared -o bin/libjsbus.so -fPIC" />
            <!-- Ubuntu -->
            <arg line="-I/usr/lib/jvm/java-${env.STORLETS_JDK_VERSION}-openjdk-amd64/include/" />
            <arg line="-I/usr/lib/jvm/java-${env.STORLETS_JDK_VERSION}-openjdk-amd64/include/linux/" />
            <!-- CentOS -->
            <arg line="-I/usr/lib/jvm/java-${env.STORLETS_JDK_VERSION}-openjdk/include/" />
            <arg line="-I/usr/lib/jvm/java-${env.STORLETS_JDK_VERSION}-openjdk/include/linux" />
            <!-- common -->
            <arg line="-I../../c/sbus/" />
            <arg line="SBusJNI.c ../../c/sbus/sbus.c" />
        </exec>
    </target>

    <target name="jar" depends="so">
        <jar destfile="SBusJavaFacade.jar" basedir="bin">
            <manifest>
                <attribute name="Main-Class"
                           value="org.openstack.storlet.sbus.SBus" />
            </manifest>
        </jar>
        <move file="SBusJavaFacade.jar" todir="bin/"/>
    </target>

    <target name="build" depends="clean, jar">
    </target>

    <target name="install" depends="build">
        <mkdir dir="${libdir}"/>
        <copy file="bin/${jarname}" todir="${libdir}"/>
        <copy file="bin/libjsbus.so" todir="${libdir}"/>
    </target>

    <target name="uninstall">
        <delete file="${libdir}/${jarname}"/>
    </target>
</project>
