# -*- shell-script -*-

#
# mknetrel.patch -- patch sources
#

dopatch () {
    cd $src
    patch -Np1 < $patch/$package.patch
    cp -p $patch/$package.patch $src/$cygwin/
}

dodiff () {
    [ -r $cygwin/.cvsignore ] || cat > $cygwin/.cvsignore <<EOF
#*
*.orig
*.rej
*~
.#*
.bash_mknetrel
*.patch
CYGWIN-PATCHES
MINGW-PATCHES
Makefile
GNUmakefile
Makefile.in
aclocal.m4
autom4te.cache
config.guess
config.sub
configure
libltdl
ltmain.sh
CVS
*[0-9].patch
EOF
    diff -purNX$cygwin/.cvsignore $netrel_root/src/$upstream . > $patch/$package.patch-
    if [ -s $patch/$package.patch- ]; then
	cp --backup -pv $patch/$package.patch- $patch/$package.patch
	cp --backup -pv $patch/$package.patch- $src/$cygwin/$package.patch
    fi
    rm $patch/$package.patch-
}
    
patchsrc () {
    [ -r $patch/$package.patch -a ! -r $src/$cygwin/$package.patch ] && dopatch
    cd $src
    upstream=$(expr "$package" : '\(.*-[-.0-9]*.*\)-[0-9]*')
    [ -r $netrel_root/src/$upstream -a -r $patch/$package.patch -a $src/$cygwin/mknetrel -nt $patch/$package.patch ] && dodiff
}
