#!/bin/csh -f
#  Master Makefile for JGOFS server
#   - note that only makefile.extention files are 'make'd
#
#  Accepts 2 kinds of command line arguments:
#    1.  clean   (build clean)  will make tree clean of targets
#    2.  subdirectory (build lib) will make only that subdir's targets
#
source build-env

#
#  make the stuff in lib, first - others depend on these
#
  set LIST=`ls -1 src/lib/makefile.*`
#
#  then, make the methods
#
  set LIST=($LIST `ls -1 src/methods/makefile.*`)
#
#  finally, make other subdirectory stuff ONE LEVEL under src
#
  set LIST=($LIST `ls -1 src/*/makefile.* | grep -v "/lib/" | grep -v "/methods/"`)

# if no arguments given on command line, make everything
#
if ( "x$1" == "x" ) then
#
# Go through and make stuff
#

 foreach g (${LIST})
    echo making $g ...
    pushd $g:h > /dev/null
    make -f $g:t
    popd > /dev/null
 end
else
  switch ( $1 )
#
# clean up all .o files and all targets - ready for a fresh build
#
    case "clean":
      foreach i (${LIST})
        echo cleaning $i ...
        pushd $i:h > /dev/null
        make -f $i:t clean
        popd > /dev/null
      end
      breaksw
    default:
      set LIST=`ls src/$1/makefile.*`
      if ("x$LIST" != "x") then
        foreach m (${LIST})
          echo making $m ...
          pushd $m:h > /dev/null
          make -f $m:t
          popd > /dev/null
        end
      else
        echo "Error!  Either the subdirectory src/$1 is not found"
        echo "        or there are no makefile.X files in that subdirectory"
        echo "        where .X represents a file extension."
      endif
      breaksw
  endsw
endif
