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