#!/bin/sh
#####
# NAME
#	recursive-make - execute make command in all subdirectories
# SYNOPSYS
#	recursive-make [make-option]
# DESCRIPTION
#  Execute @code{make} command for each subdirectories which
#  has @file{Makefile} with given options.
# COPYRIGHT
#  Copyright (C) 2000,2001 Steel Wheels Project.
#  This file is a apart of the papaya utilities. 
#  If you need the information of copyright of this file, see COPYING
#  file distributed with file or see http://www.asahi-net.or.jp/~em7t-hmd
#  web page.
# BUGS
#	the Makefile in current directory will be ignored.

gmake_command="/usr/pkg/bin/gmake" ;

DIRLIST=`find . -name Makefile -print` ;
CURDIR=`pwd` ;

for ONEDIR in ${DIRLIST} ; do
	DSTDIR=`echo $ONEDIR | sed 's!/Makefile!!'` ;
	if [ $DSTDIR != "." ] ; then
		echo "make $* in \"$DSTDIR\"" >&2 ;
		cd ${DSTDIR} 
		if ! $gmake_command $* ; then
			echo "making in \"$ONEDIR\" was failed" >&2 ;
			exit 1 ;
		fi ;
		cd ${CURDIR} ;
	fi ;
done ;

exit 0 ;

