#!/bin/bash 

# Copyright (c) 2004-2007, The PalCom Project consortium.
# See http://www.ist-palcom.org/consortium.
# 
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
# 
#     * Redistributions in binary form must reproduce the above
#       copyright notice, this list of conditions and the following
#       disclaimer in the documentation and/or other materials provided
#       with the distribution.
# 
#     * Neither the name of the PalCom Project nor the names of its
#       contributors may be used to endorse or promote products derived
#       from this software without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


# set -x

# Builds the basic developer tools and libraries for Pal-VM and/or JVM.

QUIET=0
BUILD_ARGS=
ROOT=`pal-dev-root`

function usage ()
{
    echo "Usage: pal-dev-build [options]"
    echo "Build basic PalCom developer tools and libraries for Pal-VM and/or JVM"
    echo "  Options:"
    echo "       -h  display this help"
    echo "       -J  build PalCom tools and libraries for JVM"
    echo "       -P  build PalCom tools and libraries for Pal-VM (default)"
    echo "       -j  build PalCom javadoc"
    echo ""
    echo "  Additional options available when using -P:"
    echo "       -r  build pal-vm with resource counters enabled"
    echo "       -d  do NOT build VM-developer versions of pal-vm"
    echo "       -q  be quiet - display output only when error"
    
}

# Check arguments
for a 
do
  if [ "$a" == "-h" ]; then 
      usage
      exit
  fi
  if [ "$a" == "-J" ]; then 
      JVM=1
      continue
  fi
  if [ "$a" == "-P" ]; then 
      PALVM=1
      continue
  fi
  if [ "$a" == "-r" ]; then 
      PALVM_ARGS="$PALVM_ARGS $a"
      continue
  fi
  if [ "$a" == "-d" ]; then 
      PALVM_ARGS="$PALVM_ARGS $a"
      continue
  fi
  if [ "$a" == "-q" ]; then 
      PALVM_ARGS="$PALVM_ARGS $a"
      continue
  fi
  echo Illegal option: $a
  usage
  exit 1
done

set -e  # exit on error

if [ -z "$PALVM" -a -z "$JVM" ]; then
    PALVM=1 # default
fi 

if [ "$PALVM" == "1" ]; then
    pal-dev-build-for-palvm $PALVM_ARGS
else
    echo ''; echo "###### Not building for Pal-VM. Use -P to force. ######" 
fi 

if [ "$JVM" == "1" ]; then
    pal-dev-build-for-jvm
else
    echo ''; echo "###### Not building for JVM. Use -J to force. ######" 
fi 

if [ "$JAVADOC" == "1" ]; then
    pal-dev-build-javadoc
else
    echo ''; echo "###### Not building javadoc (use -j to force). ######" 
fi 



echo ''; echo '###### Done ######'

trap - EXIT  # execute nothing on exit
exit 0
