#!/bin/bash

# Wrapper script for fabric.Main, the Fabric compiler.

source "$(dirname $0)/defs"

while true; do
  case "$1" in
    "") break;;
    -v) verbose="1"; shift;;
    -j)
      shift
      vmargs="${vmargs} '$1'"
      shift
      ;;
    -sigcp)
      shift
      sigcp="${sigcp}:$1"
      shift
      ;;
    -filsigcp)
      shift
      filsigcp="${filsigcp}:$1"
      shift
      ;;
    -cp)
      shift
      cp="${cp}:$1"
      shift
      ;;
    -rdebug)
      shift
      vmargs="${vmargs} -Xdebug -Xrunjdwp:transport=dt_socket,address=6666,server=y,suspend=y"
      ;;

    *) args="${args} '$1'"; shift;;
  esac
done

classpath="${FABC_CP}:${cp}:${classpath}"

# Jar files should always appear *after* their corresponding class directories.
sigcp="${TOP}/sig-classes/fabric:${TOP}/lib/fabric-sig.jar:${sigcp}"
filsigcp="${TOP}/sig-classes/fabil:${TOP}/lib/fabric-il-sig.jar:${filsigcp}"

command="\"${JAVA}\" ${vmargs} -classpath \"$(fixpath ${classpath})\" \
                   fabric.Main -sigcp \"$(fixpath ${sigcp})\" \
                               -filsigcp \"$(fixpath ${filsigcp})\" ${args}"

if [ -n "${verbose}" ]
then
  echo "${command}"
fi

eval "${command}"
