#!/bin/sh
#
#  does a make in each subdirectories that contains a Makefile
#  (code is seriously stripped-down version of jrv script)

# ensure a standard environment
SHELL=/bin/sh;	export SHELL

date

# remember directory in which began
HERE=`pwd`

# find all the Makefiles.
# pipe through "sed" to remove leading and trailing noise.
# read the results to drive a loop.

find . -name Makefile -print | sort |
sed -e 's!\./!!' -e 's!/Makefile!!' |
while read subd
do
    # change to where began (since previous iteration does cd)
    cd $HERE

    # echo subdirectory and go there.
    echo "$subd:"
    cd $subd

    ## echo make in $subd
    make

done  # <|find

# now check and clean up snippets

echo now checking for tabs
while read pat # reading  < SPatterns -- redirected below
do
    grep -r --include "$pat" '	' .
#    echo $pat
done < SPatterns

echo "now fixing indentation"
# after fixing, check results with differ or differw
#
# note: if Indent fails in middle of file
# then fix original and remake in that directory.
while read pat # reading  < SPatterns -- redirected below
do
    find . -name "$pat" -exec SIndent {} \;
#    echo $pat
done < SPatterns

date
exit 0
