#!/bih/sh

#
# Qt4 distribution RPM archive creator.
#
# NOTE: This script requires the basic set of unix tools such as cp, mkdir,
# pwd, readlink, find etc.
#

#
# Defaults
#

#
# Functions
#

die() { echo "ERROR: $@"; cd "$start_dir"; exit 1; }

run()
{
    echo "$@"
    "$@" || die \
"Last command failed (exit status $?)."
}

cmd_create()
{
    local src_base="$1"

    [ -d "$src_base" ] || die "'$src_base' is not a directory."

    run cmd /c env.cmd rpmbuild -D "QT_SOURCE_TREE $src_base" -bc qt.spec
}

#
# Main
#

script_path=$(readlink -e $0)
script_dir=${script_path%/*}
script_name=$(basename $0)

start_dir=$(pwd)

# Parse arguments

cmd_help()
{
    echo \
"
Usage:
  $script_name test [options]   ...

Options:
  <srcdir>      (*) Qt SVN source tree location
"
}

case "$1" in
    test)
        if [ -n "$2" ]; then
            cmd_create $(echo "$2" | tr '\\' '/')
        else
            cmd_help
        fi;;
    -h|-?|--help|*) cmd_help;;
esac

# end of story

exit 0
