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