#!/bin/bash

PROJECT=icmake

cd ~/git/${PROJECT}/src

./manpages

if [ -e /usr/share/common-licenses/GPL ] ; then
    cp /usr/share/common-licenses/GPL ${PROJECT}/LICENSE
fi

# VERSION=`grep VERSION icmake/VERSION | 
#   sed 's/[[:space:]]*#define[[:space:]]\+VERSION[[:space:]]\+"\(.*\)".*/\1/'`

. ${PROJECT}/VERSION                    # load the version

DISTRIBUTION=${PROJECT}-${VERSION}      # define the distribution's dir name

tgz()
{
    ln -s ${PROJECT} ${DISTRIBUTION}        # distribution's dir name
    tar czvf $1 --exclude-from=excluded ${DISTRIBUTION}/*
    rm ${DISTRIBUTION}  ${PROJECT}/LICENSE  # rm the link/license file
}

case "$1" in 
    (d)
        mkdir -p ../tarballs
        tgz ../tarballs/${PROJECT}_${VERSION}.orig.tar.gz
    ;;

    (l|o)
        tgz ${PROJECT}_${VERSION}.tar.gz

        if [ "$1" == "o" ]
        then
            scp ${PROJECT}_${VERSION}.tar.gz \
              oosix:git/${PROJECT}/tarballs/${PROJECT}_${VERSION}.orig.tar.gz

            rm ${PROJECT}_${VERSION}.tar.gz
        fi
    ;;

    (*)
        echo "
Provide arg:
    d (debian)  to create a .orig.tar.gz archive in 
                ../tarballs/${PROJECT}/tarballs
    l (local)   to create ${PROJECT}_${VERSION}.tar.gz in this directory
    o (upload)  same as 'l', but upload to oosix and show MD5 hash
"
    exit 1
    ;;

esac
