xref: /openbmc/qemu/Makefile (revision 86044b24)
1# Makefile for QEMU.
2
3ifneq ($(words $(subst :, ,$(CURDIR))), 1)
4  $(error main directory cannot contain spaces nor colons)
5endif
6
7# Always point to the root of the build tree (needs GNU make).
8BUILD_DIR=$(CURDIR)
9
10# Before including a proper config-host.mak, assume we are in the source tree
11SRC_PATH=.
12
13UNCHECKED_GOALS := %clean TAGS cscope ctags dist \
14    html info pdf txt \
15    help check-help print-% \
16    docker docker-% vm-help vm-test vm-build-%
17
18print-%:
19	@echo '$*=$($*)'
20
21# All following code might depend on configuration variables
22ifneq ($(wildcard config-host.mak),)
23# Put the all: rule here so that config-host.mak can contain dependencies.
24all:
25include config-host.mak
26
27git-submodule-update:
28
29.PHONY: git-submodule-update
30
31git_module_status := $(shell \
32  cd '$(SRC_PATH)' && \
33  GIT="$(GIT)" ./scripts/git-submodule.sh status $(GIT_SUBMODULES); \
34  echo $$?; \
35)
36
37ifeq (1,$(git_module_status))
38ifeq (no,$(GIT_UPDATE))
39git-submodule-update:
40	$(call quiet-command, \
41            echo && \
42            echo "GIT submodule checkout is out of date. Please run" && \
43            echo "  scripts/git-submodule.sh update $(GIT_SUBMODULES)" && \
44            echo "from the source directory checkout $(SRC_PATH)" && \
45            echo && \
46            exit 1)
47else
48git-submodule-update:
49	$(call quiet-command, \
50          (cd $(SRC_PATH) && GIT="$(GIT)" ./scripts/git-submodule.sh update $(GIT_SUBMODULES)), \
51          "GIT","$(GIT_SUBMODULES)")
52endif
53endif
54
55.git-submodule-status: git-submodule-update config-host.mak
56
57# Check that we're not trying to do an out-of-tree build from
58# a tree that's been used for an in-tree build.
59ifneq ($(realpath $(SRC_PATH)),$(realpath .))
60ifneq ($(wildcard $(SRC_PATH)/config-host.mak),)
61$(error This is an out of tree build but your source tree ($(SRC_PATH)) \
62seems to have been used for an in-tree build. You can fix this by running \
63"$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source tree)
64endif
65endif
66
67CONFIG_SOFTMMU := $(if $(filter %-softmmu,$(TARGET_DIRS)),y)
68CONFIG_USER_ONLY := $(if $(filter %-user,$(TARGET_DIRS)),y)
69CONFIG_XEN := $(CONFIG_XEN_BACKEND)
70CONFIG_ALL=y
71-include config-all-devices.mak
72-include config-all-disas.mak
73
74config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
75	@echo $@ is out-of-date, running configure
76	@./config.status
77else
78config-host.mak:
79ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
80	@echo "Please call configure before running make!"
81	@exit 1
82endif
83endif
84
85include $(SRC_PATH)/rules.mak
86
87# lor is defined in rules.mak
88CONFIG_BLOCK := $(call lor,$(CONFIG_SOFTMMU),$(CONFIG_TOOLS))
89
90# Create QEMU_PKGVERSION and FULL_VERSION strings
91# If PKGVERSION is set, use that; otherwise get version and -dirty status from git
92QEMU_PKGVERSION := $(if $(PKGVERSION),$(PKGVERSION),$(shell \
93  cd $(SRC_PATH); \
94  if test -e .git; then \
95    git describe --match 'v*' 2>/dev/null | tr -d '\n'; \
96    if ! git diff-index --quiet HEAD &>/dev/null; then \
97      echo "-dirty"; \
98    fi; \
99  fi))
100
101# Either "version (pkgversion)", or just "version" if pkgversion not set
102FULL_VERSION := $(if $(QEMU_PKGVERSION),$(VERSION) ($(QEMU_PKGVERSION)),$(VERSION))
103
104generated-files-y = qemu-version.h config-host.h qemu-options.def
105
106GENERATED_QAPI_FILES = qapi/qapi-builtin-types.h qapi/qapi-builtin-types.c
107GENERATED_QAPI_FILES += qapi/qapi-types.h qapi/qapi-types.c
108GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-types-%.h)
109GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-types-%.c)
110GENERATED_QAPI_FILES += qapi/qapi-builtin-visit.h qapi/qapi-builtin-visit.c
111GENERATED_QAPI_FILES += qapi/qapi-visit.h qapi/qapi-visit.c
112GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-visit-%.h)
113GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-visit-%.c)
114GENERATED_QAPI_FILES += qapi/qapi-commands.h qapi/qapi-commands.c
115GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-commands-%.h)
116GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-commands-%.c)
117GENERATED_QAPI_FILES += qapi/qapi-emit-events.h qapi/qapi-emit-events.c
118GENERATED_QAPI_FILES += qapi/qapi-events.h qapi/qapi-events.c
119GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-events-%.h)
120GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-events-%.c)
121GENERATED_QAPI_FILES += qapi/qapi-introspect.c qapi/qapi-introspect.h
122GENERATED_QAPI_FILES += qapi/qapi-doc.texi
123
124generated-files-y += $(GENERATED_QAPI_FILES)
125
126generated-files-y += trace/generated-tcg-tracers.h
127
128generated-files-y += trace/generated-helpers-wrappers.h
129generated-files-y += trace/generated-helpers.h
130generated-files-y += trace/generated-helpers.c
131
132generated-files-$(CONFIG_TRACE_UST) += trace-ust-all.h
133generated-files-$(CONFIG_TRACE_UST) += trace-ust-all.c
134
135generated-files-y += module_block.h
136
137TRACE_HEADERS = trace-root.h $(trace-events-subdirs:%=%/trace.h)
138TRACE_SOURCES = trace-root.c $(trace-events-subdirs:%=%/trace.c)
139TRACE_DTRACE =
140ifdef CONFIG_TRACE_DTRACE
141TRACE_HEADERS += trace-dtrace-root.h $(trace-events-subdirs:%=%/trace-dtrace.h)
142TRACE_DTRACE += trace-dtrace-root.dtrace $(trace-events-subdirs:%=%/trace-dtrace.dtrace)
143endif
144ifdef CONFIG_TRACE_UST
145TRACE_HEADERS += trace-ust-root.h $(trace-events-subdirs:%=%/trace-ust.h)
146endif
147
148generated-files-y += $(TRACE_HEADERS)
149generated-files-y += $(TRACE_SOURCES)
150generated-files-y += $(BUILD_DIR)/trace-events-all
151generated-files-y += .git-submodule-status
152
153trace-group-name = $(shell dirname $1 | sed -e 's/[^a-zA-Z0-9]/_/g')
154
155tracetool-y = $(SRC_PATH)/scripts/tracetool.py
156tracetool-y += $(shell find $(SRC_PATH)/scripts/tracetool -name "*.py")
157
158%/trace.h: %/trace.h-timestamp
159	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
160%/trace.h-timestamp: $(SRC_PATH)/%/trace-events $(tracetool-y) $(BUILD_DIR)/config-host.mak
161	$(call quiet-command,$(TRACETOOL) \
162		--group=$(call trace-group-name,$@) \
163		--format=h \
164		--backends=$(TRACE_BACKENDS) \
165		$< > $@,"GEN","$(@:%-timestamp=%)")
166
167%/trace.c: %/trace.c-timestamp
168	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
169%/trace.c-timestamp: $(SRC_PATH)/%/trace-events $(tracetool-y) $(BUILD_DIR)/config-host.mak
170	$(call quiet-command,$(TRACETOOL) \
171		--group=$(call trace-group-name,$@) \
172		--format=c \
173		--backends=$(TRACE_BACKENDS) \
174		$< > $@,"GEN","$(@:%-timestamp=%)")
175
176%/trace-ust.h: %/trace-ust.h-timestamp
177	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
178%/trace-ust.h-timestamp: $(SRC_PATH)/%/trace-events $(tracetool-y) $(BUILD_DIR)/config-host.mak
179	$(call quiet-command,$(TRACETOOL) \
180		--group=$(call trace-group-name,$@) \
181		--format=ust-events-h \
182		--backends=$(TRACE_BACKENDS) \
183		$< > $@,"GEN","$(@:%-timestamp=%)")
184
185%/trace-dtrace.dtrace: %/trace-dtrace.dtrace-timestamp
186	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
187%/trace-dtrace.dtrace-timestamp: $(SRC_PATH)/%/trace-events $(BUILD_DIR)/config-host.mak $(tracetool-y)
188	$(call quiet-command,$(TRACETOOL) \
189		--group=$(call trace-group-name,$@) \
190		--format=d \
191		--backends=$(TRACE_BACKENDS) \
192		$< > $@,"GEN","$(@:%-timestamp=%)")
193
194%/trace-dtrace.h: %/trace-dtrace.dtrace $(tracetool-y)
195	$(call quiet-command,dtrace -o $@ -h -s $<, "GEN","$@")
196
197%/trace-dtrace.o: %/trace-dtrace.dtrace $(tracetool-y)
198
199
200trace-root.h: trace-root.h-timestamp
201	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
202trace-root.h-timestamp: $(SRC_PATH)/trace-events $(tracetool-y) $(BUILD_DIR)/config-host.mak
203	$(call quiet-command,$(TRACETOOL) \
204		--group=root \
205		--format=h \
206		--backends=$(TRACE_BACKENDS) \
207		$< > $@,"GEN","$(@:%-timestamp=%)")
208
209trace-root.c: trace-root.c-timestamp
210	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
211trace-root.c-timestamp: $(SRC_PATH)/trace-events $(tracetool-y) $(BUILD_DIR)/config-host.mak
212	$(call quiet-command,$(TRACETOOL) \
213		--group=root \
214		--format=c \
215		--backends=$(TRACE_BACKENDS) \
216		$< > $@,"GEN","$(@:%-timestamp=%)")
217
218trace-ust-root.h: trace-ust-root.h-timestamp
219	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
220trace-ust-root.h-timestamp: $(SRC_PATH)/trace-events $(tracetool-y) $(BUILD_DIR)/config-host.mak
221	$(call quiet-command,$(TRACETOOL) \
222		--group=root \
223		--format=ust-events-h \
224		--backends=$(TRACE_BACKENDS) \
225		$< > $@,"GEN","$(@:%-timestamp=%)")
226
227trace-ust-all.h: trace-ust-all.h-timestamp
228	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
229trace-ust-all.h-timestamp: $(trace-events-files) $(tracetool-y) $(BUILD_DIR)/config-host.mak
230	$(call quiet-command,$(TRACETOOL) \
231		--group=all \
232		--format=ust-events-h \
233		--backends=$(TRACE_BACKENDS) \
234		$(trace-events-files) > $@,"GEN","$(@:%-timestamp=%)")
235
236trace-ust-all.c: trace-ust-all.c-timestamp
237	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
238trace-ust-all.c-timestamp: $(trace-events-files) $(tracetool-y) $(BUILD_DIR)/config-host.mak
239	$(call quiet-command,$(TRACETOOL) \
240		--group=all \
241		--format=ust-events-c \
242		--backends=$(TRACE_BACKENDS) \
243		$(trace-events-files) > $@,"GEN","$(@:%-timestamp=%)")
244
245trace-dtrace-root.dtrace: trace-dtrace-root.dtrace-timestamp
246	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
247trace-dtrace-root.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak $(tracetool-y)
248	$(call quiet-command,$(TRACETOOL) \
249		--group=root \
250		--format=d \
251		--backends=$(TRACE_BACKENDS) \
252		$< > $@,"GEN","$(@:%-timestamp=%)")
253
254trace-dtrace-root.h: trace-dtrace-root.dtrace
255	$(call quiet-command,dtrace -o $@ -h -s $<, "GEN","$@")
256
257trace-dtrace-root.o: trace-dtrace-root.dtrace
258
259KEYCODEMAP_GEN = $(SRC_PATH)/ui/keycodemapdb/tools/keymap-gen
260KEYCODEMAP_CSV = $(SRC_PATH)/ui/keycodemapdb/data/keymaps.csv
261
262KEYCODEMAP_FILES = \
263		 ui/input-keymap-atset1-to-qcode.c \
264		 ui/input-keymap-linux-to-qcode.c \
265		 ui/input-keymap-qcode-to-atset1.c \
266		 ui/input-keymap-qcode-to-atset2.c \
267		 ui/input-keymap-qcode-to-atset3.c \
268		 ui/input-keymap-qcode-to-linux.c \
269		 ui/input-keymap-qcode-to-qnum.c \
270		 ui/input-keymap-qcode-to-sun.c \
271		 ui/input-keymap-qnum-to-qcode.c \
272		 ui/input-keymap-usb-to-qcode.c \
273		 ui/input-keymap-win32-to-qcode.c \
274		 ui/input-keymap-x11-to-qcode.c \
275		 ui/input-keymap-xorgevdev-to-qcode.c \
276		 ui/input-keymap-xorgkbd-to-qcode.c \
277		 ui/input-keymap-xorgxquartz-to-qcode.c \
278		 ui/input-keymap-xorgxwin-to-qcode.c \
279		 ui/input-keymap-osx-to-qcode.c \
280		 $(NULL)
281
282generated-files-$(CONFIG_SOFTMMU) += $(KEYCODEMAP_FILES)
283
284ui/input-keymap-%.c: $(KEYCODEMAP_GEN) $(KEYCODEMAP_CSV) $(SRC_PATH)/ui/Makefile.objs
285	$(call quiet-command,\
286	    stem=$* && src=$${stem%-to-*} dst=$${stem#*-to-} && \
287	    test -e $(KEYCODEMAP_GEN) && \
288	    $(PYTHON) $(KEYCODEMAP_GEN) \
289	          --lang glib2 \
290	          --varname qemu_input_map_$${src}_to_$${dst} \
291	          code-map $(KEYCODEMAP_CSV) $${src} $${dst} \
292	        > $@ || rm -f $@, "GEN", "$@")
293
294$(KEYCODEMAP_GEN): .git-submodule-status
295$(KEYCODEMAP_CSV): .git-submodule-status
296
297edk2-decompressed = $(basename $(wildcard pc-bios/edk2-*.fd.bz2))
298pc-bios/edk2-%.fd: pc-bios/edk2-%.fd.bz2
299	$(call quiet-command,bzip2 -d -c $< > $@,"BUNZIP2",$<)
300
301# Don't try to regenerate Makefile or configure
302# We don't generate any of them
303Makefile: ;
304configure: ;
305
306.PHONY: all clean cscope distclean html info install install-doc \
307	pdf txt recurse-all dist msi FORCE
308
309$(call set-vpath, $(SRC_PATH))
310
311LIBS+=-lz $(LIBS_TOOLS)
312
313vhost-user-json-y =
314HELPERS-y =
315
316HELPERS-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_LINUX)) = qemu-bridge-helper$(EXESUF)
317
318ifdef CONFIG_LINUX
319ifdef CONFIG_VIRGL
320ifdef CONFIG_GBM
321HELPERS-y += vhost-user-gpu$(EXESUF)
322vhost-user-json-y += contrib/vhost-user-gpu/50-qemu-gpu.json
323endif
324endif
325endif
326
327# Sphinx does not allow building manuals into the same directory as
328# the source files, so if we're doing an in-tree QEMU build we must
329# build the manuals into a subdirectory (and then install them from
330# there for 'make install'). For an out-of-tree build we can just
331# use the docs/ subdirectory in the build tree as normal.
332ifeq ($(realpath $(SRC_PATH)),$(realpath .))
333MANUAL_BUILDDIR := docs/built
334else
335MANUAL_BUILDDIR := docs
336endif
337
338ifdef BUILD_DOCS
339DOCS=qemu-doc.html qemu-doc.txt qemu.1 qemu-img.1 qemu-nbd.8 $(MANUAL_BUILDDIR)/interop/qemu-ga.8
340DOCS+=docs/interop/qemu-qmp-ref.html docs/interop/qemu-qmp-ref.txt docs/interop/qemu-qmp-ref.7
341DOCS+=docs/interop/qemu-ga-ref.html docs/interop/qemu-ga-ref.txt docs/interop/qemu-ga-ref.7
342DOCS+=docs/qemu-block-drivers.7
343DOCS+=docs/qemu-cpu-models.7
344ifdef CONFIG_VIRTFS
345DOCS+=fsdev/virtfs-proxy-helper.1
346endif
347ifdef CONFIG_TRACE_SYSTEMTAP
348DOCS+=scripts/qemu-trace-stap.1
349endif
350else
351DOCS=
352endif
353
354SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet) BUILD_DIR=$(BUILD_DIR)
355SUBDIR_DEVICES_MAK=$(patsubst %, %/config-devices.mak, $(filter %-softmmu, $(TARGET_DIRS)))
356SUBDIR_DEVICES_MAK_DEP=$(patsubst %, %.d, $(SUBDIR_DEVICES_MAK))
357
358ifeq ($(SUBDIR_DEVICES_MAK),)
359config-all-devices.mak: config-host.mak
360	$(call quiet-command,echo '# no devices' > $@,"GEN","$@")
361else
362config-all-devices.mak: $(SUBDIR_DEVICES_MAK) config-host.mak
363	$(call quiet-command, sed -n \
364             's|^\([^=]*\)=\(.*\)$$|\1:=$$(findstring y,$$(\1)\2)|p' \
365             $(SUBDIR_DEVICES_MAK) | sort -u > $@, \
366             "GEN","$@")
367endif
368
369-include $(SUBDIR_DEVICES_MAK_DEP)
370
371# This has to be kept in sync with Kconfig.host.
372MINIKCONF_ARGS = \
373    $(CONFIG_MINIKCONF_MODE) \
374    $@ $*/config-devices.mak.d $< $(MINIKCONF_INPUTS) \
375    CONFIG_KVM=$(CONFIG_KVM) \
376    CONFIG_SPICE=$(CONFIG_SPICE) \
377    CONFIG_IVSHMEM=$(CONFIG_IVSHMEM) \
378    CONFIG_TPM=$(CONFIG_TPM) \
379    CONFIG_XEN=$(CONFIG_XEN) \
380    CONFIG_OPENGL=$(CONFIG_OPENGL) \
381    CONFIG_X11=$(CONFIG_X11) \
382    CONFIG_VHOST_USER=$(CONFIG_VHOST_USER) \
383    CONFIG_VIRTFS=$(CONFIG_VIRTFS) \
384    CONFIG_LINUX=$(CONFIG_LINUX) \
385    CONFIG_PVRDMA=$(CONFIG_PVRDMA)
386
387MINIKCONF_INPUTS = $(SRC_PATH)/Kconfig.host $(SRC_PATH)/hw/Kconfig
388MINIKCONF = $(PYTHON) $(SRC_PATH)/scripts/minikconf.py \
389
390$(SUBDIR_DEVICES_MAK): %/config-devices.mak: default-configs/%.mak $(MINIKCONF_INPUTS) $(BUILD_DIR)/config-host.mak
391	$(call quiet-command, $(MINIKCONF) $(MINIKCONF_ARGS) > $@.tmp, "GEN", "$@.tmp")
392	$(call quiet-command, if test -f $@; then \
393	  if cmp -s $@.old $@; then \
394	    mv $@.tmp $@; \
395	    cp -p $@ $@.old; \
396	  else \
397	    if test -f $@.old; then \
398	      echo "WARNING: $@ (user modified) out of date.";\
399	    else \
400	      echo "WARNING: $@ out of date.";\
401	    fi; \
402	    echo "Run \"$(MAKE) defconfig\" to regenerate."; \
403	    rm $@.tmp; \
404	  fi; \
405	 else \
406	  mv $@.tmp $@; \
407	  cp -p $@ $@.old; \
408	 fi,"GEN","$@");
409
410defconfig:
411	rm -f config-all-devices.mak $(SUBDIR_DEVICES_MAK)
412
413ifneq ($(wildcard config-host.mak),)
414include $(SRC_PATH)/Makefile.objs
415endif
416
417dummy := $(call unnest-vars,, \
418                stub-obj-y \
419                authz-obj-y \
420                chardev-obj-y \
421                util-obj-y \
422                qga-obj-y \
423                elf2dmp-obj-y \
424                ivshmem-client-obj-y \
425                ivshmem-server-obj-y \
426                rdmacm-mux-obj-y \
427                libvhost-user-obj-y \
428                vhost-user-scsi-obj-y \
429                vhost-user-blk-obj-y \
430                vhost-user-input-obj-y \
431                vhost-user-gpu-obj-y \
432                qga-vss-dll-obj-y \
433                block-obj-y \
434                block-obj-m \
435                crypto-obj-y \
436                crypto-user-obj-y \
437                qom-obj-y \
438                io-obj-y \
439                common-obj-y \
440                common-obj-m \
441                ui-obj-y \
442                ui-obj-m \
443                audio-obj-y \
444                audio-obj-m \
445                trace-obj-y)
446
447include $(SRC_PATH)/tests/Makefile.include
448
449all: $(DOCS) $(if $(BUILD_DOCS),sphinxdocs) $(TOOLS) $(HELPERS-y) recurse-all modules $(vhost-user-json-y)
450
451qemu-version.h: FORCE
452	$(call quiet-command, \
453                (printf '#define QEMU_PKGVERSION "$(QEMU_PKGVERSION)"\n'; \
454		printf '#define QEMU_FULL_VERSION "$(FULL_VERSION)"\n'; \
455		) > $@.tmp)
456	$(call quiet-command, if ! cmp -s $@ $@.tmp; then \
457	  mv $@.tmp $@; \
458	 else \
459	  rm $@.tmp; \
460	 fi)
461
462config-host.h: config-host.h-timestamp
463config-host.h-timestamp: config-host.mak
464qemu-options.def: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool
465	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$@")
466
467TARGET_DIRS_RULES := $(foreach t, all clean install, $(addsuffix /$(t), $(TARGET_DIRS)))
468
469SOFTMMU_ALL_RULES=$(filter %-softmmu/all, $(TARGET_DIRS_RULES))
470$(SOFTMMU_ALL_RULES): $(authz-obj-y)
471$(SOFTMMU_ALL_RULES): $(block-obj-y)
472$(SOFTMMU_ALL_RULES): $(chardev-obj-y)
473$(SOFTMMU_ALL_RULES): $(crypto-obj-y)
474$(SOFTMMU_ALL_RULES): $(io-obj-y)
475$(SOFTMMU_ALL_RULES): config-all-devices.mak
476$(SOFTMMU_ALL_RULES): $(edk2-decompressed)
477
478.PHONY: $(TARGET_DIRS_RULES)
479# The $(TARGET_DIRS_RULES) are of the form SUBDIR/GOAL, so that
480# $(dir $@) yields the sub-directory, and $(notdir $@) yields the sub-goal
481$(TARGET_DIRS_RULES):
482	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" $(notdir $@),)
483
484DTC_MAKE_ARGS=-I$(SRC_PATH)/dtc VPATH=$(SRC_PATH)/dtc -C dtc V="$(V)" LIBFDT_srcdir=$(SRC_PATH)/dtc/libfdt
485DTC_CFLAGS=$(CFLAGS) $(QEMU_CFLAGS)
486DTC_CPPFLAGS=-I$(BUILD_DIR)/dtc -I$(SRC_PATH)/dtc -I$(SRC_PATH)/dtc/libfdt
487
488.PHONY: dtc/all
489dtc/all: .git-submodule-status dtc/libfdt dtc/tests
490	$(call quiet-command,$(MAKE) $(DTC_MAKE_ARGS) CPPFLAGS="$(DTC_CPPFLAGS)" CFLAGS="$(DTC_CFLAGS)" LDFLAGS="$(LDFLAGS)" ARFLAGS="$(ARFLAGS)" CC="$(CC)" AR="$(AR)" LD="$(LD)" $(SUBDIR_MAKEFLAGS) libfdt/libfdt.a,)
491
492dtc/%: .git-submodule-status
493	@mkdir -p $@
494
495# Overriding CFLAGS causes us to lose defines added in the sub-makefile.
496# Not overriding CFLAGS leads to mis-matches between compilation modes.
497# Therefore we replicate some of the logic in the sub-makefile.
498# Remove all the extra -Warning flags that QEMU uses that Capstone doesn't;
499# no need to annoy QEMU developers with such things.
500CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS))
501CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM
502CAP_CFLAGS += -DCAPSTONE_HAS_ARM
503CAP_CFLAGS += -DCAPSTONE_HAS_ARM64
504CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC
505CAP_CFLAGS += -DCAPSTONE_HAS_X86
506
507.PHONY: capstone/all
508capstone/all: .git-submodule-status
509	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS) $(BUILD_DIR)/capstone/$(LIBCAPSTONE))
510
511.PHONY: slirp/all
512slirp/all: .git-submodule-status
513	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp		\
514		BUILD_DIR="$(BUILD_DIR)/slirp" 			\
515		PKG_CONFIG="$(PKG_CONFIG)" 				\
516		CC="$(CC)" AR="$(AR)" 	LD="$(LD)" RANLIB="$(RANLIB)"	\
517		CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(LDFLAGS)")
518
519# Compatibility gunk to keep make working across the rename of targets
520# for recursion, to be removed some time after 4.1.
521subdir-dtc: dtc/all
522subdir-capstone: capstone/all
523subdir-slirp: slirp/all
524
525$(filter %/all, $(TARGET_DIRS_RULES)): libqemuutil.a $(common-obj-y) \
526	$(qom-obj-y) $(crypto-user-obj-$(CONFIG_USER_ONLY))
527
528ROM_DIRS = $(addprefix pc-bios/, $(ROMS))
529ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS)))
530# Only keep -O and -g cflags
531.PHONY: $(ROM_DIRS_RULES)
532$(ROM_DIRS_RULES):
533	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" CFLAGS="$(filter -O% -g%,$(CFLAGS))" $(notdir $@),)
534
535.PHONY: recurse-all recurse-clean recurse-install
536recurse-all: $(addsuffix /all, $(TARGET_DIRS) $(ROM_DIRS))
537recurse-clean: $(addsuffix /clean, $(TARGET_DIRS) $(ROM_DIRS))
538recurse-install: $(addsuffix /install, $(TARGET_DIRS))
539$(addsuffix /install, $(TARGET_DIRS)): all
540
541$(BUILD_DIR)/version.o: $(SRC_PATH)/version.rc config-host.h
542	$(call quiet-command,$(WINDRES) -I$(BUILD_DIR) -o $@ $<,"RC","version.o")
543
544Makefile: $(version-obj-y)
545
546######################################################################
547# Build libraries
548
549libqemuutil.a: $(util-obj-y) $(trace-obj-y) $(stub-obj-y)
550libvhost-user.a: $(libvhost-user-obj-y) $(util-obj-y) $(stub-obj-y)
551
552######################################################################
553
554COMMON_LDADDS = libqemuutil.a
555
556qemu-img.o: qemu-img-cmds.h
557
558qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
559qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
560qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
561
562qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS)
563
564qemu-keymap$(EXESUF): qemu-keymap.o ui/input-keymap.o $(COMMON_LDADDS)
565
566qemu-edid$(EXESUF): qemu-edid.o hw/display/edid-generate.o $(COMMON_LDADDS)
567
568fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS)
569fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap
570
571scsi/qemu-pr-helper$(EXESUF): scsi/qemu-pr-helper.o scsi/utils.o $(authz-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
572ifdef CONFIG_MPATH
573scsi/qemu-pr-helper$(EXESUF): LIBS += -ludev -lmultipath -lmpathpersist
574endif
575
576qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool
577	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$@")
578
579qemu-ga$(EXESUF): LIBS = $(LIBS_QGA)
580qemu-ga$(EXESUF): QEMU_CFLAGS += -I qga/qapi-generated
581
582qemu-keymap$(EXESUF): LIBS += $(XKBCOMMON_LIBS)
583qemu-keymap$(EXESUF): QEMU_CFLAGS += $(XKBCOMMON_CFLAGS)
584
585qapi-py = $(SRC_PATH)/scripts/qapi/__init__.py \
586$(SRC_PATH)/scripts/qapi/commands.py \
587$(SRC_PATH)/scripts/qapi/common.py \
588$(SRC_PATH)/scripts/qapi/doc.py \
589$(SRC_PATH)/scripts/qapi/error.py \
590$(SRC_PATH)/scripts/qapi/events.py \
591$(SRC_PATH)/scripts/qapi/expr.py \
592$(SRC_PATH)/scripts/qapi/gen.py \
593$(SRC_PATH)/scripts/qapi/introspect.py \
594$(SRC_PATH)/scripts/qapi/parser.py \
595$(SRC_PATH)/scripts/qapi/schema.py \
596$(SRC_PATH)/scripts/qapi/source.py \
597$(SRC_PATH)/scripts/qapi/types.py \
598$(SRC_PATH)/scripts/qapi/visit.py \
599$(SRC_PATH)/scripts/qapi-gen.py
600
601qga/qapi-generated/qga-qapi-types.c qga/qapi-generated/qga-qapi-types.h \
602qga/qapi-generated/qga-qapi-visit.c qga/qapi-generated/qga-qapi-visit.h \
603qga/qapi-generated/qga-qapi-commands.h qga/qapi-generated/qga-qapi-commands.c \
604qga/qapi-generated/qga-qapi-doc.texi: \
605qga/qapi-generated/qapi-gen-timestamp ;
606qga/qapi-generated/qapi-gen-timestamp: $(SRC_PATH)/qga/qapi-schema.json $(qapi-py)
607	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-gen.py \
608		-o qga/qapi-generated -p "qga-" $<, \
609		"GEN","$(@:%-timestamp=%)")
610	@>$@
611
612qapi-modules = $(SRC_PATH)/qapi/qapi-schema.json \
613               $(QAPI_MODULES:%=$(SRC_PATH)/qapi/%.json)
614
615$(GENERATED_QAPI_FILES): qapi-gen-timestamp ;
616qapi-gen-timestamp: $(qapi-modules) $(qapi-py)
617	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-gen.py \
618		-o "qapi" -b $<, \
619		"GEN","$(@:%-timestamp=%)")
620	@>$@
621
622QGALIB_GEN=$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-visit.h qga-qapi-commands.h)
623$(qga-obj-y): $(QGALIB_GEN)
624
625qemu-ga$(EXESUF): $(qga-obj-y) $(COMMON_LDADDS)
626	$(call LINK, $^)
627
628ifdef QEMU_GA_MSI_ENABLED
629QEMU_GA_MSI=qemu-ga-$(ARCH).msi
630
631msi: $(QEMU_GA_MSI)
632
633$(QEMU_GA_MSI): qemu-ga.exe $(QGA_VSS_PROVIDER)
634
635$(QEMU_GA_MSI): config-host.mak
636
637$(QEMU_GA_MSI):  $(SRC_PATH)/qga/installer/qemu-ga.wxs
638	$(call quiet-command,QEMU_GA_VERSION="$(QEMU_GA_VERSION)" QEMU_GA_MANUFACTURER="$(QEMU_GA_MANUFACTURER)" QEMU_GA_DISTRO="$(QEMU_GA_DISTRO)" BUILD_DIR="$(BUILD_DIR)" \
639	wixl -o $@ $(QEMU_GA_MSI_ARCH) $(QEMU_GA_MSI_WITH_VSS) $(QEMU_GA_MSI_MINGW_DLL_PATH) $<,"WIXL","$@")
640else
641msi:
642	@echo "MSI build not configured or dependency resolution failed (reconfigure with --enable-guest-agent-msi option)"
643endif
644
645ifneq ($(EXESUF),)
646.PHONY: qemu-ga
647qemu-ga: qemu-ga$(EXESUF) $(QGA_VSS_PROVIDER) $(QEMU_GA_MSI)
648endif
649
650elf2dmp$(EXESUF): $(elf2dmp-obj-y)
651	$(call LINK, $^)
652
653ifdef CONFIG_IVSHMEM
654ivshmem-client$(EXESUF): $(ivshmem-client-obj-y) $(COMMON_LDADDS)
655	$(call LINK, $^)
656ivshmem-server$(EXESUF): $(ivshmem-server-obj-y) $(COMMON_LDADDS)
657	$(call LINK, $^)
658endif
659vhost-user-scsi$(EXESUF): $(vhost-user-scsi-obj-y) libvhost-user.a
660	$(call LINK, $^)
661vhost-user-blk$(EXESUF): $(vhost-user-blk-obj-y) libvhost-user.a
662	$(call LINK, $^)
663
664rdmacm-mux$(EXESUF): LIBS += "-libumad"
665rdmacm-mux$(EXESUF): $(rdmacm-mux-obj-y) $(COMMON_LDADDS)
666	$(call LINK, $^)
667
668vhost-user-gpu$(EXESUF): $(vhost-user-gpu-obj-y) $(libvhost-user-obj-y) libqemuutil.a libqemustub.a
669	$(call LINK, $^)
670
671ifdef CONFIG_VHOST_USER_INPUT
672ifdef CONFIG_LINUX
673vhost-user-input$(EXESUF): $(vhost-user-input-obj-y) libvhost-user.a libqemuutil.a
674	$(call LINK, $^)
675
676# build by default, do not install
677all: vhost-user-input$(EXESUF)
678endif
679endif
680
681module_block.h: $(SRC_PATH)/scripts/modules/module_block.py config-host.mak
682	$(call quiet-command,$(PYTHON) $< $@ \
683	$(addprefix $(SRC_PATH)/,$(patsubst %.mo,%.c,$(block-obj-m))), \
684	"GEN","$@")
685
686ifdef CONFIG_GCOV
687.PHONY: clean-coverage
688clean-coverage:
689	$(call quiet-command, \
690		find . \( -name '*.gcda' -o -name '*.gcov' \) -type f -exec rm {} +, \
691		"CLEAN", "coverage files")
692endif
693
694clean: recurse-clean
695# avoid old build problems by removing potentially incorrect old files
696	rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
697	rm -f qemu-options.def
698	rm -f *.msi
699	find . \( -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name '*.[oda]' \) -type f \
700		! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \
701		! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \
702		! -path ./roms/edk2/BaseTools/Source/Python/UPT/Dll/sqlite3.dll \
703		-exec rm {} +
704	rm -f $(edk2-decompressed)
705	rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) TAGS cscope.* *.pod *~ */*~
706	rm -f fsdev/*.pod scsi/*.pod
707	rm -f qemu-img-cmds.h
708	rm -f ui/shader/*-vert.h ui/shader/*-frag.h
709	@# May not be present in generated-files-y
710	rm -f trace/generated-tracers-dtrace.dtrace*
711	rm -f trace/generated-tracers-dtrace.h*
712	rm -f $(foreach f,$(generated-files-y),$(f) $(f)-timestamp)
713	rm -f qapi-gen-timestamp
714	rm -rf qga/qapi-generated
715	rm -f config-all-devices.mak
716
717VERSION ?= $(shell cat VERSION)
718
719dist: qemu-$(VERSION).tar.bz2
720
721qemu-%.tar.bz2:
722	$(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)"
723
724define clean-manual =
725rm -rf $(MANUAL_BUILDDIR)/$1/_static
726rm -f $(MANUAL_BUILDDIR)/$1/objects.inv $(MANUAL_BUILDDIR)/$1/searchindex.js $(MANUAL_BUILDDIR)/$1/*.html
727endef
728
729distclean: clean
730	rm -f config-host.mak config-host.h* config-host.ld $(DOCS) qemu-options.texi qemu-img-cmds.texi qemu-monitor.texi qemu-monitor-info.texi
731	rm -f tests/tcg/config-*.mak
732	rm -f config-all-devices.mak config-all-disas.mak config.status
733	rm -f $(SUBDIR_DEVICES_MAK)
734	rm -f po/*.mo tests/qemu-iotests/common.env
735	rm -f roms/seabios/config.mak roms/vgabios/config.mak
736	rm -f qemu-doc.info qemu-doc.aux qemu-doc.cp qemu-doc.cps
737	rm -f qemu-doc.fn qemu-doc.fns qemu-doc.info qemu-doc.ky qemu-doc.kys
738	rm -f qemu-doc.log qemu-doc.pdf qemu-doc.pg qemu-doc.toc qemu-doc.tp
739	rm -f qemu-doc.vr qemu-doc.txt
740	rm -f config.log
741	rm -f linux-headers/asm
742	rm -f docs/version.texi
743	rm -f docs/interop/qemu-ga-qapi.texi docs/interop/qemu-qmp-qapi.texi
744	rm -f docs/interop/qemu-qmp-ref.7 docs/interop/qemu-ga-ref.7
745	rm -f docs/interop/qemu-qmp-ref.txt docs/interop/qemu-ga-ref.txt
746	rm -f docs/interop/qemu-qmp-ref.pdf docs/interop/qemu-ga-ref.pdf
747	rm -f docs/interop/qemu-qmp-ref.html docs/interop/qemu-ga-ref.html
748	rm -f docs/qemu-block-drivers.7
749	rm -f docs/qemu-cpu-models.7
750	rm -rf .doctrees
751	$(call clean-manual,devel)
752	$(call clean-manual,interop)
753	$(call clean-manual,specs)
754	for d in $(TARGET_DIRS); do \
755	rm -rf $$d || exit 1 ; \
756        done
757	rm -Rf .sdk
758	if test -f dtc/version_gen.h; then $(MAKE) $(DTC_MAKE_ARGS) clean; fi
759
760KEYMAPS=da     en-gb  et  fr     fr-ch  is  lt  no  pt-br  sv \
761ar      de     en-us  fi  fr-be  hr     it  lv  nl         pl  ru     th \
762de-ch  es     fo  fr-ca  hu     ja  mk  pt  sl     tr \
763bepo    cz
764
765ifdef INSTALL_BLOBS
766BLOBS=bios.bin bios-256k.bin sgabios.bin vgabios.bin vgabios-cirrus.bin \
767vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin vgabios-virtio.bin \
768vgabios-ramfb.bin vgabios-bochs-display.bin vgabios-ati.bin \
769ppc_rom.bin openbios-sparc32 openbios-sparc64 openbios-ppc QEMU,tcx.bin QEMU,cgthree.bin \
770pxe-e1000.rom pxe-eepro100.rom pxe-ne2k_pci.rom \
771pxe-pcnet.rom pxe-rtl8139.rom pxe-virtio.rom \
772efi-e1000.rom efi-eepro100.rom efi-ne2k_pci.rom \
773efi-pcnet.rom efi-rtl8139.rom efi-virtio.rom \
774efi-e1000e.rom efi-vmxnet3.rom \
775qemu-nsis.bmp \
776bamboo.dtb canyonlands.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \
777multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin \
778s390-ccw.img s390-netboot.img \
779slof.bin skiboot.lid \
780palcode-clipper \
781u-boot.e500 u-boot-sam460-20100605.bin \
782qemu_vga.ndrv \
783edk2-licenses.txt \
784hppa-firmware.img \
785opensbi-riscv32-virt-fw_jump.bin \
786opensbi-riscv64-sifive_u-fw_jump.bin opensbi-riscv64-virt-fw_jump.bin
787
788
789DESCS=50-edk2-i386-secure.json 50-edk2-x86_64-secure.json \
79060-edk2-aarch64.json 60-edk2-arm.json 60-edk2-i386.json 60-edk2-x86_64.json
791else
792BLOBS=
793DESCS=
794endif
795
796# Note that we manually filter-out the non-Sphinx documentation which
797# is currently built into the docs/interop directory in the build tree,
798# and also any sphinx-built manpages.
799define install-manual =
800for d in $$(cd $(MANUAL_BUILDDIR) && find $1 -type d); do $(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)/$$d"; done
801for f in $$(cd $(MANUAL_BUILDDIR) && find $1 -type f -a '!' '(' -name '*.[0-9]' -o -name 'qemu-*-qapi.*' -o -name 'qemu-*-ref.*' ')' ); do $(INSTALL_DATA) "$(MANUAL_BUILDDIR)/$$f" "$(DESTDIR)$(qemu_docdir)/$$f"; done
802endef
803
804# Note that we deliberately do not install the "devel" manual: it is
805# for QEMU developers, and not interesting to our users.
806.PHONY: install-sphinxdocs
807install-sphinxdocs: sphinxdocs
808	$(call install-manual,interop)
809	$(call install-manual,specs)
810
811install-doc: $(DOCS) install-sphinxdocs
812	$(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)"
813	$(INSTALL_DATA) qemu-doc.html "$(DESTDIR)$(qemu_docdir)"
814	$(INSTALL_DATA) qemu-doc.txt "$(DESTDIR)$(qemu_docdir)"
815	$(INSTALL_DATA) docs/interop/qemu-qmp-ref.html "$(DESTDIR)$(qemu_docdir)"
816	$(INSTALL_DATA) docs/interop/qemu-qmp-ref.txt "$(DESTDIR)$(qemu_docdir)"
817ifdef CONFIG_POSIX
818	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1"
819	$(INSTALL_DATA) qemu.1 "$(DESTDIR)$(mandir)/man1"
820	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man7"
821	$(INSTALL_DATA) docs/interop/qemu-qmp-ref.7 "$(DESTDIR)$(mandir)/man7"
822	$(INSTALL_DATA) docs/qemu-block-drivers.7 "$(DESTDIR)$(mandir)/man7"
823	$(INSTALL_DATA) docs/qemu-cpu-models.7 "$(DESTDIR)$(mandir)/man7"
824ifeq ($(CONFIG_TOOLS),y)
825	$(INSTALL_DATA) qemu-img.1 "$(DESTDIR)$(mandir)/man1"
826	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man8"
827	$(INSTALL_DATA) qemu-nbd.8 "$(DESTDIR)$(mandir)/man8"
828endif
829ifdef CONFIG_TRACE_SYSTEMTAP
830	$(INSTALL_DATA) scripts/qemu-trace-stap.1 "$(DESTDIR)$(mandir)/man1"
831endif
832ifneq (,$(findstring qemu-ga,$(TOOLS)))
833	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/interop/qemu-ga.8 "$(DESTDIR)$(mandir)/man8"
834	$(INSTALL_DATA) docs/interop/qemu-ga-ref.html "$(DESTDIR)$(qemu_docdir)"
835	$(INSTALL_DATA) docs/interop/qemu-ga-ref.txt "$(DESTDIR)$(qemu_docdir)"
836	$(INSTALL_DATA) docs/interop/qemu-ga-ref.7 "$(DESTDIR)$(mandir)/man7"
837endif
838endif
839ifdef CONFIG_VIRTFS
840	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1"
841	$(INSTALL_DATA) fsdev/virtfs-proxy-helper.1 "$(DESTDIR)$(mandir)/man1"
842endif
843
844install-datadir:
845	$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)"
846
847install-localstatedir:
848ifdef CONFIG_POSIX
849ifneq (,$(findstring qemu-ga,$(TOOLS)))
850	$(INSTALL_DIR) "$(DESTDIR)$(qemu_localstatedir)"/run
851endif
852endif
853
854ICON_SIZES=16x16 24x24 32x32 48x48 64x64 128x128 256x256 512x512
855
856install: all $(if $(BUILD_DOCS),install-doc) install-datadir install-localstatedir \
857	$(if $(INSTALL_BLOBS),$(edk2-decompressed)) \
858	recurse-install
859ifneq ($(TOOLS),)
860	$(call install-prog,$(TOOLS),$(DESTDIR)$(bindir))
861endif
862ifneq ($(CONFIG_MODULES),)
863	$(INSTALL_DIR) "$(DESTDIR)$(qemu_moddir)"
864	for s in $(modules-m:.mo=$(DSOSUF)); do \
865		t="$(DESTDIR)$(qemu_moddir)/$$(echo $$s | tr / -)"; \
866		$(INSTALL_LIB) $$s "$$t"; \
867		test -z "$(STRIP)" || $(STRIP) "$$t"; \
868	done
869endif
870ifneq ($(HELPERS-y),)
871	$(call install-prog,$(HELPERS-y),$(DESTDIR)$(libexecdir))
872endif
873ifneq ($(vhost-user-json-y),)
874	$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/vhost-user/"
875	for x in $(vhost-user-json-y); do \
876		$(INSTALL_DATA) $$x "$(DESTDIR)$(qemu_datadir)/vhost-user/"; \
877	done
878endif
879ifdef CONFIG_TRACE_SYSTEMTAP
880	$(INSTALL_PROG) "scripts/qemu-trace-stap" $(DESTDIR)$(bindir)
881endif
882ifneq ($(BLOBS),)
883	set -e; for x in $(BLOBS); do \
884		$(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(qemu_datadir)"; \
885	done
886endif
887ifdef INSTALL_BLOBS
888	set -e; for x in $(edk2-decompressed); do \
889		$(INSTALL_DATA) $$x "$(DESTDIR)$(qemu_datadir)"; \
890	done
891endif
892ifneq ($(DESCS),)
893	$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/firmware"
894	set -e; tmpf=$$(mktemp); trap 'rm -f -- "$$tmpf"' EXIT; \
895	for x in $(DESCS); do \
896		sed -e 's,@DATADIR@,$(qemu_datadir),' \
897			"$(SRC_PATH)/pc-bios/descriptors/$$x" > "$$tmpf"; \
898		$(INSTALL_DATA) "$$tmpf" \
899			"$(DESTDIR)$(qemu_datadir)/firmware/$$x"; \
900	done
901endif
902	for s in $(ICON_SIZES); do \
903		mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/$${s}/apps"; \
904		$(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu_$${s}.png \
905			"$(DESTDIR)$(qemu_icondir)/hicolor/$${s}/apps/qemu.png"; \
906	done; \
907	mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/32x32/apps"; \
908	$(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu_32x32.bmp \
909		"$(DESTDIR)$(qemu_icondir)/hicolor/32x32/apps/qemu.bmp"; \
910	mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/scalable/apps"; \
911	$(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu.svg \
912		"$(DESTDIR)$(qemu_icondir)/hicolor/scalable/apps/qemu.svg"
913	mkdir -p "$(DESTDIR)$(qemu_desktopdir)"
914	$(INSTALL_DATA) $(SRC_PATH)/ui/qemu.desktop \
915		"$(DESTDIR)$(qemu_desktopdir)/qemu.desktop"
916ifdef CONFIG_GTK
917	$(MAKE) -C po $@
918endif
919	$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps"
920	set -e; for x in $(KEYMAPS); do \
921		$(INSTALL_DATA) $(SRC_PATH)/pc-bios/keymaps/$$x "$(DESTDIR)$(qemu_datadir)/keymaps"; \
922	done
923	$(INSTALL_DATA) $(BUILD_DIR)/trace-events-all "$(DESTDIR)$(qemu_datadir)/trace-events-all"
924
925.PHONY: ctags
926ctags:
927	rm -f tags
928	find "$(SRC_PATH)" -name '*.[hc]' -exec ctags --append {} +
929
930.PHONY: TAGS
931TAGS:
932	rm -f TAGS
933	find "$(SRC_PATH)" -name '*.[hc]' -exec etags --append {} +
934
935cscope:
936	rm -f "$(SRC_PATH)"/cscope.*
937	find "$(SRC_PATH)/" -name "*.[chsS]" -print | sed 's,^\./,,' > "$(SRC_PATH)/cscope.files"
938	cscope -b -i"$(SRC_PATH)/cscope.files"
939
940# opengl shader programs
941ui/shader/%-vert.h: $(SRC_PATH)/ui/shader/%.vert $(SRC_PATH)/scripts/shaderinclude.pl
942	@mkdir -p $(dir $@)
943	$(call quiet-command,\
944		perl $(SRC_PATH)/scripts/shaderinclude.pl $< > $@,\
945		"VERT","$@")
946
947ui/shader/%-frag.h: $(SRC_PATH)/ui/shader/%.frag $(SRC_PATH)/scripts/shaderinclude.pl
948	@mkdir -p $(dir $@)
949	$(call quiet-command,\
950		perl $(SRC_PATH)/scripts/shaderinclude.pl $< > $@,\
951		"FRAG","$@")
952
953ui/shader.o: $(SRC_PATH)/ui/shader.c \
954	ui/shader/texture-blit-vert.h \
955	ui/shader/texture-blit-flip-vert.h \
956	ui/shader/texture-blit-frag.h
957
958# documentation
959MAKEINFO=makeinfo
960MAKEINFOINCLUDES= -I docs -I $(<D) -I $(@D)
961MAKEINFOFLAGS=--no-split --number-sections $(MAKEINFOINCLUDES)
962TEXI2PODFLAGS=$(MAKEINFOINCLUDES) -DVERSION="$(VERSION)" -DCONFDIR="$(qemu_confdir)"
963TEXI2PDFFLAGS=$(if $(V),,--quiet) -I $(SRC_PATH) $(MAKEINFOINCLUDES)
964
965docs/version.texi: $(SRC_PATH)/VERSION config-host.mak
966	$(call quiet-command,(\
967		echo "@set VERSION $(VERSION)" && \
968		echo "@set CONFDIR $(qemu_confdir)" \
969	)> $@,"GEN","$@")
970
971%.html: %.texi docs/version.texi
972	$(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --no-headers \
973	--html $< -o $@,"GEN","$@")
974
975%.info: %.texi docs/version.texi
976	$(call quiet-command,$(MAKEINFO) $(MAKEINFOFLAGS) $< -o $@,"GEN","$@")
977
978%.txt: %.texi docs/version.texi
979	$(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --no-headers \
980	--plaintext $< -o $@,"GEN","$@")
981
982%.pdf: %.texi docs/version.texi
983	$(call quiet-command,texi2pdf $(TEXI2PDFFLAGS) $< -o $@,"GEN","$@")
984
985# Sphinx builds all its documentation at once in one invocation
986# and handles "don't rebuild things unless necessary" itself.
987# The '.doctrees' files are cached information to speed this up.
988.PHONY: sphinxdocs
989sphinxdocs: $(MANUAL_BUILDDIR)/devel/index.html $(MANUAL_BUILDDIR)/interop/index.html $(MANUAL_BUILDDIR)/specs/index.html
990
991# Canned command to build a single manual
992# Arguments: $1 = manual name, $2 = Sphinx builder ('html' or 'man')
993# Note the use of different doctree for each (manual, builder) tuple;
994# this works around Sphinx not handling parallel invocation on
995# a single doctree: https://github.com/sphinx-doc/sphinx/issues/2946
996build-manual = $(call quiet-command,CONFDIR="$(qemu_confdir)" sphinx-build $(if $(V),,-q) -W -n -b $2 -D version=$(VERSION) -D release="$(FULL_VERSION)" -d .doctrees/$1-$2 $(SRC_PATH)/docs/$1 $(MANUAL_BUILDDIR)/$1 ,"SPHINX","$(MANUAL_BUILDDIR)/$1")
997# We assume all RST files in the manual's directory are used in it
998manual-deps = $(wildcard $(SRC_PATH)/docs/$1/*.rst) $(SRC_PATH)/docs/$1/conf.py $(SRC_PATH)/docs/conf.py
999
1000$(MANUAL_BUILDDIR)/devel/index.html: $(call manual-deps,devel)
1001	$(call build-manual,devel,html)
1002
1003$(MANUAL_BUILDDIR)/interop/index.html: $(call manual-deps,interop)
1004	$(call build-manual,interop,html)
1005
1006$(MANUAL_BUILDDIR)/specs/index.html: $(call manual-deps,specs)
1007	$(call build-manual,specs,html)
1008
1009$(MANUAL_BUILDDIR)/interop/qemu-ga.8: $(call manual-deps,interop)
1010	$(call build-manual,interop,man)
1011
1012qemu-options.texi: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool
1013	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@")
1014
1015qemu-monitor.texi: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
1016	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@")
1017
1018qemu-monitor-info.texi: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
1019	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@")
1020
1021qemu-img-cmds.texi: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool
1022	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@")
1023
1024docs/interop/qemu-qmp-qapi.texi: qapi/qapi-doc.texi
1025	@cp -p $< $@
1026
1027docs/interop/qemu-ga-qapi.texi: qga/qapi-generated/qga-qapi-doc.texi
1028	@cp -p $< $@
1029
1030qemu.1: qemu-doc.texi qemu-options.texi qemu-monitor.texi qemu-monitor-info.texi
1031qemu.1: qemu-option-trace.texi
1032qemu-img.1: qemu-img.texi qemu-option-trace.texi qemu-img-cmds.texi
1033fsdev/virtfs-proxy-helper.1: fsdev/virtfs-proxy-helper.texi
1034qemu-nbd.8: qemu-nbd.texi qemu-option-trace.texi
1035docs/qemu-block-drivers.7: docs/qemu-block-drivers.texi
1036docs/qemu-cpu-models.7: docs/qemu-cpu-models.texi
1037scripts/qemu-trace-stap.1: scripts/qemu-trace-stap.texi
1038
1039html: qemu-doc.html docs/interop/qemu-qmp-ref.html docs/interop/qemu-ga-ref.html sphinxdocs
1040info: qemu-doc.info docs/interop/qemu-qmp-ref.info docs/interop/qemu-ga-ref.info
1041pdf: qemu-doc.pdf docs/interop/qemu-qmp-ref.pdf docs/interop/qemu-ga-ref.pdf
1042txt: qemu-doc.txt docs/interop/qemu-qmp-ref.txt docs/interop/qemu-ga-ref.txt
1043
1044qemu-doc.html qemu-doc.info qemu-doc.pdf qemu-doc.txt: \
1045	qemu-img.texi qemu-nbd.texi qemu-options.texi \
1046	qemu-tech.texi qemu-option-trace.texi \
1047	qemu-deprecated.texi qemu-monitor.texi qemu-img-cmds.texi \
1048	qemu-monitor-info.texi docs/qemu-block-drivers.texi \
1049	docs/qemu-cpu-models.texi docs/security.texi
1050
1051docs/interop/qemu-ga-ref.dvi docs/interop/qemu-ga-ref.html \
1052    docs/interop/qemu-ga-ref.info docs/interop/qemu-ga-ref.pdf \
1053    docs/interop/qemu-ga-ref.txt docs/interop/qemu-ga-ref.7: \
1054	docs/interop/qemu-ga-ref.texi docs/interop/qemu-ga-qapi.texi
1055
1056docs/interop/qemu-qmp-ref.dvi docs/interop/qemu-qmp-ref.html \
1057    docs/interop/qemu-qmp-ref.info docs/interop/qemu-qmp-ref.pdf \
1058    docs/interop/qemu-qmp-ref.txt docs/interop/qemu-qmp-ref.7: \
1059	docs/interop/qemu-qmp-ref.texi docs/interop/qemu-qmp-qapi.texi
1060
1061$(filter %.1 %.7 %.8,$(DOCS)): scripts/texi2pod.pl
1062
1063# Reports/Analysis
1064
1065%/coverage-report.html:
1066	@mkdir -p $*
1067	$(call quiet-command,\
1068		gcovr -r $(SRC_PATH) \
1069		$(foreach t, $(TARGET_DIRS), --object-directory $(BUILD_DIR)/$(t)) \
1070		 --object-directory $(BUILD_DIR) \
1071		-p --html --html-details -o $@, \
1072		"GEN", "coverage-report.html")
1073
1074.PHONY: coverage-report
1075coverage-report: $(CURDIR)/reports/coverage/coverage-report.html
1076
1077ifdef CONFIG_WIN32
1078
1079INSTALLER = qemu-setup-$(VERSION)$(EXESUF)
1080
1081nsisflags = -V2 -NOCD
1082
1083ifneq ($(wildcard $(SRC_PATH)/dll),)
1084ifeq ($(ARCH),x86_64)
1085# 64 bit executables
1086DLL_PATH = $(SRC_PATH)/dll/w64
1087nsisflags += -DW64
1088else
1089# 32 bit executables
1090DLL_PATH = $(SRC_PATH)/dll/w32
1091endif
1092endif
1093
1094.PHONY: installer
1095installer: $(INSTALLER)
1096
1097INSTDIR=/tmp/qemu-nsis
1098
1099$(INSTALLER): install-doc $(SRC_PATH)/qemu.nsi
1100	$(MAKE) install prefix=${INSTDIR}
1101ifdef SIGNCODE
1102	(cd ${INSTDIR}; \
1103         for i in *.exe; do \
1104           $(SIGNCODE) $${i}; \
1105         done \
1106        )
1107endif # SIGNCODE
1108	(cd ${INSTDIR}; \
1109         for i in qemu-system-*.exe; do \
1110           arch=$${i%.exe}; \
1111           arch=$${arch#qemu-system-}; \
1112           echo Section \"$$arch\" Section_$$arch; \
1113           echo SetOutPath \"\$$INSTDIR\"; \
1114           echo File \"\$${BINDIR}\\$$i\"; \
1115           echo SectionEnd; \
1116         done \
1117        ) >${INSTDIR}/system-emulations.nsh
1118	makensis $(nsisflags) \
1119                $(if $(BUILD_DOCS),-DCONFIG_DOCUMENTATION="y") \
1120                $(if $(CONFIG_GTK),-DCONFIG_GTK="y") \
1121                -DBINDIR="${INSTDIR}" \
1122                $(if $(DLL_PATH),-DDLLDIR="$(DLL_PATH)") \
1123                -DSRCDIR="$(SRC_PATH)" \
1124                -DOUTFILE="$(INSTALLER)" \
1125                -DDISPLAYVERSION="$(VERSION)" \
1126                $(SRC_PATH)/qemu.nsi
1127	rm -r ${INSTDIR}
1128ifdef SIGNCODE
1129	$(SIGNCODE) $(INSTALLER)
1130endif # SIGNCODE
1131endif # CONFIG_WIN
1132
1133# Add a dependency on the generated files, so that they are always
1134# rebuilt before other object files
1135ifneq ($(wildcard config-host.mak),)
1136ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
1137Makefile: $(generated-files-y)
1138endif
1139endif
1140
1141.SECONDARY: $(TRACE_HEADERS) $(TRACE_HEADERS:%=%-timestamp) \
1142	$(TRACE_SOURCES) $(TRACE_SOURCES:%=%-timestamp) \
1143	$(TRACE_DTRACE) $(TRACE_DTRACE:%=%-timestamp)
1144
1145# Include automatically generated dependency files
1146# Dependencies in Makefile.objs files come from our recursive subdir rules
1147-include $(wildcard *.d tests/*.d)
1148
1149include $(SRC_PATH)/tests/docker/Makefile.include
1150include $(SRC_PATH)/tests/vm/Makefile.include
1151
1152.PHONY: help
1153help:
1154	@echo  'Generic targets:'
1155	@echo  '  all             - Build all'
1156ifdef CONFIG_MODULES
1157	@echo  '  modules         - Build all modules'
1158endif
1159	@echo  '  dir/file.o      - Build specified target only'
1160	@echo  '  install         - Install QEMU, documentation and tools'
1161	@echo  '  ctags/TAGS      - Generate tags file for editors'
1162	@echo  '  cscope          - Generate cscope index'
1163	@echo  ''
1164	@$(if $(TARGET_DIRS), \
1165		echo 'Architecture specific targets:'; \
1166		$(foreach t, $(TARGET_DIRS), \
1167		printf "  %-30s - Build for %s\\n" $(t)/all $(t);) \
1168		echo '')
1169	@echo  'Cleaning targets:'
1170	@echo  '  clean           - Remove most generated files but keep the config'
1171ifdef CONFIG_GCOV
1172	@echo  '  clean-coverage  - Remove coverage files'
1173endif
1174	@echo  '  distclean       - Remove all generated files'
1175	@echo  '  dist            - Build a distributable tarball'
1176	@echo  ''
1177	@echo  'Test targets:'
1178	@echo  '  check           - Run all tests (check-help for details)'
1179	@echo  '  docker          - Help about targets running tests inside containers'
1180	@echo  '  vm-help         - Help about targets running tests inside VM'
1181	@echo  ''
1182	@echo  'Documentation targets:'
1183	@echo  '  html info pdf txt'
1184	@echo  '                  - Build documentation in specified format'
1185ifdef CONFIG_GCOV
1186	@echo  '  coverage-report - Create code coverage report'
1187endif
1188	@echo  ''
1189ifdef CONFIG_WIN32
1190	@echo  'Windows targets:'
1191	@echo  '  installer       - Build NSIS-based installer for QEMU'
1192ifdef QEMU_GA_MSI_ENABLED
1193	@echo  '  msi             - Build MSI-based installer for qemu-ga'
1194endif
1195	@echo  ''
1196endif
1197	@echo  '  $(MAKE) [targets]      (quiet build, default)'
1198	@echo  '  $(MAKE) V=1 [targets]  (verbose build)'
1199