blob: f81c25f032b96b0841279471aaca3661a006f8c9 [file] [log] [blame]
# This file is intended to be included from each subdirectory makefile.
# Subdirectory makefiles must define:
# SubDirs - The subdirectories to traverse.
# Subdirectory makefiles may define:
# ModuleName - The library name for objects in that directory.
# ObjNames - The objects available in that directory.
# Implementation - The library configuration the objects should go in (Generic
# or Optimized)
# Dependencies - Any dependences for the object files.
# OnlyArchs - Only build the objects for the listed archs.
# OnlyConfigs - Only build the objects for the listed configurations.
ifeq ($(Dir),)
$(error "No Dir variable defined.")
# Include child makefile fragments
# The list of variables which are intended to be overridden in a subdirectory
# makefile.
RequiredSubdirVariables := SubDirs
OptionalSubdirVariables := ModuleName OnlyArchs OnlyConfigs \
ObjNames Implementation Dependencies
# Template: subdir_traverse_template subdir
define subdir_traverse_template
$(call Set,Dir,$(1))
ifneq ($(DEBUGMAKE),)
$$(info MAKE: $(Dir): Processing subdirectory)
# Construct the variable key for this directory.
$(call Set,DirKey,SubDir.$(subst .,,$(subst /,__,$(1))))
$(call Append,SubDirKeys,$(DirKey))
$(call Set,$(DirKey).Dir,$(Dir))
# Reset subdirectory specific variables to sentinel value.
$$(foreach var,$$(RequiredSubdirVariables) $$(OptionalSubdirVariables),\
$$(call Set,$$(var),UNDEFINED))
# Get the subdirectory variables.
include $(1)/
ifeq ($(DEBUGMAKE),2)
$$(foreach var,$(RequiredSubdirVariables) $(OptionalSubdirVariables),\
$$(if $$(call strneq,UNDEFINED,$$($$(var))), \
$$(info MAKE: $(Dir): $$(var) is defined), \
$$(info MAKE: $(Dir): $$(var) is undefined)))
# Check for undefined required variables, and unset sentinel value from optional
# variables.
$$(foreach var,$(RequiredSubdirVariables),\
$$(if $$(call strneq,UNDEFINED,$$($$(var))),, \
$$(error $(Dir): variable '$$(var)' was not undefined)))
$$(foreach var,$(OptionalSubdirVariables),\
$$(if $$(call strneq,UNDEFINED,$$($$(var))),, \
$$(call Set,$$(var),)))
# Collect all subdirectory variables for subsequent use.
$$(foreach var,$(RequiredSubdirVariables) $(OptionalSubdirVariables),\
$$(call Set,$(DirKey).$$(var),$$($$(var))))
# Recurse.
include make/
# Restore directory variable, for cleanliness.
$$(call Set,Dir,$(1))
ifneq ($(DEBUGMAKE),)
$$(info MAKE: $$(Dir): Done processing subdirectory)
# Evaluate this now so we do not have to worry about order of evaluation.
SubDirsList := $(strip \
$(if $(call streq,.,$(Dir)),\
ifeq ($(SubDirsList),)
ifneq ($(DEBUGMAKE),)
$(info MAKE: Descending into subdirs: $(SubDirsList))
$(foreach subdir,$(SubDirsList),\
$(eval $(call subdir_traverse_template,$(subdir))))