1# This file is intended to be included from each subdirectory makefile.
2#
3# Subdirectory makefiles must define:
4#   SubDirs - The subdirectories to traverse.
5#
6# Subdirectory makefiles may define:
7#   ModuleName - The library name for objects in that directory.
8#   ObjNames - The objects available in that directory.
9#   Implementation - The library configuration the objects should go in (Generic
10#                    or Optimized)
11#   Dependencies - Any dependences for the object files.
12#   OnlyArchs - Only build the objects for the listed archs.
13#   OnlyConfigs - Only build the objects for the listed configurations.
14
15ifeq ($(Dir),)
16  $(error "No Dir variable defined.")
17endif
18
19###
20# Include child makefile fragments
21
22# The list of variables which are intended to be overridden in a subdirectory
23# makefile.
24RequiredSubdirVariables := SubDirs 
25OptionalSubdirVariables := ModuleName OnlyArchs OnlyConfigs \
26	ObjNames Implementation Dependencies
27
28# Template: subdir_traverse_template subdir
29define subdir_traverse_template
30$(call Set,Dir,$(1))
31ifneq ($(DEBUGMAKE),)
32  $$(info MAKE: $(Dir): Processing subdirectory)
33endif
34
35# Construct the variable key for this directory.
36$(call Set,DirKey,SubDir.$(subst .,,$(subst /,__,$(1))))
37$(call Append,SubDirKeys,$(DirKey))
38$(call Set,$(DirKey).Dir,$(Dir))
39
40# Reset subdirectory specific variables to sentinel value.
41$$(foreach var,$$(RequiredSubdirVariables) $$(OptionalSubdirVariables),\
42  $$(call Set,$$(var),UNDEFINED))
43
44# Get the subdirectory variables.
45include $(1)/Makefile.mk
46
47ifeq ($(DEBUGMAKE),2)
48$$(foreach var,$(RequiredSubdirVariables) $(OptionalSubdirVariables),\
49  $$(if $$(call strneq,UNDEFINED,$$($$(var))), \
50	$$(info MAKE: $(Dir): $$(var) is defined), \
51	$$(info MAKE: $(Dir): $$(var) is undefined)))
52endif
53
54# Check for undefined required variables, and unset sentinel value from optional
55# variables.
56$$(foreach var,$(RequiredSubdirVariables),\
57  $$(if $$(call strneq,UNDEFINED,$$($$(var))),, \
58	$$(error $(Dir): variable '$$(var)' was not undefined)))
59$$(foreach var,$(OptionalSubdirVariables),\
60  $$(if $$(call strneq,UNDEFINED,$$($$(var))),, \
61	$$(call Set,$$(var),)))
62
63# Collect all subdirectory variables for subsequent use.
64$$(foreach var,$(RequiredSubdirVariables) $(OptionalSubdirVariables),\
65  $$(call Set,$(DirKey).$$(var),$$($$(var))))
66
67# Recurse.
68include make/subdir.mk
69
70# Restore directory variable, for cleanliness.
71$$(call Set,Dir,$(1))
72
73ifneq ($(DEBUGMAKE),)
74  $$(info MAKE: $$(Dir): Done processing subdirectory)
75endif
76endef
77
78# Evaluate this now so we do not have to worry about order of evaluation.
79
80SubDirsList := $(strip \
81  $(if $(call streq,.,$(Dir)),\
82       $(SubDirs),\
83       $(SubDirs:%=$(Dir)/%)))
84ifeq ($(SubDirsList),)
85else
86  ifneq ($(DEBUGMAKE),)
87    $(info MAKE: Descending into subdirs: $(SubDirsList))
88  endif
89
90  $(foreach subdir,$(SubDirsList),\
91	$(eval $(call subdir_traverse_template,$(subdir))))
92endif
93