#! /bin/sh -e

# DP: The gpc patch from the gpc tarball.

if [ "x$gpc_gcc_patch" = "x" ]
then
  gpc_gcc_patch=gcc-3.2.1.diff
fi

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.diff
gpc_gcc_patch=debian/patches/gcc-3.4.diff8

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 -p2 < ${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 -p2 < ${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
