
#
# aimk [-here] [-nomk] [ make args ... ]
#
# Architecture Dependent Make Facility.  Automatically sets PVM
# machine-type for make to use.
#
# This is a heuristic thing that may need to be tuned from time
# to time.  I don't know of a real solution to determining the
# machine type.  Claims to pick one of:
#   ALPHA, AFX8, BFLY, BSD386, CNVX, CM2, CM5, CRAY, CRAYSMP, DGAV,
#   HP300, HPPA, I860, KSR1, NEXT, PGON, PMAX, RS6K, SGI, SUN2, SUN3,
#   SUN4, SYMM, TITN, UVAX, VAX,
#   UNKNOWN
# Need to do:
#   IPSC2
#
# Aimk exports environment variables that can be used in makefiles
#   ARCH = the selected architecture
#   ARCHLIB = arch-specific libraries needed when using libpvm
#
# Notes:
#   1. Local people mess with things.
#   2. It's good to try a few things for robustness.
#
# 22 Jul 1991  Robert Manchek  manchek@CS.UTK.EDU.
# 16 Jan 1993  rewrote for Bourne shell
#

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

#
# begin section that may need to be tuned.
#
ARCH=UNKNOWN

if [ -f /bin/uname ]; then
	os="`/bin/uname -s`"
	ht="`/bin/uname -m`"
	osht="$os,$ht"

	case "$osht" in
	SunOS,sun3* ) ARCH=SUN3 ;;
	SunOS,sun4* ) ARCH=SUN4 ;;
	ULTRIX,RISC ) ARCH=PMAX ;;
	ULTRIX,VAX )  ARCH=UVAX ;;
	AIX,* )       ARCH=RS6K ;;
	*,9000/* )    ARCH=HPPA ;;
	IRIX,* )      ARCH=SGI ;;
	*,alpha )     ARCH=ALPHA ;;
	CRSOS,smp )   ARCH=CRAYSMP ;;
	*,paragon )   ARCH=PGON ;;
	dgux,AViiON ) ARCH=DGAV ;;
	esac
fi

if [ "$ARCH" = UNKNOWN ]; then
	if [ -f /bin/arch ]; then
		case "`/bin/arch`" in
		ksr1 ) ARCH=KSR1 ;;
		sun2 ) ARCH=SUN2 ;;
		sun3 ) ARCH=SUN3 ;;
		sun4 ) ARCH=SUN4 ;;
		esac
	fi
fi

if [ "$ARCH" = UNKNOWN ]; then

	if [ -f /ultrixboot ]; then
		if [ -f /pcs750.bin ]; then
			ARCH=UVAX
		else
			ARCH=PMAX
		fi
	else
		if [ -f /pcs750.bin ]; then ARCH=VAX; fi
	fi

	if [ -d /usr/alliant ]; then ARCH=AFX8; fi
	if [ -f /usr/bin/cluster ]; then ARCH=BFLY; fi
	if [ -d /usr/convex ]; then ARCH=CNVX; fi
	if [ -f /unicos ]; then ARCH=CRAY; fi
	if [ -f /hp-ux ]; then ARCH=HP300; fi
	if [ -f /usr/bin/getcube ]; then ARCH=I860; fi
	if [ -f /usr/bin/asm56000 ]; then ARCH=NEXT; fi
	if [ -f /etc/vg ]; then ARCH=RS6K; fi
	if [ -d /usr/include/caif ]; then ARCH=RT; fi
	if [ -f /dynix ]; then ARCH=SYMM; fi
	if [ -f /bin/titan ]; then ARCH=TITN; fi

	if [ -f /usr/bin/machine ]; then
		case "`/usr/bin/machine`" in
		i386 ) ARCH=BSD386 ;;
		esac
	fi
fi

if [ "$ARCH" = SUN4 -a -f /dev/cm ]; then ARCH=CM2; fi
if [ "$ARCH" = SUN4 -a -f /dev/cmni ]; then ARCH=CM5; fi

#
# ugh, done.
#

#
# get lflags
#

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

export ARCH
export ARCHLIB

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

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

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

echo done.
exit

