xref: /openbmc/qemu/Makefile (revision ff219dca)
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
124generated-files-y += target/s390x/gen-features.h
125target/s390x/gen-features.h: Makefile.ninja
126
127generated-files-y += .git-submodule-status
128
129# Don't try to regenerate Makefile or configure
130# We don't generate any of them
131Makefile: ;
132configure: ;
133
134.PHONY: all clean cscope distclean html info install install-doc \
135	pdf txt recurse-all dist msi FORCE
136
137$(call set-vpath, $(SRC_PATH))
138
139LIBS+=-lz $(LIBS_TOOLS)
140
141# Sphinx does not allow building manuals into the same directory as
142# the source files, so if we're doing an in-tree QEMU build we must
143# build the manuals into a subdirectory (and then install them from
144# there for 'make install'). For an out-of-tree build we can just
145# use the docs/ subdirectory in the build tree as normal.
146ifeq ($(realpath $(SRC_PATH)),$(realpath .))
147MANUAL_BUILDDIR := docs/built
148else
149MANUAL_BUILDDIR := docs
150endif
151
152ifdef BUILD_DOCS
153DOCS+=$(MANUAL_BUILDDIR)/system/qemu.1
154DOCS+=$(MANUAL_BUILDDIR)/tools/qemu-img.1
155DOCS+=$(MANUAL_BUILDDIR)/tools/qemu-nbd.8
156DOCS+=$(MANUAL_BUILDDIR)/interop/qemu-ga.8
157ifeq ($(CONFIG_LINUX)$(CONFIG_SECCOMP)$(CONFIG_LIBCAP_NG),yyy)
158DOCS+=$(MANUAL_BUILDDIR)/tools/virtiofsd.1
159endif
160DOCS+=$(MANUAL_BUILDDIR)/system/qemu-block-drivers.7
161DOCS+=docs/interop/qemu-qmp-ref.html docs/interop/qemu-qmp-ref.txt docs/interop/qemu-qmp-ref.7
162DOCS+=docs/interop/qemu-ga-ref.html docs/interop/qemu-ga-ref.txt docs/interop/qemu-ga-ref.7
163DOCS+=$(MANUAL_BUILDDIR)/system/qemu-cpu-models.7
164DOCS+=$(MANUAL_BUILDDIR)/index.html
165ifdef CONFIG_VIRTFS
166DOCS+=$(MANUAL_BUILDDIR)/tools/virtfs-proxy-helper.1
167endif
168ifdef CONFIG_TRACE_SYSTEMTAP
169DOCS+=$(MANUAL_BUILDDIR)/tools/qemu-trace-stap.1
170endif
171else
172DOCS=
173endif
174
175SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet) BUILD_DIR=$(BUILD_DIR)
176
177ifneq ($(wildcard config-host.mak),)
178include $(SRC_PATH)/Makefile.objs
179endif
180
181dummy := $(call unnest-vars,, \
182                storage-daemon-obj-y \
183                storage-daemon-obj-m \
184                common-obj-y \
185                common-obj-m)
186
187include $(SRC_PATH)/tests/Makefile.include
188
189all: $(DOCS) $(if $(BUILD_DOCS),sphinxdocs) recurse-all modules
190
191config-host.h: config-host.h-timestamp
192config-host.h-timestamp: config-host.mak
193
194TARGET_DIRS_RULES := $(foreach t, all fuzz clean install, $(addsuffix /$(t), $(TARGET_DIRS)))
195
196SOFTMMU_ALL_RULES=$(filter %-softmmu/all, $(TARGET_DIRS_RULES))
197$(SOFTMMU_ALL_RULES): $(authz-obj-y)
198$(SOFTMMU_ALL_RULES): $(block-obj-y)
199$(SOFTMMU_ALL_RULES): $(storage-daemon-obj-y)
200$(SOFTMMU_ALL_RULES): $(chardev-obj-y)
201$(SOFTMMU_ALL_RULES): $(crypto-obj-y)
202$(SOFTMMU_ALL_RULES): $(io-obj-y)
203$(SOFTMMU_ALL_RULES): $(qom-obj-y)
204$(SOFTMMU_ALL_RULES): config-all-devices.mak
205
206SOFTMMU_FUZZ_RULES=$(filter %-softmmu/fuzz, $(TARGET_DIRS_RULES))
207$(SOFTMMU_FUZZ_RULES): $(authz-obj-y)
208$(SOFTMMU_FUZZ_RULES): $(block-obj-y)
209$(SOFTMMU_FUZZ_RULES): $(chardev-obj-y)
210$(SOFTMMU_FUZZ_RULES): $(crypto-obj-y)
211$(SOFTMMU_FUZZ_RULES): $(io-obj-y)
212$(SOFTMMU_FUZZ_RULES): config-all-devices.mak
213$(SOFTMMU_FUZZ_RULES): $(edk2-decompressed)
214
215# meson: this is sub-optimal but going away after conversion
216TARGET_DEPS = $(patsubst %,%-config-target.h, $(TARGET_DIRS))
217TARGET_DEPS += $(patsubst %,%-config-devices.h, $(filter %-softmmu,$(TARGET_DIRS)))
218TARGET_DEPS += $(patsubst %,libqemu-%.fa, $(TARGET_DIRS))
219
220.PHONY: $(TARGET_DIRS_RULES)
221# The $(TARGET_DIRS_RULES) are of the form SUBDIR/GOAL, so that
222# $(dir $@) yields the sub-directory, and $(notdir $@) yields the sub-goal
223$(TARGET_DIRS_RULES): $(TARGET_DEPS)
224	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" $(notdir $@),)
225
226# LIBFDT_lib="": avoid breaking existing trees with objects requiring -fPIC
227DTC_MAKE_ARGS=-I$(SRC_PATH)/dtc VPATH=$(SRC_PATH)/dtc -C dtc V="$(V)" LIBFDT_lib=""
228DTC_CFLAGS=$(CFLAGS) $(QEMU_CFLAGS)
229DTC_CPPFLAGS=-I$(SRC_PATH)/dtc/libfdt
230
231.PHONY: dtc/all
232dtc/all: .git-submodule-status dtc/libfdt
233	$(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,)
234
235dtc/%: .git-submodule-status
236	@mkdir -p $@
237
238# Overriding CFLAGS causes us to lose defines added in the sub-makefile.
239# Not overriding CFLAGS leads to mis-matches between compilation modes.
240# Therefore we replicate some of the logic in the sub-makefile.
241# Remove all the extra -Warning flags that QEMU uses that Capstone doesn't;
242# no need to annoy QEMU developers with such things.
243CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS))
244CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM
245CAP_CFLAGS += -DCAPSTONE_HAS_ARM
246CAP_CFLAGS += -DCAPSTONE_HAS_ARM64
247CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC
248CAP_CFLAGS += -DCAPSTONE_HAS_X86
249
250.PHONY: capstone/all
251capstone/all: .git-submodule-status
252	$(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))
253
254.PHONY: slirp/all
255slirp/all: .git-submodule-status
256	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp		\
257		BUILD_DIR="$(BUILD_DIR)/slirp" 			\
258		PKG_CONFIG="$(PKG_CONFIG)" 				\
259		CC="$(CC)" AR="$(AR)" 	LD="$(LD)" RANLIB="$(RANLIB)"	\
260		CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)")
261
262$(filter %/all, $(TARGET_DIRS_RULES)): libqemuutil.a $(common-obj-y) \
263	$(qom-obj-y) block.syms qemu.syms
264
265$(filter %/fuzz, $(TARGET_DIRS_RULES)): libqemuutil.a $(common-obj-y) \
266	$(qom-obj-y) $(crypto-user-obj-$(CONFIG_USER_ONLY))
267
268ROM_DIRS = $(addprefix pc-bios/, $(ROMS))
269ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS)))
270# Only keep -O and -g cflags
271.PHONY: $(ROM_DIRS_RULES)
272$(ROM_DIRS_RULES):
273	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" CFLAGS="$(filter -O% -g%,$(CFLAGS))" $(notdir $@),)
274
275.PHONY: recurse-all recurse-clean recurse-install
276recurse-all: $(addsuffix /all, $(TARGET_DIRS) $(ROM_DIRS))
277recurse-clean: $(addsuffix /clean, $(TARGET_DIRS) $(ROM_DIRS))
278recurse-install: $(addsuffix /install, $(TARGET_DIRS))
279$(addsuffix /install, $(TARGET_DIRS)): all
280
281$(BUILD_DIR)/version.o: $(SRC_PATH)/version.rc config-host.h
282	$(call quiet-command,$(WINDRES) -I$(BUILD_DIR) -o $@ $<,"RC","version.o")
283
284Makefile: $(version-obj-y)
285
286######################################################################
287
288COMMON_LDADDS = libqemuutil.a
289
290qemu-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)
291
292clean: recurse-clean ninja-clean clean-ctlist
293	-test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean
294# avoid old build problems by removing potentially incorrect old files
295	rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
296	find . \( -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name '*.[oda]' \) -type f \
297		! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \
298		! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \
299		! -path ./roms/edk2/BaseTools/Source/Python/UPT/Dll/sqlite3.dll \
300		-exec rm {} +
301	rm -f TAGS cscope.* *.pod *~ */*~
302	rm -f fsdev/*.pod scsi/*.pod
303	rm -f $(foreach f,$(generated-files-y),$(f) $(f)-timestamp)
304
305VERSION ?= $(shell cat VERSION)
306
307dist: qemu-$(VERSION).tar.bz2
308
309qemu-%.tar.bz2:
310	$(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)"
311
312define clean-manual =
313rm -rf $(MANUAL_BUILDDIR)/$1/_static
314rm -f $(MANUAL_BUILDDIR)/$1/objects.inv $(MANUAL_BUILDDIR)/$1/searchindex.js $(MANUAL_BUILDDIR)/$1/*.html
315endef
316
317distclean: clean ninja-distclean
318	-test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean -g
319	rm -f config-host.mak config-host.h* $(DOCS)
320	rm -f tests/tcg/config-*.mak
321	rm -f config-all-disas.mak config.status
322	rm -f po/*.mo tests/qemu-iotests/common.env
323	rm -f roms/seabios/config.mak roms/vgabios/config.mak
324	rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols
325	rm -rf meson-private meson-logs meson-info compile_commands.json
326	rm -f Makefile.ninja ninjatool ninjatool.stamp Makefile.mtest
327	rm -f config.log
328	rm -f linux-headers/asm
329	rm -f docs/version.texi
330	rm -f docs/interop/qemu-ga-qapi.texi docs/interop/qemu-qmp-qapi.texi
331	rm -f docs/interop/qemu-qmp-ref.7 docs/interop/qemu-ga-ref.7
332	rm -f docs/interop/qemu-qmp-ref.txt docs/interop/qemu-ga-ref.txt
333	rm -f docs/interop/qemu-qmp-ref.pdf docs/interop/qemu-ga-ref.pdf
334	rm -f docs/interop/qemu-qmp-ref.html docs/interop/qemu-ga-ref.html
335	rm -rf .doctrees
336	$(call clean-manual,devel)
337	$(call clean-manual,interop)
338	$(call clean-manual,specs)
339	$(call clean-manual,system)
340	$(call clean-manual,tools)
341	$(call clean-manual,user)
342	for d in $(TARGET_DIRS); do \
343	rm -rf $$d || exit 1 ; \
344        done
345	rm -Rf .sdk
346
347KEYMAPS=da     en-gb  et  fr     fr-ch  is  lt  no  pt-br  sv \
348ar      de     en-us  fi  fr-be  hr     it  lv  nl         pl  ru     th \
349de-ch  es     fo  fr-ca  hu     ja  mk  pt  sl     tr \
350bepo    cz
351
352ifdef INSTALL_BLOBS
353BLOBS=bios.bin bios-256k.bin bios-microvm.bin sgabios.bin vgabios.bin vgabios-cirrus.bin \
354vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin vgabios-virtio.bin \
355vgabios-ramfb.bin vgabios-bochs-display.bin vgabios-ati.bin \
356openbios-sparc32 openbios-sparc64 openbios-ppc QEMU,tcx.bin QEMU,cgthree.bin \
357pxe-e1000.rom pxe-eepro100.rom pxe-ne2k_pci.rom \
358pxe-pcnet.rom pxe-rtl8139.rom pxe-virtio.rom \
359efi-e1000.rom efi-eepro100.rom efi-ne2k_pci.rom \
360efi-pcnet.rom efi-rtl8139.rom efi-virtio.rom \
361efi-e1000e.rom efi-vmxnet3.rom \
362qemu-nsis.bmp \
363bamboo.dtb canyonlands.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \
364multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin \
365s390-ccw.img s390-netboot.img \
366slof.bin skiboot.lid \
367palcode-clipper \
368u-boot.e500 u-boot-sam460-20100605.bin \
369qemu_vga.ndrv \
370edk2-licenses.txt \
371hppa-firmware.img \
372opensbi-riscv32-sifive_u-fw_jump.bin opensbi-riscv32-virt-fw_jump.bin \
373opensbi-riscv64-sifive_u-fw_jump.bin opensbi-riscv64-virt-fw_jump.bin
374else
375BLOBS=
376endif
377
378# Note that we manually filter-out the non-Sphinx documentation which
379# is currently built into the docs/interop directory in the build tree,
380# and also any sphinx-built manpages.
381define install-manual =
382for d in $$(cd $(MANUAL_BUILDDIR) && find $1 -type d); do $(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)/$$d"; done
383for 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
384endef
385
386# Note that we deliberately do not install the "devel" manual: it is
387# for QEMU developers, and not interesting to our users.
388.PHONY: install-sphinxdocs
389install-sphinxdocs: sphinxdocs
390	$(call install-manual,interop)
391	$(call install-manual,specs)
392	$(call install-manual,system)
393	$(call install-manual,tools)
394	$(call install-manual,user)
395
396install-doc: $(DOCS) install-sphinxdocs
397	$(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)"
398	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/index.html "$(DESTDIR)$(qemu_docdir)"
399	$(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)/interop"
400	$(INSTALL_DATA) docs/interop/qemu-qmp-ref.html "$(DESTDIR)$(qemu_docdir)/interop"
401	$(INSTALL_DATA) docs/interop/qemu-qmp-ref.txt "$(DESTDIR)$(qemu_docdir)/interop"
402ifdef CONFIG_POSIX
403	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1"
404	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/system/qemu.1 "$(DESTDIR)$(mandir)/man1"
405	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man7"
406	$(INSTALL_DATA) docs/interop/qemu-qmp-ref.7 "$(DESTDIR)$(mandir)/man7"
407	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/system/qemu-block-drivers.7 "$(DESTDIR)$(mandir)/man7"
408	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/system/qemu-cpu-models.7 "$(DESTDIR)$(mandir)/man7"
409ifeq ($(CONFIG_TOOLS),y)
410	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/tools/qemu-img.1 "$(DESTDIR)$(mandir)/man1"
411	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man8"
412	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/tools/qemu-nbd.8 "$(DESTDIR)$(mandir)/man8"
413endif
414ifdef CONFIG_TRACE_SYSTEMTAP
415	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/tools/qemu-trace-stap.1 "$(DESTDIR)$(mandir)/man1"
416endif
417ifeq ($(CONFIG_GUEST_AGENT),y)
418	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/interop/qemu-ga.8 "$(DESTDIR)$(mandir)/man8"
419	$(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)/interop"
420	$(INSTALL_DATA) docs/interop/qemu-ga-ref.html "$(DESTDIR)$(qemu_docdir)/interop"
421	$(INSTALL_DATA) docs/interop/qemu-ga-ref.txt "$(DESTDIR)$(qemu_docdir)/interop"
422	$(INSTALL_DATA) docs/interop/qemu-ga-ref.7 "$(DESTDIR)$(mandir)/man7"
423endif
424endif
425ifdef CONFIG_VIRTFS
426	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1"
427	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/tools/virtfs-proxy-helper.1 "$(DESTDIR)$(mandir)/man1"
428endif
429ifeq ($(CONFIG_LINUX)$(CONFIG_SECCOMP)$(CONFIG_LIBCAP_NG),yyy)
430	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/tools/virtiofsd.1 "$(DESTDIR)$(mandir)/man1"
431endif
432
433install-datadir:
434	$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)"
435
436install-localstatedir:
437ifdef CONFIG_POSIX
438ifeq ($(CONFIG_GUEST_AGENT),y)
439	$(INSTALL_DIR) "$(DESTDIR)$(qemu_localstatedir)"/run
440endif
441endif
442
443ICON_SIZES=16x16 24x24 32x32 48x48 64x64 128x128 256x256 512x512
444
445install-includedir:
446	$(INSTALL_DIR) "$(DESTDIR)$(includedir)"
447
448# Needed by "meson install"
449export DESTDIR
450install: all $(if $(BUILD_DOCS),install-doc) \
451	install-datadir install-localstatedir install-includedir \
452	recurse-install
453ifdef CONFIG_TRACE_SYSTEMTAP
454	$(INSTALL_PROG) "scripts/qemu-trace-stap" $(DESTDIR)$(bindir)
455endif
456ifneq ($(BLOBS),)
457	set -e; for x in $(BLOBS); do \
458		$(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(qemu_datadir)"; \
459	done
460endif
461	for s in $(ICON_SIZES); do \
462		mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/$${s}/apps"; \
463		$(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu_$${s}.png \
464			"$(DESTDIR)$(qemu_icondir)/hicolor/$${s}/apps/qemu.png"; \
465	done; \
466	mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/32x32/apps"; \
467	$(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu_32x32.bmp \
468		"$(DESTDIR)$(qemu_icondir)/hicolor/32x32/apps/qemu.bmp"; \
469	mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/scalable/apps"; \
470	$(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu.svg \
471		"$(DESTDIR)$(qemu_icondir)/hicolor/scalable/apps/qemu.svg"
472	mkdir -p "$(DESTDIR)$(qemu_desktopdir)"
473	$(INSTALL_DATA) $(SRC_PATH)/ui/qemu.desktop \
474		"$(DESTDIR)$(qemu_desktopdir)/qemu.desktop"
475ifdef CONFIG_GTK
476	$(MAKE) -C po $@
477endif
478ifeq ($(CONFIG_PLUGIN),y)
479	$(INSTALL_DATA) $(SRC_PATH)/include/qemu/qemu-plugin.h "$(DESTDIR)$(includedir)/qemu-plugin.h"
480endif
481	$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps"
482	set -e; for x in $(KEYMAPS); do \
483		$(INSTALL_DATA) $(SRC_PATH)/pc-bios/keymaps/$$x "$(DESTDIR)$(qemu_datadir)/keymaps"; \
484	done
485	for d in $(TARGET_DIRS); do \
486	$(MAKE) $(SUBDIR_MAKEFLAGS) TARGET_DIR=$$d/ -C $$d $@ || exit 1 ; \
487        done
488
489# documentation
490MAKEINFO=makeinfo
491MAKEINFOINCLUDES= -I docs -I $(<D) -I $(@D)
492MAKEINFOFLAGS=--no-split --number-sections $(MAKEINFOINCLUDES)
493TEXI2PODFLAGS=$(MAKEINFOINCLUDES) -DVERSION="$(VERSION)" -DCONFDIR="$(qemu_confdir)"
494TEXI2PDFFLAGS=$(if $(V),,--quiet) -I $(SRC_PATH) $(MAKEINFOINCLUDES)
495
496docs/version.texi: $(SRC_PATH)/VERSION config-host.mak
497	$(call quiet-command,(\
498		echo "@set VERSION $(VERSION)" && \
499		echo "@set CONFDIR $(qemu_confdir)" \
500	)> $@,"GEN","$@")
501
502%.html: %.texi docs/version.texi
503	$(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --no-headers \
504	--html $< -o $@,"GEN","$@")
505
506%.info: %.texi docs/version.texi
507	$(call quiet-command,$(MAKEINFO) $(MAKEINFOFLAGS) $< -o $@,"GEN","$@")
508
509%.txt: %.texi docs/version.texi
510	$(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --no-headers \
511	--plaintext $< -o $@,"GEN","$@")
512
513%.pdf: %.texi docs/version.texi
514	$(call quiet-command,texi2pdf $(TEXI2PDFFLAGS) $< -o $@,"GEN","$@")
515
516# Sphinx builds all its documentation at once in one invocation
517# and handles "don't rebuild things unless necessary" itself.
518# The '.doctrees' files are cached information to speed this up.
519.PHONY: sphinxdocs
520sphinxdocs: $(MANUAL_BUILDDIR)/devel/index.html \
521            $(MANUAL_BUILDDIR)/interop/index.html \
522            $(MANUAL_BUILDDIR)/specs/index.html \
523            $(MANUAL_BUILDDIR)/system/index.html \
524            $(MANUAL_BUILDDIR)/tools/index.html \
525            $(MANUAL_BUILDDIR)/user/index.html
526
527# Canned command to build a single manual
528# Arguments: $1 = manual name, $2 = Sphinx builder ('html' or 'man')
529# Note the use of different doctree for each (manual, builder) tuple;
530# this works around Sphinx not handling parallel invocation on
531# a single doctree: https://github.com/sphinx-doc/sphinx/issues/2946
532build-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")
533# We assume all RST files in the manual's directory are used in it
534manual-deps = $(wildcard $(SRC_PATH)/docs/$1/*.rst $(SRC_PATH)/docs/$1/*/*.rst) \
535              $(SRC_PATH)/docs/defs.rst.inc \
536              $(SRC_PATH)/docs/$1/conf.py $(SRC_PATH)/docs/conf.py \
537              $(SRC_PATH)/docs/sphinx/*.py
538# Macro to write out the rule and dependencies for building manpages
539# Usage: $(call define-manpage-rule,manualname,manpage1 manpage2...[,extradeps])
540# 'extradeps' is optional, and specifies extra files (eg .hx files) that
541# the manual page depends on.
542define define-manpage-rule
543$(call atomic,$(foreach manpage,$2,$(MANUAL_BUILDDIR)/$1/$(manpage)),$(call manual-deps,$1) $3)
544	$(call build-manual,$1,man)
545endef
546
547$(MANUAL_BUILDDIR)/devel/index.html: $(call manual-deps,devel)
548	$(call build-manual,devel,html)
549
550$(MANUAL_BUILDDIR)/interop/index.html: $(call manual-deps,interop)
551	$(call build-manual,interop,html)
552
553$(MANUAL_BUILDDIR)/specs/index.html: $(call manual-deps,specs)
554	$(call build-manual,specs,html)
555
556$(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
557	$(call build-manual,system,html)
558
559$(MANUAL_BUILDDIR)/tools/index.html: $(call manual-deps,tools) $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/docs/qemu-option-trace.rst.inc
560	$(call build-manual,tools,html)
561
562$(MANUAL_BUILDDIR)/user/index.html: $(call manual-deps,user)
563	$(call build-manual,user,html)
564
565$(call define-manpage-rule,interop,qemu-ga.8)
566
567$(call define-manpage-rule,system,qemu.1 qemu-block-drivers.7 qemu-cpu-models.7)
568
569$(call define-manpage-rule,tools,\
570       qemu-img.1 qemu-nbd.8 qemu-trace-stap.1\
571       virtiofsd.1 virtfs-proxy-helper.1,\
572       $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/docs/qemu-option-trace.rst.inc)
573
574$(MANUAL_BUILDDIR)/index.html: $(SRC_PATH)/docs/index.html.in qemu-version.h
575	@mkdir -p "$(MANUAL_BUILDDIR)"
576	$(call quiet-command, sed "s|@@VERSION@@|${VERSION}|g" $< >$@, \
577             "GEN","$@")
578
579docs/interop/qemu-qmp-qapi.texi: qapi/qapi-doc.texi
580	@cp -p $< $@
581
582docs/interop/qemu-ga-qapi.texi: qga/qga-qapi-doc.texi
583	@cp -p $< $@
584
585html: docs/interop/qemu-qmp-ref.html docs/interop/qemu-ga-ref.html sphinxdocs
586info: docs/interop/qemu-qmp-ref.info docs/interop/qemu-ga-ref.info
587pdf: docs/interop/qemu-qmp-ref.pdf docs/interop/qemu-ga-ref.pdf
588txt: docs/interop/qemu-qmp-ref.txt docs/interop/qemu-ga-ref.txt
589
590docs/interop/qemu-ga-ref.dvi docs/interop/qemu-ga-ref.html \
591    docs/interop/qemu-ga-ref.info docs/interop/qemu-ga-ref.pdf \
592    docs/interop/qemu-ga-ref.txt docs/interop/qemu-ga-ref.7: \
593	docs/interop/qemu-ga-ref.texi docs/interop/qemu-ga-qapi.texi
594
595docs/interop/qemu-qmp-ref.dvi docs/interop/qemu-qmp-ref.html \
596    docs/interop/qemu-qmp-ref.info docs/interop/qemu-qmp-ref.pdf \
597    docs/interop/qemu-qmp-ref.txt docs/interop/qemu-qmp-ref.7: \
598	docs/interop/qemu-qmp-ref.texi docs/interop/qemu-qmp-qapi.texi
599
600$(filter %.1 %.7 %.8,$(DOCS)): scripts/texi2pod.pl
601
602# Reports/Analysis
603
604%/coverage-report.html:
605	@mkdir -p $*
606	$(call quiet-command,\
607		gcovr -r $(SRC_PATH) \
608		$(foreach t, $(TARGET_DIRS), --object-directory $(BUILD_DIR)/$(t)) \
609		 --object-directory $(BUILD_DIR) \
610		-p --html --html-details -o $@, \
611		"GEN", "coverage-report.html")
612
613.PHONY: coverage-report
614coverage-report: $(CURDIR)/reports/coverage/coverage-report.html
615
616ifdef CONFIG_WIN32
617
618INSTALLER = qemu-setup-$(VERSION)$(EXESUF)
619
620nsisflags = -V2 -NOCD
621
622ifneq ($(wildcard $(SRC_PATH)/dll),)
623ifeq ($(ARCH),x86_64)
624# 64 bit executables
625DLL_PATH = $(SRC_PATH)/dll/w64
626nsisflags += -DW64
627else
628# 32 bit executables
629DLL_PATH = $(SRC_PATH)/dll/w32
630endif
631endif
632
633.PHONY: installer
634installer: $(INSTALLER)
635
636INSTDIR=/tmp/qemu-nsis
637
638$(INSTALLER): $(SRC_PATH)/qemu.nsi
639	$(MAKE) install DESTDIR=${INSTDIR}
640ifdef SIGNCODE
641	(cd ${INSTDIR}/${bindir}; \
642         for i in *.exe; do \
643           $(SIGNCODE) $${i}; \
644         done \
645        )
646endif # SIGNCODE
647	(cd ${INSTDIR}/${bindir}; \
648         for i in qemu-system-*.exe; do \
649           arch=$${i%.exe}; \
650           arch=$${arch#qemu-system-}; \
651           echo Section \"$$arch\" Section_$$arch; \
652           echo SetOutPath \"\$$INSTDIR\"; \
653           echo File \"\$${BINDIR}\\$$i\"; \
654           echo SectionEnd; \
655         done \
656        ) >${INSTDIR}/${bindir}/system-emulations.nsh
657	makensis $(nsisflags) \
658                $(if $(BUILD_DOCS),-DCONFIG_DOCUMENTATION="y") \
659                $(if $(CONFIG_GTK),-DCONFIG_GTK="y") \
660                -DBINDIR="${INSTDIR}/${bindir}" \
661                $(if $(DLL_PATH),-DDLLDIR="$(DLL_PATH)") \
662                -DSRCDIR="$(SRC_PATH)" \
663                -DOUTFILE="$(INSTALLER)" \
664                -DDISPLAYVERSION="$(VERSION)" \
665                $(SRC_PATH)/qemu.nsi
666	rm -r ${INSTDIR}
667ifdef SIGNCODE
668	$(SIGNCODE) $(INSTALLER)
669endif # SIGNCODE
670endif # CONFIG_WIN
671
672# Add a dependency on the generated files, so that they are always
673# rebuilt before other object files
674ifneq ($(wildcard config-host.mak),)
675ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
676Makefile: $(generated-files-y)
677endif
678endif
679
680# Include automatically generated dependency files
681# Dependencies in Makefile.objs files come from our recursive subdir rules
682-include $(wildcard *.d tests/*.d)
683
684include $(SRC_PATH)/tests/docker/Makefile.include
685include $(SRC_PATH)/tests/vm/Makefile.include
686
687print-help-run = printf "  %-30s - %s\\n" "$1" "$2"
688print-help = $(quiet-@)$(call print-help-run,$1,$2)
689
690.PHONY: help
691help:
692	@echo  'Generic targets:'
693	$(call print-help,all,Build all)
694ifdef CONFIG_MODULES
695	$(call print-help,modules,Build all modules)
696endif
697	$(call print-help,dir/file.o,Build specified target only)
698	$(call print-help,install,Install QEMU, documentation and tools)
699	$(call print-help,ctags/TAGS,Generate tags file for editors)
700	$(call print-help,cscope,Generate cscope index)
701	$(call print-help,sparse,Run sparse on the QEMU source)
702	@echo  ''
703	@$(if $(TARGET_DIRS), \
704		echo 'Architecture specific targets:'; \
705		$(foreach t, $(TARGET_DIRS), \
706		$(call print-help-run,$(t)/all,Build for $(t)); \
707		$(if $(CONFIG_FUZZ), \
708			$(if $(findstring softmmu,$(t)), \
709				$(call print-help-run,$(t)/fuzz,Build fuzzer for $(t)); \
710		))) \
711		echo '')
712	@echo  'Cleaning targets:'
713	$(call print-help,clean,Remove most generated files but keep the config)
714	$(call print-help,distclean,Remove all generated files)
715	$(call print-help,dist,Build a distributable tarball)
716	@echo  ''
717	@echo  'Test targets:'
718	$(call print-help,check,Run all tests (check-help for details))
719	$(call print-help,docker,Help about targets running tests inside containers)
720	$(call print-help,vm-help,Help about targets running tests inside VM)
721	@echo  ''
722	@echo  'Documentation targets:'
723	$(call print-help,html info pdf txt,Build documentation in specified format)
724	@echo  ''
725ifdef CONFIG_WIN32
726	@echo  'Windows targets:'
727	$(call print-help,installer,Build NSIS-based installer for QEMU)
728ifdef QEMU_GA_MSI_ENABLED
729	$(call print-help,msi,Build MSI-based installer for qemu-ga)
730endif
731	@echo  ''
732endif
733	$(call print-help,$(MAKE) [targets],(quiet build, default))
734	$(call print-help,$(MAKE) V=1 [targets],(verbose build))
735