xref: /openbmc/qemu/Makefile (revision 0ab8ed18a6fe98bfc82705b0f041fbf2a8ca5b60)
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 docker docker-%
10
11# All following code might depend on configuration variables
12ifneq ($(wildcard config-host.mak),)
13# Put the all: rule here so that config-host.mak can contain dependencies.
14all:
15include config-host.mak
16
17# Check that we're not trying to do an out-of-tree build from
18# a tree that's been used for an in-tree build.
19ifneq ($(realpath $(SRC_PATH)),$(realpath .))
20ifneq ($(wildcard $(SRC_PATH)/config-host.mak),)
21$(error This is an out of tree build but your source tree ($(SRC_PATH)) \
22seems to have been used for an in-tree build. You can fix this by running \
23"make distclean && rm -rf *-linux-user *-softmmu" in your source tree)
24endif
25endif
26
27CONFIG_SOFTMMU := $(if $(filter %-softmmu,$(TARGET_DIRS)),y)
28CONFIG_USER_ONLY := $(if $(filter %-user,$(TARGET_DIRS)),y)
29CONFIG_ALL=y
30-include config-all-devices.mak
31-include config-all-disas.mak
32
33config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios
34	@echo $@ is out-of-date, running configure
35	@# TODO: The next lines include code which supports a smooth
36	@# transition from old configurations without config.status.
37	@# This code can be removed after QEMU 1.7.
38	@if test -x config.status; then \
39	    ./config.status; \
40        else \
41	    sed -n "/.*Configured with/s/[^:]*: //p" $@ | sh; \
42	fi
43else
44config-host.mak:
45ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
46	@echo "Please call configure before running make!"
47	@exit 1
48endif
49endif
50
51include $(SRC_PATH)/rules.mak
52
53GENERATED_HEADERS = qemu-version.h config-host.h qemu-options.def
54GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h qapi-event.h
55GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c qapi-event.c
56GENERATED_HEADERS += qmp-introspect.h
57GENERATED_SOURCES += qmp-introspect.c
58
59GENERATED_HEADERS += trace/generated-tcg-tracers.h
60
61GENERATED_HEADERS += trace/generated-helpers-wrappers.h
62GENERATED_HEADERS += trace/generated-helpers.h
63GENERATED_SOURCES += trace/generated-helpers.c
64
65ifdef CONFIG_TRACE_UST
66GENERATED_HEADERS += trace-ust-all.h
67GENERATED_SOURCES += trace-ust-all.c
68endif
69
70GENERATED_HEADERS += module_block.h
71
72TRACE_HEADERS = trace-root.h $(trace-events-subdirs:%=%/trace.h)
73TRACE_SOURCES = trace-root.c $(trace-events-subdirs:%=%/trace.c)
74TRACE_DTRACE =
75ifdef CONFIG_TRACE_DTRACE
76TRACE_HEADERS += trace-dtrace-root.h $(trace-events-subdirs:%=%/trace-dtrace.h)
77TRACE_DTRACE += trace-dtrace-root.dtrace $(trace-events-subdirs:%=%/trace-dtrace.dtrace)
78endif
79ifdef CONFIG_TRACE_UST
80TRACE_HEADERS += trace-ust-root.h $(trace-events-subdirs:%=%/trace-ust.h)
81endif
82
83GENERATED_HEADERS += $(TRACE_HEADERS)
84GENERATED_SOURCES += $(TRACE_SOURCES)
85
86trace-group-name = $(shell dirname $1 | sed -e 's/[^a-zA-Z0-9]/_/g')
87
88%/trace.h: %/trace.h-timestamp
89	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
90%/trace.h-timestamp: $(SRC_PATH)/%/trace-events $(tracetool-y)
91	$(call quiet-command,$(TRACETOOL) \
92		--group=$(call trace-group-name,$@) \
93		--format=h \
94		--backends=$(TRACE_BACKENDS) \
95		$< > $@,"GEN","$(@:%-timestamp=%)")
96
97%/trace.c: %/trace.c-timestamp
98	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
99%/trace.c-timestamp: $(SRC_PATH)/%/trace-events $(tracetool-y)
100	$(call quiet-command,$(TRACETOOL) \
101		--group=$(call trace-group-name,$@) \
102		--format=c \
103		--backends=$(TRACE_BACKENDS) \
104		$< > $@,"GEN","$(@:%-timestamp=%)")
105
106%/trace-ust.h: %/trace-ust.h-timestamp
107	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
108%/trace-ust.h-timestamp: $(SRC_PATH)/%/trace-events $(tracetool-y)
109	$(call quiet-command,$(TRACETOOL) \
110		--group=$(call trace-group-name,$@) \
111		--format=ust-events-h \
112		--backends=$(TRACE_BACKENDS) \
113		$< > $@,"GEN","$(@:%-timestamp=%)")
114
115%/trace-dtrace.dtrace: %/trace-dtrace.dtrace-timestamp
116	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
117%/trace-dtrace.dtrace-timestamp: $(SRC_PATH)/%/trace-events $(BUILD_DIR)/config-host.mak $(tracetool-y)
118	$(call quiet-command,$(TRACETOOL) \
119		--group=$(call trace-group-name,$@) \
120		--format=d \
121		--backends=$(TRACE_BACKENDS) \
122		$< > $@,"GEN","$(@:%-timestamp=%)")
123
124%/trace-dtrace.h: %/trace-dtrace.dtrace $(tracetool-y)
125	$(call quiet-command,dtrace -o $@ -h -s $<, "GEN","$@")
126
127%/trace-dtrace.o: %/trace-dtrace.dtrace $(tracetool-y)
128
129
130trace-root.h: trace-root.h-timestamp
131	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
132trace-root.h-timestamp: $(SRC_PATH)/trace-events $(tracetool-y)
133	$(call quiet-command,$(TRACETOOL) \
134		--group=root \
135		--format=h \
136		--backends=$(TRACE_BACKENDS) \
137		$< > $@,"GEN","$(@:%-timestamp=%)")
138
139trace-root.c: trace-root.c-timestamp
140	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
141trace-root.c-timestamp: $(SRC_PATH)/trace-events $(tracetool-y)
142	$(call quiet-command,$(TRACETOOL) \
143		--group=root \
144		--format=c \
145		--backends=$(TRACE_BACKENDS) \
146		$< > $@,"GEN","$(@:%-timestamp=%)")
147
148trace-ust-root.h: trace-ust-root.h-timestamp
149	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
150trace-ust-root.h-timestamp: $(SRC_PATH)/trace-events $(tracetool-y)
151	$(call quiet-command,$(TRACETOOL) \
152		--group=root \
153		--format=ust-events-h \
154		--backends=$(TRACE_BACKENDS) \
155		$< > $@,"GEN","$(@:%-timestamp=%)")
156
157trace-ust-all.h: trace-ust-all.h-timestamp
158	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
159trace-ust-all.h-timestamp: $(trace-events-files) $(tracetool-y)
160	$(call quiet-command,$(TRACETOOL) \
161		--group=all \
162		--format=ust-events-h \
163		--backends=$(TRACE_BACKENDS) \
164		$(trace-events-files) > $@,"GEN","$(@:%-timestamp=%)")
165
166trace-ust-all.c: trace-ust-all.c-timestamp
167	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
168trace-ust-all.c-timestamp: $(trace-events-files) $(tracetool-y)
169	$(call quiet-command,$(TRACETOOL) \
170		--group=all \
171		--format=ust-events-c \
172		--backends=$(TRACE_BACKENDS) \
173		$(trace-events-files) > $@,"GEN","$(@:%-timestamp=%)")
174
175trace-dtrace-root.dtrace: trace-dtrace-root.dtrace-timestamp
176	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
177trace-dtrace-root.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak $(tracetool-y)
178	$(call quiet-command,$(TRACETOOL) \
179		--group=root \
180		--format=d \
181		--backends=$(TRACE_BACKENDS) \
182		$< > $@,"GEN","$(@:%-timestamp=%)")
183
184trace-dtrace-root.h: trace-dtrace-root.dtrace
185	$(call quiet-command,dtrace -o $@ -h -s $<, "GEN","$@")
186
187trace-dtrace-root.o: trace-dtrace-root.dtrace
188
189# Don't try to regenerate Makefile or configure
190# We don't generate any of them
191Makefile: ;
192configure: ;
193
194.PHONY: all clean cscope distclean html info install install-doc \
195	pdf txt recurse-all speed test dist msi FORCE
196
197$(call set-vpath, $(SRC_PATH))
198
199LIBS+=-lz $(LIBS_TOOLS)
200
201HELPERS-$(CONFIG_LINUX) = qemu-bridge-helper$(EXESUF)
202
203ifdef BUILD_DOCS
204DOCS=qemu-doc.html qemu-doc.txt qemu.1 qemu-img.1 qemu-nbd.8 qemu-ga.8
205DOCS+=docs/qemu-qmp-ref.html docs/qemu-qmp-ref.txt docs/qemu-qmp-ref.7
206DOCS+=docs/qemu-ga-ref.html docs/qemu-ga-ref.txt docs/qemu-ga-ref.7
207ifdef CONFIG_VIRTFS
208DOCS+=fsdev/virtfs-proxy-helper.1
209endif
210else
211DOCS=
212endif
213
214SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory) BUILD_DIR=$(BUILD_DIR)
215SUBDIR_DEVICES_MAK=$(patsubst %, %/config-devices.mak, $(TARGET_DIRS))
216SUBDIR_DEVICES_MAK_DEP=$(patsubst %, %-config-devices.mak.d, $(TARGET_DIRS))
217
218ifeq ($(SUBDIR_DEVICES_MAK),)
219config-all-devices.mak:
220	$(call quiet-command,echo '# no devices' > $@,"GEN","$@")
221else
222config-all-devices.mak: $(SUBDIR_DEVICES_MAK)
223	$(call quiet-command, sed -n \
224             's|^\([^=]*\)=\(.*\)$$|\1:=$$(findstring y,$$(\1)\2)|p' \
225             $(SUBDIR_DEVICES_MAK) | sort -u > $@, \
226             "GEN","$@")
227endif
228
229-include $(SUBDIR_DEVICES_MAK_DEP)
230
231%/config-devices.mak: default-configs/%.mak $(SRC_PATH)/scripts/make_device_config.sh
232	$(call quiet-command, \
233            $(SHELL) $(SRC_PATH)/scripts/make_device_config.sh $< $*-config-devices.mak.d $@ > $@.tmp,"GEN","$@.tmp")
234	$(call quiet-command, if test -f $@; then \
235	  if cmp -s $@.old $@; then \
236	    mv $@.tmp $@; \
237	    cp -p $@ $@.old; \
238	  else \
239	    if test -f $@.old; then \
240	      echo "WARNING: $@ (user modified) out of date.";\
241	    else \
242	      echo "WARNING: $@ out of date.";\
243	    fi; \
244	    echo "Run \"make defconfig\" to regenerate."; \
245	    rm $@.tmp; \
246	  fi; \
247	 else \
248	  mv $@.tmp $@; \
249	  cp -p $@ $@.old; \
250	 fi,"GEN","$@");
251
252defconfig:
253	rm -f config-all-devices.mak $(SUBDIR_DEVICES_MAK)
254
255ifneq ($(wildcard config-host.mak),)
256include $(SRC_PATH)/Makefile.objs
257endif
258
259dummy := $(call unnest-vars,, \
260                stub-obj-y \
261                util-obj-y \
262                qga-obj-y \
263                ivshmem-client-obj-y \
264                ivshmem-server-obj-y \
265                libvhost-user-obj-y \
266                qga-vss-dll-obj-y \
267                block-obj-y \
268                block-obj-m \
269                crypto-obj-y \
270                crypto-aes-obj-y \
271                qom-obj-y \
272                io-obj-y \
273                common-obj-y \
274                common-obj-m \
275                trace-obj-y)
276
277ifneq ($(wildcard config-host.mak),)
278include $(SRC_PATH)/tests/Makefile.include
279endif
280
281all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all modules
282
283qemu-version.h: FORCE
284	$(call quiet-command, \
285		(cd $(SRC_PATH); \
286		printf '#define QEMU_PKGVERSION '; \
287		if test -n "$(PKGVERSION)"; then \
288			printf '"$(PKGVERSION)"\n'; \
289		else \
290			if test -d .git; then \
291				printf '" ('; \
292				git describe --match 'v*' 2>/dev/null | tr -d '\n'; \
293				if ! git diff-index --quiet HEAD &>/dev/null; then \
294					printf -- '-dirty'; \
295				fi; \
296				printf ')"\n'; \
297			else \
298				printf '""\n'; \
299			fi; \
300		fi) > $@.tmp)
301	$(call quiet-command, cmp -s $@ $@.tmp || mv $@.tmp $@)
302
303config-host.h: config-host.h-timestamp
304config-host.h-timestamp: config-host.mak
305qemu-options.def: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool
306	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$@")
307
308SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_DIRS))
309SOFTMMU_SUBDIR_RULES=$(filter %-softmmu,$(SUBDIR_RULES))
310
311$(SOFTMMU_SUBDIR_RULES): $(block-obj-y)
312$(SOFTMMU_SUBDIR_RULES): $(crypto-obj-y)
313$(SOFTMMU_SUBDIR_RULES): $(io-obj-y)
314$(SOFTMMU_SUBDIR_RULES): config-all-devices.mak
315
316subdir-%:
317	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $* V="$(V)" TARGET_DIR="$*/" all,)
318
319subdir-pixman: pixman/Makefile
320	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C pixman V="$(V)" all,)
321
322pixman/Makefile: $(SRC_PATH)/pixman/configure
323	(cd pixman; CFLAGS="$(CFLAGS) -fPIC $(extra_cflags) $(extra_ldflags)" $(SRC_PATH)/pixman/configure $(AUTOCONF_HOST) --disable-gtk --disable-shared --enable-static)
324
325$(SRC_PATH)/pixman/configure:
326	(cd $(SRC_PATH)/pixman; autoreconf -v --install)
327
328DTC_MAKE_ARGS=-I$(SRC_PATH)/dtc VPATH=$(SRC_PATH)/dtc -C dtc V="$(V)" LIBFDT_srcdir=$(SRC_PATH)/dtc/libfdt
329DTC_CFLAGS=$(CFLAGS) $(QEMU_CFLAGS)
330DTC_CPPFLAGS=-I$(BUILD_DIR)/dtc -I$(SRC_PATH)/dtc -I$(SRC_PATH)/dtc/libfdt
331
332subdir-dtc:dtc/libfdt dtc/tests
333	$(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,)
334
335dtc/%:
336	mkdir -p $@
337
338$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY)) $(trace-obj-y)
339
340ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS))
341# Only keep -O and -g cflags
342romsubdir-%:
343	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C pc-bios/$* V="$(V)" TARGET_DIR="$*/" CFLAGS="$(filter -O% -g%,$(CFLAGS))",)
344
345ALL_SUBDIRS=$(TARGET_DIRS) $(patsubst %,pc-bios/%, $(ROMS))
346
347recurse-all: $(SUBDIR_RULES) $(ROMSUBDIR_RULES)
348
349$(BUILD_DIR)/version.o: $(SRC_PATH)/version.rc config-host.h
350	$(call quiet-command,$(WINDRES) -I$(BUILD_DIR) -o $@ $<,"RC","version.o")
351
352Makefile: $(version-obj-y)
353
354######################################################################
355# Build libraries
356
357libqemustub.a: $(stub-obj-y)
358libqemuutil.a: $(util-obj-y)
359
360######################################################################
361
362COMMON_LDADDS = $(trace-obj-y) libqemuutil.a libqemustub.a
363
364qemu-img.o: qemu-img-cmds.h
365
366qemu-img$(EXESUF): qemu-img.o $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
367qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
368qemu-io$(EXESUF): qemu-io.o $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
369
370qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS)
371
372fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS)
373fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap
374
375qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool
376	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$@")
377
378qemu-ga$(EXESUF): LIBS = $(LIBS_QGA)
379qemu-ga$(EXESUF): QEMU_CFLAGS += -I qga/qapi-generated
380
381gen-out-type = $(subst .,-,$(suffix $@))
382
383qapi-py = $(SRC_PATH)/scripts/qapi.py $(SRC_PATH)/scripts/ordereddict.py
384qapi-py += $(SRC_PATH)/scripts/qapi2texi.py
385
386qga/qapi-generated/qga-qapi-types.c qga/qapi-generated/qga-qapi-types.h :\
387$(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
388	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \
389		$(gen-out-type) -o qga/qapi-generated -p "qga-" $<, \
390		"GEN","$@")
391qga/qapi-generated/qga-qapi-visit.c qga/qapi-generated/qga-qapi-visit.h :\
392$(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
393	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py \
394		$(gen-out-type) -o qga/qapi-generated -p "qga-" $<, \
395		"GEN","$@")
396qga/qapi-generated/qga-qmp-commands.h qga/qapi-generated/qga-qmp-marshal.c :\
397$(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
398	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \
399		$(gen-out-type) -o qga/qapi-generated -p "qga-" $<, \
400		"GEN","$@")
401
402qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
403               $(SRC_PATH)/qapi/block.json $(SRC_PATH)/qapi/block-core.json \
404               $(SRC_PATH)/qapi/event.json $(SRC_PATH)/qapi/introspect.json \
405               $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \
406               $(SRC_PATH)/qapi/trace.json
407
408qapi-types.c qapi-types.h :\
409$(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
410	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \
411		$(gen-out-type) -o "." -b $<, \
412		"GEN","$@")
413qapi-visit.c qapi-visit.h :\
414$(qapi-modules) $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
415	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py \
416		$(gen-out-type) -o "." -b $<, \
417		"GEN","$@")
418qapi-event.c qapi-event.h :\
419$(qapi-modules) $(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
420	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \
421		$(gen-out-type) -o "." $<, \
422		"GEN","$@")
423qmp-commands.h qmp-marshal.c :\
424$(qapi-modules) $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
425	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \
426		$(gen-out-type) -o "." $<, \
427		"GEN","$@")
428qmp-introspect.h qmp-introspect.c :\
429$(qapi-modules) $(SRC_PATH)/scripts/qapi-introspect.py $(qapi-py)
430	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-introspect.py \
431		$(gen-out-type) -o "." $<, \
432		"GEN","$@")
433
434QGALIB_GEN=$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-visit.h qga-qmp-commands.h)
435$(qga-obj-y) qemu-ga.o: $(QGALIB_GEN)
436
437qemu-ga$(EXESUF): $(qga-obj-y) $(COMMON_LDADDS)
438	$(call LINK, $^)
439
440ifdef QEMU_GA_MSI_ENABLED
441QEMU_GA_MSI=qemu-ga-$(ARCH).msi
442
443msi: $(QEMU_GA_MSI)
444
445$(QEMU_GA_MSI): qemu-ga.exe $(QGA_VSS_PROVIDER)
446
447$(QEMU_GA_MSI): config-host.mak
448
449$(QEMU_GA_MSI):  $(SRC_PATH)/qga/installer/qemu-ga.wxs
450	$(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)" \
451	wixl -o $@ $(QEMU_GA_MSI_ARCH) $(QEMU_GA_MSI_WITH_VSS) $(QEMU_GA_MSI_MINGW_DLL_PATH) $<,"WIXL","$@")
452else
453msi:
454	@echo "MSI build not configured or dependency resolution failed (reconfigure with --enable-guest-agent-msi option)"
455endif
456
457ifneq ($(EXESUF),)
458.PHONY: qemu-ga
459qemu-ga: qemu-ga$(EXESUF) $(QGA_VSS_PROVIDER) $(QEMU_GA_MSI)
460endif
461
462ivshmem-client$(EXESUF): $(ivshmem-client-obj-y) $(COMMON_LDADDS)
463	$(call LINK, $^)
464ivshmem-server$(EXESUF): $(ivshmem-server-obj-y) $(COMMON_LDADDS)
465	$(call LINK, $^)
466
467module_block.h: $(SRC_PATH)/scripts/modules/module_block.py config-host.mak
468	$(call quiet-command,$(PYTHON) $< $@ \
469	$(addprefix $(SRC_PATH)/,$(patsubst %.mo,%.c,$(block-obj-m))), \
470	"GEN","$@")
471
472clean:
473# avoid old build problems by removing potentially incorrect old files
474	rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
475	rm -f qemu-options.def
476	rm -f *.msi
477	find . \( -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name '*.[oda]' \) -type f -exec rm {} +
478	rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
479	rm -f fsdev/*.pod
480	rm -f qemu-img-cmds.h
481	rm -f ui/shader/*-vert.h ui/shader/*-frag.h
482	@# May not be present in GENERATED_HEADERS
483	rm -f trace/generated-tracers-dtrace.dtrace*
484	rm -f trace/generated-tracers-dtrace.h*
485	rm -f $(foreach f,$(GENERATED_HEADERS),$(f) $(f)-timestamp)
486	rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp)
487	rm -rf qapi-generated
488	rm -rf qga/qapi-generated
489	for d in $(ALL_SUBDIRS); do \
490	if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
491	rm -f $$d/qemu-options.def; \
492        done
493	rm -f $(SUBDIR_DEVICES_MAK) config-all-devices.mak
494
495VERSION ?= $(shell cat VERSION)
496
497dist: qemu-$(VERSION).tar.bz2
498
499qemu-%.tar.bz2:
500	$(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)"
501
502distclean: clean
503	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
504	rm -f config-all-devices.mak config-all-disas.mak config.status
505	rm -f po/*.mo tests/qemu-iotests/common.env
506	rm -f roms/seabios/config.mak roms/vgabios/config.mak
507	rm -f qemu-doc.info qemu-doc.aux qemu-doc.cp qemu-doc.cps
508	rm -f qemu-doc.fn qemu-doc.fns qemu-doc.info qemu-doc.ky qemu-doc.kys
509	rm -f qemu-doc.log qemu-doc.pdf qemu-doc.pg qemu-doc.toc qemu-doc.tp
510	rm -f qemu-doc.vr qemu-doc.txt
511	rm -f config.log
512	rm -f linux-headers/asm
513	rm -f qemu-ga-qapi.texi qemu-qapi.texi
514	rm -f docs/qemu-qmp-ref.7 docs/qemu-ga-ref.7
515	rm -f docs/qemu-qmp-ref.txt docs/qemu-ga-ref.txt
516	rm -f docs/qemu-qmp-ref.pdf docs/qemu-ga-ref.pdf
517	rm -f docs/qemu-qmp-ref.html docs/qemu-ga-ref.html
518	for d in $(TARGET_DIRS); do \
519	rm -rf $$d || exit 1 ; \
520        done
521	rm -Rf .sdk
522	if test -f pixman/config.log; then $(MAKE) -C pixman distclean; fi
523	if test -f dtc/version_gen.h; then $(MAKE) $(DTC_MAKE_ARGS) clean; fi
524
525KEYMAPS=da     en-gb  et  fr     fr-ch  is  lt  modifiers  no  pt-br  sv \
526ar      de     en-us  fi  fr-be  hr     it  lv  nl         pl  ru     th \
527common  de-ch  es     fo  fr-ca  hu     ja  mk  nl-be      pt  sl     tr \
528bepo    cz
529
530ifdef INSTALL_BLOBS
531BLOBS=bios.bin bios-256k.bin sgabios.bin vgabios.bin vgabios-cirrus.bin \
532vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin vgabios-virtio.bin \
533acpi-dsdt.aml \
534ppc_rom.bin openbios-sparc32 openbios-sparc64 openbios-ppc QEMU,tcx.bin QEMU,cgthree.bin \
535pxe-e1000.rom pxe-eepro100.rom pxe-ne2k_pci.rom \
536pxe-pcnet.rom pxe-rtl8139.rom pxe-virtio.rom \
537efi-e1000.rom efi-eepro100.rom efi-ne2k_pci.rom \
538efi-pcnet.rom efi-rtl8139.rom efi-virtio.rom \
539efi-e1000e.rom efi-vmxnet3.rom \
540qemu-icon.bmp qemu_logo_no_text.svg \
541bamboo.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \
542multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin \
543s390-ccw.img \
544spapr-rtas.bin slof.bin skiboot.lid \
545palcode-clipper \
546u-boot.e500
547else
548BLOBS=
549endif
550
551install-doc: $(DOCS)
552	$(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)"
553	$(INSTALL_DATA) qemu-doc.html "$(DESTDIR)$(qemu_docdir)"
554	$(INSTALL_DATA) qemu-doc.txt "$(DESTDIR)$(qemu_docdir)"
555	$(INSTALL_DATA) docs/qemu-qmp-ref.html "$(DESTDIR)$(qemu_docdir)"
556	$(INSTALL_DATA) docs/qemu-qmp-ref.txt "$(DESTDIR)$(qemu_docdir)"
557ifdef CONFIG_POSIX
558	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1"
559	$(INSTALL_DATA) qemu.1 "$(DESTDIR)$(mandir)/man1"
560	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man7"
561	$(INSTALL_DATA) docs/qemu-qmp-ref.7 "$(DESTDIR)$(mandir)/man7"
562ifneq ($(TOOLS),)
563	$(INSTALL_DATA) qemu-img.1 "$(DESTDIR)$(mandir)/man1"
564	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man8"
565	$(INSTALL_DATA) qemu-nbd.8 "$(DESTDIR)$(mandir)/man8"
566endif
567ifneq (,$(findstring qemu-ga,$(TOOLS)))
568	$(INSTALL_DATA) qemu-ga.8 "$(DESTDIR)$(mandir)/man8"
569	$(INSTALL_DATA) docs/qemu-ga-ref.html "$(DESTDIR)$(qemu_docdir)"
570	$(INSTALL_DATA) docs/qemu-ga-ref.txt "$(DESTDIR)$(qemu_docdir)"
571	$(INSTALL_DATA) docs/qemu-ga-ref.7 "$(DESTDIR)$(mandir)/man7"
572endif
573endif
574ifdef CONFIG_VIRTFS
575	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1"
576	$(INSTALL_DATA) fsdev/virtfs-proxy-helper.1 "$(DESTDIR)$(mandir)/man1"
577endif
578
579install-datadir:
580	$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)"
581
582install-localstatedir:
583ifdef CONFIG_POSIX
584ifneq (,$(findstring qemu-ga,$(TOOLS)))
585	$(INSTALL_DIR) "$(DESTDIR)$(qemu_localstatedir)"/run
586endif
587endif
588
589
590install: all $(if $(BUILD_DOCS),install-doc) \
591install-datadir install-localstatedir
592ifneq ($(TOOLS),)
593	$(call install-prog,$(subst qemu-ga,qemu-ga$(EXESUF),$(TOOLS)),$(DESTDIR)$(bindir))
594endif
595ifneq ($(CONFIG_MODULES),)
596	$(INSTALL_DIR) "$(DESTDIR)$(qemu_moddir)"
597	for s in $(modules-m:.mo=$(DSOSUF)); do \
598		t="$(DESTDIR)$(qemu_moddir)/$$(echo $$s | tr / -)"; \
599		$(INSTALL_LIB) $$s "$$t"; \
600		test -z "$(STRIP)" || $(STRIP) "$$t"; \
601	done
602endif
603ifneq ($(HELPERS-y),)
604	$(call install-prog,$(HELPERS-y),$(DESTDIR)$(libexecdir))
605endif
606ifneq ($(BLOBS),)
607	set -e; for x in $(BLOBS); do \
608		$(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(qemu_datadir)"; \
609	done
610endif
611ifeq ($(CONFIG_GTK),y)
612	$(MAKE) -C po $@
613endif
614	$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps"
615	set -e; for x in $(KEYMAPS); do \
616		$(INSTALL_DATA) $(SRC_PATH)/pc-bios/keymaps/$$x "$(DESTDIR)$(qemu_datadir)/keymaps"; \
617	done
618	$(INSTALL_DATA) $(BUILD_DIR)/trace-events-all "$(DESTDIR)$(qemu_datadir)/trace-events-all"
619	for d in $(TARGET_DIRS); do \
620	$(MAKE) $(SUBDIR_MAKEFLAGS) TARGET_DIR=$$d/ -C $$d $@ || exit 1 ; \
621        done
622
623# various test targets
624test speed: all
625	$(MAKE) -C tests/tcg $@
626
627.PHONY: ctags
628ctags:
629	rm -f tags
630	find "$(SRC_PATH)" -name '*.[hc]' -exec ctags --append {} +
631
632.PHONY: TAGS
633TAGS:
634	rm -f TAGS
635	find "$(SRC_PATH)" -name '*.[hc]' -exec etags --append {} +
636
637cscope:
638	rm -f "$(SRC_PATH)"/cscope.*
639	find "$(SRC_PATH)/" -name "*.[chsS]" -print | sed 's,^\./,,' > "$(SRC_PATH)/cscope.files"
640	cscope -b -i"$(SRC_PATH)/cscope.files"
641
642# opengl shader programs
643ui/shader/%-vert.h: $(SRC_PATH)/ui/shader/%.vert $(SRC_PATH)/scripts/shaderinclude.pl
644	@mkdir -p $(dir $@)
645	$(call quiet-command,\
646		perl $(SRC_PATH)/scripts/shaderinclude.pl $< > $@,\
647		"VERT","$@")
648
649ui/shader/%-frag.h: $(SRC_PATH)/ui/shader/%.frag $(SRC_PATH)/scripts/shaderinclude.pl
650	@mkdir -p $(dir $@)
651	$(call quiet-command,\
652		perl $(SRC_PATH)/scripts/shaderinclude.pl $< > $@,\
653		"FRAG","$@")
654
655ui/console-gl.o: $(SRC_PATH)/ui/console-gl.c \
656	ui/shader/texture-blit-vert.h ui/shader/texture-blit-frag.h
657
658# documentation
659MAKEINFO=makeinfo
660MAKEINFOFLAGS=--no-split --number-sections -D 'VERSION $(VERSION)'
661TEXIFLAG=$(if $(V),,--quiet) --command='@set VERSION $(VERSION)'
662
663%.html: %.texi
664	$(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --no-headers \
665	--html $< -o $@,"GEN","$@")
666
667%.info: %.texi
668	$(call quiet-command,$(MAKEINFO) $(MAKEINFOFLAGS) $< -o $@,"GEN","$@")
669
670%.txt: %.texi
671	$(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --no-headers \
672	--plaintext $< -o $@,"GEN","$@")
673
674%.pdf: %.texi
675	$(call quiet-command,texi2pdf $(TEXIFLAG) -I $(SRC_PATH) -I . $< -o $@,"GEN","$@")
676
677qemu-options.texi: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool
678	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@")
679
680qemu-monitor.texi: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
681	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@")
682
683qemu-monitor-info.texi: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
684	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@")
685
686qemu-img-cmds.texi: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool
687	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@")
688
689qemu-qapi.texi: $(qapi-modules) $(qapi-py)
690	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi2texi.py $< > $@,"GEN","$@")
691
692qemu-ga-qapi.texi: $(SRC_PATH)/qga/qapi-schema.json $(qapi-py)
693	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi2texi.py $< > $@,"GEN","$@")
694
695qemu.1: qemu-doc.texi qemu-options.texi qemu-monitor.texi qemu-monitor-info.texi
696qemu.1: qemu-option-trace.texi
697qemu-img.1: qemu-img.texi qemu-option-trace.texi qemu-img-cmds.texi
698fsdev/virtfs-proxy-helper.1: fsdev/virtfs-proxy-helper.texi
699qemu-nbd.8: qemu-nbd.texi qemu-option-trace.texi
700qemu-ga.8: qemu-ga.texi
701
702html: qemu-doc.html docs/qemu-qmp-ref.html docs/qemu-ga-ref.html
703info: qemu-doc.info docs/qemu-qmp-ref.info docs/qemu-ga-ref.info
704pdf: qemu-doc.pdf docs/qemu-qmp-ref.pdf docs/qemu-ga-ref.pdf
705txt: qemu-doc.txt docs/qemu-qmp-ref.txt docs/qemu-ga-ref.txt
706
707qemu-doc.html qemu-doc.info qemu-doc.pdf qemu-doc.txt: \
708	qemu-img.texi qemu-nbd.texi qemu-options.texi qemu-option-trace.texi \
709	qemu-monitor.texi qemu-img-cmds.texi qemu-ga.texi \
710	qemu-monitor-info.texi
711
712docs/qemu-ga-ref.dvi docs/qemu-ga-ref.html docs/qemu-ga-ref.info docs/qemu-ga-ref.pdf docs/qemu-ga-ref.txt docs/qemu-ga-ref.7: \
713docs/qemu-ga-ref.texi qemu-ga-qapi.texi
714
715docs/qemu-qmp-ref.dvi docs/qemu-qmp-ref.html docs/qemu-qmp-ref.info docs/qemu-qmp-ref.pdf docs/qemu-qmp-ref.txt docs/qemu-qmp-ref.7: \
716docs/qemu-qmp-ref.texi qemu-qapi.texi
717
718
719ifdef CONFIG_WIN32
720
721INSTALLER = qemu-setup-$(VERSION)$(EXESUF)
722
723nsisflags = -V2 -NOCD
724
725ifneq ($(wildcard $(SRC_PATH)/dll),)
726ifeq ($(ARCH),x86_64)
727# 64 bit executables
728DLL_PATH = $(SRC_PATH)/dll/w64
729nsisflags += -DW64
730else
731# 32 bit executables
732DLL_PATH = $(SRC_PATH)/dll/w32
733endif
734endif
735
736.PHONY: installer
737installer: $(INSTALLER)
738
739INSTDIR=/tmp/qemu-nsis
740
741$(INSTALLER): $(SRC_PATH)/qemu.nsi
742	$(MAKE) install prefix=${INSTDIR}
743ifdef SIGNCODE
744	(cd ${INSTDIR}; \
745         for i in *.exe; do \
746           $(SIGNCODE) $${i}; \
747         done \
748        )
749endif # SIGNCODE
750	(cd ${INSTDIR}; \
751         for i in qemu-system-*.exe; do \
752           arch=$${i%.exe}; \
753           arch=$${arch#qemu-system-}; \
754           echo Section \"$$arch\" Section_$$arch; \
755           echo SetOutPath \"\$$INSTDIR\"; \
756           echo File \"\$${BINDIR}\\$$i\"; \
757           echo SectionEnd; \
758         done \
759        ) >${INSTDIR}/system-emulations.nsh
760	makensis $(nsisflags) \
761                $(if $(BUILD_DOCS),-DCONFIG_DOCUMENTATION="y") \
762                $(if $(CONFIG_GTK),-DCONFIG_GTK="y") \
763                -DBINDIR="${INSTDIR}" \
764                $(if $(DLL_PATH),-DDLLDIR="$(DLL_PATH)") \
765                -DSRCDIR="$(SRC_PATH)" \
766                -DOUTFILE="$(INSTALLER)" \
767                -DDISPLAYVERSION="$(VERSION)" \
768                $(SRC_PATH)/qemu.nsi
769	rm -r ${INSTDIR}
770ifdef SIGNCODE
771	$(SIGNCODE) $(INSTALLER)
772endif # SIGNCODE
773endif # CONFIG_WIN
774
775# Add a dependency on the generated files, so that they are always
776# rebuilt before other object files
777ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
778Makefile: $(GENERATED_HEADERS)
779endif
780
781.SECONDARY: $(TRACE_HEADERS) $(TRACE_HEADERS:%=%-timestamp) \
782	$(TRACE_SOURCES) $(TRACE_SOURCES:%=%-timestamp) \
783	$(TRACE_DTRACE) $(TRACE_DTRACE:%=%-timestamp)
784
785# Include automatically generated dependency files
786# Dependencies in Makefile.objs files come from our recursive subdir rules
787-include $(wildcard *.d tests/*.d)
788
789include $(SRC_PATH)/tests/docker/Makefile.include
790
791.PHONY: help
792help:
793	@echo  'Generic targets:'
794	@echo  '  all             - Build all'
795	@echo  '  dir/file.o      - Build specified target only'
796	@echo  '  install         - Install QEMU, documentation and tools'
797	@echo  '  ctags/TAGS      - Generate tags file for editors'
798	@echo  '  cscope          - Generate cscope index'
799	@echo  ''
800	@$(if $(TARGET_DIRS), \
801		echo 'Architecture specific targets:'; \
802		$(foreach t, $(TARGET_DIRS), \
803		printf "  %-30s - Build for %s\\n" $(patsubst %,subdir-%,$(t)) $(t);) \
804		echo '')
805	@echo  'Cleaning targets:'
806	@echo  '  clean           - Remove most generated files but keep the config'
807	@echo  '  distclean       - Remove all generated files'
808	@echo  '  dist            - Build a distributable tarball'
809	@echo  ''
810	@echo  'Test targets:'
811	@echo  '  check           - Run all tests (check-help for details)'
812	@echo  '  docker          - Help about targets running tests inside Docker containers'
813	@echo  ''
814	@echo  'Documentation targets:'
815	@echo  '  html info pdf txt'
816	@echo  '                  - Build documentation in specified format'
817	@echo  ''
818ifdef CONFIG_WIN32
819	@echo  'Windows targets:'
820	@echo  '  installer       - Build NSIS-based installer for QEMU'
821ifdef QEMU_GA_MSI_ENABLED
822	@echo  '  msi             - Build MSI-based installer for qemu-ga'
823endif
824	@echo  ''
825endif
826	@echo  '  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
827