]> cloudbase.mooo.com Git - z180-stamp.git/blob - mk/footer.mk
Rename dir Z180 --> z180
[z180-stamp.git] / mk / footer.mk
1 define FOOTER
2 SUBDIRS_$(d) := $(patsubst %/,%,$(addprefix $(d)/,$(SUBDIRS)))
3
4 ifneq ($(strip $(OBJS)),)
5 OBJS_$(d) := $(addprefix $(OBJPATH)/,$(OBJS))
6 else # Populate OBJS_ from SRCS
7
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))
12 endif
13
14 OBJS_$(d) := $(addprefix $(OBJPATH)/,$(addsuffix .o,$(basename $(SRCS))))
15 endif
16
17 CLEAN_$(d) := $(CLEAN_$(d)) $(filter /%,$(CLEAN) $(TARGETS)) $(addprefix $(d)/,$(filter-out /%,$(CLEAN)))
18
19 ifdef TARGETS
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))))
29 else
30 TARGETS_$(d) := $(OBJS_$(d))
31 endif
32
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)))))
37
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))
41 endif
42 $(foreach v,$(INHERIT_DIR_VARS_$(d)),$(if $($(v)_$(d)),,$(eval $(v)_$(d) := $($(v)_$(parent_dir)))))
43
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))))
49
50 .PHONY: dir_$(d) clean_$(d) clean_extra_$(d) clean_tree_$(d) dist_clean_$(d)
51 .SECONDARY: $(OBJPATH)
52
53 # Whole tree targets
54 all :: $(TARGETS_$(d))
55
56 clean_all :: clean_$(d)
57
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)
61
62 # No point to enforce clean_extra dependency if CLEAN is empty
63 ifeq ($(strip $(CLEAN_$(d))),)
64 dist_clean_$(d) :
65 else
66 dist_clean_$(d) : clean_extra_$(d)
67 endif
68 rm -rf $(DIST_CLEAN_DIR)
69 endif
70
71 ########################################################################
72 # Per directory targets #
73 ########################################################################
74
75 # Again - no point to enforce clean_extra dependency if CLEAN is empty
76 ifeq ($(strip $(CLEAN_$(d))),)
77 clean_$(d) :
78 else
79 clean_$(d) : clean_extra_$(d)
80 endif
81 rm -f $(CLEAN_DIR)/*
82
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
85 # TOP_BUILD_DIR below
86 clean_extra_$(d) :
87 rm -rf $(filter %/,$(CLEAN_$(subst clean_extra_,,$@))); rm -f $(filter-out %/,$(CLEAN_$(subst clean_extra_,,$@)))
88
89 clean_tree_$(d) : clean_$(d) $(foreach sd,$(SUBDIRS_$(d)),clean_tree_$(sd))
90
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)),)
94
95 SUBDIRS_TGTS := $(foreach sd,$(SUBDIRS_$(d)),$(TARGETS_$(sd)))
96
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))))
101
102 # Target rules for all "non automatic" targets
103 $(foreach tgt,$(filter-out $(AUTO_TGTS),$(TARGETS_$(d))),$(eval $(call tgt_rule,$(tgt))))
104
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))
108
109 # If the directory is just for grouping its targets will be targets from
110 # all subdirectories
111 ifeq ($(strip $(TARGETS_$(d))),)
112 TARGETS_$(d) := $(SUBDIRS_TGTS)
113 endif
114
115 # This is a default rule - see Makefile
116 dir_$(d) : $(TARGETS_$(d))
117
118 endif
119 endef