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