#! /bin/sh -e

# DP: Add "(Debian <package version>)" to the gcc version string

pkgversion=
if [ -n "$DEB_VERSION" ]; then
    pkgversion=" $DEB_VERSION"
fi

dir=gcc
if [ $# -eq 3 -a "$2" = '-d' ]; then
    dir=$3/gcc
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
	sed -e '/version_string/s/"\([^"]*\)"/"\1 (Debian'"$pkgversion"')"/' \
	  $dir/version.c > $dir/version.c.new \
	    && mv -f $dir/version.c.new $dir/version.c
	;;
    -unpatch)
	sed -e 's/ *(Debian.*)//g' -e 's/Debian *//' \
	  $dir/version.c > $dir/version.c.new \
	    && mv -f $dir/version.c.new $dir/version.c
	;;
    *)
	echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
	exit 1
esac
exit 0
