#!/bin/csh -x
#
# Last Edited: Mon Apr 17 10:02:30 PDT 1995
#
# _make_mg_ide
#
# Called by make_mg_ide
#
# Usage: _make_mg_ide [nopurge] [noupdate] [noclobber] [irix_hdrs]
# 	noclobber, noupdate, and nopurge are optional args to prevent clobbering
#	p_tupdates or p_purges. The default is to purge, clobber, and update 
#	everything.
#
# This script does the following tasks in the future tree:
#
#	0. Save the current gold.ide to gold.ide.$LOGFILE
#	1. p_check and p_purge obsolete files in $WORKAREA/irix/kern, include
#	2. p_tupdate $WORKAREA/irix/kern, include
#	2a. check files in gfx/kern, gfx/include and p_tupdate.
#	3. p_check and p_purge obsolete files in $WORKAREA/stand which affect
#		building the mardi gras ide.
#	4. p_tupdate $WORKAREA/stand  files which affect the mardi gras ide
#		(e.g. lib, ide/IP22, ide_alloc.c, etc)
#	5. "make headers" in irix/kern, irix/include
#	6. "make" in the lib area
#	7. "make" in the ide area
#
#	In the lotus tree, the script will do steps:
#	0, 2a, 3, 4, 6, and 7. Steps 1, 2, and 5 are not performed.
#
#	All the actions of the script are kept in log files stored at:
#		$WORKAREA/stand/arcs/ide/IP22/graphics/mgras/buildlog/*
#	
#		where the files will be stored as timestamps, e.g. 941130_1034
#		will represent the log file from Nov 11, 1994 1034.
#
#	8. Check the log file for any build errors by grepping for strings
#		like: error, warning, etc
#

echo; echo "Script started at `date`"; echo

#
# Set some env vars
#
setenv PRODUCT 4DMG

#
# Get arguments, $1 = nopurge, $2 = noupdate, $3 = noclobber
#
unalias rm
setenv INSTOPTS -t
setenv PURGE   	$1
setenv UPDATE  	$2
setenv CLOBBER 	$3
setenv LOGFILE 	$4
setenv WORKAREA $5
setenv ROOT 	$6
setenv TOOLROOT $7
setenv IRIX_HDRS $8

set path = ($path /usr/local/bin/ptools .)

echo "CLOBBER: $CLOBBER"
echo "UPDATE: $UPDATE"
echo "PURGE: $PURGE"
echo "LOGFILE: $LOGFILE"
echo "WORKAREA: $WORKAREA"
echo "ROOT: $ROOT"
echo "TOOLROOT: $TOOLROOT"
echo "IRIX_HDRS: $IRIX_HDRS"

echo $WORKAREA | grep -i lotus >! /dev/null
if ($status == 0 ) then
	setenv LOTUS_TREE 1
else
	setenv LOTUS_TREE 0
endif
echo "LOTUS: $LOTUS_TREE"
#
# Save the current shell.ide
#
if (-d $WORKAREA/stand/arcs/ide/4DMG.O) then
	cd $WORKAREA/stand/arcs/ide/4DMG.O
	if (-e mgshell.ide) then
		setenv olddate `ls -al mgshell.ide | awk '{printf("%s_%d_%s", $6,$7,$8)}'`
		echo "Copying the current mgshell.ide to gold.ide.$olddate"
		cp mgshell.ide /usr/local/boot/gold.ide.$olddate
	endif
endif
#
# Check irix/kern, irix/include
#
if ($LOTUS_TREE == 0) then
echo "Checking $WORKAREA/irix/kern"
cd $WORKAREA/irix/kern

if ($PURGE) then
	echo "Checking and purging files..."
	p_check -s -v | p_purge -u -v -y -i 
#else
#	echo "No files will be purged since -nopurge was specified"
#	p_check -s -v
endif

if ($UPDATE) then
	echo "Updating files..."
	p_tupdate -v
#else
#	p_tupdate -n
endif

echo "Checking $WORKAREA/irix/include"
cd $WORKAREA/irix/include

if ($PURGE) then
	echo "Checking and purging files..."
	p_check -v -s | p_purge -u -v -y -i 
#else
#	echo "No files will be purged since -nopurge was specified"
#	p_check -v -s
endif

if ($UPDATE) then
	echo "Updating files..."
	p_tupdate -v
#else
#	p_tupdate -n
endif

endif # LOTUS

################
if ($IRIX_HDRS == 1) then
cd $WORKAREA/stand/arcs/ide/IP22/graphics/MGRAS
_banyan_hdr
endif  # IRIX_HDRS

################

#
# Checking gfx/kern
#
echo "Checking $WORKAREA/gfx/kern"
cd $WORKAREA/gfx/kern

if ($PURGE) then
	echo "Checking and purging files..."
	p_check -v -s | p_purge -u -v -y -i 
endif

if ($UPDATE) then
	echo "Updating files..."
	p_tupdate -v
endif
#
# Checking gfx/include
#
echo "Checking $WORKAREA/gfx/include"
cd $WORKAREA/gfx/include

if ($PURGE) then
	echo "Checking and purging files..."
	p_check -v -s | p_purge -u -v -y -i 
endif

if ($UPDATE) then
	echo "Updating files..."
	p_tupdate -v
endif
#
# Check stand/arcs/* top-level files
#
# Check stand/arcs/* top-level files
#
echo "Checking $WORKAREA/stand/arcs top-level files"
cd $WORKAREA/stand/arcs

if ($UPDATE) then
   p_tupdate -v R4000defs commondefs commonrules newvers.sh ENDIANdefs MIdefs 
#else
#   p_tupdate -n R4000defs commondefs commonrules newvers.sh ENDIANdefs MIdefs 
endif
#
# Check stand/arcs/include
#
echo "Checking $WORKAREA/stand/arcs/include"
cd $WORKAREA/stand/arcs/include

if ($PURGE) then
	echo "Checking and purging files..."
	p_check -v -s | p_purge -u -v -y -i	
#else
#	echo "No files will be purged since -nopurge was specified"
#	p_check -v -s 
endif

if ($UPDATE) then
	p_tupdate -v
#else
#	p_tupdate -n
endif
#
# Check stand/arcs/scripts
#
echo "Checking $WORKAREA/stand/arcs/scripts"
cd $WORKAREA/stand/arcs/scripts

if ($PURGE) then
	echo "Checking and purging files..."
	p_check -v -s | p_purge -u -v -y -i
#else
#	echo "No files will be purged since -nopurge was specified"
#	p_check -v -s
endif

if ($UPDATE) then
	p_tupdate -v
#else
#	p_tupdate -n
endif
#
# Check stand/arcs/lib
#
echo "Checking $WORKAREA/stand/arcs/lib"
cd $WORKAREA/stand/arcs/lib

if ($PURGE) then
	echo "Checking and purging files..."
	p_check -v -s | p_purge -u -v -y -i
#else
#	echo "No files will be purged since -nopurge was specified"
#	p_check -v -s
endif

if ($UPDATE) then
	p_tupdate -v
#else
#	p_tupdate -n
endif

#
# Check stand/arcs/ide
#
echo "Checking $WORKAREA/stand/arcs/ide"
cd $WORKAREA/stand/arcs/ide

if ($PURGE) then
	echo "Checking and purging files..."
	p_check -v -s | p_purge -u -v -y -i
#else
#	echo "No files will be purged since -nopurge was specified"
#	p_check -v -s
endif

if ($UPDATE) then
	p_tupdate -v -x stand/arcs/ide/EVEREST,stand/arcs/ide/IP19,stand/arcs/ide/IP20
#else
#	p_tupdate -n -x stand/arcs/ide/EVEREST,stand/arcs/ide/IP19,stand/arcs/ide/IP20
endif

#
# make headers in irix/kern, irix/include, gfx/kern, gfx/include
#
if ($LOTUS_TREE == 0) then
	echo "Doing a make headers in irix/kern, irix/include"
	cd $WORKAREA/irix/kern
	make headers &
	cd $WORKAREA/irix/include
	make headers &
endif
echo "Doing a make headers in gfx/kern, gfx/include"
cd $WORKAREA/gfx/kern
make headers &
cd $WORKAREA/gfx/include
make headers &
wait

#
#
# doing a make in arcs/lib, arcs/ide
#
if ($CLOBBER) then
	echo "Doing a make clobber in arcs/lib and arcs/ide"
	cd $WORKAREA/stand/arcs/lib
	make clobber &
	cd $WORKAREA/stand/arcs/ide
	make clobber &
	wait
endif

echo "Doing a make in arcs/lib"
cd $WORKAREA/stand/arcs/lib
make

echo "Doing a make in arcs/ide"
if ($LOTUS_TREE == 0) then
	cd $WORKAREA/stand/arcs/ide/IP22/graphics
	make -f Makefile.mgras
endif
cd $WORKAREA/stand/arcs/ide
make -f Makefile.mgras
