blob: f81c25f032b96b0841279471aaca3661a006f8c9 [file] [log] [blame]
Daniel Dunbar557a6ea2010-01-13 16:13:01 +00001# This file is intended to be included from each subdirectory makefile.
Daniel Dunbarfaf01502010-01-18 06:48:33 +00002#
3# Subdirectory makefiles must define:
4# SubDirs - The subdirectories to traverse.
Stephen Hines2d1fdb22014-05-28 23:58:16 -07005#
6# Subdirectory makefiles may define:
7# ModuleName - The library name for objects in that directory.
Daniel Dunbarfaf01502010-01-18 06:48:33 +00008# ObjNames - The objects available in that directory.
Nico Weberfc375d12012-06-14 19:58:46 +00009# Implementation - The library configuration the objects should go in (Generic
10# or Optimized)
Daniel Dunbarfaf01502010-01-18 06:48:33 +000011# Dependencies - Any dependences for the object files.
Daniel Dunbarfaf01502010-01-18 06:48:33 +000012# OnlyArchs - Only build the objects for the listed archs.
13# OnlyConfigs - Only build the objects for the listed configurations.
Daniel Dunbarb3a69012009-06-26 16:47:03 +000014
15ifeq ($(Dir),)
16 $(error "No Dir variable defined.")
17endif
18
Daniel Dunbarb3a69012009-06-26 16:47:03 +000019###
20# Include child makefile fragments
21
Daniel Dunbarfaf01502010-01-18 06:48:33 +000022# The list of variables which are intended to be overridden in a subdirectory
23# makefile.
Stephen Hines2d1fdb22014-05-28 23:58:16 -070024RequiredSubdirVariables := SubDirs
25OptionalSubdirVariables := ModuleName OnlyArchs OnlyConfigs \
26 ObjNames Implementation Dependencies
Daniel Dunbarfaf01502010-01-18 06:48:33 +000027
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
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000035# 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
Daniel Dunbarfaf01502010-01-18 06:48:33 +000040# 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),\
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000049 $$(if $$(call strneq,UNDEFINED,$$($$(var))), \
Daniel Dunbarfaf01502010-01-18 06:48:33 +000050 $$(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),\
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000057 $$(if $$(call strneq,UNDEFINED,$$($$(var))),, \
Daniel Dunbarfaf01502010-01-18 06:48:33 +000058 $$(error $(Dir): variable '$$(var)' was not undefined)))
59$$(foreach var,$(OptionalSubdirVariables),\
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000060 $$(if $$(call strneq,UNDEFINED,$$($$(var))),, \
Daniel Dunbarfaf01502010-01-18 06:48:33 +000061 $$(call Set,$$(var),)))
62
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000063# Collect all subdirectory variables for subsequent use.
64$$(foreach var,$(RequiredSubdirVariables) $(OptionalSubdirVariables),\
65 $$(call Set,$(DirKey).$$(var),$$($$(var))))
66
Daniel Dunbarfaf01502010-01-18 06:48:33 +000067# Recurse.
68include make/subdir.mk
69
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000070# Restore directory variable, for cleanliness.
Daniel Dunbarfaf01502010-01-18 06:48:33 +000071$$(call Set,Dir,$(1))
72
73ifneq ($(DEBUGMAKE),)
74 $$(info MAKE: $$(Dir): Done processing subdirectory)
75endif
76endef
77
Daniel Dunbar557a6ea2010-01-13 16:13:01 +000078# Evaluate this now so we do not have to worry about order of evaluation.
Daniel Dunbar48464e02010-01-18 06:49:33 +000079
80SubDirsList := $(strip \
81 $(if $(call streq,.,$(Dir)),\
82 $(SubDirs),\
83 $(SubDirs:%=$(Dir)/%)))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000084ifeq ($(SubDirsList),)
85else
Daniel Dunbarfaf01502010-01-18 06:48:33 +000086 ifneq ($(DEBUGMAKE),)
Daniel Dunbarb3a69012009-06-26 16:47:03 +000087 $(info MAKE: Descending into subdirs: $(SubDirsList))
88 endif
Daniel Dunbarb3a69012009-06-26 16:47:03 +000089
Daniel Dunbarfaf01502010-01-18 06:48:33 +000090 $(foreach subdir,$(SubDirsList),\
91 $(eval $(call subdir_traverse_template,$(subdir))))
92endif