#! /bin/sh

# The following if/fi block gives you flexibility in choosing the pathname
# for make(1).
if
	test "$1" != ""		# the make pathaname was passed as an argument
then
	MAKE="$1" ; export MAKE	# so use the pathname
	if
		test ! -x "$MAKE" # if the pathname is wrong, stop right now
	then
		echo "$MAKE does not exist as an executable file."
		exit 2
	fi
elif
	test ! -z "$MAKE"		# otherwise, check for environment variable
then
	if
		test ! -x "$MAKE"	# if the pathname is wrong, stop right now
	then
		echo "You have MAKE defined as an environment variable, but"
		echo "it does not exist as an executable file."
		exit 2
	fi
else
	MAKE=make ; export MAKE	# no variable, so let the user's path decide
fi

# This test always exits with a zero status, because there is no single way
# of choosing a shell that can be considered correct.

echo 'Checking SHELL environment variable' > shell.log
if
	SHELL=/bin/csh ; export SHELL
	$MAKE -f shell.mk cshell > shell.log 2>&1
then
	echo 'This version of make invokes the SHELL from the user environment'
else
	echo 'This version of make overrides the user environment with Bourne shell'
fi

echo 'Checking SHELL macro' > shell.log
if
	$MAKE -f shell.mk SHELL=/bin/csh cshell > shell.log 2>&1
then
	echo 'This version of make allows you to explicitly set the SHELL'
else
	echo 'This version of make enforces the use of Bourne shell at the top level'
fi

echo 'Checking SHELL macro recursively' > shell.log
if
	$MAKE -f shell.mk recurs > shell.log 2>&1
then
	echo 'This version of make allows the SHELL to be set on recursive makes'
else
	echo 'This version of make enforces the use of Bourne shell at all levels'
fi

rm -f shell.log
exit 0

# Other possibly useful tests, not run here
# $MAKE -f shell.mk SHELL=/bin/sh bourneshell > shell.log 2>&1
# $MAKE -f shell.mk SHELL=/bin/junk echo > shell.log 2>&1
