#! /bin/sh
exitstat=0

# 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

rm -rf sub empty.o check new_file
mkdir sub
echo 'A file in the subdirectory' > sub/file
mkdir sub/lower
echo 'A file in the lower subdirectory' > sub/lower/file

echo 'Checking VPATH for explicit object dependency' > vpath.log
if
	$MAKE -f vpath.mk check VPATH=sub > vpath.log 2>&1
then
	echo 'This version of make supports VPATH'
	rm -rf check new_file sub/check sub/new_file

	echo 'Checking VPATH for relative pathname' > vpath.log
	if
		$MAKE -f vpath.mk lowercheck VPATH=sub > vpath.log 2>&1
	then
		echo 'This version of make searches VPATH for relative pathnames'
	else
		echo 'This version of make does not search VPATH for relative pathnames'
	fi
	echo 'main(){}' > sub/empty.c

	echo 'Checking VPATH for object dependency not in the makefile' > vpath.log
	if
		$MAKE -f vpath.mk empty.o VPATH=sub > vpath.log 2>&1
	then
		echo 'This version of make searches VPATH for implicit prerequisites'
	else
		echo 'This version of make does not search VPATH for implicit prerequisites'
	fi
	rm -rf check new_file
	touch sub/new_file

	echo 'Checking VPATH for word on command line' > vpath.log
	if
		$MAKE -f vpath.mk check VPATH=sub 2>&1 | grep 'sub/new_file' > vpath.log 2>&1
	then
		echo 'This version of make searches VPATH for tokens on command lines'
	else
		echo 'This version of make does not search VPATH for tokens on command lines'
	fi
	rm -rf check new_file
	cp vpath.mk sub/tmp$$.mk

	echo 'Checking VPATH for makefiles' > vpath.log
	if
		$MAKE -f tmp$$.mk check VPATH=sub > vpath.log 2>&1
	then
		echo 'This version of make searches VPATH for description files'
	else
		echo 'This version of make does not search VPATH for description files'
	fi
	rm -rf check
	echo "include tmp$$.mk" > top$$.mk

	echo 'Checking VPATH for include files' > vpath.log
	if
		$MAKE -f top$$.mk check VPATH=sub 2>&1 | grep 'file' > vpath.log 2>&1
	then
		echo 'This version of make searches VPATH for include files'
	else
		echo 'This version of make does not search VPATH for include files'
	fi
else
	echo 'This version of make does not support VPATH'
	exitstat=1
fi
rm -rf sub empty.o check new_file top$$.mk vpath.log
exit $exitstat
