blob: 6dadc7b613170f33b63579ae6c5384a30e477037 [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.
5# ObjNames - The objects available in that directory.
Nico Weberfc375d12012-06-14 19:58:46 +00006# Implementation - The library configuration the objects should go in (Generic
7# or Optimized)
Daniel Dunbarfaf01502010-01-18 06:48:33 +00008# Dependencies - Any dependences for the object files.
9#
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.
Daniel Dunbarb3a69012009-06-26 16:47:03 +000013
14ifeq ($(Dir),)
15 $(error "No Dir variable defined.")
16endif
17
Daniel Dunbarb3a69012009-06-26 16:47:03 +000018###
19# Include child makefile fragments
20
Daniel Dunbarfaf01502010-01-18 06:48:33 +000021# The list of variables which are intended to be overridden in a subdirectory
22# makefile.
Daniel Dunbarf06648a2011-12-02 02:42:07 +000023RequiredSubdirVariables := \
24 ModuleName SubDirs ObjNames Implementation Dependencies
Daniel Dunbarfaf01502010-01-18 06:48:33 +000025OptionalSubdirVariables := OnlyArchs OnlyConfigs
26
27# Template: subdir_traverse_template subdir
28define subdir_traverse_template
29$(call Set,Dir,$(1))
30ifneq ($(DEBUGMAKE),)
31 $$(info MAKE: $(Dir): Processing subdirectory)
32endif
33
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000034# 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))
38
Daniel Dunbarfaf01502010-01-18 06:48:33 +000039# Reset subdirectory specific variables to sentinel value.
40$$(foreach var,$$(RequiredSubdirVariables) $$(OptionalSubdirVariables),\
41 $$(call Set,$$(var),UNDEFINED))
42
43# Get the subdirectory variables.
44include $(1)/Makefile.mk
45
46ifeq ($(DEBUGMAKE),2)
47$$(foreach var,$(RequiredSubdirVariables) $(OptionalSubdirVariables),\
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000048 $$(if $$(call strneq,UNDEFINED,$$($$(var))), \
Daniel Dunbarfaf01502010-01-18 06:48:33 +000049 $$(info MAKE: $(Dir): $$(var) is defined), \
50 $$(info MAKE: $(Dir): $$(var) is undefined)))
51endif
52
53# Check for undefined required variables, and unset sentinel value from optional
54# variables.
55$$(foreach var,$(RequiredSubdirVariables),\
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000056 $$(if $$(call strneq,UNDEFINED,$$($$(var))),, \
Daniel Dunbarfaf01502010-01-18 06:48:33 +000057 $$(error $(Dir): variable '$$(var)' was not undefined)))
58$$(foreach var,$(OptionalSubdirVariables),\
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000059 $$(if $$(call strneq,UNDEFINED,$$($$(var))),, \
Daniel Dunbarfaf01502010-01-18 06:48:33 +000060 $$(call Set,$$(var),)))
61
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000062# Collect all subdirectory variables for subsequent use.
63$$(foreach var,$(RequiredSubdirVariables) $(OptionalSubdirVariables),\
64 $$(call Set,$(DirKey).$$(var),$$($$(var))))
65
Daniel Dunbarfaf01502010-01-18 06:48:33 +000066# Recurse.
67include make/subdir.mk
68
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000069# Restore directory variable, for cleanliness.
Daniel Dunbarfaf01502010-01-18 06:48:33 +000070$$(call Set,Dir,$(1))
71
72ifneq ($(DEBUGMAKE),)
73 $$(info MAKE: $$(Dir): Done processing subdirectory)
74endif
75endef
76
Daniel Dunbar557a6ea2010-01-13 16:13:01 +000077# Evaluate this now so we do not have to worry about order of evaluation.
Daniel Dunbar48464e02010-01-18 06:49:33 +000078
79SubDirsList := $(strip \
80 $(if $(call streq,.,$(Dir)),\
81 $(SubDirs),\
82 $(SubDirs:%=$(Dir)/%)))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000083ifeq ($(SubDirsList),)
84else
Daniel Dunbarfaf01502010-01-18 06:48:33 +000085 ifneq ($(DEBUGMAKE),)
Daniel Dunbarb3a69012009-06-26 16:47:03 +000086 $(info MAKE: Descending into subdirs: $(SubDirsList))
87 endif
Daniel Dunbarb3a69012009-06-26 16:47:03 +000088
Daniel Dunbarfaf01502010-01-18 06:48:33 +000089 $(foreach subdir,$(SubDirsList),\
90 $(eval $(call subdir_traverse_template,$(subdir))))
91endif