#!/bin/sh
#	buildinclude --
#		Build a include tree from an RCS tree
# sas 850219
# munging bog 850718
# bog 850809 - more munging. Kernel tree now includes usr.include, full of 
#  the toplevel includes. This needs to be handled specially, since it stays
#  at the top of the target directory.
# bog 850815 - make link of s32 to machine. Kludge city.
#

case $# in
2)	;;
*)	
	echo "usage: buildinclude <subdir> <destination dir>"
	exit 1
	;;
esac

echo ""
if [ -r $1/includelist ]; then
	echo "using $1/includelist as directory tree specification"
	dirlist=`cat $1/includelist`
else
	echo "$1/includelist does not exist."
	exit 2
fi

if [ -d $2 ]; then
	echo -n "$2 exists...hit <cr> to clear directory: "
	read x
	rm -rf $2
fi

echo -n "making $2..."
mkdir $2
echo "done"


for e in $dirlist
	do
	case $e in
	h)
		mkdir $2/sys
		for f in $e/RCS/*.h,v
			do
			co $f $2/sys/`basename $f ,v`
		done
		;;
	usr.include)
		for f in $e/RCS/*.h,v
			do
			co $f $2/`basename $f ,v`
		done
		;;
	*)
		mkdir $2/$e
		for f in $e/RCS/*.h,v
			do
			co $f $2/$e/`basename $f ,v`
		done
	esac
done

if [ -d $2/s32 ]; then
	echo "linking $2/machine to $2/s32"
	cd $2
	rm -rf machine
	ln -s s32 machine
fi

echo "done ($0)."
