#!/bin/sh
#
#	aimk.sh
#
#	Architecture Dependent Make Facility.  Automatically sets PVM
#	machine-type for make to use.
#
#	usage:
#	    aimk [-here] [-nomk] [ make args ... ]
#
#	09 Apr 1993  Manchek
#

makeincwd=0
nomk=0
found=1
while [ $# -ge 1 -a $found = 1 ]; do
	found=0
	case "$1" in
	-here ) makeincwd=1; shift; found=1 ;;
	-nomk ) nomk=1 shift; found=1 ;;
	esac
done

case "x$PVM_ROOT" in x )
	if [ -d $HOME/pvm3 ]; then
		PVM_ROOT=$HOME/pvm3
	else
		echo aimk: PVM_ROOT not defined >&2
		exit 1
	fi
;; esac

case "x$PVM_ARCH" in x )
	PVM_ARCH="`$PVM_ROOT/lib/pvmgetarch`"
	case "x$PVM_ARCH" in x )
		echo aimk: can\'t set arch >&2
		exit 1
	;; esac
;; esac

#
# get lflags
#

ARCHLIB=""
case "$ARCH" in
BSD386 | PGON ) ARCHLIB="-lrpc" ;;
I860 | IPSC2 )  ARCHLIB="-lrpc -lsocket" ;;
SGI )           ARCHLIB="-lsun" ;;
esac

export ARCHLIB
export PVM_ARCH

#
# run make in cwd or subdir if exists.
#

if [ $nomk = 1 ]; then echo $PVM_ARCH; exit 0; fi

if [ $makeincwd = 0 -a -d $PVM_ARCH ]; then
	echo making in $PVM_ARCH/ for $PVM_ARCH
	(cd $PVM_ARCH; make PVM_ARCH=$PVM_ARCH $@)
else
	echo making in . for $PVM_ARCH
	make PVM_ARCH=$PVM_ARCH $@
fi

echo done.
exit

