#!/bin/csh -f
#
# Copyright(c) Sophist Solutions Inc. 1990-1992.  All rights reserved
#
# $Header: /fuji/lewis/RCS/makeConfig,v 1.4 1992/12/07 04:05:55 lewis Exp $
#
#
#
# Description:
# 	Usage: makeConfig <MainDir> <Suffix> <MakefileSuffix> [<ConfigFileSuffix>]
#
#
# TODO:
#
#
# Notes:
#
#
# Changes:
#	$Log: makeConfig,v $
#		Revision 1.4  1992/12/07  04:05:55  lewis
#		*** empty log message ***
#
#		Revision 1.3  1992/12/05  03:57:28  lewis
#		Support for .pc extension that runs PCXLate and gets rid of crap
#		I'm not using right now.
#
#		Revision 1.2  1992/06/26  05:15:25  lewis
#		Use MLF Script instead of direct call to find - just make that
#		functionality more easily doable in peices.
#
#		Revision 1.2  1992/04/09  15:23:11  lewis
#		Added header to this script, and changed it to only link makefiles,
#		and build objects directories when the makefile suffix is .unix
#		(so we dont have to delete the right afterwards for the mac).
#
#
#


# Check usage...
if ( $#argv < 3 ) then
	echo "Usage: $0 <StroikaDir> <appendage> <MakefileAppendage> [<ConfigFileSuffix>]"
	exit 1
endif

set MainDir=$1
set NewDir=$2
set MakefileSuffix=$3
set ConfigFileSuffix=""

if ( $#argv >= 4 ) then
	set ConfigFileSuffix=$4
endif

# Do some sanity checking...
if ( ! -e $MainDir ) then
	echo "$MainDir does not exist! exiting..."
	exit 1
endif


# Delete target directory, if it exists. Well rebuild it.
if ( -e $NewDir ) then
	echo "Directory $NewDir exists ... deleting..."
	sleep 2; # just in case...
	rm -rf $NewDir
endif



echo "Making parallel hierarchy of directories and crosslinking rcsdirs..."
makeParallel $MainDir $NewDir


# dont show everything getting checked out, who cares ... shouldnt
# be any overwrites at this point anyway...
echo "Checking out files .."
checkOutAll $NewDir >& /dev/null < /dev/null


if ($MakefileSuffix == ".unix") then
	echo "Making makefiles links, object directories, and src crosslinks..."
	MFL $NewDir $MakefileSuffix
endif

if ($MakefileSuffix == ".mac") then
	(patchMacText $NewDir)
	(cd $NewDir; find . -name RCS -exec rm {} \;)
endif
if ($MakefileSuffix == ".pc") then
	(cd $NewDir; find . -name RCS -exec rm {} \;)
	(echo "PCXLate of Library/Foundation...")
	(cd $NewDir/Library; PCXLate -di ../Etc/PCNameMapDictionary Foundation Fnd)
	(cd $NewDir/Library/Fnd; rm -f Makefile.mac Makefile.unx)
	(cd $NewDir/Library; rm -rf Foundation Graphix Framework User)
	(cd $NewDir/Library; rm -f BuildFlungeFlags FlungeFlags Makefile.mac Makefile.unx)
	(echo "PCXLate of Demos/Foundation...")
	(cd $NewDir/Demos; PCXLate -di ../Etc/PCNameMapDictionary Foundation Fnd)
	(cd $NewDir/Demos; rm -rf Foundation Graphix)
	(cd $NewDir/Demos; rm -f Fnd/Makefile.mac Fnd/Makefile.unx Fnd/Project.mpw)
	(echo "PCXLate of TestSuites/Foundation...")
	(cd $NewDir/TestSuites; PCXLate -di ../Etc/PCNameMapDictionary Foundation Fnd)
	(cd $NewDir/TestSuites; rm -rf Foundation Graphix)
	(cd $NewDir/TestSuites; rm -f Fnd/Makefile.mac Fnd/Makefile.unx Fnd/Project.mpw)
	(cd $NewDir; mv TestSuites TestSuit)
	(cd $NewDir/; rm -f Config; mv Config.bc Config; rm -f Config.*; mv Config Config.bc)
	(cd $NewDir/; rm -f *.mac *.unix *.Unix *.MPW)
	(cd $NewDir; rm -rf Applications ChangeLog Etc ProjectStartup Scripts StroikaBugs TODO Tools)
endif
if ($MakefileSuffix == ".unix") then
	(cd $NewDir; _linkConfigs Config .) >& /dev/null
	# make the Include Dir
	(cd $NewDir;\
		mkdir Includes;\
		cd Includes;\
		ln -s ../Library/Foundation/Headers/ Foundation;\
		ln -s ../Library/Graphix/Headers/ Graphix;\
		ln -s ../Library/Framework/Headers/ Framework;\
		ln -s ../Library/User/Headers/ User;\
		ln -s ../Library/StroikaVersion StroikaVersion;\
		ln -s ../Library/Stroika-Globals.hh Stroika-Globals.hh;\
	)
endif


if ($MakefileSuffix == ".unix") then
	(cd $NewDir; rm Config; ln -s Config.$ConfigFileSuffix Config)
endif



# For gnuemacs:
# Local Variables: ***
# mode:Text ***
# tab-width:4 ***
# End: ***
