#!/bin/sh

# Copyright (C) 2004, 2005, 2008 Simon Josefsson.
#
# This file is part of Autobuild.
#
# Autobuild is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Autobuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Autobuild.  If not, see <http://www.gnu.org/licenses/>.

prog="`basename \"$0\"`"
rcs_revision='$Revision: 1.5 $'
rcs_version=`set - $rcs_revision; echo $2`
program=`echo $0 | sed -e 's!.*/!!'`
version="abbuild (autobuild) $rcs_version

Copyright (C) 2004 Simon Josefsson
There is NO warranty.  You may redistribute this software under the
terms of the GNU General Public License.  For more information about
these matters, see the file named COPYING."

usage="Usage: $prog [OPTION]... FILE SYSTEM HOSTS...

Build FILE on compile host HOST, using the specified SYSTEM.

Abbuild will invoke the command \"abbuild-SYSTEM FILE HOST\".
Available systems include \"sourceforge\".

Options:
  -v, --verbose        Produce verbose output.
  -h, --help           Display this help and exit successfully.
      --version        Display version information and exit successfully. 

Simple example:
  $prog yourproject-4.2.tar.gz sourceforge amd64-linux1

For details on each system, invoke the system specific script directly:
  $prog-sourceforge --help

Report bugs to <bug-autobuild@josefsson.org>."

while test $# -gt 0; do
    case $1 in
	-v) VERBOSE=t;;
	-h) echo "$usage"; exit 0;;
	--help) echo "$usage"; exit 0;;
	--version) echo "$version"; exit 0;;
	-*)
	    echo "$0: Unknown or ambiguous option \`$1'." >&2
	    echo "$0: Try \`--help' for more information." >&2
	    exit 1;;
	*)
	    if test -z "$FILE"; then
		FILE=$1
	    elif test -z "$SYSTEM"; then
		SYSTEM=$1
	    else
		break;
	    fi;;
    esac
    shift
done

if test -z "$FILE" || test -z "$SYSTEM" || test $# -eq 0; then
    echo "$usage"
    exit 0
fi

while test $# -gt 0; do
    HOST="$1"
    shift

    test -z "$VERBOSE" || echo "Invoking \`abbuild-$SYSTEM $FILE $HOST'..."
    abbuild-$SYSTEM "$FILE" "$HOST"
    test -z "$VERBOSE" || echo "Command returned exit code $?..."
done
