#*************************************************************************
# Copyright (c) 2002 The University of Chicago, as Operator of Argonne
#     National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
#     Operator of Los Alamos National Laboratory.
# EPICS BASE Versions 3.13.7
# and higher are distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution. 
#*************************************************************************
#
#  $Revision-Id$
#
 

ARCHS += $(BUILD_ARCHS) host cross
ACTIONS += clean inc depends build install buildInstall
 
dirPart = $(word 1, $(subst $(DIVIDER), ,$@))
actionArchPart = $(join $(word 2, $(subst $(DIVIDER), ,$@)), \
 $(addprefix $(DIVIDER),$(word 3, $(subst $(DIVIDER), ,$@))))
 
dirActionArchTargets = $(foreach dir, $(DIRS), \
                       $(foreach action, $(ACTIONS),\
                       $(foreach arch, $(ARCHS), \
                       $(dir)$(DIVIDER)$(action)$(DIVIDER)$(arch))))
dirArchTargets += $(foreach dir, $(DIRS), \
                  $(foreach arch, $(ARCHS),\
                  $(dir)$(DIVIDER)$(arch)))
dirActionTargets += $(foreach dir, $(DIRS), \
                    $(foreach action, $(ACTIONS),\
                    $(dir)$(DIVIDER)$(action)))
actionArchTargets = $(foreach action, $(ACTIONS),\
                    $(foreach arch, $(ARCHS), \
                    $(action)$(DIVIDER)$(arch)))
ifeq ($(MAKE_INC_TARGET_FIRST),YES)
all install :: inc buildInstall 
$(ARCHS) $(installArchTargets) :: inc
else
all install :: buildInstall 
endif


rebuild:: clean all

$(DIRS) $(dirActionTargets) $(dirArchTargets)$(dirActionArchTargets) ::
	$(MAKE) -C $(dirPart) $(actionArchPart)

$(ARCHS) $(ACTIONS) $(actionArchTargets) ::%: \
	$(foreach dir, $(DIRS), $(dir)$(DIVIDER)%)
 

.PHONY :: $(DIRS) all rebuild
.PHONY :: $(ARCHS) $(ACTIONS)
.PHONY :: $(dirActionTargets) $(dirArchTargets)
.PHONY :: $(dirActionArchTargets)
.PHONY :: $(actionArchTargets)

