#	Copyright (c) 1984 AT&T
#	  All Rights Reserved

#	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#	The copyright notice above does not evidence any
#	actual or intended publication of such source code.

#ident	"@(#)mk::mk	1.10"
#
#	Shell script for rebuilding the UNIX System
#
trap "exit 1" 1 2 3 15
if [ "$ROOT" = "" ]
then
	PATH=/bin:/etc:/usr/bin; export PATH
fi

UID_NAME=`id|sed 's/[()]/ /gp'|awk '{print $2}'`

# Check for the existance of target directories
test -d ${ROOT:-"/"} || mkdir -p $ROOT
cat -s target.dirs	|	# print contents of the target directory list
egrep -v "^$|^#"	|	# get rid of blank lines and comments
while read TARGETDIR MODE OWNER GROUP
do
	if [ ! -d ${ROOT}/$TARGETDIR ]
	then
		mkdir ${ROOT}/$TARGETDIR
		if [ ! -d ${ROOT}/$TARGETDIR ]
		then
			echo "$0: stop: make of directory ${ROOT}/$TARGETDIR failed"
			exit 1
		fi
			
	fi
	if [ "$UID_NAME" = "root" ]
	then
		if [ ! -z "$MODE" -a "$MODE" != "-" ]
		then
			chmod $MODE ${ROOT}/$TARGETDIR
		fi
		if [ ! -z "$OWNER" -a "$OWNER" != "-" ]
		then
			chown $OWNER ${ROOT}/$TARGETDIR
		fi
		if [ ! -z "$GROUP" -a "$GROUP" != "-" ]
		then
			chgrp $GROUP ${ROOT}/$TARGETDIR
		fi
	fi
done

#	install /usr/include and /usr/include/sys header files
./:mkhead
./:mksyshead
#	build and install the C library
./:mklib libc
#	build the C compilation tools
if vax || pdp11
then
	./:mkcmd $* cc
else
	./:mkcmd sgs
fi
#	build the other libraries
./:mklib \*
#	build the system administration tools
if [ "$ROOT" != "" ]
then
	./:mkcmd .adm
fi
#	build all the commands
./:mkcmd $* \*
#	build stand-alone system, if appropriate
if vax || pdp11
then
	./:mkstand
fi
#	build the OS itself
./:mkuts
#	build the compatibility package
if [ -d ucbcmd -d -s ucbhead -d -s ucblib ]
then
	./:mkucb
fi
exit 0
