#!/bin/sh

KATANA=/usr/share/katana/build
TMPDIR=.katana

case "$#" in
0)
    echo >&2 "katana: error: nothing to do"
    exit 1 ;;
1)
    case "$1" in
    prep|build|install|clean)
        echo >&2 "katana: this is katana2 --  please update your scripts"
        exit 1
    esac
esac

set -e
export PS4="+$PS4"
if [ -d $TMPDIR ]; then
    echo >&2 "${PS4}rm -rf $TMPDIR"
    rm -rf $TMPDIR
fi
echo >&2 "${PS4}mkdir $TMPDIR"
mkdir $TMPDIR

# Stage 1: create the per-package jarfiles.
python $KATANA/stage1.py --output $TMPDIR $* | sh -ex

# Stage 2: compile the per-package jarfiles into shared libraries.
python $KATANA/stage2.py $TMPDIR/*.jar | sh -ex

# Stage 3: copy the sources to where find-debuginfo expects to find them.
python $KATANA/stage3.py $TMPDIR/*.jar | sh -ex
