]>
Commit | Line | Data |
---|---|---|
17759187 | 1 | |
5609c512 AB |
2 | # These are used when we want to do substitutions without confusing Make |
3 | NULL := | |
4 | SPACE := $(NULL) # | |
2f4e4dc2 FZ |
5 | COMMA := , |
6 | ||
5ab28867 JQ |
7 | # Don't use implicit rules or variables |
8 | # we have explicit rules for everything | |
9 | MAKEFLAGS += -rR | |
10 | ||
11 | # Files with this suffixes are final, don't try to generate them | |
12 | # using implicit rules | |
a273f4ce PB |
13 | %/trace-events: |
14 | %.hx: | |
15 | %.py: | |
16 | %.objs: | |
5ab28867 JQ |
17 | %.d: |
18 | %.h: | |
19 | %.c: | |
c3dc9fd5 | 20 | %.cc: |
83f73fce | 21 | %.cpp: |
5ab28867 JQ |
22 | %.m: |
23 | %.mak: | |
24 | ||
7ebf54bc | 25 | # Flags for dependency generation |
998b7b1d | 26 | QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(@D)/$(*F).d |
02d5467e | 27 | |
ba78db44 DB |
28 | # Compiler searches the source file dir first, but in vpath builds |
29 | # we need to make it search the build dir too, before any other | |
30 | # explicit search paths. There are two search locations in the build | |
31 | # dir, one absolute and the other relative to the compiler working | |
32 | # directory. These are the same for target-independent files, but | |
33 | # different for target-dependent ones. | |
a81df1b6 | 34 | QEMU_LOCAL_INCLUDES = -iquote $(BUILD_DIR) -iquote $(BUILD_DIR)/$(@D) -iquote $(@D) |
9d9199a0 | 35 | |
c261d774 | 36 | WL_U := -Wl,-u, |
4852ee95 | 37 | find-symbols = $(if $1, $(sort $(shell $(NM) -P -g $1 | $2))) |
c261d774 FZ |
38 | defined-symbols = $(call find-symbols,$1,awk '$$2!="U"{print $$1}') |
39 | undefined-symbols = $(call find-symbols,$1,awk '$$2=="U"{print $$1}') | |
40 | ||
1f0a1d8a MAL |
41 | WL := -Wl, |
42 | ifdef CONFIG_DARWIN | |
43 | whole-archive = $(WL)-force_load,$1 | |
44 | else | |
45 | whole-archive = $(WL)--whole-archive $1 $(WL)--no-whole-archive | |
46 | endif | |
47 | ||
c261d774 FZ |
48 | # All the .mo objects in -m variables are also added into corresponding -y |
49 | # variable in unnest-vars, but filtered out here, when LINK is called. | |
50 | # | |
51 | # The .mo objects are supposed to be linked as a DSO, for module build. So here | |
52 | # they are only used as a placeholders to generate those "archive undefined" | |
53 | # symbol options (-Wl,-u,$symbol_name), which are the archive functions | |
54 | # referenced by the code in the DSO. | |
55 | # | |
56 | # Also the presence in -y variables will also guarantee they are built before | |
57 | # linking executables that will load them. So we can look up symbol reference | |
58 | # in LINK. | |
59 | # | |
60 | # This is necessary because the exectuable itself may not use the function, in | |
61 | # which case the function would not be linked in. Then the DSO loading will | |
62 | # fail because of the missing symbol. | |
3154fee4 | 63 | process-archive-undefs = $(filter-out %.a %.fa %.mo %$(DSOSUF),$1) \ |
c261d774 | 64 | $(addprefix $(WL_U), \ |
1f0a1d8a | 65 | $(filter $(call defined-symbols,$(filter %.a %.fa, $1)), \ |
3154fee4 | 66 | $(call undefined-symbols,$(filter %.mo %$(DSOSUF),$1)))) \ |
1f0a1d8a MAL |
67 | $(foreach l,$(filter %.fa,$1),$(call whole-archive,$l)) \ |
68 | $(filter %.a,$1) | |
c261d774 | 69 | |
3154fee4 | 70 | extract-libs = $(strip $(foreach o,$(filter-out %.mo %$(DSOSUF),$1),$($o-libs))) |
17969268 | 71 | expand-objs = $(strip $(sort $(filter %.o,$1)) \ |
3154fee4 MAL |
72 | $(foreach o,$(filter %.mo %$(DSOSUF),$1),$($o-objs)) \ |
73 | $(filter-out %.o %.mo %$(DSOSUF),$1)) | |
5c0d52bc | 74 | |
0e8c9214 | 75 | %.o: %.c |
ac76f9d1 | 76 | @mkdir -p $(dir $@) |
ba78db44 DB |
77 | $(call quiet-command,$(CC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \ |
78 | $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \ | |
79 | -c -o $@ $<,"CC","$(TARGET_DIR)$@") | |
17759187 | 80 | |
3144f78b PM |
81 | # If we have a CXX we might have some C++ objects, in which case we |
82 | # must link with the C++ compiler, not the plain C compiler. | |
83 | LINKPROG = $(or $(CXX),$(CC)) | |
84 | ||
db5adeaa | 85 | LINK = $(call quiet-command, $(LINKPROG) $(CFLAGS) $(QEMU_LDFLAGS) -o $@ \ |
c261d774 | 86 | $(call process-archive-undefs, $1) \ |
8000047e | 87 | $(call extract-libs,$1) $(LIBS),"LINK","$(TARGET_DIR)$@") |
44dc0ca3 | 88 | |
5f6f0e27 | 89 | %.o: %.S |
ba78db44 DB |
90 | $(call quiet-command,$(CCAS) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \ |
91 | $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) \ | |
92 | -c -o $@ $<,"CCAS","$(TARGET_DIR)$@") | |
17759187 | 93 | |
c3dc9fd5 | 94 | %.o: %.cc |
ba78db44 | 95 | $(call quiet-command,$(CXX) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \ |
086d5f75 | 96 | $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CXXFLAGS) $($@-cflags) \ |
ba78db44 | 97 | -c -o $@ $<,"CXX","$(TARGET_DIR)$@") |
c3dc9fd5 | 98 | |
83f73fce | 99 | %.o: %.cpp |
ba78db44 | 100 | $(call quiet-command,$(CXX) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \ |
086d5f75 | 101 | $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CXXFLAGS) $($@-cflags) \ |
ba78db44 | 102 | -c -o $@ $<,"CXX","$(TARGET_DIR)$@") |
83f73fce | 103 | |
17759187 | 104 | %.o: %.m |
ba78db44 DB |
105 | $(call quiet-command,$(OBJCC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \ |
106 | $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \ | |
107 | -c -o $@ $<,"OBJC","$(TARGET_DIR)$@") | |
17759187 | 108 | |
2c13ec50 | 109 | %.o: %.dtrace |
0bdb12c7 | 110 | $(call quiet-command,dtrace -o $@ -G -s $<,"GEN","$(TARGET_DIR)$@") |
2c13ec50 | 111 | |
d24697e1 FZ |
112 | DSO_OBJ_CFLAGS := -fPIC -DBUILD_DSO |
113 | module-common.o: CFLAGS += $(DSO_OBJ_CFLAGS) | |
db5adeaa | 114 | %$(DSOSUF): QEMU_LDFLAGS += $(LDFLAGS_SHARED) |
c261d774 | 115 | %$(DSOSUF): %.mo |
17969268 | 116 | $(call LINK,$^) |
e26110cf | 117 | @# Copy to build root so modules can be loaded when program started without install |
0bdb12c7 | 118 | $(if $(findstring /,$@),$(call quiet-command,cp $@ $(subst /,-,$@),"CP","$(subst /,-,$@)")) |
17969268 | 119 | |
c261d774 | 120 | |
7ecf44a5 | 121 | LD_REL := $(CC) -nostdlib $(LD_REL_FLAGS) |
c261d774 FZ |
122 | |
123 | %.mo: | |
0bdb12c7 | 124 | $(call quiet-command,$(LD_REL) -o $@ $^,"LD","$(TARGET_DIR)$@") |
c261d774 | 125 | |
17969268 FZ |
126 | .PHONY: modules |
127 | modules: | |
128 | ||
3aa892d7 | 129 | %$(EXESUF): %.o |
1f0a1d8a | 130 | $(call LINK,$(filter %.o %.a %.mo %.fa, $^)) |
4f188f88 | 131 | |
93a0dba7 | 132 | %.a: |
0bdb12c7 | 133 | $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"AR","$(TARGET_DIR)$@") |
93a0dba7 | 134 | |
0bdb12c7 PM |
135 | # Usage: $(call quiet-command,command and args,"NAME","args to print") |
136 | # This will run "command and args", and either: | |
137 | # if V=1 just print the whole command and args | |
138 | # otherwise print the 'quiet' output in the format " NAME args to print" | |
139 | # NAME should be a short name of the command, 7 letters or fewer. | |
140 | # If called with only a single argument, will print nothing in quiet mode. | |
9df43317 PB |
141 | quiet-command-run = $(if $(V),,$(if $2,printf " %-7s %s\n" $2 $3 && ))$1 |
142 | quiet-@ = $(if $(V),,@) | |
143 | quiet-command = $(quiet-@)$(call quiet-command-run,$1,$2,$3) | |
70071e17 JQ |
144 | |
145 | # cc-option | |
8a2e6ab5 | 146 | # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0) |
70071e17 | 147 | |
fc3baad7 TM |
148 | cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \ |
149 | >/dev/null 2>&1 && echo OK), $2, $3) | |
036999e9 PB |
150 | cc-c-option = $(if $(shell $(CC) $1 $2 -c -o /dev/null -xc /dev/null \ |
151 | >/dev/null 2>&1 && echo OK), $2, $3) | |
1215c6e7 | 152 | |
d52c454a | 153 | VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc Kconfig% %.json.in |
288e7bcc | 154 | set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1))) |
076d2471 | 155 | |
0d659426 MT |
156 | # install-prog list, dir |
157 | define install-prog | |
158 | $(INSTALL_DIR) "$2" | |
159 | $(INSTALL_PROG) $1 "$2" | |
160 | $(if $(STRIP),$(STRIP) $(foreach T,$1,"$2/$(notdir $T)"),) | |
161 | endef | |
162 | ||
2b2e59e6 PB |
163 | # find-in-path |
164 | # Usage: $(call find-in-path, prog) | |
165 | # Looks in the PATH if the argument contains no slash, else only considers one | |
166 | # specific directory. Returns an # empty string if the program doesn't exist | |
167 | # there. | |
88071589 | 168 | find-in-path = $(if $(findstring /, $1), \ |
2b2e59e6 PB |
169 | $(wildcard $1), \ |
170 | $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH))))) | |
171 | ||
837a2e26 PM |
172 | # Logical functions (for operating on y/n values like CONFIG_FOO vars) |
173 | # Inputs to these must be either "y" (true) or "n" or "" (both false) | |
174 | # Output is always either "y" or "n". | |
175 | # Usage: $(call land,$(CONFIG_FOO),$(CONFIG_BAR)) | |
176 | # Logical NOT | |
177 | lnot = $(if $(subst n,,$1),n,y) | |
178 | # Logical AND | |
179 | land = $(if $(findstring yy,$1$2),y,n) | |
180 | # Logical OR | |
181 | lor = $(if $(findstring y,$1$2),y,n) | |
182 | # Logical XOR (note that this is the inverse of leqv) | |
183 | lxor = $(if $(filter $(call lnot,$1),$(call lnot,$2)),n,y) | |
184 | # Logical equivalence (note that leqv "","n" is true) | |
185 | leqv = $(if $(filter $(call lnot,$1),$(call lnot,$2)),y,n) | |
186 | # Logical if: like make's $(if) but with an leqv-like test | |
187 | lif = $(if $(subst n,,$1),$2,$3) | |
188 | ||
9ef622e3 PM |
189 | # String testing functions: inputs to these can be any string; |
190 | # the output is always either "y" or "n". Leading and trailing whitespace | |
191 | # is ignored when comparing strings. | |
192 | # String equality | |
193 | eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y) | |
194 | # String inequality | |
195 | ne = $(if $(subst $2,,$1)$(subst $1,,$2),y,n) | |
196 | # Emptiness/non-emptiness tests: | |
197 | isempty = $(if $1,n,y) | |
198 | notempty = $(if $1,y,n) | |
199 | ||
7586317b MT |
200 | .PHONY: clean-timestamp |
201 | clean-timestamp: | |
202 | rm -f *.timestamp | |
203 | clean: clean-timestamp | |
204 | ||
7dbbbb0c MT |
205 | # will delete the target of a rule if commands exit with a nonzero exit status |
206 | .DELETE_ON_ERROR: | |
e05804ee | 207 | |
1c33ac57 FZ |
208 | # save-vars |
209 | # Usage: $(call save-vars, vars) | |
210 | # Save each variable $v in $vars as save-vars-$v, save their object's | |
5ffb3505 PB |
211 | # variables, then clear $v. saved-vars-$v contains the variables that |
212 | # where saved for the objects, in order to speedup load-vars. | |
1c33ac57 FZ |
213 | define save-vars |
214 | $(foreach v,$1, | |
215 | $(eval save-vars-$v := $(value $v)) | |
5ffb3505 PB |
216 | $(eval saved-vars-$v := $(foreach o,$($v), \ |
217 | $(if $($o-cflags), $o-cflags $(eval save-vars-$o-cflags := $($o-cflags))$(eval $o-cflags := )) \ | |
218 | $(if $($o-libs), $o-libs $(eval save-vars-$o-libs := $($o-libs))$(eval $o-libs := )) \ | |
219 | $(if $($o-objs), $o-objs $(eval save-vars-$o-objs := $($o-objs))$(eval $o-objs := )))) | |
1c33ac57 | 220 | $(eval $v := )) |
5c0d52bc FZ |
221 | endef |
222 | ||
1c33ac57 FZ |
223 | # load-vars |
224 | # Usage: $(call load-vars, vars, add_var) | |
225 | # Load the saved value for each variable in @vars, and the per object | |
226 | # variables. | |
227 | # Append @add_var's current value to the loaded value. | |
228 | define load-vars | |
229 | $(eval $2-new-value := $(value $2)) | |
230 | $(foreach v,$1, | |
231 | $(eval $v := $(value save-vars-$v)) | |
5ffb3505 PB |
232 | $(foreach o,$(saved-vars-$v), |
233 | $(eval $o := $(save-vars-$o)) $(eval save-vars-$o := )) | |
234 | $(eval save-vars-$v := ) | |
235 | $(eval saved-vars-$v := )) | |
1c33ac57 | 236 | $(eval $2 := $(value $2) $($2-new-value)) |
e05804ee PB |
237 | endef |
238 | ||
1c33ac57 FZ |
239 | # fix-paths |
240 | # Usage: $(call fix-paths, obj_path, src_path, vars) | |
241 | # Add prefix @obj_path to all objects in @vars, and add prefix @src_path to all | |
242 | # directories in @vars. | |
243 | define fix-paths | |
244 | $(foreach v,$3, | |
245 | $(foreach o,$($v), | |
246 | $(if $($o-libs), | |
247 | $(eval $1$o-libs := $($o-libs))) | |
248 | $(if $($o-cflags), | |
249 | $(eval $1$o-cflags := $($o-cflags))) | |
250 | $(if $($o-objs), | |
251 | $(eval $1$o-objs := $(addprefix $1,$($o-objs))))) | |
252 | $(eval $v := $(addprefix $1,$(filter-out %/,$($v))) \ | |
253 | $(addprefix $2,$(filter %/,$($v))))) | |
e05804ee PB |
254 | endef |
255 | ||
1c33ac57 FZ |
256 | # unnest-var-recursive |
257 | # Usage: $(call unnest-var-recursive, obj_prefix, vars, var) | |
258 | # | |
259 | # Unnest @var by including subdir Makefile.objs, while protect others in @vars | |
260 | # unchanged. | |
261 | # | |
262 | # @obj_prefix is the starting point of object path prefix. | |
263 | # | |
264 | define unnest-var-recursive | |
265 | $(eval dirs := $(sort $(filter %/,$($3)))) | |
266 | $(eval $3 := $(filter-out %/,$($3))) | |
267 | $(foreach d,$(dirs:%/=%), | |
268 | $(call save-vars,$2) | |
269 | $(eval obj := $(if $1,$1/)$d) | |
270 | $(eval -include $(SRC_PATH)/$d/Makefile.objs) | |
271 | $(call fix-paths,$(if $1,$1/)$d/,$d/,$2) | |
272 | $(call load-vars,$2,$3) | |
273 | $(call unnest-var-recursive,$1,$2,$3)) | |
17969268 FZ |
274 | endef |
275 | ||
1c33ac57 FZ |
276 | # unnest-vars |
277 | # Usage: $(call unnest-vars, obj_prefix, vars) | |
278 | # | |
279 | # @obj_prefix: object path prefix, can be empty, or '..', etc. Don't include | |
280 | # ending '/'. | |
281 | # | |
282 | # @vars: the list of variable names to unnest. | |
283 | # | |
284 | # This macro will scan subdirectories's Makefile.objs, include them, to build | |
285 | # up each variable listed in @vars. | |
286 | # | |
287 | # Per object and per module cflags and libs are saved with relative path fixed | |
288 | # as well, those variables include -libs, -cflags and -objs. Items in -objs are | |
289 | # also fixed to relative path against SRC_PATH plus the prefix @obj_prefix. | |
290 | # | |
291 | # All nested variables postfixed by -m in names are treated as DSO variables, | |
292 | # and will be built as modules, if enabled. | |
293 | # | |
294 | # A simple example of the unnest: | |
295 | # | |
296 | # obj_prefix = .. | |
297 | # vars = hot cold | |
298 | # hot = fire.o sun.o season/ | |
299 | # cold = snow.o water/ season/ | |
300 | # | |
301 | # Unnest through a faked source directory structure: | |
302 | # | |
303 | # SRC_PATH | |
304 | # ├── water | |
305 | # │ └── Makefile.objs──────────────────┐ | |
306 | # │ │ hot += steam.o │ | |
307 | # │ │ cold += ice.mo │ | |
308 | # │ │ ice.mo-libs := -licemaker │ | |
309 | # │ │ ice.mo-objs := ice1.o ice2.o │ | |
310 | # │ └──────────────────────────────┘ | |
311 | # │ | |
312 | # └── season | |
313 | # └── Makefile.objs──────┐ | |
314 | # │ hot += summer.o │ | |
315 | # │ cold += winter.o │ | |
316 | # └──────────────────┘ | |
317 | # | |
318 | # In the end, the result will be: | |
319 | # | |
320 | # hot = ../fire.o ../sun.o ../season/summer.o | |
321 | # cold = ../snow.o ../water/ice.mo ../season/winter.o | |
322 | # ../water/ice.mo-libs = -licemaker | |
323 | # ../water/ice.mo-objs = ../water/ice1.o ../water/ice2.o | |
324 | # | |
9ab71e5e | 325 | # Note that 'hot' didn't include 'water/' in the input, so 'steam.o' is not |
1c33ac57 FZ |
326 | # included. |
327 | # | |
e05804ee | 328 | define unnest-vars |
1c33ac57 FZ |
329 | # In the case of target build (i.e. $1 == ..), fix path for top level |
330 | # Makefile.objs objects | |
331 | $(if $1,$(call fix-paths,$1/,,$2)) | |
332 | ||
333 | # Descend and include every subdir Makefile.objs | |
c88f68ec FZ |
334 | $(foreach v, $2, |
335 | $(call unnest-var-recursive,$1,$2,$v) | |
336 | # Pass the .mo-cflags and .mo-libs along to its member objects | |
337 | $(foreach o, $(filter %.mo,$($v)), | |
338 | $(foreach p,$($o-objs), | |
339 | $(if $($o-cflags), $(eval $p-cflags += $($o-cflags))) | |
340 | $(if $($o-libs), $(eval $p-libs += $($o-libs)))))) | |
341 | ||
342 | # For all %.mo objects that are directly added into -y, just expand them | |
343 | $(foreach v,$(filter %-y,$2), | |
344 | $(eval $v := $(foreach o,$($v),$(if $($o-objs),$($o-objs),$o)))) | |
1c33ac57 FZ |
345 | |
346 | $(foreach v,$(filter %-m,$2), | |
347 | # All .o found in *-m variables are single object modules, create .mo | |
348 | # for them | |
349 | $(foreach o,$(filter %.o,$($v)), | |
350 | $(eval $(o:%.o=%.mo)-objs := $o)) | |
351 | # Now unify .o in -m variable to .mo | |
352 | $(eval $v := $($v:%.o=%.mo)) | |
353 | $(eval modules-m += $($v)) | |
354 | ||
355 | # For module build, build shared libraries during "make modules" | |
356 | # For non-module build, add -m to -y | |
357 | $(if $(CONFIG_MODULES), | |
c261d774 | 358 | $(foreach o,$($v), |
d24697e1 | 359 | $(eval $($o-objs): CFLAGS += $(DSO_OBJ_CFLAGS)) |
c261d774 FZ |
360 | $(eval $o: $($o-objs))) |
361 | $(eval $(patsubst %-m,%-y,$v) += $($v)) | |
1c33ac57 FZ |
362 | $(eval modules: $($v:%.mo=%$(DSOSUF))), |
363 | $(eval $(patsubst %-m,%-y,$v) += $(call expand-objs, $($v))))) | |
364 | ||
365 | # Post-process all the unnested vars | |
366 | $(foreach v,$2, | |
367 | $(foreach o, $(filter %.mo,$($v)), | |
368 | # Find all the .mo objects in variables and add dependency rules | |
369 | # according to .mo-objs. Report error if not set | |
370 | $(if $($o-objs), | |
5e5733e5 | 371 | $(eval $(o:%.mo=%$(DSOSUF)): module-common.o $($o-objs)))) |
1c33ac57 FZ |
372 | $(shell mkdir -p ./ $(sort $(dir $($v)))) |
373 | # Include all the .d files | |
1f0a1d8a | 374 | $(eval -include $(patsubst %.o,%.d,$(patsubst %.mo,%.d,$(filter %.o,$($v))))) |
1c33ac57 | 375 | $(eval $v := $(filter-out %/,$($v)))) |
e05804ee | 376 | endef |
76480423 MAL |
377 | |
378 | TEXI2MAN = $(call quiet-command, \ | |
d59157ea | 379 | perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $(TEXI2PODFLAGS) $< $@.pod && \ |
76480423 MAL |
380 | $(POD2MAN) --section=$(subst .,,$(suffix $@)) --center=" " --release=" " $@.pod > $@, \ |
381 | "GEN","$@") | |
382 | ||
383 | %.1: | |
384 | $(call TEXI2MAN) | |
56e8bdd4 MAL |
385 | %.7: |
386 | $(call TEXI2MAN) | |
76480423 MAL |
387 | %.8: |
388 | $(call TEXI2MAN) | |
d52c454a | 389 | |
e0f3728d PM |
390 | # Support for building multiple output files by atomically executing |
391 | # a single rule which depends on several input files (so the rule | |
392 | # will be executed exactly once, not once per output file, and | |
393 | # not multiple times in parallel.) For more explanation see: | |
394 | # https://www.cmcrossroads.com/article/atomic-rules-gnu-make | |
395 | ||
396 | # Given a space-separated list of filenames, create the name of | |
397 | # a 'sentinel' file to use to indicate that they have been built. | |
398 | # We use fixed text on the end to avoid accidentally triggering | |
399 | # automatic pattern rules, and . on the start to make the file | |
400 | # not show up in ls output. | |
401 | sentinel = .$(subst $(SPACE),_,$(subst /,_,$1)).sentinel. | |
402 | ||
403 | # Define an atomic rule that builds multiple outputs from multiple inputs. | |
404 | # To use: | |
405 | # $(call atomic,out1 out2 ...,in1 in2 ...) | |
406 | # <TAB>rule to do the operation | |
407 | # | |
408 | # Make 4.3 will have native support for this, and you would be able | |
409 | # to instead write: | |
410 | # out1 out2 ... &: in1 in2 ... | |
411 | # <TAB>rule to do the operation | |
412 | # | |
413 | # The way this works is that it creates a make rule | |
414 | # "out1 out2 ... : sentinel-file ; @:" which says that the sentinel | |
415 | # depends on the dependencies, and the rule to do that is "do nothing". | |
416 | # Then we have a rule | |
417 | # "sentinel-file : in1 in2 ..." | |
418 | # whose commands start with "touch sentinel-file" and then continue | |
419 | # with the rule text provided by the user of this 'atomic' function. | |
420 | # The foreach... is there to delete the sentinel file if any of the | |
421 | # output files don't exist, so that we correctly rebuild in that situation. | |
422 | atomic = $(eval $1: $(call sentinel,$1) ; @:) \ | |
423 | $(call sentinel,$1) : $2 ; @touch $$@ \ | |
424 | $(foreach t,$1,$(if $(wildcard $t),,$(shell rm -f $(call sentinel,$1)))) | |
1a28f878 PMD |
425 | |
426 | print-%: | |
427 | @echo '$*=$($*)' |