## -*- mode: Makefile -*-
##
## Copyright (c) 2000 University of Utah and the Flux Group.
## All rights reserved.
## 
## This file is part of the Knit component composition software.
## 
## Permission to use, copy, modify, distribute, and sell this software and
## its documentation is hereby granted without fee, provided that the above
## copyright notice and this permission/disclaimer notice is retained in all
## copies or modified versions, and that both notices appear in supporting
## documentation.  THE COPYRIGHT HOLDERS PROVIDE THIS SOFTWARE "AS IS" AND
## WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION,
## THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
## PURPOSE.  THE COPYRIGHT HOLDERS DISCLAIM ANY LIABILITY OF ANY KIND FOR
## ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
## 
## Users are requested, but not required, to send to csl-dist@cs.utah.edu any
## improvements that they make and grant Univ. of Utah redistribution rights.
##

## This Makefile defines a set of targets and rules that are appropriate for an
## intermediate directory in the tree.  All targets are made by descending into
## one or more of the immediate subdirectories of the current directory.  The
## set of subdirectories is determined dynamically; there is no need to edit
## this Makefile when the set of subdirectories changes.
##
## In addition to the standard targets (e.g., `all' and `clean'), this Makefile
## defines targets of the form `<subdir>.<action>' so that one can take a
## specific action on a specific subdirectory.  For example, if there were a
## subdirectory named `src', this Makefile would define targets like `src.all'
## and `src.clean'.  Making `<subdir>' is the same as making `<subdir>.all'.
##
## The subdirectories are assumed to be independent from one another, i.e.,
## they can be built in any order.

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

## `ACTIONS' is the set of actions that may be taken on a subdirectory or on
## the current directory.  These become phony targets.
##
ACTIONS = all install clean veryclean

## `SUBDIRS' is the set of immediate subdirectories that contain Makefiles.
## These are the directories that we will descend into.
##
SUBDIRS = $(patsubst %/,%,$(dir $(wildcard */GNUmakefile)))

## `TARGETS' is the set of all `<subdir>.<action>' targets.
##
TARGETS = $(foreach action,$(ACTIONS),$(addsuffix .$(action),$(SUBDIRS)))

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

## Explicitly mention `all' first, so that it will be the default target.  This
## must be a double colon rule; see the rule for `ACTIONS' below.
##
.PHONY: all
all::

## Rules for generic actions.  Each is made by applying the action to all of
## the subdirectories.  Note that these are defined as double-colon rules so
## that one can add extra statements in separate rules if necessary.
##
.PHONY: $(ACTIONS)
$(ACTIONS):: %: $(addsuffix .%,$(SUBDIRS))

## Rules for targets of the form `<subdir>.<action>'.
##
.PHONY: $(TARGETS)
$(TARGETS):
	@$(MAKE) -C $(basename $@) $(patsubst .%,%,$(suffix $@))

## Making a subdirectory is the same as making `<subdir>.<all>'.
##
.PHONY: $(SUBDIRS)
$(SUBDIRS): %: %.all

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

## Any extra actions can be defined here, e.g.:
##
## clean::
##	$(RM) core

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

## End of file.

