#! /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

echo 'Checking basic (object) syntax'  > lib_build.log
if
	$MAKE -f lib_build.mk | grep 'object' > lib_build.log 2>&1
then
	echo 'This version of make supports (object) for libraries'
else
	echo 'This version of make does not support (object) for libraries'
	exitstat=1
fi

echo 'mod1(){}' > mod1.c
echo 'mod2(){}' > mod2.c

echo 'Building dummy library'  > lib_build.log
$MAKE -f lib_build.mk libmods.a > lib_build.log 2>&1
touch mod1.c

echo 'Checking (object) syntax in context of a real library'  > lib_build.log
if
	$MAKE -f lib_build.mk libmods.a\(mod1.o\) > lib_build.log 2>&1
then
	echo 'This version of make supports (object) for libraries'
else
	echo 'This version of make does not support (object) for libraries'
	exitstat=1
fi

echo 'Updating an object file for next test'  > lib_build.log
$MAKE -f lib_build.mk mod1.o > lib_build.log 2>&1

#
# PORTABILITY PROBLEM: Most compilers create an object module named
# _mod1 (with a leading underscore) for a C module named mod1.  If
# this test fails, try running "nm mod1.o" to find out what the object
# module is named and make sure the script runs with the correct
# module name.
#
ENTRY_POINT="_mod1"
echo "Trying to rebuild object file that contains module: $ENTRY_POINT" > lib_build.log
if
	$MAKE -f lib_build.mk libmods.a\(\($ENTRY_POINT\)\) > lib_build.log 2>&1
then
	echo 'This version of make supports ((entry)) for libraries'
	echo "Name of entry is in format $ENTRY_POINT for a module named mod1"
else
	echo 'This version of make does not support ((entry)) for libraries'
	exitstat=1
fi
rm -f libmods.a mod1.o mod2.o mod1.c mod2.c lib_build.log
exit $exitstat

# second form of test -- simpler, but might fail.
# Sun system gets upset if you try to rebuild libc.a.
echo 'Checking (object) syntax in context of a real library'  > lib_build.log
if
	$MAKE /lib/libc.a\(printf.o\) > lib_build.log 2>&1
then
	echo 'This version of make supports (object) for libraries'
else
	echo 'This version of make does not support (object) for libraries'
	exitstat=1
fi
echo 'Checking ((entry)) syntax in context of a real library' > lib_build.logif
	$MAKE /lib/libc.a\(\(_printf\)\) > lib_build.log 2>&1
then
	echo 'This version of make supports ((entry)) for libraries'
else
	echo 'This version of make does not support ((entry)) for libraries'
	exitstat=1
fi
rm -f lib_build.log
exit $exitstat
