-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdepends.mk
102 lines (87 loc) · 2.78 KB
/
depends.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
ifndef BS__DEPENDS_MK
BS__DEPENDS_MK=1
# needed due to no escaping.
comma=,
# Functions for dealing with dependencies.
#
# These are dependencies between libraries/executables that control linker
# flags, not file-based dependencies between (e.g.) .cc and .o files.
# expand-target-dependencies
#
# Arguments: target name
#
# Returns the linker options required to link all of the given target's link
# dependencies.
#
expand-target-dependencies = \
$(foreach d,$($(1)_LIBRARIES), \
$(call expand-dependency,$(d))) \
$(if $($(1)_CONTAINS), \
-Wl$(comma)--whole-archive \
$(foreach d,$($(1)_CONTAINS), \
$(call expand-dependency,$(d))) \
-Wl$(comma)--no-whole-archive \
)
# expand-dependency
#
# Arguments: a dependency specification
#
# Returns the linker option required to bring in a given dependency spec.
#
# Used internally by expand-target-dependencies.
#
expand-dependency = \
$(if $(filter -%,$(1)), \
$(1), \
$(addprefix -L,$(call get-unless-default,$(dir $(_BS_BUILD_TARGET_$(1))),$(BUILDDIR)/$(LIBDIR)/)) \
-l$(LIBRARY_NAME_$(1)) \
)
# expand-target-dependency-files
#
# Arguments: target name
#
# Returns the list of (library) files that the target should depend on, in addition to its objects
#
expand-target-dependency-files = \
$(foreach d,$($(1)_LIBRARIES) $($(1)_CONTAINS), \
$(call expand-dependency-file,$(d)))
# expand-target-dependency-dsos
#
# Arguments: target name
#
# Returns the list of DSO files on which the target depends
#
expand-target-dependency-dsos = $(filter %.so, $(expand-target-dependency-files))
# expand-target-dependency-statics
#
# Arguments: target name
#
# Returns the list of static library files on which the target depends
#
expand-target-dependency-statics = $(filter-out %.so, $(expand-target-dependency-files))
# expand-target-dependency-makefiles
#
# Arguments: target name
#
# Returns the list of makefiles modifications to which should trigger rebuilding this target.
# It's a bit heuristic; technically a change to any build.mk file *could* change the build
# behaviour of any target, but this is what's most likely to be right most of the time. Do a
# full rebuild if in doubt.
expand-target-dependency-makefiles = $(addsuffix /build.mk, \
$(patsubst %/,%,$(call expand-subdir-plus-parents,$(SUBDIR_$(1)))))
expand-subdir-plus-parents = $(if $(filter ./,$(1)),, \
$(1) $(call expand-subdir-plus-parents,$(dir $(patsubst %/,%,$(1)))))
# expand-dependency-file
#
# Arguments: a dependency specification
#
# Returns the filename, if local to this project, that satisfies the dependency
#
# Used internally by expand-target-dependency-files
#
expand-dependency-file = \
$(if $(filter -l%,$(1)), \
, \
$(_BS_BUILD_TARGET_$(1)) \
)
endif