-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubdir.mk
70 lines (54 loc) · 2.32 KB
/
subdir.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
ifndef BS__SUBDIR_MK
BS__SUBDIR_MK=1
# In this file resides most of the scary voodoo. Essentially, we include
# build.mk from each subdirectory in turn, doing appropriate reassignments to
# isolate its settings from those in any other subdirectory.
#
# Annoyingly, the use of eval on every line inside here is, I think, required
# to support recursive including (and hence SUBDIRS more than one level deep).
#
# Essentially, the first include must be processed completely before we can
# know how many other include statements will be needed, hence it must be
# eval-ed in here, and everything else then cascades -- we need to do the other
# processing of this subdir before doing anything to the next one, so that must
# be eval-ed immediately, etc.
# Arguments: subdir, target type
define process-subdir-target-type
$(foreach target, $($(2)S), \
$(eval _BS_ALL_TARGETS += $(1)/$(target)) \
$(eval _BS_TARGET_TYPE_$(1)/$(target) = $(2)) \
$(eval _BS_BUILD_TARGET_$(1)/$(target) = \
$(BUILDDIR)/$$(call get-default,$($(target)_FILENAME),$$(call _BS_DEFAULT_OUTPUT_$(2),$(target),$(1)/$(target)))) \
$(eval _BS_EXTRA_TARGETS_$(1)/$(target) = \
$(call _BS_EXTRA_TARGETS_$(2),$(1)/$(target))) \
$(eval SUBDIR_$(1)/$(target) = $(1)) \
$(eval $(call _BS_EXTRA_TARGET_SETTINGS_$(2),$(1),$(target))) \
$(foreach v,$(TARGET_VARIABLES), \
$(eval $(1)/$(target)_$(v)=$(value $(target)_$(v))) \
) \
)
endef
# Arguments: subdir path
define subdir-include
$(eval SUBDIR=$(1))
$(eval _BS_ALL_SUBDIRS += $(SUBDIR))
$(eval $(call save-vars,$(SUBDIR_VARIABLES),subdir_$(1)))
$(foreach v,$(SUBDIR_VARIABLES),$(eval $(v)=))
$(eval include $(1)/build.mk)
$(foreach type, $(_BS_SUPPORTED_TARGETS), \
$(eval $(call process-subdir-target-type,$(1),$(type))))
$(foreach v,$(SUBDIR_VARIABLES), \
$(eval $(1)_$(v)=$($(v))) \
)
$(foreach v,$($(1)_SUBDIRS), \
$(eval $(call subdir-include,$(1)/$(v))))
$(eval $(call load-vars,subdir_$(1)))
endef
# Variables usable by subdir build.mk files
TMPDIR=$(TMPROOT)/$(SUBDIR)
GENERATED_SOURCE_DIR=$(TMPDIR)/generated_source
#include $(foreach s,$(SUBDIRS),$(s)/build.mk)
$(foreach s,$(SUBDIRS),$(eval $(call subdir-include,$(s))))
ALL_BUILD_TARGETS += $(foreach t, $(_BS_ALL_TARGETS), \
$(_BS_BUILD_TARGET_$(t)) $(_BS_EXTRA_TARGETS_$(t)) $(_BS_EXTRA_TARGET_DEPS_$(t)))
endif