#! make -f
#============================================================================
# Project:  RevolutionSDK Extentions - buildtools
# File:     submakerules
#
# Copyright 2006 Nintendo.  All rights reserved.
#
# These coded instructions, statements, and computer programs contain
# proprietary information of Nintendo of America Inc. and/or Nintendo
# Company Ltd., and are protected by Federal copyright law.  They may
# not be disclosed to third parties or copied or duplicated in any form,
# in whole or in part, without the prior written consent of Nintendo.
#============================================================================
include $(REVOLUTION_EXT_ROOT)/build/buildtools/commondefs.rex

#
SUBDIR_FLAGS +=

define MAKE_SUBDIR
    +$(foreach DIR,$(SUBDIRS),$(MAKE) $(SUBDIR_FLAGS) -C $(DIR) $(MAKECMDGOALS) $(AND)) true
    +$(foreach FILE,$(SUBMAKES),$(MAKE) $(SUBDIR_FLAGS) -C $(dir $(FILE)) -f $(notdir $(FILE)) $(MAKECMDGOALS) $(AND)) true
endef

define MAKE_SUBDIR_IF_EXIST
    +$(foreach DIR,$(SUBDIRS),\
	if [ -f $(DIR)/Makefile -o -f $(DIR)/makefile -o -f $(DIR)/GNUmakefile ]; then	\
		$(MAKE) $(SUBDIR_FLAGS) -C $(DIR) $(MAKECMDGOALS) ;			\
	fi $(AND)) true
    +$(foreach FILE,$(SUBMAKES),\
	if [ -f $(FILE) ]; then \
		$(MAKE) $(SUBDIR_FLAGS) -C $(dir $(FILE)) -f $(notdir $(FILE)) $(MAKECMDGOALS) ; \
	fi $(AND)) true
endef


PHONY_TARGETS	= build clean clobber install

.PHONY: $(PHONY_TARGETS)

build install:
	@$(MAKE_SUBDIR_IF_EXIST)
	@$(ECHO_CURDIR)

clean:
	@$(MAKE_SUBDIR_IF_EXIST)
	@$(ECHO_CURDIR)
ifneq	($(REX_CLEAN),)
	@rm -rf $(REX_CLEAN)
endif

distclean clobber:
	@$(MAKE_SUBDIR_IF_EXIST)
	@$(ECHO_CURDIR)
ifneq	($(REX_CLOBBER)$(REX_DISTCLEAN),)
	@rm -rf $(REX_CLOBBER) $(REX_DISTCLEAN)
endif

#======== End of submakerules ========#
