#!/bin/sh
#	Clean [dir]...
# This is a recursive cleanup script.  Give it one or more directory names,
# and it will do a "make clean" in all of them that contain a makefile with
# a "clean:" entry.  It do the job recursively, cleaning out subdirectories.
# If no directories are named, the current directory (and its subdirectories)
# will be cleaned.  Note that we follow symbolic links, which is thorough,
# but has potential problems with loops.  The "for f in `ls`" is also a
# rather inefficient way to do recursion.  See the CleanSubDirs script for
# an alternative (and faster) way to do this job.
#
if [ $# -lt 1 ];then set .;fi
D=`pwd`
for d
do	cd $d
	echo Clean `pwd`
	if grep -s '\<clean\> *:' [Mm]akefile # >/dev/null 2>&1
	then make clean # >/dev/null 2>&1
	fi
	for f in `ls`
	do	if [ -d $f ];then Clean $f;fi
	done
	cd $D
done
