#create or apply the patch file for directfb

#add to your bashrc if you do this a lot
#_mkpatch()
#{
#    local cur
#    COMPREPLY=()
#    cur=${COMP_WORDS[COMP_CWORD]}
#    [ $COMP_CWORD = 1 ] && \
#    COMPREPLY=( $( compgen -W 'create apply configure' -- $cur ) )
#    return 0
#}
#complete -F _mkpatch -o default $0


function run_configure(){
	(cd ../../; autoconf)
	(cd ../../; automake-1.7 gdk/directfb/Makefile)
	(cd ../../; automake-1.7 docs/tools/Makefile)
	(cd ../../; automake-1.7 gdk/Makefile)
	(cd ../../; automake-1.7 gtk/Makefile)
	#needed since configure.in does not gen po/Makefile
	(cd ../../; ./configure)
	(cd ../../; ./configure --with-gdktarget=directfb)
}

function apply_patch(){
	patch -b -p0 < ./gtk-directfb.patch
	run_configure;
}

function create_patch () {
sep="==================================================================="
echo $sep >> gtk-directfb.patch
diff -u -w  ../../configure.in.orig ../../configure.in > gtk-directfb.patch
echo $sep >> gtk-directfb.patch
diff -u -w  ../../gtk/Makefile.am.orig ../../gtk/Makefile.am >> gtk-directfb.patch
echo $sep >> gtk-directfb.patch
diff -u -w  ../../gdk/gdk.symbols.orig ../../gdk/gdk.symbols >> gtk-directfb.patch
echo $sep >> gtk-directfb.patch
diff -u -w  ../../gdk/Makefile.am.orig ../../gdk/Makefile.am >>  gtk-directfb.patch
echo $sep >> gtk-directfb.patch
diff -u -w  ../../docs/tools/Makefile.am.orig ../../docs/tools/Makefile.am >>  gtk-directfb.patch

diff -u -w  ../../gtk/gtkplug-stub.c.orig ../../gtk/gtkplug-stub.c >>  gtk-directfb.patch
diff -u -w  ../../gtk/gtksocket-stub.c.orig ../../gtk/gtksocket-stub.c >>  gtk-directfb.patch
}

case "$1" in
	create)
		create_patch;
	;;
	apply)
		apply_patch
	;;
	configure)
		run_configure
	;;
	  *)
    echo $"Usage: mkpatch {create|apply|configure}"
    exit 1
esac

