## -*- mode: Makefile -*-
##
## Copyright (c) 2000 University of Utah and the Flux Group.
## All rights reserved.
## 
## Permission to use, copy, modify, and distribute this file
## for any purpose with or without restriction is hereby granted.
##

## 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.

