1 # This file is intended to be included from each subdirectory makefile.
3 # Subdirectory makefiles must define:
4 # SubDirs - The subdirectories to traverse.
5 # ObjNames - The objects available in that directory.
6 # Implementation - The library configuration the objects should go in (Generic
8 # Dependencies - Any dependences for the object files.
10 # Subdirectory makefiles may define:
11 # OnlyArchs - Only build the objects for the listed archs.
12 # OnlyConfigs - Only build the objects for the listed configurations.
15 $(error
"No Dir variable defined.")
19 # Include child makefile fragments
21 # The list of variables which are intended to be overridden in a subdirectory
23 RequiredSubdirVariables
:= \
24 ModuleName SubDirs ObjNames Implementation Dependencies
25 OptionalSubdirVariables
:= OnlyArchs OnlyConfigs
27 # Template: subdir_traverse_template subdir
28 define subdir_traverse_template
31 $$(info MAKE
: $(Dir
): Processing subdirectory
)
34 # Construct the variable key for this directory.
35 $(call Set
,DirKey
,SubDir.
$(subst .
,,$(subst /,__
,$(1))))
36 $(call Append
,SubDirKeys
,$(DirKey
))
37 $(call Set
,$(DirKey
).Dir
,$(Dir
))
39 # Reset subdirectory specific variables to sentinel value.
40 $$(foreach var
,$$(RequiredSubdirVariables
) $$(OptionalSubdirVariables
),\
41 $$(call Set
,$$(var
),UNDEFINED
))
43 # Get the subdirectory variables.
44 include $(1)/Makefile.mk
47 $$(foreach var
,$(RequiredSubdirVariables
) $(OptionalSubdirVariables
),\
48 $$(if
$$(call strneq
,UNDEFINED
,$$($$(var
))), \
49 $$(info MAKE
: $(Dir
): $$(var
) is defined
), \
50 $$(info MAKE
: $(Dir
): $$(var
) is undefined
)))
53 # Check for undefined required variables, and unset sentinel value from optional
55 $$(foreach var
,$(RequiredSubdirVariables
),\
56 $$(if
$$(call strneq
,UNDEFINED
,$$($$(var
))),, \
57 $$(error
$(Dir
): variable
'$$(var)' was not undefined
)))
58 $$(foreach var
,$(OptionalSubdirVariables
),\
59 $$(if
$$(call strneq
,UNDEFINED
,$$($$(var
))),, \
60 $$(call Set
,$$(var
),)))
62 # Collect all subdirectory variables for subsequent use.
63 $$(foreach var
,$(RequiredSubdirVariables
) $(OptionalSubdirVariables
),\
64 $$(call Set
,$(DirKey
).
$$(var
),$$($$(var
))))
67 include make
/subdir.mk
69 # Restore directory variable, for cleanliness.
73 $$(info MAKE
: $$(Dir
): Done processing subdirectory
)
77 # Evaluate this now so we do not have to worry about order of evaluation.
79 SubDirsList
:= $(strip \
80 $(if
$(call streq
,.
,$(Dir
)),\
82 $(SubDirs
:%=$(Dir
)/%)))
83 ifeq ($(SubDirsList
),)
86 $(info MAKE
: Descending into subdirs
: $(SubDirsList
))
89 $(foreach subdir
,$(SubDirsList
),\
90 $(eval
$(call subdir_traverse_template
,$(subdir
))))