usage="\
Usage: $0 [options]
Options:
	-f <mcflags>, --flags <mcflags>
		Pass EXTRA_MCFLAGS=<mcflags> as an option to \`mmake check'.
	-m <mgnucflags>, --mgnucflags <mgnucflags>
		Pass EXTRA_MGNUCFLAGS=<mgnucflags> as an option to \`mmake check'.
	-c <cflags>, --cflags <cflags>
		Pass EXTRA_CFLAGS=<cflags> as an option to \`mmake check'.
	-l <mlflags>, --mlflags <mlflags>
		Pass EXTRA_MLFLAGS=<mlflags> as an option to \`mmake check'.
	-g <grade>, --grade <grade>
		Pass GRADE=<grade> as an option to \`mmake check'.
	-j <num-jobs>, --jobs <num-jobs>
		Run using <num-jobs> different parallel processes.
"

jfactor=""
flagsopt=""
mgnucflagsopt=""
cflagsopt=""
mlflagsopt=""
gradeopt=""
fflag=""
mflag=""
cflag=""
lflag=""
gflag=""

while [ $# -gt 0 ]; do
	case "$1" in

	-f|--flags)
		fflag="-f '$2'"
		flagsopt="EXTRA_MCFLAGS='$2'"
		shift ;;

	-m|--mgnucflags)
		mflag="-m '$2'"
		mgnucflagsopt="EXTRA_MGNUCFLAGS='$2'"
		shift ;;

	-c|--cflags)
		cflag="-c '$2'"
		cflagsopt="EXTRA_CFLAGS='$2'"
		shift ;;

	-l|--mlflags)
		lflag="-l '$2'"
		mlflagsopt="EXTRA_MLFLAGS='$2'"
		shift ;;

	-g|--grade)
		gflag="-g $2"
		gradeopt="GRADE=$2"
		shift ;;

	-j|--jobs)
		jfactor="-j$2"; shift ;;
	-j*)
		jfactor="-j` expr $1 : '-j\(.*\)' `" ;;
	--jobs*)
		jfactor="--jobs` expr $1 : '--jobs\(.*\)' `" ;;

	--)	
		shift; break ;;
	-*)
		echo "$0: unknown option \`$1'" 1>&2
		echo "$usage" 1>&2
		exit 1 ;;
	*)
		break ;;
	esac
	shift
done

if [ $# -ne 0 ]; then
	echo "$0: unexpected argument(s) \`$*'" 1>&2
	echo "$usage" 1>&2
	exit 1
fi

mmakeopts="$jfactor $flagsopt $mgnucflagsopt $cflagsopt $mlflagsopt $gradeopt"
runtestopts="$jfactor $mflag $cflag $lflag $fflag $gflag"
