Home | History | Annotate | Download | only in make
      1 # This file is intended to be included from each subdirectory makefile.
      2 #
      3 # Subdirectory makefiles must define:
      4 #   SubDirs - The subdirectories to traverse.
      5 #
      6 # Subdirectory makefiles may define:
      7 #   ModuleName - The library name for objects in that directory.
      8 #   ObjNames - The objects available in that directory.
      9 #   Implementation - The library configuration the objects should go in (Generic
     10 #                    or Optimized)
     11 #   Dependencies - Any dependences for the object files.
     12 #   OnlyArchs - Only build the objects for the listed archs.
     13 #   OnlyConfigs - Only build the objects for the listed configurations.
     14 
     15 ifeq ($(Dir),)
     16   $(error "No Dir variable defined.")
     17 endif
     18 
     19 ###
     20 # Include child makefile fragments
     21 
     22 # The list of variables which are intended to be overridden in a subdirectory
     23 # makefile.
     24 RequiredSubdirVariables := SubDirs 
     25 OptionalSubdirVariables := ModuleName OnlyArchs OnlyConfigs \
     26 	ObjNames Implementation Dependencies
     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 
     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 
     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),\
     49   $$(if $$(call strneq,UNDEFINED,$$($$(var))), \
     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),\
     57   $$(if $$(call strneq,UNDEFINED,$$($$(var))),, \
     58 	$$(error $(Dir): variable '$$(var)' was not undefined)))
     59 $$(foreach var,$(OptionalSubdirVariables),\
     60   $$(if $$(call strneq,UNDEFINED,$$($$(var))),, \
     61 	$$(call Set,$$(var),)))
     62 
     63 # Collect all subdirectory variables for subsequent use.
     64 $$(foreach var,$(RequiredSubdirVariables) $(OptionalSubdirVariables),\
     65   $$(call Set,$(DirKey).$$(var),$$($$(var))))
     66 
     67 # Recurse.
     68 include make/subdir.mk
     69 
     70 # Restore directory variable, for cleanliness.
     71 $$(call Set,Dir,$(1))
     72 
     73 ifneq ($(DEBUGMAKE),)
     74   $$(info MAKE: $$(Dir): Done processing subdirectory)
     75 endif
     76 endef
     77 
     78 # Evaluate this now so we do not have to worry about order of evaluation.
     79 
     80 SubDirsList := $(strip \
     81   $(if $(call streq,.,$(Dir)),\
     82        $(SubDirs),\
     83        $(SubDirs:%=$(Dir)/%)))
     84 ifeq ($(SubDirsList),)
     85 else
     86   ifneq ($(DEBUGMAKE),)
     87     $(info MAKE: Descending into subdirs: $(SubDirsList))
     88   endif
     89 
     90   $(foreach subdir,$(SubDirsList),\
     91 	$(eval $(call subdir_traverse_template,$(subdir))))
     92 endif
     93