#!/usr/bin/env bash

VERSION="1.0.4"
PATCHLEVEL="p1"

if [ $# -ne 0 ]; then
    UPSTREAM_SOURCE_DIRECTORY=$1
    echo "Using tarballs from $UPSTREAM_SOURCE_DIRECTORY instead of downloading"
fi

SPKG_ROOT=`pwd`

set -e
shopt -s extglob

# Download sources
URL="http://www.cs.uwaterloo.ca/~astorjoh/"
if [ -z "$UPSTREAM_SOURCE_DIRECTORY" ]; then
    tar xjf <( curl -L "$URL/iml-$VERSION.tar.bz2" )
else
    tar xjf "$UPSTREAM_SOURCE_DIRECTORY/iml-$VERSION.tar.bz2"
fi

mv "iml-$VERSION" "iml-$VERSION$PATCHLEVEL"
tar cjf "iml-$VERSION$PATCHLEVEL.tar.bz2" "iml-$VERSION$PATCHLEVEL"
