Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / nlfaultinjection / repo / third_party / nlbuild-autotools / repo / automake / post / rules / foreigndeps.am
1 #
2 #    Copyright 2020 nlbuild-autotools Authors. All Rights Reserved.
3 #
4 #    Licensed under the Apache License, Version 2.0 (the "License");
5 #    you may not use this file except in compliance with the License.
6 #    You may obtain a copy of the License at
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS,
12 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #    See the License for the specific language governing permissions and
14 #    limitations under the License.
15 #
16
17 #
18 #    Description:
19 #      This file is the automake header for building foreign make
20 #      (that is, outside of the current make directory) dependencies.
21 #
22 #      Two types of foreign make dependencies are supported:
23 #
24 #        * file
25 #
26 #            EXPLICIT dependecies that follow the form '<DIR>/<TARGET>'
27 #            where '$(MAKE) -C <DIR> <TARGET>' will produce and satisfy
28 #            the desired dependency expected by the current make file
29 #
30 #        * subdir
31 #
32 #            IMPLICIT dependecies that follow the form '<DIR>'
33 #            where '$(MAKE) -C <DIR>' will produce and satisfy
34 #            the desired dependencies expected by the current
35 #            make file.
36 #
37 #      This defines make targets and commands for handling such
38 #      foreign make dependencies.  overridden by project make files.
39 #
40
41 # The user-supported and -visible targets for foreign dependencies are:
42 #
43 #   * nlforeign-deps
44 #
45 #       Build all foreign target dependencies, including both files or
46 #       subdirectories.
47 #
48 #   * nlforeign-file-deps
49 #
50 #       Build only foreign file target dependencies.
51 #
52 #   * nlforeign-subdir-deps
53 #
54 #       Build only foreign subdirectory target dependencies.
55 #
56
57 .PHONY: nlforeign-file-deps nlforeign-subdir-deps nlforeign-deps
58
59 nlforeign-deps: nlforeign-file-deps nlforeign-subdir-deps
60
61 nlforeign-file-deps:
62
63 nlforeign-subdir-deps:
64
65 #
66 # if defined(NLFOREIGN_FILE_DEPENDENCIES) || defined(NLFOREIGN_SUBDIR_DEPENDENCIES)
67 #
68 ifneq ($(strip $(NLFOREIGN_FILE_DEPENDENCIES)$(NLFOREIGN_SUBDIR_DEPENDENCIES)),)
69
70 #
71 # Foreign target dependency sentinel file management
72 #
73
74 # All foreign target dependency sentinel files are of the form
75 # [.<path>]<sentinel file stem><unique invocation qualifier, where
76 # [.<path>] is only included if the <path> is non-empty.
77
78 # This defines the <sentinel file stem>.
79
80 NLFOREIGN_DEPENDENCIES_SENTINEL_STEM      := .nlbuild_foreign_deps_
81
82 # This defines the <unique invocation qualifier>.
83 #
84 # Check to see if NLFOREIGN_DEPENDENCIES_SENTINEL_ID has been set for
85 # this make invocation.
86
87 ifneq ($(origin NLFOREIGN_DEPENDENCIES_SENTINEL_ID),environment)
88
89   # the parent of this shell is the "root" make invocation
90   override NLFOREIGN_DEPENDENCIES_SENTINEL_ID:=$(shell echo $$PPID)
91
92   # makes makedirs_id an environment var
93   export NLFOREIGN_DEPENDENCIES_SENTINEL_ID
94
95 endif
96
97 #
98 # nlforeign-create-dependencies-sentinel-name <target path> <unique invocation qualifier>
99 #
100 # This creates a name for a foreign target dependency sentinel
101 # file using the specified target path and unique invocation
102 # qualifier.
103 #
104 # The target path will be transformed by eliding double-dot (..)
105 # sequences, transforming path separators (/) into underscores (_),
106 # and transforming dots (.) into underscores (_).
107 #
108 define nlforeign-create-dependencies-sentinel-name
109 $(if $(1),.$(subst .,_,$(subst /,_,$(subst ..,,$(1)))),)$(NLFOREIGN_DEPENDENCIES_SENTINEL_STEM)$(2)
110 endef
111
112 #
113 # nlforeign-create-unique-dependencies-sentinel-name <target path> <unique invocation qualifier>
114 #
115 # This creates a unique name for a foreign target dependency sentinel
116 # file using the specified target path, qualified by the current make
117 # process identifier.
118 #
119 define nlforeign-create-unique-dependencies-sentinel-name
120 $(call nlforeign-create-dependencies-sentinel-name,$(1),$(NLFOREIGN_DEPENDENCIES_SENTINEL_ID))
121 endef
122
123 #
124 # MARK: NLFOREIGN_SUBDIR_DEPENDENCIES
125 #
126 ifdef NLFOREIGN_SUBDIR_DEPENDENCIES
127
128 ifeq ($(MAKECMDGOALS),$(filter-out clean distclean maintainer-clean,$(MAKECMDGOALS)))
129
130 # Always ensure that nlforeign-subdir-deps runs first against any
131 # non-clean target goals such that make file maintainers do not have
132 # to set up any explicit dependencies when they define
133 # NLFOREIGN_SUBDIR_DEPENDENCIES.
134 #
135 # Do this by tricking make into building nlforeign-subdir-deps first
136 # by forcing it to try to make an include file that depends on
137 # nlforeign-subdir-deps.
138
139 -include .nlforeign_deps_trick_never_exists.min
140
141 .nlforeign_deps_trick_never_exists.min: nlforeign-subdir-deps
142
143 endif # ifeq ($(MAKECMDGOALS),$(filter-out clean distclean maintainer-clean,$(MAKECMDGOALS)))
144
145 define nlforeign-subdir-make
146         $(NL_V_PROGRESS) "MAKE" "$(1)"
147         +$(NL_V_AT)$(MAKE) $(MFLAGS) -C "$(1)"
148 endef # nlforeign-subdir-make
149
150 #
151 # nlforeign-create-unique-subdir-dependencies-sentinel-name <target subdirectory>
152 #
153 # This creates the name of a foreign subdirectory dependency sentinel
154 # file of the form:
155 #
156 #   <target subdirectory>/<sentinel stem><sentinel unique id>
157 #
158 define nlforeign-create-unique-subdir-dependencies-sentinel-name
159 $(call Deslashify,$(1))/$(call nlforeign-create-unique-dependencies-sentinel-name,$(notdir $(call Slashify,$(1))))
160 endef
161
162 #
163 # nlforeign-create-unique-subdir-dependencies-sentinel-name-glob <target subdirectory> <glob pattern>
164 #
165 # This creates the glob name pattern of a foreign subdirectory
166 # dependency sentinel file of the form:
167 #
168 #   <target subdirectory>/<sentinel stem><glob pattern>
169 #
170 define nlforeign-create-unique-subdir-dependencies-sentinel-name-glob
171 $(call Deslashify,$(1))/$(call nlforeign-create-dependencies-sentinel-name,$(notdir $(call Slashify,$(1))),$(2))
172 endef
173
174 #
175 # nlforeign-subdir-dependency-template <foreign subdir target>
176 #
177 # This template defines targets and associated commands for building a
178 # foreign subdir target depedendency via a subdirectory make (for
179 # example, `make -C ../foo` for directory '../foo').
180 #
181 define nlforeign-subdir-dependency-template
182
183 # The foreign subdirectory dependency depends on a sentinel for it such that
184 # make is forced to visit the directory (should any of its
185 # dependencies have changed since the last visit).
186
187 NLFOREIGN_SUBDIR_CLEANFILE_GLOBS += $(call nlforeign-create-unique-subdir-dependencies-sentinel-name-glob,$(1),*)
188
189 nlforeign-subdir-deps: $(call nlforeign-create-unique-subdir-dependencies-sentinel-name,$(1)) 
190
191 $$(call nlforeign-create-unique-subdir-dependencies-sentinel-name,$(1)):
192         $(NL_V_AT)touch "$$(@)"
193         $(call nlforeign-subdir-make,$(1))
194         $(NL_V_AT)$(RM) $(filter-out $$(@),$(wildcard $(call nlforeign-create-unique-subdir-dependencies-sentinel-name-glob,$(1),*)))
195
196 endef # nlforeign-subdir-dependency-template
197
198 # Clean up any foreign subdirectory dependency sentinel files by
199 # hooking on any clean target is invoked.
200 #
201 # NOTE: We CANNOT just hook on 'clean-local' since it won't be recognized
202 # unless the make file including this one uses it.
203
204 clean distclean maintainer-clean: nlforeign-subdir-dependency-clean
205
206 nlforeign-subdir-dependency-clean:
207         $(NL_V_AT)$(RM) $(NLFOREIGN_SUBDIR_CLEANFILE_GLOBS)
208
209 # Instantiate the foreign subdirectory dependency template for each
210 # subdirectory in NLFOREIGN_SUBDIR_DEPENDENCIES.
211
212 $(foreach nlforeign-subdir-dependency,$(NLFOREIGN_SUBDIR_DEPENDENCIES),$(eval $(call nlforeign-subdir-dependency-template,$(nlforeign-subdir-dependency))))
213
214 endif # NLFOREIGN_SUBDIR_DEPENDENCIES
215
216 #
217 # MARK: NLFOREIGN_FILE_DEPENDENCIES
218 #
219 ifdef NLFOREIGN_FILE_DEPENDENCIES
220
221 nlforeign-file-deps: $(NLFOREIGN_FILE_DEPENDENCIES)
222
223 define nlforeign-file-make
224         $(NL_V_PROGRESS) "MAKE" "$(1)"
225         +$(NL_V_AT)$(MAKE) $(MFLAGS) -C "$(dir $(1))" "$(notdir $(1))"
226 endef # nlforeign-file-make
227
228 #
229 # nlforeign-create-unique-file-dependencies-sentinel-name <target file
230 #
231 # This creates the name of a foreign file dependency sentinel file of
232 # the form:
233 #
234 #   $(dir <target file>)/$(notdir <target file>)<sentinel stem><sentinel unique id>
235 #
236 define nlforeign-create-unique-file-dependencies-sentinel-name
237 $(call Deslashify,$(dir $(1)))/$(call nlforeign-create-unique-dependencies-sentinel-name,$(notdir $(1)))
238 endef
239
240 #
241 # nlforeign-create-unique-file-dependencies-sentinel-name-glob <target file <glob pattern>
242 #
243 # This creates the glob name pattern of a foreign file dependency
244 # sentinel file of the form:
245 #
246 #    $(dir <target file>)/$(notdir <target file>)<sentinel stem><glob pattern>
247 #
248 define nlforeign-create-unique-file-dependencies-sentinel-name-glob
249 $(call Deslashify,$(dir $(1)))/$(call nlforeign-create-dependencies-sentinel-name,$(notdir $(1)),$(2))
250 endef
251
252 #
253 # nlforeign-file-dependency-template <foreign file target>
254 #
255 # This template defines targets and associated commands for building a
256 # foreign file target depedendency via a subdirectory make (for
257 # example, `make -C ../foo bar` for target 'bar' in directory
258 # '../foo').
259 #
260 define nlforeign-file-dependency-template
261
262 # The foreign file dependency depends on a sentinel for it such that
263 # make is forced to visit the directory that creates it (should any of
264 # its dependencies have changed since the last visit).
265
266 NLFOREIGN_FILE_CLEANFILE_GLOBS += $(call nlforeign-create-unique-file-dependencies-sentinel-name-glob,$(1),*)
267
268 $(1): $$(call nlforeign-create-unique-file-dependencies-sentinel-name,$(1))
269         $(call nlforeign-file-make,$(1))
270
271 $$(call nlforeign-create-unique-file-dependencies-sentinel-name,$(1)):
272         $(NL_V_AT)touch "$$(@)"
273         $(NL_V_AT)$(RM) $(filter-out $$(@),$(wildcard $(call nlforeign-create-unique-file-dependencies-sentinel-name-glob,$(1),*)))
274
275 endef # nlforeign-file-dependency-template
276
277 # Clean up any foreign file dependency sentinel files by hooking on
278 # any clean target is invoked.
279 #
280 # NOTE: We CANNOT just hook on 'clean-local' since it won't be recognized
281 # unless the make file including this one uses it.
282
283 clean distclean maintainer-clean: nlforeign-file-dependency-clean
284
285 nlforeign-file-dependency-clean:
286         $(NL_V_AT)$(RM) $(NLFOREIGN_FILE_CLEANFILE_GLOBS)
287
288 # Instantiate the foreign file dependency template for each file in
289 # NLFOREIGN_FILE_DEPENDENCIES.
290
291 $(foreach nlforeign-file-dependency,$(NLFOREIGN_FILE_DEPENDENCIES),$(eval $(call nlforeign-file-dependency-template,$(nlforeign-file-dependency))))
292
293 endif # NLFOREIGN_FILE_DEPENDENCIES
294
295 endif # NLFOREIGN_FILE_DEPENDENCIES || NLFOREIGN_SUBDIR_DEPENDENCIES