#!/bin/sh
# @(#)LOAD version 3.24 created 12/20/94
# @(#)Copyright (c), 1987, 1994 StatSci, Inc.  All rights reserved.
#usage: Splus LOAD [sourcefile ...] [objfile ...] [archive ...] 
#	[macro=value ...] [CHAPTERS=chapters] 
#	[objfile ...] [archive ...]
VERSION=$SHOME/newfun/lib/main.a
L=$SHOME/newfun/lib export L
what=local.Sqpe
opts=

case $# in
0) set *.[rcfyl];;
esac

export local_load here
for i
do
case "$i" in
"*.[rcfyl]") echo nothing to LOAD; exit 1;;
*load_time.c) ;; #ignore
*.[crfyl] )
	this=`echo $i|sed 's/..$/.o/'`
	local_load="$local_load $this"
	need="$need $this"
	;;
CHAPTERS=*) eval $i
	for i in `echo $CHAPTERS|tr ':' ' '`
	do
		case $i in
		/*) local_load="$local_load $i.a";;
		*) local_load="$local_load $i/`basename $i`.a"
		esac
	done
	boots="$boots `echo $CHAPTERS|tr ':' ' '`"
	;;
*=*) opts="$opts \"$i\""
	;;
*) misc="$misc $i";;
esac
done

local_load="$local_load $L/maps.a $L/mathematic.a"
boots="$boots $L/maps $L/mathematic"

local_load="$local_load $misc"

if test -s $what; then
	mv $what  o$what;
	restore="mv o$what $what; exit 1"
else
	restore="exit 1"
fi

if test -r Makefile; then
	if grep '^include.*S_makefile' Makefile >/dev/null; then
		# from CHAPTER
		mf="-f Makefile"
	else
		mf="-f $L/S_makefile -f Makefile"
	fi
	echo Using ./Makefile in addition to $L/S_makefile
else
	mf="-f $L/S_makefile"
	if test -r makefile; then
		mf="$mf -f makefile"
		echo Using ./makefile in addition to $L/S_makefile
	fi
fi

export local_load
echo local_load="$local_load"
Splus BOOTSTRAP $boots	#create S_load_time file
if [ `PLATFORM` = "APOLLO" ] ; then mf="-P $mf" ; fi
eval "make $mf VERSION=$VERSION $need $what $opts" || $restore

if test -s o$what;then rm o$what; fi
exit 0
