#! /bin/sh
#
# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.
#
#ident "$Header: :mkbcs 1.8 90/04/21 $"
#
#
#	Shell script for building the BCS-specific files.
#
trap "exit 1" 1 2 3 15
date
MAKE=${MAKE:-make}
SRCDIR=${SRC:-$ROOT/usr/src}/bcs
if [ -f /dynix ]
then
   chown=/etc/chown
else
   chown=/bin/chown
fi
chgrp=/bin/chgrp

# Make sure there is really work to be done in this view
#
if [ ! -d $SRCDIR ]
then
        exit 0
fi

cd $SRCDIR

###############################################################################
# Create the binary tree (if it is not already there)			      #
###############################################################################

if [ ! -d $ROOT ]
then
	mkdir  $ROOT
fi
if [ ! -d $ROOT/usr ]
then
	mkdir  $ROOT/usr
fi
if [ ! -d $ROOT/usr/include ]
then
	mkdir  $ROOT/usr/include
fi
if [ ! -d $ROOT/usr/include/bcs ]
then
	mkdir  $ROOT/usr/include/bcs
fi
if [ ! -d $ROOT/usr/include/bcs/sys ]
then
	mkdir  $ROOT/usr/include/bcs/sys
fi
if [ ! -d $ROOT/usr/include/bcs/sys/fs ]
then
	mkdir  $ROOT/usr/include/bcs/sys/fs
fi
if [ ! -d $ROOT/lib ]
then
	mkdir  $ROOT/lib
fi
if [ ! -d $ROOT/lib/bcs ]
then
	mkdir  $ROOT/lib/bcs
	chown bin $ROOT/lib/bcs
	chgrp bin $ROOT/lib/bcs
	chmod 775 $ROOT/lib/bcs
	
fi
if [ ! -d $ROOT/usr/lib ]
then
	mkdir  $ROOT/usr/lib
fi
if [ ! -d $ROOT/usr/lib/bcs ]
then
	mkdir  $ROOT/usr/lib/bcs
	chown bin $ROOT/usr/lib/bcs
	chgrp bin $ROOT/usr/lib/bcs
	chmod 775 $ROOT/usr/lib/bcs
fi
if [ ! -d $ROOT/usr/lib/bcs/libp ]
then
	mkdir  $ROOT/usr/lib/bcs/libp
	chown bin $ROOT/usr/lib/bcs/libp
	chgrp bin $ROOT/usr/lib/bcs/libp
	chmod 775 $ROOT/usr/lib/bcs/libp
fi

###############################################################################
# Clean up any previous files						      #
###############################################################################
find $ROOT/usr/include/bcs -type f -print | xargs rm -f

###############################################################################
# Copy BCS header files to the tmpos                                          #
###############################################################################
(cd head; find . -print | cpio -pvdmu $ROOT/usr/include/bcs)
rm -f $ROOT/usr/include/bcs/sys.*
cp head/sys.i386 $ROOT/usr/include/bcs/sys.s
find $ROOT/usr/include/bcs -name ".ccsmark" -print | xargs rm -f
find $ROOT/usr/include/bcs -type d -print | xargs chmod 775
find $ROOT/usr/include/bcs -type f -print | xargs chmod 444
find $ROOT/usr/include/bcs -print | xargs chown bin
find $ROOT/usr/include/bcs -print | xargs chgrp bin

###############################################################################
# Make and install the BCS libc.a					      #
###############################################################################
(cd libc;
	PARALLEL=20 export PARALLEL;
	$MAKE -P20 -f libc.mk install;
	if [ $? -ne 0 ] 
	then
		echo ":mkbcs: *** $MAKE failed using libc.mk";
	fi;
) &

###############################################################################
# Make and install the BCS libnsl.a					      #
###############################################################################
(cd nsl;
	PARALLEL=20 export PARALLEL;
	$MAKE -P20 -f nsl.mk install;
	if [ $? -ne 0 ] 
	then
		echo ":mkbcs: *** $MAKE failed using nsl.mk";
	fi;
) &

###############################################################################
# Make and install the BCS libg.a					      #
###############################################################################
(cd libg;
	PARALLEL=20 export PARALLEL;
	$MAKE -P20 -f libg.mk install;
	if [ $? -ne 0 ] 
	then
		echo ":mkbcs: *** $MAKE failed using libg.mk";
	fi;
) &

###############################################################################
# Make and install the BCS libPW.a					      #
###############################################################################
(cd libPW;
	PARALLEL=20 export PARALLEL;
	$MAKE -P20 -f libPW.mk install;
	if [ $? -ne 0 ] 
	then
		echo ":mkbcs: *** $MAKE failed using libPW.mk";
	fi;
) &

###############################################################################
# Make and install the BCS libm.a					      #
###############################################################################
(cd libm;
	PARALLEL=20 export PARALLEL;
	$MAKE -P20 -f libm.mk install;
	if [ $? -ne 0 ] 
	then
		echo ":mkbcs: *** $MAKE failed using libm.mk";
	fi;
) &

###############################################################################
# Make and install the BCS libmalloc.a					      #
###############################################################################
(cd libmalloc;
	PARALLEL=20 export PARALLEL;
	$MAKE -P20 -f libmalloc.mk install;
	if [ $? -ne 0 ] 
	then
		echo ":mkbcs: *** $MAKE failed using libmalloc.mk";
	fi;
) &
###############################################################################
# Make and install the BCS libl.a					      #
###############################################################################
(cd libl;
	PARALLEL=20 export PARALLEL;
	$MAKE -P20 -f libl.mk install;
	if [ $? -ne 0 ] 
	then
		echo ":mkbcs: *** $MAKE failed using libl.mk";
	fi;
) &
###############################################################################
wait
date
exit 0
