
# Note - important blank line on top of file - prevents csh problems

# Set up loading for internal-function version of S executive
# reads list of directories (in $F) where internal things reside
#  Creates $I/inftbl.m $I/inlink.m
cd $M
case $# in
	1) list=$1;;
	0) list=infun.list;;
	*)echo "Usage INTERNAL [inlist]"; exit 1;;
esac

if test ! -r $list; then echo "Cannot open $list"; exit 1; fi
echo "Creating internal functions from list in $list"
cd $F; ls -d *lib | sort -u - $M/stop.list >/tmp/stop$$
cd $M
comm -23 $list /tmp/stop$$ >/tmp/list$$

# loop through all directories on the list making the internal routines
# and collecting the list of object file names
# for use when loading the executive

(
	for i in `cat /tmp/list$$`
	do
		cd $F/$i
		echo DIRECTORY $i
		$C/MAKE internal || exit 1
	done
) 2>&1 |
awk '
/DIRECTORY/ { dir = $2 }
/INTERNALS/ { for(i=2; i<=NF; i++) print(dir "/" $i) } ' |
sort -u >$M/load.list 

# create the relocatable object file with all $F object code in it
cd $M
$C/MAKE ILIST

# Pick out the function names in the Smakefiles listed in $list
# note that only lines containing ":" and "inter[face]" are included

cd $F
cat `sed </tmp/list$$ 's/$/\/Smakefile/'`|
	grep ":" |
	grep inter|
	egrep -v "internal|CINTER"|
	sed "s/:.*//"|
	awk -f $A/infun.awk

mv /tmp/inftbl.m /tmp/inlink.m $M


cd $M
echo 'Making the routines in the main ...'
$C/MAKE inftbl.o inlink.o
rm /tmp/stop$$ /tmp/list$$
