#! /bin/sh -e

# DP: The gcc patch from the gpc tarball, updated for 3.3.6.

pdir=gcc
if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="$3/gcc"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi

gpc_gcc_patch=$pdir/p/diffs/gcc-3.3.5.diff
gpc_gcc_patch=debian/patches/gcc-3.3.6.diff
gpc_gcc_patch=debian/patches/gcc-3.3.6orig.diff

case "$1" in
    -patch)
	# keep the backup files ... to regenerate p/diffs/${gpc_gcc_patch}
	# dan@debian.org: no, don't.  Apply it by hand if you need to regen.
	# get the patch from the gpc source
	echo Using patch file ${gpc_gcc_patch}
	patch -d $pdir -f -p1 < ${gpc_gcc_patch}
	#pf=`echo $0 | sed 's/\.dpatch/.diff/'`
	#patch -d $pdir -f -p1 < $pf
	;;
    -unpatch)
	# get the patch from the gpc source
	echo Using patch file ${gpc_gcc_patch}
	patch -d $pdir -f -R -p1 < ${gpc_gcc_patch}
	#pf=`echo $0 | sed 's/\.dpatch/.diff/'`
	#patch -d $pdir -f -R -p1 < $pf
	;;
    *)
	echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
	exit 1
esac
exit 0
