# These macros are used for descending into various subdirectories.
# 
# The general idea of these macros is that we want make to descend into
# every subdirectory of the current directory except for certain ones
# that are skipped.  The different macros have different criteria for
# determining which ones are skipped.
# 
# In all cases the "listdirs" script in the tools directory is used to
# generate a list of directories to consider.  This script returns all
# subdirs of the current dir except certain ones that we never want to
# go into (see the comments in that script for details).
# 
# In addition, all the macros below test to make sure that a directory
# contains a Makefile (with a capital M) before desending into it.
# 
# 
########################################################################

# skip none --- go into every subdir meeting the above conditions:

DO_DIRS =						\
	( dirs=`${GEOM}/tools/listdirs` ;		\
	  for dir in $$dirs ; do			\
	    if [ -d $$dir -a -f $$dir/Makefile ] ; then	\
	      echo "\tcd $$dir ; ${RMAKE} $@" ;		\
	      ( cd $$dir ; ${RMAKE} $@ ) ;		\
	    fi ;					\
	  done )

########################################################################

# Only go into directories appropriate for this machine.
# Specifically, if a directory has object (O.*) subdirs, only go into
# it if there it has an object subdir for this machine (named
# O.${MACHTYPE}).  Also, only go into object subdirs for this machine.

DO_DIRS_THIS_MACH =							\
	( dirs=`${GEOM}/tools/listdirs` ;				\
	  for dir in $$dirs ; do					\
	    case $$dir in						\
	      O.*)							\
	        if [ $$dir = O.${MACHTYPE} -a -f $$dir/Makefile ] ; then \
	          echo "\tcd $$dir ; ${RMAKE} $@" ;			\
	          ( cd $$dir ; ${RMAKE} $@ ) ;				\
	        fi							\
		;;							\
	      *)							\
		if [ -d $$dir/O.${MACHTYPE} -o				\
			"`cd $$dir; echo O.*`" = "O.*" ] ; then		\
		  if [ -f $$dir/Makefile ] ; then			\
	            echo "\tcd $$dir ; ${RMAKE} $@" ;			\
	            ( cd $$dir ; ${RMAKE} $@ ) ;			\
		  fi ;							\
		fi ; 							\
		;;							\
	    esac ;							\
	  done )

########################################################################

# Only go into directories appropriate for this machine (i.e. same as
# DO_DIRS_THIS_MACH), but don't go into any object directories.

DO_DIRS_THIS_MACH_NO_OBJ =						\
	( dirs=`${GEOM}/tools/listdirs` ;				\
	  for dir in $$dirs ; do					\
	    case $$dir in						\
	      O.*)							\
		;;							\
	      *)							\
		if [ -d $$dir/O.${MACHTYPE} -o				\
				"`cd $$dir; echo O.*`" = "O.*" ]; then	\
		  if [ -f $$dir/Makefile ] ; then			\
	            echo "\tcd $$dir ; ${RMAKE} $@" ;			\
	            ( cd $$dir ; ${RMAKE} $@ ) ;			\
		  fi ;							\
		fi ; 							\
		;;							\
	    esac ;							\
	  done )

########################################################################

# Only go into source directories --- skip all object directories.
# This goes into all source directories, regardless of machine type.

DO_DIRS_NO_OBJ =					\
	( dirs=`${GEOM}/tools/listdirs` ;		\
	  for dir in $$dirs ; do			\
	    case $$dir in				\
	      O.*)					\
		;;					\
	      *)					\
		if [ -f $$dir/Makefile ] ; then		\
	          echo "\tcd $$dir ; ${RMAKE} $@" ;	\
	          ( cd $$dir ; ${RMAKE} $@ ) ;		\
		fi ;					\
		;;					\
	    esac ;					\
	  done )


########################################################################

# just in case I forgot to change some makefiles:

DO_DIRS_NO_MACH = \
  @( echo "" ; \
     echo "" ; \
     echo "" ; \
     echo "WARNING: obsolete make macro DO_DIRS_NO_MACH called" ; \
     echo "  by make in directory `pwd`.  The name of this macro" ; \
     echo "  has been changed to DO_DIRS_NO_OBJ.  Please tell" ; \
     echo "  mbp@geom.umn.edu about this." ; \
     echo "" ; \
     echo "" ; \
     echo "" ; ) ; \
  ${DO_DIRS_NO_OBJ}
