#!/bin/sh

# gmake wrapper script

# This is needed because the name of the make command in the cernlib source
# is assumed to be "gmake", but GNU Make is simply called "make" in most
# Linux distributions.

# Do not install this script to somewhere in a standard $PATH;
# it should be used only for the cernlib build process.

if [ "x$ADDONDIR" = x ] ; then
	echo "gmake: this script is not intended to be used outside the" 1>&2
	echo "       cernlib build process!" 1>&2
	exit 1
fi

MAKE=""

# see if there is a "gmake" other than this script
oldIFS="$IFS"
IFS=":"
oldADDONDIR="$ADDONDIR"
ADDONDIR=""
for dir in $PATH ; do
	if [ -x "$dir/gmake" ] && [ -f "$dir/gmake" ] && \
	   ! "$dir/gmake" --not-a-real-flag 2>&1 | grep -q cernlib ; then
		MAKE="$dir/gmake"
		break
	fi
done
export IFS="$oldIFS" ADDONDIR="$oldADDONDIR"

# if not, try to use "make"
# This is easier since we don't have to tiptoe around ourselves
[ "x$MAKE" = x ] && which make > /dev/null 2>&1 && MAKE=make

if [ "x$MAKE" = x ] ; then
	echo "gmake: wrapper script can find neither gmake nor make in \$PATH!"
	exit 1
fi

exec "$MAKE" "$@"

