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