10cb3fb1eSpbrook# Makefile for QEMU. 20cb3fb1eSpbrook 34ace32e2SAntonio Ospiteifneq ($(words $(subst :, ,$(CURDIR))), 1) 44ace32e2SAntonio Ospite $(error main directory cannot contain spaces nor colons) 54ace32e2SAntonio Ospiteendif 64ace32e2SAntonio Ospite 7519e1693SStefan Weil# Always point to the root of the build tree (needs GNU make). 8519e1693SStefan WeilBUILD_DIR=$(CURDIR) 9388d4758SLluís Vilanova 10eaa2ddbbSFam Zheng# Before including a proper config-host.mak, assume we are in the source tree 11eaa2ddbbSFam ZhengSRC_PATH=. 12eaa2ddbbSFam Zheng 13660f7930SPaolo Bonzini# Don't use implicit rules or variables 14660f7930SPaolo Bonzini# we have explicit rules for everything 15660f7930SPaolo BonziniMAKEFLAGS += -rR 16660f7930SPaolo Bonzini 17660f7930SPaolo Bonzini# Usage: $(call quiet-command,command and args,"NAME","args to print") 18660f7930SPaolo Bonzini# This will run "command and args", and either: 19660f7930SPaolo Bonzini# if V=1 just print the whole command and args 20660f7930SPaolo Bonzini# otherwise print the 'quiet' output in the format " NAME args to print" 21660f7930SPaolo Bonzini# NAME should be a short name of the command, 7 letters or fewer. 22660f7930SPaolo Bonzini# If called with only a single argument, will print nothing in quiet mode. 23660f7930SPaolo Bonziniquiet-command-run = $(if $(V),,$(if $2,printf " %-7s %s\n" $2 $3 && ))$1 24660f7930SPaolo Bonziniquiet-@ = $(if $(V),,@) 25660f7930SPaolo Bonziniquiet-command = $(quiet-@)$(call quiet-command-run,$1,$2,$3) 26660f7930SPaolo Bonzini 2728fa2927SPhilippe Mathieu-DaudéUNCHECKED_GOALS := %clean TAGS cscope ctags dist \ 28de1da442SMarc-André Lureau help check-help print-% \ 294f2f6276SPhilippe Mathieu-Daudé docker docker-% vm-help vm-test vm-build-% 30eaa2ddbbSFam Zheng 31250b086eSLluís Vilanova# All following code might depend on configuration variables 3255d7e8f6Saurel32ifneq ($(wildcard config-host.mak),) 331ad2134fSPaul Brook# Put the all: rule here so that config-host.mak can contain dependencies. 348f67aa82SStefan Weilall: 35ad064840Spbrookinclude config-host.mak 36d1bd2423SPeter Maydell 37aef45d51SDaniel P. Berrangegit-submodule-update: 38aef45d51SDaniel P. Berrange 39aef45d51SDaniel P. Berrange.PHONY: git-submodule-update 40aef45d51SDaniel P. Berrange 41aef45d51SDaniel P. Berrangegit_module_status := $(shell \ 42aef45d51SDaniel P. Berrange cd '$(SRC_PATH)' && \ 43cc84d63aSDaniel P. Berrange GIT="$(GIT)" ./scripts/git-submodule.sh status $(GIT_SUBMODULES); \ 44aef45d51SDaniel P. Berrange echo $$?; \ 45aef45d51SDaniel P. Berrange) 46aef45d51SDaniel P. Berrange 47aef45d51SDaniel P. Berrangeifeq (1,$(git_module_status)) 48f62bbee5SDaniel P. Berrangeifeq (no,$(GIT_UPDATE)) 49f62bbee5SDaniel P. Berrangegit-submodule-update: 50f62bbee5SDaniel P. Berrange $(call quiet-command, \ 51f62bbee5SDaniel P. Berrange echo && \ 52f62bbee5SDaniel P. Berrange echo "GIT submodule checkout is out of date. Please run" && \ 53f62bbee5SDaniel P. Berrange echo " scripts/git-submodule.sh update $(GIT_SUBMODULES)" && \ 54f62bbee5SDaniel P. Berrange echo "from the source directory checkout $(SRC_PATH)" && \ 55f62bbee5SDaniel P. Berrange echo && \ 56f62bbee5SDaniel P. Berrange exit 1) 57f62bbee5SDaniel P. Berrangeelse 58aef45d51SDaniel P. Berrangegit-submodule-update: 59aef45d51SDaniel P. Berrange $(call quiet-command, \ 60cc84d63aSDaniel P. Berrange (cd $(SRC_PATH) && GIT="$(GIT)" ./scripts/git-submodule.sh update $(GIT_SUBMODULES)), \ 61aef45d51SDaniel P. Berrange "GIT","$(GIT_SUBMODULES)") 62aef45d51SDaniel P. Berrangeendif 63aef45d51SDaniel P. Berrangeendif 64aef45d51SDaniel P. Berrange 65a5665051SPaolo Bonziniexport NINJA=./ninjatool 66a5665051SPaolo Bonzini 67a5665051SPaolo Bonzini# Running meson regenerates both build.ninja and ninjatool, and that is 68a5665051SPaolo Bonzini# enough to prime the rest of the build. 69a5665051SPaolo Bonzinininjatool: build.ninja 70a5665051SPaolo Bonzini 71a5665051SPaolo BonziniMakefile.ninja: build.ninja ninjatool 72d7986405SGreg Kurz ./ninjatool -t ninja2make --omit clean dist uninstall cscope TAGS ctags < $< > $@ 73a5665051SPaolo Bonzini-include Makefile.ninja 74a5665051SPaolo Bonzini 75a5665051SPaolo Bonzini${ninja-targets-c_COMPILER} ${ninja-targets-cpp_COMPILER}: .var.command += -MP 76a5665051SPaolo Bonzini 77245dac4aSPaolo Bonzini# If MESON is empty, the rule will be re-evaluated after Makefiles are 78245dac4aSPaolo Bonzini# reread (and MESON won't be empty anymore). 79245dac4aSPaolo Bonziniifneq ($(MESON),) 80245dac4aSPaolo BonziniMakefile.mtest: build.ninja scripts/mtest2make.py 819ed7247aSPaolo Bonzini $(MESON) introspect --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@ 82245dac4aSPaolo Bonzini-include Makefile.mtest 83245dac4aSPaolo Bonziniendif 84245dac4aSPaolo Bonzini 85660f7930SPaolo BonziniMakefile: .git-submodule-status 8692712822SDaniel P. Berrange.git-submodule-status: git-submodule-update config-host.mak 87aef45d51SDaniel P. Berrange 88d1bd2423SPeter Maydell# Check that we're not trying to do an out-of-tree build from 89d1bd2423SPeter Maydell# a tree that's been used for an in-tree build. 90d1bd2423SPeter Maydellifneq ($(realpath $(SRC_PATH)),$(realpath .)) 91d1bd2423SPeter Maydellifneq ($(wildcard $(SRC_PATH)/config-host.mak),) 92d1bd2423SPeter Maydell$(error This is an out of tree build but your source tree ($(SRC_PATH)) \ 93d1bd2423SPeter Maydellseems to have been used for an in-tree build. You can fix this by running \ 94b98a3baeSPhilippe Mathieu-Daudé"$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source tree) 95d1bd2423SPeter Maydellendif 96d1bd2423SPeter Maydellendif 97d1bd2423SPeter Maydell 983a6b016dSMarkus Armbrusterconfig-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION 99e5efe7f5SJuan Quintela @echo $@ is out-of-date, running configure 100a5665051SPaolo Bonzini @if test -f meson-private/coredata.dat; then \ 101a5665051SPaolo Bonzini ./config.status --skip-meson; \ 102a5665051SPaolo Bonzini else \ 103a5665051SPaolo Bonzini ./config.status; \ 104a5665051SPaolo Bonzini fi 10526fffe29SEmilio G. Cota 10626fffe29SEmilio G. Cota# Force configure to re-run if the API symbols are updated 10726fffe29SEmilio G. Cotaifeq ($(CONFIG_PLUGIN),y) 10826fffe29SEmilio G. Cotaconfig-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols 109*c17a386bSAlex Bennée 110*c17a386bSAlex Bennée.PHONY: plugins 111*c17a386bSAlex Bennéeplugins: 112*c17a386bSAlex Bennée $(call quiet-command,\ 113*c17a386bSAlex Bennée $(MAKE) $(SUBDIR_MAKEFLAGS) -C contrib/plugins V="$(V)", \ 114*c17a386bSAlex Bennée "BUILD", "example plugins") 11526fffe29SEmilio G. Cotaendif 11626fffe29SEmilio G. Cota 11755d7e8f6Saurel32else 11855d7e8f6Saurel32config-host.mak: 119eaa2ddbbSFam Zhengifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail)) 12055d7e8f6Saurel32 @echo "Please call configure before running make!" 12155d7e8f6Saurel32 @exit 1 12255d7e8f6Saurel32endif 1237748b8cbSMike Frysingerendif 124766a487aSbellard 1259f5d9597SGreg Kurz# Only needed in case Makefile.ninja does not exist. 1269f5d9597SGreg Kurz.PHONY: ninja-clean ninja-distclean clean-ctlist 1279f5d9597SGreg Kurzclean-ctlist: 1289f5d9597SGreg Kurzninja-clean:: 1299f5d9597SGreg Kurzninja-distclean:: 1309f5d9597SGreg Kurzbuild.ninja: config-host.mak 1319f5d9597SGreg Kurz 132d9ace8b3SJuan Quintela# Don't try to regenerate Makefile or configure 133d9ace8b3SJuan Quintela# We don't generate any of them 134d9ace8b3SJuan QuintelaMakefile: ; 135d9ace8b3SJuan Quintelaconfigure: ; 136d9ace8b3SJuan Quintela 137acfdaac5SPaolo Bonzini.PHONY: all clean cscope distclean install \ 138acfdaac5SPaolo Bonzini recurse-all dist msi FORCE 1390cb3fb1eSpbrook 140660f7930SPaolo BonziniSUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet) 141a992fe3dSPaul Brook 14246e7b706SFam Zhenginclude $(SRC_PATH)/tests/Makefile.include 143992aeb8eSPaolo Bonzini 144484e2cc7SPaolo Bonziniall: recurse-all 145859aef02SPaolo BonziniMakefile: $(addsuffix /all, $(SUBDIRS)) 146b9dea4fbSpbrook 14767953a37SClaudio Fontana# LIBFDT_lib="": avoid breaking existing trees with objects requiring -fPIC 14867953a37SClaudio FontanaDTC_MAKE_ARGS=-I$(SRC_PATH)/dtc VPATH=$(SRC_PATH)/dtc -C dtc V="$(V)" LIBFDT_lib="" 149965f486cSPeter MaydellDTC_CFLAGS=$(CFLAGS) $(QEMU_CFLAGS) 15067953a37SClaudio FontanaDTC_CPPFLAGS=-I$(SRC_PATH)/dtc/libfdt 151a540f158SPeter Crosthwaite 1523b8593eeSMarkus Armbruster.PHONY: dtc/all 15367953a37SClaudio Fontanadtc/all: .git-submodule-status dtc/libfdt 15467953a37SClaudio Fontana $(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,) 155a540f158SPeter Crosthwaite 15600525864SAaron Lindsaydtc/%: .git-submodule-status 157814e1110SJan Kiszka @mkdir -p $@ 158a540f158SPeter Crosthwaite 159e219c499SRichard Henderson# Overriding CFLAGS causes us to lose defines added in the sub-makefile. 160e219c499SRichard Henderson# Not overriding CFLAGS leads to mis-matches between compilation modes. 161e219c499SRichard Henderson# Therefore we replicate some of the logic in the sub-makefile. 162e219c499SRichard Henderson# Remove all the extra -Warning flags that QEMU uses that Capstone doesn't; 163e219c499SRichard Henderson# no need to annoy QEMU developers with such things. 164feabc71dSPaolo BonziniCAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS) 165e219c499SRichard HendersonCAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM 166e219c499SRichard HendersonCAP_CFLAGS += -DCAPSTONE_HAS_ARM 167e219c499SRichard HendersonCAP_CFLAGS += -DCAPSTONE_HAS_ARM64 168e219c499SRichard HendersonCAP_CFLAGS += -DCAPSTONE_HAS_POWERPC 169e219c499SRichard HendersonCAP_CFLAGS += -DCAPSTONE_HAS_X86 170e219c499SRichard Henderson 1713b8593eeSMarkus Armbruster.PHONY: capstone/all 1723b8593eeSMarkus Armbrustercapstone/all: .git-submodule-status 1739f81aeb5SAlistair Francis $(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)) 174e219c499SRichard Henderson 1753b8593eeSMarkus Armbruster.PHONY: slirp/all 1763b8593eeSMarkus Armbrusterslirp/all: .git-submodule-status 177daa79d9aSAlex Bennée $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp \ 178daa79d9aSAlex Bennée BUILD_DIR="$(BUILD_DIR)/slirp" \ 179daa79d9aSAlex Bennée PKG_CONFIG="$(PKG_CONFIG)" \ 180daa79d9aSAlex Bennée CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" \ 181db5adeaaSPaolo Bonzini CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)") 182675b9b53SMarc-André Lureau 1833b8593eeSMarkus ArmbrusterROM_DIRS = $(addprefix pc-bios/, $(ROMS)) 1841338a4b7SMarkus ArmbrusterROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS))) 185a9c87304SMarc-André Lureau# Only keep -O and -g cflags 1861338a4b7SMarkus Armbruster.PHONY: $(ROM_DIRS_RULES) 1871338a4b7SMarkus Armbruster$(ROM_DIRS_RULES): 18849b7d744SPaolo Bonzini $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" $(notdir $@),) 189c05ac895SPaul Brook 1905e6d1573SPaolo Bonzini.PHONY: recurse-all recurse-clean 19149b7d744SPaolo Bonzinirecurse-all: $(addsuffix /all, $(ROM_DIRS)) 1925e6d1573SPaolo Bonzinirecurse-clean: $(addsuffix /clean, $(ROM_DIRS)) 1934aa42531Spbrook 1943bc2f570SPaolo Bonzini###################################################################### 1954fb240a4Sbellard 196a5665051SPaolo Bonziniclean: recurse-clean ninja-clean clean-ctlist 1979f5d9597SGreg Kurz if test -f ninjatool; then ./ninjatool $(if $(V),-v,) -t clean; fi 1982d80ae89Sbellard# avoid old build problems by removing potentially incorrect old files 19925be210fSJuan Quintela rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h 200484e2cc7SPaolo Bonzini find . \( -name '*.so' -o -name '*.dll' -o -name '*.[oda]' \) -type f \ 20123858f40SLaszlo Ersek ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \ 20223858f40SLaszlo Ersek ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \ 20323858f40SLaszlo Ersek ! -path ./roms/edk2/BaseTools/Source/Python/UPT/Dll/sqlite3.dll \ 20423858f40SLaszlo Ersek -exec rm {} + 205c3a0ee84SPaolo Bonzini rm -f TAGS cscope.* *.pod *~ */*~ 206b855f8d1SPaolo Bonzini rm -f fsdev/*.pod scsi/*.pod 20731e31b8aSbellard 208859aef02SPaolo BonziniVERSION = $(shell cat $(SRC_PATH)/VERSION) 20934bb443eSAnthony Liguori 21034bb443eSAnthony Liguoridist: qemu-$(VERSION).tar.bz2 21134bb443eSAnthony Liguori 21234bb443eSAnthony Liguoriqemu-%.tar.bz2: 21334bb443eSAnthony Liguori $(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)" 21434bb443eSAnthony Liguori 215a5665051SPaolo Bonzinidistclean: clean ninja-distclean 216a5665051SPaolo Bonzini -test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean -g 217acfdaac5SPaolo Bonzini rm -f config-host.mak config-host.h* 2182038f8c8SPaolo Bonzini rm -f tests/tcg/config-*.mak 2192becc36aSPaolo Bonzini rm -f config-all-disas.mak config.status 220e8f3bd71SMarc-André Lureau rm -f tests/qemu-iotests/common.env 221fc8e320eSMagnus Damm rm -f roms/seabios/config.mak roms/vgabios/config.mak 22226fffe29SEmilio G. Cota rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols 22364ed6f92SPaolo Bonzini rm -f *-config-target.h *-config-devices.mak *-config-devices.h 224a5665051SPaolo Bonzini rm -rf meson-private meson-logs meson-info compile_commands.json 225245dac4aSPaolo Bonzini rm -f Makefile.ninja ninjatool ninjatool.stamp Makefile.mtest 226793553acSAlexandre Raymond rm -f config.log 22767ed96f9SPeter Maydell rm -f linux-headers/asm 228d9840e25STomoki Sekiyama rm -Rf .sdk 2297d13299dSbellard 230d7986405SGreg Kurz.PHONY: ctags 231d7986405SGreg Kurzctags: 232d7986405SGreg Kurz rm -f tags 233d7986405SGreg Kurz find "$(SRC_PATH)" -name '*.[hc]' -exec ctags --append {} + 234d7986405SGreg Kurz 235d7986405SGreg Kurz.PHONY: TAGS 236d7986405SGreg KurzTAGS: 237d7986405SGreg Kurz rm -f TAGS 238d7986405SGreg Kurz find "$(SRC_PATH)" -name '*.[hc]' -exec etags --append {} + 239d7986405SGreg Kurz 240d7986405SGreg Kurz.PHONY: cscope 241d7986405SGreg Kurzcscope: 242d7986405SGreg Kurz rm -f "$(SRC_PATH)"/cscope.* 243d7986405SGreg Kurz find "$(SRC_PATH)/" -name "*.[chsS]" -print | sed -e 's,^\./,,' > "$(SRC_PATH)/cscope.files" 244d7986405SGreg Kurz cscope -b -i"$(SRC_PATH)/cscope.files" 245d7986405SGreg Kurz 246a5665051SPaolo Bonzini# Needed by "meson install" 247a5665051SPaolo Bonziniexport DESTDIR 248612384d7Sbellard 249324027c2SFam Zhenginclude $(SRC_PATH)/tests/docker/Makefile.include 250b1fb9a63SFam Zhenginclude $(SRC_PATH)/tests/vm/Makefile.include 2510d8e065fSMarc-André Lureau 252c355de59SPhilippe Mathieu-Daudéprint-help-run = printf " %-30s - %s\\n" "$1" "$2" 253c355de59SPhilippe Mathieu-Daudéprint-help = $(quiet-@)$(call print-help-run,$1,$2) 254c355de59SPhilippe Mathieu-Daudé 2550d8e065fSMarc-André Lureau.PHONY: help 2560d8e065fSMarc-André Lureauhelp: 2570d8e065fSMarc-André Lureau @echo 'Generic targets:' 258c355de59SPhilippe Mathieu-Daudé $(call print-help,all,Build all) 259c355de59SPhilippe Mathieu-Daudé $(call print-help,dir/file.o,Build specified target only) 260c355de59SPhilippe Mathieu-Daudé $(call print-help,install,Install QEMU, documentation and tools) 261c355de59SPhilippe Mathieu-Daudé $(call print-help,ctags/TAGS,Generate tags file for editors) 262c355de59SPhilippe Mathieu-Daudé $(call print-help,cscope,Generate cscope index) 263968b4db3SPaolo Bonzini $(call print-help,sparse,Run sparse on the QEMU source) 2640d8e065fSMarc-André Lureau @echo '' 265*c17a386bSAlex Bennéeifeq ($(CONFIG_PLUGIN),y) 266*c17a386bSAlex Bennée @echo 'Plugin targets:' 267*c17a386bSAlex Bennée $(call print-help,plugins,Build the example TCG plugins) 268*c17a386bSAlex Bennée @echo '' 269*c17a386bSAlex Bennéeendif 2700d8e065fSMarc-André Lureau @echo 'Cleaning targets:' 271c355de59SPhilippe Mathieu-Daudé $(call print-help,clean,Remove most generated files but keep the config) 272c355de59SPhilippe Mathieu-Daudé $(call print-help,distclean,Remove all generated files) 273c355de59SPhilippe Mathieu-Daudé $(call print-help,dist,Build a distributable tarball) 2740d8e065fSMarc-André Lureau @echo '' 2750d8e065fSMarc-André Lureau @echo 'Test targets:' 276c355de59SPhilippe Mathieu-Daudé $(call print-help,check,Run all tests (check-help for details)) 2779ed7247aSPaolo Bonzini $(call print-help,bench,Run all benchmarks) 278c355de59SPhilippe Mathieu-Daudé $(call print-help,docker,Help about targets running tests inside containers) 279c355de59SPhilippe Mathieu-Daudé $(call print-help,vm-help,Help about targets running tests inside VM) 2800d8e065fSMarc-André Lureau @echo '' 2810d8e065fSMarc-André Lureau @echo 'Documentation targets:' 282acfdaac5SPaolo Bonzini $(call print-help,html info pdf txt man,Build documentation in specified format) 2830d8e065fSMarc-André Lureau @echo '' 2840d8e065fSMarc-André Lureauifdef CONFIG_WIN32 2850d8e065fSMarc-André Lureau @echo 'Windows targets:' 286c355de59SPhilippe Mathieu-Daudé $(call print-help,installer,Build NSIS-based installer for QEMU) 2870d8e065fSMarc-André Lureauifdef QEMU_GA_MSI_ENABLED 288c355de59SPhilippe Mathieu-Daudé $(call print-help,msi,Build MSI-based installer for qemu-ga) 2890d8e065fSMarc-André Lureauendif 2900d8e065fSMarc-André Lureau @echo '' 2910d8e065fSMarc-André Lureauendif 292c355de59SPhilippe Mathieu-Daudé $(call print-help,$(MAKE) [targets],(quiet build, default)) 293c355de59SPhilippe Mathieu-Daudé $(call print-help,$(MAKE) V=1 [targets],(verbose build)) 294660f7930SPaolo Bonzini 295660f7930SPaolo Bonzini# will delete the target of a rule if commands exit with a nonzero exit status 296660f7930SPaolo Bonzini.DELETE_ON_ERROR: 297660f7930SPaolo Bonzini 298660f7930SPaolo Bonziniprint-%: 299660f7930SPaolo Bonzini @echo '$*=$($*)' 300