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 help check-help print-% \ 15 docker docker-% vm-help vm-test vm-build-% 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 51export NINJA=./ninjatool 52 53# Running meson regenerates both build.ninja and ninjatool, and that is 54# enough to prime the rest of the build. 55ninjatool: build.ninja 56 57# Only needed in case Makefile.ninja does not exist. 58.PHONY: ninja-clean ninja-distclean clean-ctlist 59clean-ctlist: 60ninja-clean:: 61ninja-distclean:: 62build.ninja: config-host.mak 63 64Makefile.ninja: build.ninja ninjatool 65 ./ninjatool -t ninja2make --omit clean dist uninstall < $< > $@ 66-include Makefile.ninja 67 68${ninja-targets-c_COMPILER} ${ninja-targets-cpp_COMPILER}: .var.command += -MP 69 70# If MESON is empty, the rule will be re-evaluated after Makefiles are 71# reread (and MESON won't be empty anymore). 72ifneq ($(MESON),) 73Makefile.mtest: build.ninja scripts/mtest2make.py 74 $(MESON) introspect --tests | $(PYTHON) scripts/mtest2make.py > $@ 75-include Makefile.mtest 76endif 77 78.git-submodule-status: git-submodule-update config-host.mak 79 80# Check that we're not trying to do an out-of-tree build from 81# a tree that's been used for an in-tree build. 82ifneq ($(realpath $(SRC_PATH)),$(realpath .)) 83ifneq ($(wildcard $(SRC_PATH)/config-host.mak),) 84$(error This is an out of tree build but your source tree ($(SRC_PATH)) \ 85seems to have been used for an in-tree build. You can fix this by running \ 86"$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source tree) 87endif 88endif 89 90CONFIG_SOFTMMU := $(if $(filter %-softmmu,$(TARGET_DIRS)),y) 91CONFIG_USER_ONLY := $(if $(filter %-user,$(TARGET_DIRS)),y) 92CONFIG_XEN := $(CONFIG_XEN_BACKEND) 93CONFIG_ALL=y 94-include config-all-devices.mak 95-include config-all-disas.mak 96 97config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION 98 @echo $@ is out-of-date, running configure 99 @if test -f meson-private/coredata.dat; then \ 100 ./config.status --skip-meson; \ 101 else \ 102 ./config.status; \ 103 fi 104 105# Force configure to re-run if the API symbols are updated 106ifeq ($(CONFIG_PLUGIN),y) 107config-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols 108endif 109 110else 111config-host.mak: 112ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail)) 113 @echo "Please call configure before running make!" 114 @exit 1 115endif 116endif 117 118include $(SRC_PATH)/rules.mak 119 120# lor is defined in rules.mak 121CONFIG_BLOCK := $(call lor,$(CONFIG_SOFTMMU),$(CONFIG_TOOLS)) 122 123generated-files-y += .git-submodule-status 124 125# Don't try to regenerate Makefile or configure 126# We don't generate any of them 127Makefile: ; 128configure: ; 129 130.PHONY: all clean cscope distclean install \ 131 recurse-all dist msi FORCE 132 133$(call set-vpath, $(SRC_PATH)) 134 135LIBS+=-lz $(LIBS_TOOLS) 136 137SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet) BUILD_DIR=$(BUILD_DIR) 138 139ifneq ($(wildcard config-host.mak),) 140include $(SRC_PATH)/Makefile.objs 141endif 142 143include $(SRC_PATH)/tests/Makefile.include 144 145all: recurse-all modules 146 147# LIBFDT_lib="": avoid breaking existing trees with objects requiring -fPIC 148DTC_MAKE_ARGS=-I$(SRC_PATH)/dtc VPATH=$(SRC_PATH)/dtc -C dtc V="$(V)" LIBFDT_lib="" 149DTC_CFLAGS=$(CFLAGS) $(QEMU_CFLAGS) 150DTC_CPPFLAGS=-I$(SRC_PATH)/dtc/libfdt 151 152.PHONY: dtc/all 153dtc/all: .git-submodule-status dtc/libfdt 154 $(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,) 155 156dtc/%: .git-submodule-status 157 @mkdir -p $@ 158 159# Overriding CFLAGS causes us to lose defines added in the sub-makefile. 160# Not overriding CFLAGS leads to mis-matches between compilation modes. 161# Therefore we replicate some of the logic in the sub-makefile. 162# Remove all the extra -Warning flags that QEMU uses that Capstone doesn't; 163# no need to annoy QEMU developers with such things. 164CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) 165CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM 166CAP_CFLAGS += -DCAPSTONE_HAS_ARM 167CAP_CFLAGS += -DCAPSTONE_HAS_ARM64 168CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC 169CAP_CFLAGS += -DCAPSTONE_HAS_X86 170 171.PHONY: capstone/all 172capstone/all: .git-submodule-status 173 $(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)) 174 175.PHONY: slirp/all 176slirp/all: .git-submodule-status 177 $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp \ 178 BUILD_DIR="$(BUILD_DIR)/slirp" \ 179 PKG_CONFIG="$(PKG_CONFIG)" \ 180 CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" \ 181 CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)") 182 183ROM_DIRS = $(addprefix pc-bios/, $(ROMS)) 184ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS))) 185# Only keep -O and -g cflags 186.PHONY: $(ROM_DIRS_RULES) 187$(ROM_DIRS_RULES): 188 $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" CFLAGS="$(filter -O% -g%,$(CFLAGS))" $(notdir $@),) 189 190.PHONY: recurse-all recurse-clean 191recurse-all: $(ROM_DIRS) 192recurse-clean: $(addsuffix /clean, $(ROM_DIRS)) 193 194###################################################################### 195 196clean: recurse-clean ninja-clean clean-ctlist 197 -test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean 198# avoid old build problems by removing potentially incorrect old files 199 rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h 200 find . \( -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name '*.[oda]' \) -type f \ 201 ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \ 202 ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \ 203 ! -path ./roms/edk2/BaseTools/Source/Python/UPT/Dll/sqlite3.dll \ 204 -exec rm {} + 205 rm -f TAGS cscope.* *.pod *~ */*~ 206 rm -f fsdev/*.pod scsi/*.pod 207 rm -f $(foreach f,$(generated-files-y),$(f) $(f)-timestamp) 208 209VERSION ?= $(shell cat VERSION) 210 211dist: qemu-$(VERSION).tar.bz2 212 213qemu-%.tar.bz2: 214 $(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)" 215 216distclean: clean ninja-distclean 217 -test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean -g 218 rm -f config-host.mak config-host.h* 219 rm -f tests/tcg/config-*.mak 220 rm -f config-all-disas.mak config.status 221 rm -f po/*.mo tests/qemu-iotests/common.env 222 rm -f roms/seabios/config.mak roms/vgabios/config.mak 223 rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols 224 rm -f *-config-target.h *-config-devices.mak *-config-devices.h 225 rm -rf meson-private meson-logs meson-info compile_commands.json 226 rm -f Makefile.ninja ninjatool ninjatool.stamp Makefile.mtest 227 rm -f config.log 228 rm -f linux-headers/asm 229 rm -Rf .sdk 230 231KEYMAPS=da en-gb et fr fr-ch is lt no pt-br sv \ 232ar de en-us fi fr-be hr it lv nl pl ru th \ 233de-ch es fo fr-ca hu ja mk pt sl tr \ 234bepo cz 235 236ifdef INSTALL_BLOBS 237BLOBS=bios.bin bios-256k.bin bios-microvm.bin sgabios.bin vgabios.bin vgabios-cirrus.bin \ 238vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin vgabios-virtio.bin \ 239vgabios-ramfb.bin vgabios-bochs-display.bin vgabios-ati.bin \ 240openbios-sparc32 openbios-sparc64 openbios-ppc QEMU,tcx.bin QEMU,cgthree.bin \ 241pxe-e1000.rom pxe-eepro100.rom pxe-ne2k_pci.rom \ 242pxe-pcnet.rom pxe-rtl8139.rom pxe-virtio.rom \ 243efi-e1000.rom efi-eepro100.rom efi-ne2k_pci.rom \ 244efi-pcnet.rom efi-rtl8139.rom efi-virtio.rom \ 245efi-e1000e.rom efi-vmxnet3.rom \ 246qemu-nsis.bmp \ 247bamboo.dtb canyonlands.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \ 248multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin \ 249s390-ccw.img s390-netboot.img \ 250slof.bin skiboot.lid \ 251palcode-clipper \ 252u-boot.e500 u-boot-sam460-20100605.bin \ 253qemu_vga.ndrv \ 254edk2-licenses.txt \ 255hppa-firmware.img \ 256opensbi-riscv32-sifive_u-fw_jump.bin opensbi-riscv32-virt-fw_jump.bin \ 257opensbi-riscv64-sifive_u-fw_jump.bin opensbi-riscv64-virt-fw_jump.bin 258else 259BLOBS= 260endif 261 262install-datadir: 263 $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)" 264 265install-localstatedir: 266ifdef CONFIG_POSIX 267ifeq ($(CONFIG_GUEST_AGENT),y) 268 $(INSTALL_DIR) "$(DESTDIR)$(qemu_localstatedir)"/run 269endif 270endif 271 272ICON_SIZES=16x16 24x24 32x32 48x48 64x64 128x128 256x256 512x512 273 274# Needed by "meson install" 275export DESTDIR 276install: all install-datadir install-localstatedir 277ifdef CONFIG_TRACE_SYSTEMTAP 278 $(INSTALL_PROG) "scripts/qemu-trace-stap" $(DESTDIR)$(bindir) 279endif 280ifneq ($(BLOBS),) 281 set -e; for x in $(BLOBS); do \ 282 $(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(qemu_datadir)"; \ 283 done 284endif 285 for s in $(ICON_SIZES); do \ 286 mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/$${s}/apps"; \ 287 $(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu_$${s}.png \ 288 "$(DESTDIR)$(qemu_icondir)/hicolor/$${s}/apps/qemu.png"; \ 289 done; \ 290 mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/32x32/apps"; \ 291 $(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu_32x32.bmp \ 292 "$(DESTDIR)$(qemu_icondir)/hicolor/32x32/apps/qemu.bmp"; \ 293 mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/scalable/apps"; \ 294 $(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu.svg \ 295 "$(DESTDIR)$(qemu_icondir)/hicolor/scalable/apps/qemu.svg" 296 mkdir -p "$(DESTDIR)$(qemu_desktopdir)" 297 $(INSTALL_DATA) $(SRC_PATH)/ui/qemu.desktop \ 298 "$(DESTDIR)$(qemu_desktopdir)/qemu.desktop" 299ifdef CONFIG_GTK 300 $(MAKE) -C po $@ 301endif 302 $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps" 303 set -e; for x in $(KEYMAPS); do \ 304 $(INSTALL_DATA) $(SRC_PATH)/pc-bios/keymaps/$$x "$(DESTDIR)$(qemu_datadir)/keymaps"; \ 305 done 306 307ifdef CONFIG_WIN32 308 309INSTALLER = qemu-setup-$(VERSION)$(EXESUF) 310 311nsisflags = -V2 -NOCD 312 313ifneq ($(wildcard $(SRC_PATH)/dll),) 314ifeq ($(ARCH),x86_64) 315# 64 bit executables 316DLL_PATH = $(SRC_PATH)/dll/w64 317nsisflags += -DW64 318else 319# 32 bit executables 320DLL_PATH = $(SRC_PATH)/dll/w32 321endif 322endif 323 324.PHONY: installer 325installer: $(INSTALLER) 326 327INSTDIR=/tmp/qemu-nsis 328 329$(INSTALLER): $(SRC_PATH)/qemu.nsi 330 $(MAKE) install DESTDIR=${INSTDIR} 331ifdef SIGNCODE 332 (cd ${INSTDIR}/${bindir}; \ 333 for i in *.exe; do \ 334 $(SIGNCODE) $${i}; \ 335 done \ 336 ) 337endif # SIGNCODE 338 (cd ${INSTDIR}/${bindir}; \ 339 for i in qemu-system-*.exe; do \ 340 arch=$${i%.exe}; \ 341 arch=$${arch#qemu-system-}; \ 342 echo Section \"$$arch\" Section_$$arch; \ 343 echo SetOutPath \"\$$INSTDIR\"; \ 344 echo File \"\$${BINDIR}\\$$i\"; \ 345 echo SectionEnd; \ 346 done \ 347 ) >${INSTDIR}/${bindir}/system-emulations.nsh 348 makensis $(nsisflags) \ 349 $(if $(BUILD_DOCS),-DCONFIG_DOCUMENTATION="y") \ 350 $(if $(CONFIG_GTK),-DCONFIG_GTK="y") \ 351 -DBINDIR="${INSTDIR}/${bindir}" \ 352 $(if $(DLL_PATH),-DDLLDIR="$(DLL_PATH)") \ 353 -DSRCDIR="$(SRC_PATH)" \ 354 -DOUTFILE="$(INSTALLER)" \ 355 -DDISPLAYVERSION="$(VERSION)" \ 356 $(SRC_PATH)/qemu.nsi 357 rm -r ${INSTDIR} 358ifdef SIGNCODE 359 $(SIGNCODE) $(INSTALLER) 360endif # SIGNCODE 361endif # CONFIG_WIN 362 363# Add a dependency on the generated files, so that they are always 364# rebuilt before other object files 365ifneq ($(wildcard config-host.mak),) 366ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail)) 367Makefile: $(generated-files-y) 368endif 369endif 370 371# Include automatically generated dependency files 372# Dependencies in Makefile.objs files come from our recursive subdir rules 373-include $(wildcard *.d tests/*.d) 374 375include $(SRC_PATH)/tests/docker/Makefile.include 376include $(SRC_PATH)/tests/vm/Makefile.include 377 378print-help-run = printf " %-30s - %s\\n" "$1" "$2" 379print-help = $(quiet-@)$(call print-help-run,$1,$2) 380 381.PHONY: help 382help: 383 @echo 'Generic targets:' 384 $(call print-help,all,Build all) 385ifdef CONFIG_MODULES 386 $(call print-help,modules,Build all modules) 387endif 388 $(call print-help,dir/file.o,Build specified target only) 389 $(call print-help,install,Install QEMU, documentation and tools) 390 $(call print-help,ctags/TAGS,Generate tags file for editors) 391 $(call print-help,cscope,Generate cscope index) 392 $(call print-help,sparse,Run sparse on the QEMU source) 393 @echo '' 394 @echo 'Cleaning targets:' 395 $(call print-help,clean,Remove most generated files but keep the config) 396 $(call print-help,distclean,Remove all generated files) 397 $(call print-help,dist,Build a distributable tarball) 398 @echo '' 399 @echo 'Test targets:' 400 $(call print-help,check,Run all tests (check-help for details)) 401 $(call print-help,docker,Help about targets running tests inside containers) 402 $(call print-help,vm-help,Help about targets running tests inside VM) 403 @echo '' 404 @echo 'Documentation targets:' 405 $(call print-help,html info pdf txt man,Build documentation in specified format) 406 @echo '' 407ifdef CONFIG_WIN32 408 @echo 'Windows targets:' 409 $(call print-help,installer,Build NSIS-based installer for QEMU) 410ifdef QEMU_GA_MSI_ENABLED 411 $(call print-help,msi,Build MSI-based installer for qemu-ga) 412endif 413 @echo '' 414endif 415 $(call print-help,$(MAKE) [targets],(quiet build, default)) 416 $(call print-help,$(MAKE) V=1 [targets],(verbose build)) 417