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