#! /bin/sh

# go into source directory to make ...
cd src

MAKE=${MAKE-make}

if [ "$GMAKE" = "" ]
then	# try to find gmake for use with gcc
	# (on some systems, Mac, I think, cc was gcc but make was not gmake
	#  which is a problem)
	if type gmake > /dev/null 2> /dev/null
	then	GMAKE=gmake
	else	GMAKE=make	# $MAKE ?
				# but make might be gmake while $MAKE is not
	fi
fi

# if make target is install, prevent using makefile.gcc as installation 
# target directories would be wrong
case "$1" in
*install*)	CC=true;;
esac

# if CC is explicitly set to gcc, shortcut to use it
case "$CC" in
gcc)	$GMAKE -f makefile.gcc $1
	exit;;
"")	CC=cc;;
esac

case `uname` in
Linux*)	$MAKE -f makefile.linux $1;;
Sun*)	if type $CC > /dev/null 2> /dev/null
	then	if $CC | grep "software package not installed"
		then	$MAKE -f makefile.gcc $1
		elif type $CC | grep "/ucb"
		then	$MAKE -f makefile.ucb $1
		else	$MAKE -f makefile.sun $1
		fi
	else	$MAKE -f makefile.gcc $1
	fi;;
HP*)	$MAKE -f makefile.hp $1;;
*BSD*)	$GMAKE -f makefile.bsd $1;;
CYG*)	INSTALLTARGET=installcygwin $MAKE -f makefile.cygwin $1;;
Darwin*)
	if type gcc > /dev/null 2> /dev/null
	then	$MAKE -f makefile.osx $1
	else	echo Mac compilation should have gcc available -
		echo keyboard mappings do not compile with cc
		false
	fi;;
Interix)
	$MAKE -f makefile.interix $1;;
*)	echo trying to make in GNU mode
	$MAKE -f makefile.gcc $1;;
esac
