#! /bin/bash
#
# bin/make-specfile
# Part of ComixCursors, a desktop cursor theme.
#
# Copyright © 2010 Ben Finney <ben+gnome@benfinney.id.au>
# Copyright © 2010 Jens Luetkens <j.luetkens@hamburg.de>
#
# This work 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.
#
# This work 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 this work. If not, see <http://www.gnu.org/licenses/>.

# Generate the RPM spec file.

bindir="$(dirname $0)"

# argument processing and usage
function show_usage_message {
    cat <<_EOT_
Usage: $0 [option]

Generate the ComixCursors RPM spec file.

Uses the environment variables PACKAGENAME and SUMMARY to determine
the parameters of the spec file.

Options:
    -h:    Display this help text, then exit.

_EOT_
}

while getopts ":uh" opt; do
    case $opt in
        h)
            show_usage_message
            exit
            ;;
        *)
            printf "Unexpected option: -%s\n" "$OPTARG" >&2
            show_usage_message
            exit 2
            ;;
    esac
done

# start here

packagename="$PACKAGENAME"
version=$("${bindir}"/current-package-version)
summary="$SUMMARY"

specfile_template="ComixCursors.spec.in"
specfile_changelog="specfile-changelog"
specfile="${packagename}.spec"

sed \
    -e "s/PACKAGENAME/${packagename}/g" \
    -e "s/VERSION/${version}/g" \
    -e "s/SUMMARY/${summary}/g" \
    < "$specfile_template" > "${specfile}"
cat "${specfile_changelog}" >> "${specfile}"
