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