#!/bin/csh -f
# List of all the directories with makefiles that have to be produced

if ($#argv > 0) then
  set dirs=($argv)
  set quiet=no
else
  set dirs=(. ./asm ./cfunc/gen ./cfunc ./chcode ./cherm ./codegen/p1 \
	./codegen/p2 ./codegen/p3 ./codegen/com ./codegen/ligen ./codegen \
	./construct ./demo ./disassembler ./fe ./hermes/io ./hermes/defs \
	./hermes/liboot ./hermes/ligen ./hermes/absformat ./hermes \
	./interface/gentab ./interface ./li ./lib ./sysbin ./tools/make/defs \
	./tools/make ./tools/shell ./tools/printobj ./tools/distrib \
	./tools/cache ./tools/tokenize ./tools/rmanager ./tools/unixcmd \
	./tools/profile ./tools/string ./tools/pipe ./tools/pshell \
	./type/checker ./type/bootstrap ./type/defs ./type/common ./typestate \
	./windows/sunview ./windows/xwindow ./windows ./chaux )
  set quiet=yes
endif

if (! $?HROOTDIR) then
  echo -n "Root directory? "
  set HROOTDIR="$<"
endif

if (! $?HARCH) then
  echo -n "Architecture? "
  set HARCH="$<"
endif

set answer=n
while ("$answer" != "y")
  echo "Configuring Makefile's in Hermes source tree $HROOTDIR"
  echo -n "for architecture $HARCH.  Proceed? "
  set answer="$<"
  if ($answer == "n") then
    exit 1
  elseif ($answer != "y") then
    echo "Please respond 'y' or 'n'"
  else
    break
  endif
end

# the default cpp on convex machines strips trailing backslashes from
# normal text lines (bug!); pcc mode seems to work OK.	Default cpp on
# NeXT machine seems to insert a space following every macro
# expansion; -traditional mode works OK.
switch ($HARCH)
  case convex:
    set CPPFLAGS="-pcc"
    breaksw
  case NeXT:
    set CPPFLAGS="-traditional"
    breaksw
  default:
    set CPPFLAGS=
    breaksw
endsw

foreach x ($dirs)
  if (! -d $HROOTDIR/$x) then
    if ("$quiet" == "no") echo "${x}: No such directory"
    continue
  endif
  if (! -e $HROOTDIR/$x/Makefile.cpp) then
    if ("$quiet" == "no") echo "$x/Makefile.cpp: Not found"
    continue
  endif
  cd $HROOTDIR/$x
  pwd
  /lib/cpp -I$HROOTDIR/make -C -P -Uunix -U$HARCH $CPPFLAGS \
	-D_HROOTDIR_=$HROOTDIR -D_MTYPE_=$HARCH -D_MTYPE_$HARCH \
	< Makefile.cpp | sed 's=/\*=#=' | sed 's=\*/==' > Makefile
end
