#! /bin/csh -f
# script to make directories and links for an architecture
# @(#)MAKEARCH	1.40	12/15/92

if (! $?ARCH ) then
	echo The environment variable ARCH must be set.
	exit 1
endif

# optmkdir -- make a directory if it does not exist
alias optmkdir \
'if ( ! -d \!:1 ) echo making directory $cwd/\!:1 ; if ( ! -d \!:1 ) mkdir \!:1'

# optlink -- make a symbolic link if it does not exist, from a file in a
# different directory to the same name in this directory.  args: dir filename

alias optlink \
'if ( ! -e \!:2 ) echo making link \!:1/\!:2 ; if ( ! -e \!:2 ) ln -s \!:1/\!:2 .'

# Make the top-level directories
optmkdir bin.$ARCH
optmkdir lib.$ARCH
optmkdir obj.$ARCH

# Now, make stuff under obj.$ARCH

cd obj.$ARCH
optlink ../src makefile
foreach x (domains interp ptcl kernel pigiRpc pigilib libgantt ptlang xgraph)
	optmkdir $x
	cd $x
	optlink ../../src/$x makefile
	if (-r ../../src/$x/make.template) then
		optlink ../../src/$x make.template
	endif
	cd ..
end

foreach x (filters)
	optmkdir $x
	cd $x
	optlink ../../src/$x Makefile
	cd ..
end

# Make subdirectories of filters
cd filters
foreach x (optfir wfir)
	optmkdir $x
	cd $x
	optlink ../../../src/filters/$x Makefile
	cd ..
end
cd ..

# Make link for xgraph bitmaps
cd xgraph
optlink ../../src/xgraph bitmaps
cd ..

# EXPDOMAINS = experimental domains
# EXPDOMAINS = capsim bdf
set EXPDOMAINS=(cg-ddf cg56 cgc cg96)
set EXPEXTRAS=(cg56/targets cg96/targets)

cd domains
foreach x (sdf ddf de thor cg $EXPDOMAINS)
	optmkdir $x
	cd $x
	optlink ../../../src/domains/$x makefile
	foreach y (kernel stars)
		optmkdir $y
		cd $y
		optlink ../../../../src/domains/$x/$y make.template
		optlink ../../../../src/domains/$x/$y makefile
		cd ..
	end
	cd ..
end

# At this point, we are in obj.$ARCH/domains.

# create extra directories under domain-specific directories
# everything must have one slash (be two levels down)

foreach x (thor/pepp cg/targets sdf/expgraph sdf/image sdf/targets \
	ddf/constructs sdf/loopScheduler cg/parScheduler thor/analyzerX11 \
	cg/dlScheduler cg/HuScheduler cg/dcScheduler cgc/targets \
	cg56/dsp cg96/dsp sdf/dsp sdf/image $EXPEXTRAS )
	optmkdir $x
	cd $x
	optlink ../../../../src/domains/$x make.template
	optlink ../../../../src/domains/$x makefile
	cd ../..
end

# create Bitmaps for analyzerX11
cd thor/analyzerX11
optlink ../../../../src/domains/thor/analyzerX11 Bitmaps
cd ../..

# create extra subsub dirs in each domain
# everything must have two slashs (be three levels down)

foreach x ( cg56/dsp/stars cg96/dsp/stars sdf/dsp/stars sdf/image/kernel sdf/image/stars )
	optmkdir $x
	cd $x
	optlink ../../../../../src/domains/$x make.template
	optlink ../../../../../src/domains/$x makefile
	cd ../../..
end

# This is for the makefile
cd ../..
touch obj.$ARCH
