#!/bin/sh
# climbs down $1 and generates makefile stubs for use with toc trees.
# It refuses to overwrite existing files, instead doing nothing
# for dirs which already contain a Makefile
#
# Usage: $0 [path: defaults to $PWD]

dir=${1-${PWD}}
for d in $(find $dir -type d); do
    mf=$d/Makefile
    if test -f $mf; then
        echo "WARNING: $mf exist! Skipping!" 1>&2
        continue
    fi

    cd $d > /dev/null
    SUB=
    for sub in *; do
        test -d "$sub" || continue
        sub=${sub#./}
        echo "SUBDIRS += $sub" >> $mf
    done >> $mf
    echo "include toc.make" >> $mf
    echo "Created $mf" 1>&2
    cd - >  /dev/null 
done 