3 ifneq ($(words $(subst :, ,$(CURDIR))), 1)
4 $(error main directory cannot contain spaces nor colons)
7 # Always point to the root of the build tree (needs GNU make).
10 # Before including a proper config-host.mak, assume we are in the source tree
13 # Don't use implicit rules or variables
14 # we have explicit rules for everything
17 SHELL = /usr/bin/env bash -o pipefail
19 # Usage: $(call quiet-command,command and args,"NAME","args to print")
20 # This will run "command and args", and either:
21 # if V=1 just print the whole command and args
22 # otherwise print the 'quiet' output in the format " NAME args to print"
23 # NAME should be a short name of the command, 7 letters or fewer.
24 # If called with only a single argument, will print nothing in quiet mode.
25 quiet-command-run = $(if $(V),,$(if $2,printf " %-7s %s\n" $2 $3 && ))$1
26 quiet-@ = $(if $(V),,@)
27 quiet-command = $(quiet-@)$(call quiet-command-run,$1,$2,$3)
29 UNCHECKED_GOALS := %clean TAGS cscope ctags dist \
30 help check-help print-% \
31 docker docker-% vm-help vm-test vm-build-%
34 .PHONY: all clean distclean recurse-all dist msi FORCE
36 # Don't try to regenerate Makefile or configure
37 # We don't generate any of them
41 # All following code might depend on configuration variables
42 ifneq ($(wildcard config-host.mak),)
43 include config-host.mak
46 .git-submodule-status: git-submodule-update config-host.mak
47 Makefile: .git-submodule-status
49 .PHONY: git-submodule-update
51 git_module_status := $(shell \
53 GIT="$(GIT)" ./scripts/git-submodule.sh status $(GIT_SUBMODULES); \
57 ifeq (1,$(git_module_status))
58 ifeq (no,$(GIT_UPDATE))
60 $(call quiet-command, \
62 echo "GIT submodule checkout is out of date. Please run" && \
63 echo " scripts/git-submodule.sh update $(GIT_SUBMODULES)" && \
64 echo "from the source directory checkout $(SRC_PATH)" && \
69 $(call quiet-command, \
70 (cd $(SRC_PATH) && GIT="$(GIT)" ./scripts/git-submodule.sh update $(GIT_SUBMODULES)), \
71 "GIT","$(GIT_SUBMODULES)")
75 export NINJA=./ninjatool
77 # Running meson regenerates both build.ninja and ninjatool, and that is
78 # enough to prime the rest of the build.
79 ninjatool: build.ninja
81 Makefile.ninja: build.ninja ninjatool
82 ./ninjatool -t ninja2make --omit clean dist uninstall cscope TAGS ctags < $< > $@
83 -include Makefile.ninja
85 ${ninja-targets-c_COMPILER} ${ninja-targets-cpp_COMPILER}: .var.command += -MP
87 # If MESON is empty, the rule will be re-evaluated after Makefiles are
88 # reread (and MESON won't be empty anymore).
90 Makefile.mtest: build.ninja scripts/mtest2make.py
91 $(MESON) introspect --targets --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@
92 -include Makefile.mtest
95 # Ensure the build tree is okay.
96 # Check that we're not trying to do an out-of-tree build from
97 # a tree that's been used for an in-tree build.
98 ifneq ($(realpath $(SRC_PATH)),$(realpath .))
99 ifneq ($(wildcard $(SRC_PATH)/config-host.mak),)
100 $(error This is an out of tree build but your source tree ($(SRC_PATH)) \
101 seems to have been used for an in-tree build. You can fix this by running \
102 "$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source tree)
106 # force a rerun of configure if config-host.mak is too old or corrupted
108 .PHONY: config-host.mak
109 x := $(shell rm -rf meson-private meson-info meson-logs)
112 .PHONY: config-host.mak
113 x := $(shell rm -rf meson-private meson-info meson-logs)
115 ifeq ($(wildcard build.ninja),)
116 .PHONY: config-host.mak
117 x := $(shell rm -rf meson-private meson-info meson-logs)
120 config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
121 @echo $@ is out-of-date, running configure
122 @if test -f meson-private/coredata.dat; then \
123 ./config.status --skip-meson; \
128 # Force configure to re-run if the API symbols are updated
129 ifeq ($(CONFIG_PLUGIN),y)
130 config-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols
134 $(call quiet-command,\
135 $(MAKE) $(SUBDIR_MAKEFLAGS) -C contrib/plugins V="$(V)", \
136 "BUILD", "example plugins")
137 endif # $(CONFIG_PLUGIN)
139 else # config-host.mak does not exist
141 ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
142 @echo "Please call configure before running make!"
145 endif # config-host.mak does not exist
147 # Only needed in case Makefile.ninja does not exist.
148 .PHONY: ninja-clean ninja-distclean clean-ctlist
152 build.ninja: config-host.mak
154 SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet)
156 include $(SRC_PATH)/tests/Makefile.include
160 ROM_DIRS = $(addprefix pc-bios/, $(ROMS))
161 ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS)))
162 # Only keep -O and -g cflags
163 .PHONY: $(ROM_DIRS_RULES)
165 $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" $(notdir $@),)
167 .PHONY: recurse-all recurse-clean
168 recurse-all: $(addsuffix /all, $(ROM_DIRS))
169 recurse-clean: $(addsuffix /clean, $(ROM_DIRS))
171 ######################################################################
173 clean: recurse-clean ninja-clean clean-ctlist
174 if test -f ninjatool; then ./ninjatool $(if $(V),-v,) -t clean; fi
175 # avoid old build problems by removing potentially incorrect old files
176 rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
177 find . \( -name '*.so' -o -name '*.dll' -o -name '*.[oda]' \) -type f \
178 ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \
179 ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \
181 rm -f TAGS cscope.* *.pod *~ */*~
182 rm -f fsdev/*.pod scsi/*.pod
184 VERSION = $(shell cat $(SRC_PATH)/VERSION)
186 dist: qemu-$(VERSION).tar.bz2
189 $(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)"
191 distclean: clean ninja-distclean
192 -test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean -g
193 rm -f config-host.mak config-host.h*
194 rm -f tests/tcg/config-*.mak
195 rm -f config-all-disas.mak config.status
196 rm -f tests/qemu-iotests/common.env
197 rm -f roms/seabios/config.mak roms/vgabios/config.mak
198 rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols
199 rm -f *-config-target.h *-config-devices.mak *-config-devices.h
200 rm -rf meson-private meson-logs meson-info compile_commands.json
201 rm -f Makefile.ninja ninjatool ninjatool.stamp Makefile.mtest
203 rm -f linux-headers/asm
206 find-src-path = find "$(SRC_PATH)/" -path "$(SRC_PATH)/meson" -prune -o -name "*.[chsS]"
210 rm -f "$(SRC_PATH)/"tags
211 $(find-src-path) -exec ctags -f "$(SRC_PATH)/"tags --append {} +
215 rm -f "$(SRC_PATH)/"TAGS
216 $(find-src-path) -exec etags -f "$(SRC_PATH)/"TAGS --append {} +
220 rm -f "$(SRC_PATH)"/cscope.*
221 $(find-src-path) -print | sed -e 's,^\./,,' > "$(SRC_PATH)/cscope.files"
222 cscope -b -i"$(SRC_PATH)/cscope.files" -f"$(SRC_PATH)"/cscope.out
224 # Needed by "meson install"
227 include $(SRC_PATH)/tests/docker/Makefile.include
228 include $(SRC_PATH)/tests/vm/Makefile.include
230 print-help-run = printf " %-30s - %s\\n" "$1" "$2"
231 print-help = $(quiet-@)$(call print-help-run,$1,$2)
235 @echo 'Generic targets:'
236 $(call print-help,all,Build all)
237 $(call print-help,dir/file.o,Build specified target only)
238 $(call print-help,install,Install QEMU, documentation and tools)
239 $(call print-help,ctags/TAGS,Generate tags file for editors)
240 $(call print-help,cscope,Generate cscope index)
241 $(call print-help,sparse,Run sparse on the QEMU source)
243 ifeq ($(CONFIG_PLUGIN),y)
244 @echo 'Plugin targets:'
245 $(call print-help,plugins,Build the example TCG plugins)
248 @echo 'Cleaning targets:'
249 $(call print-help,clean,Remove most generated files but keep the config)
250 $(call print-help,distclean,Remove all generated files)
251 $(call print-help,dist,Build a distributable tarball)
253 @echo 'Test targets:'
254 $(call print-help,check,Run all tests (check-help for details))
255 $(call print-help,bench,Run all benchmarks)
256 $(call print-help,docker,Help about targets running tests inside containers)
257 $(call print-help,vm-help,Help about targets running tests inside VM)
259 @echo 'Documentation targets:'
260 $(call print-help,html man,Build documentation in specified format)
263 @echo 'Windows targets:'
264 $(call print-help,installer,Build NSIS-based installer for QEMU)
266 $(call print-help,msi,Build MSI-based installer for qemu-ga)
270 $(call print-help,$(MAKE) [targets],(quiet build, default))
271 $(call print-help,$(MAKE) V=1 [targets],(verbose build))
273 # will delete the target of a rule if commands exit with a nonzero exit status