#!/bin/bash

# Make command-line arguments, starting at the top-level Starlab
# (or other) directory and suppressing some extraneous output.
#
# Option "-d dir" or "-C dir" (for consistency with make) replaces
# STARLAB_PATH by dir.

list=""
dir=$STARLAB_PATH

while [ "x$1" != "x" ]; do
    if [ "x$1" = "x-d" -o "x$1" = "x-C" ]; then
	shift
	dir=$1
    else
	list="$list $1"
    fi
    shift
done

echo Making \"$list\" in $dir

# Warn if we aren't building within the current Starlab tree.

if  [ "x$dir" != "x$STARLAB_PATH" ]; then

#   The following 4 lines can be removed once sbin/make all is automatic.

    tmp=`which readlink 2> /dev/null`
    if [ "x$tmp" = "x" ]; then
	make -C $STARLAB_PATH/sbin all > /dev/null
    fi

    sl=`readlink -f $STARLAB_PATH`
    dr=`readlink -f $dir`

    tmp=`echo $dr | grep $sl`
    if [ "x$tmp" = "x" ]; then
	echo Warning: building outside the current Starlab tree
    fi
fi

make -s -C $dir $list

