]> cloudbase.mooo.com Git - z180-stamp.git/blame - mk/footer.mk
Rename dir Z180 --> z180
[z180-stamp.git] / mk / footer.mk
CommitLineData
88d31d11
L
1define FOOTER
2SUBDIRS_$(d) := $(patsubst %/,%,$(addprefix $(d)/,$(SUBDIRS)))
3
4ifneq ($(strip $(OBJS)),)
5OBJS_$(d) := $(addprefix $(OBJPATH)/,$(OBJS))
6else # Populate OBJS_ from SRCS
7
8# Expand wildcards in SRCS if they are given
9ifneq ($(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))
12endif
13
14OBJS_$(d) := $(addprefix $(OBJPATH)/,$(addsuffix .o,$(basename $(SRCS))))
15endif
16
17CLEAN_$(d) := $(CLEAN_$(d)) $(filter /%,$(CLEAN) $(TARGETS)) $(addprefix $(d)/,$(filter-out /%,$(CLEAN)))
18
19ifdef TARGETS
20abs_tgts := $(filter /%, $(TARGETS))
21rel_tgts := $(filter-out /%,$(TARGETS))
22TARGETS_$(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))))
29else
30TARGETS_$(d) := $(OBJS_$(d))
31endif
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
39ifeq ($(origin INHERIT_DIR_VARS_$(d)),undefined)
40 INHERIT_DIR_VARS_$(d) := $(or $(INHERIT_DIR_VARS_$(parent_dir)), $(INHERIT_DIR_VARS))
41endif
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
54all :: $(TARGETS_$(d))
55
56clean_all :: clean_$(d)
57
58# dist_clean is optimized in skel.mk if we are building in out of project tree
59ifeq ($(strip $(TOP_BUILD_DIR)),)
60dist_clean :: dist_clean_$(d)
61
62# No point to enforce clean_extra dependency if CLEAN is empty
63ifeq ($(strip $(CLEAN_$(d))),)
64dist_clean_$(d) :
65else
66dist_clean_$(d) : clean_extra_$(d)
67endif
68 rm -rf $(DIST_CLEAN_DIR)
69endif
70
71########################################################################
72# Per directory targets #
73########################################################################
74
75# Again - no point to enforce clean_extra dependency if CLEAN is empty
76ifeq ($(strip $(CLEAN_$(d))),)
77clean_$(d) :
78else
79clean_$(d) : clean_extra_$(d)
80endif
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
86clean_extra_$(d) :
87 rm -rf $(filter %/,$(CLEAN_$(subst clean_extra_,,$@))); rm -f $(filter-out %/,$(CLEAN_$(subst clean_extra_,,$@)))
88
89clean_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 :)
93ifeq ($(filter clean clean_% dist_clean,$(MAKECMDGOALS)),)
94
95SUBDIRS_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)
107tree_$(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
111ifeq ($(strip $(TARGETS_$(d))),)
112TARGETS_$(d) := $(SUBDIRS_TGTS)
113endif
114
115# This is a default rule - see Makefile
116dir_$(d) : $(TARGETS_$(d))
117
118endif
119endef