#! /bin/sh

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

# 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
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
		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;;
*)	echo trying to make in GNU mode
	make -f makefile.gcc $1;;
esac
