#!/bin/bash

do_it() {
	NEW=$BASE-$TREE

	echo "Building series file for $TREE"
	chmod 644 $PATCH_DIR/$TREE/*.patch
	grep "$TREE\/" $PATCH_DIR/series > series.$TREE

	echo "Creating $NEW kernel tree"
	cp -alp $BASE $NEW

	# apply quilt series
	cd $NEW
	QUILT_SERIES=$TMP/series.$TREE quilt push -aq
	cd ..

	# TODO put "changelog" in patch.
	echo "diffing $BASE and $NEW"
	diff -Naur -X ../dontdiff $BASE $NEW > $TREE-$KERNEL.patch

	echo "cleaning up $NEW"
	rm -rf $NEW
	rm series.$TREE

	echo "Patch is at $TREE-$KERNEL.patch"
	echo ""
}

KERNEL=2.6.12-rc3
BASE=linux-$KERNEL
TMP=~/linux/tmp
PATCH_DIR=~/linux/patches

cd $TMP

if [ ! -d "$BASE" ] ; then
	echo "I need $TMP/$BASE present in order to work properly."
	exit 1
fi

chmod 644 $PATCH_DIR/*.patch

TREE=usb
do_it

TREE=i2c
do_it

TREE=pci
do_it

TREE=driver
do_it

