2 SUBDIRS_
$(d
) := $(patsubst %/,%,$(addprefix $(d
)/,$(SUBDIRS
)))
4 ifneq ($(strip $(OBJS
)),)
5 OBJS_
$(d
) := $(addprefix $(OBJPATH
)/,$(OBJS
))
6 else # Populate OBJS_ from SRCS
8 # Expand wildcards in SRCS if they are given
9 ifneq ($(or
$(findstring *,$(SRCS
)),$(findstring ?
,$(SRCS
)),$(findstring ],$(SRCS
))),)
10 SRCS
:= $(notdir $(foreach sd
,.
$(SRCS_VPATH
),$(wildcard $(addprefix $(d
)/$(sd
)/,$(SRCS
)))))
11 SRCS
:= $(filter-out $(SRCS_EXCLUDES
), $(SRCS
))
14 OBJS_
$(d
) := $(addprefix $(OBJPATH
)/,$(addsuffix .o
,$(basename $(SRCS
))))
17 CLEAN_
$(d
) := $(CLEAN_
$(d
)) $(filter /%,$(CLEAN
) $(TARGETS
)) $(addprefix $(d
)/,$(filter-out /%,$(CLEAN
)))
20 abs_tgts
:= $(filter /%, $(TARGETS
))
21 rel_tgts
:= $(filter-out /%,$(TARGETS
))
22 TARGETS_
$(d
) := $(abs_tgts
) $(addprefix $(OBJPATH
)/,$(rel_tgts
))
23 $(foreach tgt
,$(filter-out $(AUTO_TGTS
),$(rel_tgts
)),$(eval
$(call save_vars
,$(OBJPATH
)/,$(tgt
))))
24 # Absolute targets are entry points for external (sub)projects which
25 # have their own build system - what is really interesting is only CMD
26 # and possibly DEPS however I use this general save_vars (two more vars
27 # that are not going to be used should not be a problem :P).
28 $(foreach tgt
,$(abs_tgts
),$(eval
$(call save_vars
,,$(tgt
))))
30 TARGETS_
$(d
) := $(OBJS_
$(d
))
33 # Save user defined vars
34 $(foreach v
,$(VERB_VARS
),$(eval
$(v
)_
$(d
) := $($v)))
35 $(foreach v
,$(OBJ_VARS
),$(eval
$(v
)_
$(d
) := $(addprefix $(OBJPATH
)/,$($v))))
36 $(foreach v
,$(DIR_VARS
),$(eval
$(v
)_
$(d
) := $(filter /%,$($v)) $(addprefix $(d
)/,$(filter-out /%,$($v)))))
38 # Update per directory variables that are automatically inherited
39 ifeq ($(origin INHERIT_DIR_VARS_
$(d
)),undefined
)
40 INHERIT_DIR_VARS_
$(d
) := $(or
$(INHERIT_DIR_VARS_
$(parent_dir
)), $(INHERIT_DIR_VARS
))
42 $(foreach v
,$(INHERIT_DIR_VARS_
$(d
)),$(if
$($(v
)_
$(d
)),,$(eval
$(v
)_
$(d
) := $($(v
)_
$(parent_dir
)))))
44 ########################################################################
45 # Inclusion of subdirectories rules - only after this line one can #
46 # refer to subdirectory targets and so on. #
47 ########################################################################
48 $(foreach sd
,$(SUBDIRS
),$(eval
$(call include_subdir_rules
,$(sd
))))
50 .PHONY
: dir_
$(d
) clean_
$(d
) clean_extra_
$(d
) clean_tree_
$(d
) dist_clean_
$(d
)
51 .SECONDARY
: $(OBJPATH
)
54 all :: $(TARGETS_
$(d
))
56 clean_all
:: clean_
$(d
)
58 # dist_clean is optimized in skel.mk if we are building in out of project tree
59 ifeq ($(strip $(TOP_BUILD_DIR
)),)
60 dist_clean
:: dist_clean_
$(d
)
62 # No point to enforce clean_extra dependency if CLEAN is empty
63 ifeq ($(strip $(CLEAN_
$(d
))),)
66 dist_clean_
$(d
) : clean_extra_
$(d
)
68 rm -rf
$(DIST_CLEAN_DIR
)
71 ########################################################################
72 # Per directory targets #
73 ########################################################################
75 # Again - no point to enforce clean_extra dependency if CLEAN is empty
76 ifeq ($(strip $(CLEAN_
$(d
))),)
79 clean_
$(d
) : clean_extra_
$(d
)
83 # clean_extra is meant for the extra output that is generated in source
84 # directory (e.g. generated source from lex/yacc) so I'm not using
87 rm -rf
$(filter %/,$(CLEAN_
$(subst clean_extra_
,,$@
))); rm -f
$(filter-out %/,$(CLEAN_
$(subst clean_extra_
,,$@
)))
89 clean_tree_
$(d
) : clean_
$(d
) $(foreach sd
,$(SUBDIRS_
$(d
)),clean_tree_
$(sd
))
91 # Skip the target rules generation and inclusion of the dependencies
92 # when we just want to clean up things :)
93 ifeq ($(filter clean clean_
% dist_clean
,$(MAKECMDGOALS
)),)
95 SUBDIRS_TGTS
:= $(foreach sd
,$(SUBDIRS_
$(d
)),$(TARGETS_
$(sd
)))
97 # Use the skeleton for the "current dir"
98 $(eval
$(call skeleton
,$(d
)))
99 # and for each SRCS_VPATH subdirectory of "current dir"
100 $(foreach vd
,$(SRCS_VPATH
),$(eval
$(call skeleton
,$(d
)/$(vd
))))
102 # Target rules for all "non automatic" targets
103 $(foreach tgt
,$(filter-out $(AUTO_TGTS
),$(TARGETS_
$(d
))),$(eval
$(call tgt_rule
,$(tgt
))))
105 # Way to build all targets in given subtree (not just current dir as via
106 # dir_$(d) - see below)
107 tree_
$(d
) : $(TARGETS_
$(d
)) $(foreach sd
,$(SUBDIRS_
$(d
)),tree_
$(sd
))
109 # If the directory is just for grouping its targets will be targets from
111 ifeq ($(strip $(TARGETS_
$(d
))),)
112 TARGETS_
$(d
) := $(SUBDIRS_TGTS
)
115 # This is a default rule - see Makefile
116 dir_
$(d
) : $(TARGETS_
$(d
))