#!/bin/csh -f

#ifndef _BLURB_
#define _BLURB_
#/*
#
#            Coda: an Experimental Distributed File System
#                             Release 3.1
#
#          Copyright (c) 1987-1995 Carnegie Mellon University
#                         All Rights Reserved
#
#Permission  to  use, copy, modify and distribute this software and its
#documentation is hereby granted,  provided  that  both  the  copyright
#notice  and  this  permission  notice  appear  in  all  copies  of the
#software, derivative works or  modified  versions,  and  any  portions
#thereof, and that both notices appear in supporting documentation, and
#that credit is given to Carnegie Mellon University  in  all  documents
#and publicity pertaining to direct or indirect use of this code or its
#derivatives.
#
#CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
#SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
#FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
#DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
#RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
#ANY DERIVATIVE WORK.
#
#Carnegie  Mellon  encourages  users  of  this  software  to return any
#improvements or extensions that  they  make,  and  to  grant  Carnegie
#Mellon the rights to redistribute these changes without encumbrance.
#*/
#
#static char *rcsid = "$Header: MAKECODA,v 3.2.2.1 95/10/11 10:00:54 raiff Exp $";
#endif /*_BLURB_*/


# Run in top-level Coda source directory
# Builds all the Coda modules in the correct order
# This script assumes you want to suppress auto RCS checkins after module installations.

# Takes a list of optional arguments specified by keywords
#	ROOT		defines the root of this release tree
#	OBJECTDIR	specifies where object files are put by make. Undefined by default.
#	FIRSTMODULE	specifies the name of the module at which to begin compilations
#			This is useful if the compilation breaks, and you want to continue
#			rather than restart

# Eg:  MAKECODA OBJECTDIR=/coda/usr/satya/testvol/OBJS/@sys ROOT=/coda/project/coda/alpha FIRSTMODULE=venus
# Eg:  MAKECODA OBJECTDIR=/tmp


# ******* Define precedence of modules ******
set    I =  (scripts)
set   II =  (igmp sunrpc sys dir mlwp)
set  III =  (rpc2 util)
set   IV =  (libal rp2gen pdbstuff blurb camstuff)
set    V =  (auth2 fail vicedep)
# The mond data collection module is only intended for the PMax
#if (`/etc/machine` == PMAX) then
set VI = (mond vv cfs login)
#else
set VI = (vv cfs login)
#endif
set  VII =  (vol resolve)
set VIII =  (venus advice repair res)
set   IX =  (rvmres volutil vtools)
set    X =  (vice)
set   XI =  (update norton asr egasr)
# If you add a new module to Coda, add it to the right set above

set TODO = ($I $II $III $IV $V $VI $VII $VIII $IX $X $XI)

# Set default definitions of key variables
# These variable override similarly named ones in Makeconf
# Note: the makebeta script edits these, so be careful to fix 
#	makebeta if you edit these in any way
set ROOT = /coda/project/coda/beta-11Oct1995_34901
set OBJECTDIR = _UNDEFINED_
set FIRSTMODULE = scripts

# ******* Process input args ********

while ($1 != "")

set KEYWORD = `expr $1 : '\(.*\)=.*'`
set VALUE = `expr $1 : '.*=\(.*\)'`

switch ($KEYWORD)

case ROOT:
	set ROOT = $VALUE
	breaksw

case OBJECTDIR:
	set OBJECTDIR = $VALUE
	breaksw

case FIRSTMODULE:
	set FIRSTMODULE = $VALUE
	breaksw

default:
	echo "Usage: MAKECODA [OBJECTDIR=<pathname for OBJECTDIR>] [ROOT=<pathname of ROOT>] [FIRSTMODULE = <first module name>]"
	exit
	breaksw

endsw

shift
end

# Let user know what values of key variables are
echo "ROOT is $ROOT"
if ($OBJECTDIR == "__UNDEFINED__") then
echo "You must explicitly define OBJECTDIR"
exit
else
echo "OBJECTDIR is $OBJECTDIR"
endif
echo "FIRSTMODULE is $FIRSTMODULE"

if ($FIRSTMODULE != "scripts") then
echo -n "Skipping the following modules: "
while ($TODO[1] != $FIRSTMODULE)
echo -n "$TODO[1] "
shift TODO
if ($#TODO == 0) then
echo ""
echo "Couldn't find module $FIRSTMODULE; exiting..."
exit
endif
end
echo ""
endif


# ******* Warn user of any "install by hand" files missing (details in README) ********


set BINSPECIAL = $ROOT/bin-special
set INCLSPECIAL = $ROOT/include-special
set LIBSPECIAL = $ROOT/lib-special


set INCLUDE_FILES = 'assert.h cthreads.h setjmp.h i386/fpreg.h i386_mach/endian.h rvm.h rds.h rvm_lwp.h rvm_segment.h rvm_statistics.h tracelib.h'

set MISSING_INCLUDES = " "

foreach F ($INCLUDE_FILES)
if (-e $INCLSPECIAL/$F) continue
set MISSING_INCLUDES = "$MISSING_INCLUDES include-special/$F"
end

set LIB_FILES = "librvm.a librvmlwp.a libseg.a librds.a librdslwp.a libtrace.a libplumber.a libnewplumb.a"
set MISSING_LIBS = ""
foreach F ($LIB_FILES)
if (-e $LIBSPECIAL/$F) continue
set MISSING_LIBS = "$MISSING_LIBS lib-special/$F"
end

set BIN_FILES = "rdsinit rvmutl"
set MISSING_BINS = ""
foreach F ($BIN_FILES)
if (-e $BINSPECIAL/$F) continue
set MISSING_BINS = "$MISSING_BINS bin-special/$F"
end

set NINCLUDES = ($MISSING_INCLUDES)
set NLIBS = ($MISSING_LIBS)
if ($#NINCLUDES != 0 || $#NLIBS != 0) then
echo "  "  
echo "ERROR: The following files to be copied in by hand are missing:"
foreach F ($MISSING_INCLUDES $MISSING_LIBS)
echo "         $F"
end
echo "  "
echo "This may result in compilation or link errors in building Coda"
set reply
while (($reply != "y") && ($reply != "n"))
echo -n "Do you still want to continue? [yn] "
set reply = "$<"
end
if ($reply == "n") exit(1)
endif 
endif


set NBINS = ($MISSING_BINS)
if ($#NBINS != 0) then
echo "WARNING: The following files to be copied in by hand are missing:"
foreach F ($MISSING_BINS)
echo "         $F"
end
echo "  "  
echo "This may cause problems when trying to set up Coda servers or clients"
set reply
while (($reply != "y") && ($reply != "n"))
echo -n "Do you still want to continue? [yn] "
set reply = "$<"
end
if ($reply == "n") exit(1)
endif


# ********* Now do the actual compilations *********

# Set environment variable to supress RCS checkins by make install's
setenv SUPPRESS_ALPHACI

# Set PLAINC to be the right compiler on the RT and the SUN4.
unsetenv PLAINC
if (`/etc/machine` == IBMRT) setenv PLAINC /usr/misc/.hc/bin/hc2
if (`/etc/machine` == SUN4) then
	setenv PLAINC /usr/misc/.gnu-comp/bin/gcc
	setenv ccC /usr/misc/.gnu-comp/bin/gcc
	setenv CC 'CC +a1'
endif


# Now do the compiles and installs
source SOURCEME
setenv ROOT $ROOT
foreach D ($TODO)
echo "----------- $D -------------"
(cd $D; set MAKEFILE=Makefile; if (-e Makefile.coda) set MAKEFILE=Makefile.coda; make -c OBJECTDIR=$OBJECTDIR ROOT=$ROOT SOURCEDIR=../REALBETA/src MODULEDIR=`pwd` -f $MAKEFILE install)
if ($status) exit
end
