#!/bin/bash

usage() {
    echo "Usage: $(basename "$0") name version"
}

if [ $# -lt 2 ]; then
    usage
    exit 1
fi

scriptdir="$(dirname "$0")"
name="$1"; shift
version="$1"; shift
files="$*"
if [ -z "$files" ]; then
    read -d\\n -r -a files < <("$scriptdir/list-source-files")
    if [ -e build_mode ]; then
	files+=(build_mode)
    fi
fi

result=../$name-$version.tar.bz2
rm -f "${result}"
for f in "${files[@]}"; do echo "$f"; done | \
    tar --owner=root --group=root --transform="s|^|$name-$version/|;s|^$name-$version/../scst/include/backport.h$|../scst/include/backport.h|;s|^$name-$version/scstadmin.sysfs$|scstadmin.sysfs|" \
	-cjf "${result}" -T- &&
    ls -l "${result}"
