#!/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: SHMAKE,v 3.5.2.1 95/10/11 10:01:16 raiff Exp $";
#endif /*_BLURB_*/


# Shadow make script for Coda development.
# Relies on the shadowing facility of CMU-CS make
# Allows you to just checkout a few file to modify in your working directory
# CAVEAT: assumes your working directory name is same as module name

if ($#argv < 1) then
echo "Usage: SHMAKE OBJECTDIR=<objectdir> [<target1> <target2> ...]"
exit(1)
endif


set SHADOW = /coda/project/coda/alpha/src 
set HERE = `pwd`
set MODULE = `basename $HERE`

# Figure out the right Makefile to use
set MAKEFILE = "$SHADOW/$MODULE/Makefile"
if (-e $SHADOW/$MODULE/Makefile.coda) set MAKEFILE = $SHADOW/$MODULE/Makefile.coda
if (-e Makefile) set MAKEFILE = Makefile
if (-e Makefile.coda) set MAKEFILE = Makefile.coda


# Scan input arguments to see if PERSONAL_INCLUDE is defined
# If so, set PIVAL to `pwd` concatenated with the command line value
# If not, set PIVAL to just `pwd`
# In all cases, ARGS contains the command line args sans PERSONAL_INCLUDE

set ARGS = ""
set PIVAL = ""

while ("$1" != "")

# Obtain next keyword, value pair
set KEYWORD = `expr "$1" : '\(.*\)=.*'`
set VALUE = `expr "$1" : '.*=\(.*\)'`


if ("$VALUE" == "") then
# We've run out of keyword, value pairs on command line
break
endif

switch ($KEYWORD)

case PERSONAL_INCLUDE:
#	Extract specified value and quit
	set PIVAL = "$VALUE"
	shift
	break

default:
#	Concatenate current arg to ARGS and move on	
	set ARGS = ($ARGS $KEYWORD"="$VALUE)
	shift
	breaksw
endsw

end


if ("$PIVAL" != "") then
# we found PERSONAL_INCLUDE on command line
set PIVAL = (`pwd` -I$PIVAL)
else 
# $ARGS is already a copy of the entire command line
set PIVAL = (`pwd`)
endif

# Assemble new command line
set ARGS = ($ARGS $*)

# Unlimit resources that keep huge binaries from linking on some platforms
unlimit stacksize
unlimit datasize

# Do the compilation after echoing the make command 
source $SHADOW/SOURCEME
echo "make -c -f $MAKEFILE SOURCEDIR=$SHADOW MODULEDIR=$SHADOW/$MODULE PERSONAL_INCLUDE='$PIVAL' $ARGS"
make -c -f $MAKEFILE SOURCEDIR=$SHADOW MODULEDIR=$SHADOW/$MODULE PERSONAL_INCLUDE="$PIVAL" $ARGS

