#
# Copyright (c) 1995,1994 The University of Utah and
# the Computer Systems Laboratory (CSL).  All rights reserved.
#
# Permission to use, copy, modify and distribute this software and its
# documentation is hereby granted, provided that both the copyright
# notice and this permission notice appear in all copies of the
# software, derivative works or modified versions, and any portions
# thereof, and that both notices appear in supporting documentation.
#
# THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
# IS" CONDITION.  THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
# ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
#
# CSL requests users of this software to return to csl-dist@cs.utah.edu any
# improvements that they make and grant CSL redistribution rights.
#

ifndef _oskit_makerules_top_
_oskit_makerules_top_ = yes

# This Makerules file is only used by top-level Makefiles
# in machine-dependent source trees.
#
# SRCTREES must contain the pathnames of all more-speific source trees.
# The first pathname is assumed to be the directory containing configstart,
# and is where the configure script is produced.
#
# SUBDIRS must be set to the complete list of subdirectories
# which contain Makefiles to descend into.
# The directories can be listed in any order.
#
# FIRST_SUBDIRS can be a subset of those subdirectories
# which must be built before all other subdirectories,
# in the order specified in FIRST_SUBDIRS.
#
# Similarly, LAST_SUBDIRS can be a subset of the SUBDIRS
# which must be built after all others,
# in the specified order.
#
# Naturally, FIRST_SUBDIRS and LAST_SUBDIRS should not overlap.

SRCTREES += $(GSRCDIR)

CONFIGDIR = $(firstword $(SRCTREES))

# Generate a final, properly-ordered list of all subdirectories.
ORDERED_SUBDIRS := $(foreach DIR,$(FIRST_SUBDIRS),$(filter $(DIR),$(SUBDIRS))) \
		   $(filter-out $(FIRST_SUBDIRS), \
		     $(filter-out $(LAST_SUBDIRS),$(SUBDIRS))) \
		   $(foreach DIR,$(LAST_SUBDIRS),$(filter $(DIR),$(SUBDIRS)))

all:
	for subdir in $(ORDERED_SUBDIRS); do $(MAKE) -C $$subdir || exit 1; done

install:
	for subdir in $(ORDERED_SUBDIRS); do $(MAKE) -C $$subdir install || exit 1; done

clean:
	for subdir in $(SUBDIRS); do $(MAKE) -C $$subdir clean; done

distclean: clean
	rm -f Makefile config.status $(addsuffix /Makefile,$(SUBDIRS))

configure: configure.in
	autoconf
	cp configure $(CONFIGDIR)/

configure.in:	$(addsuffix /aclocal.m4,$(SRCTREES))	\
		$(CONFIGDIR)/configstart		\
		$(addsuffix /configrules,$(SRCTREES))
	cat $^ >$@


endif
