xref: /openbmc/qemu/Makefile (revision 49b7d744)
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
1328fa2927SPhilippe Mathieu-DaudéUNCHECKED_GOALS := %clean TAGS cscope ctags dist \
14de1da442SMarc-André Lureau    help check-help print-% \
154f2f6276SPhilippe Mathieu-Daudé    docker docker-% vm-help vm-test vm-build-%
16eaa2ddbbSFam Zheng
17250b086eSLluís Vilanova# All following code might depend on configuration variables
1855d7e8f6Saurel32ifneq ($(wildcard config-host.mak),)
191ad2134fSPaul Brook# Put the all: rule here so that config-host.mak can contain dependencies.
208f67aa82SStefan Weilall:
21ad064840Spbrookinclude config-host.mak
22d1bd2423SPeter Maydell
23aef45d51SDaniel P. Berrangegit-submodule-update:
24aef45d51SDaniel P. Berrange
25aef45d51SDaniel P. Berrange.PHONY: git-submodule-update
26aef45d51SDaniel P. Berrange
27aef45d51SDaniel P. Berrangegit_module_status := $(shell \
28aef45d51SDaniel P. Berrange  cd '$(SRC_PATH)' && \
29cc84d63aSDaniel P. Berrange  GIT="$(GIT)" ./scripts/git-submodule.sh status $(GIT_SUBMODULES); \
30aef45d51SDaniel P. Berrange  echo $$?; \
31aef45d51SDaniel P. Berrange)
32aef45d51SDaniel P. Berrange
33aef45d51SDaniel P. Berrangeifeq (1,$(git_module_status))
34f62bbee5SDaniel P. Berrangeifeq (no,$(GIT_UPDATE))
35f62bbee5SDaniel P. Berrangegit-submodule-update:
36f62bbee5SDaniel P. Berrange	$(call quiet-command, \
37f62bbee5SDaniel P. Berrange            echo && \
38f62bbee5SDaniel P. Berrange            echo "GIT submodule checkout is out of date. Please run" && \
39f62bbee5SDaniel P. Berrange            echo "  scripts/git-submodule.sh update $(GIT_SUBMODULES)" && \
40f62bbee5SDaniel P. Berrange            echo "from the source directory checkout $(SRC_PATH)" && \
41f62bbee5SDaniel P. Berrange            echo && \
42f62bbee5SDaniel P. Berrange            exit 1)
43f62bbee5SDaniel P. Berrangeelse
44aef45d51SDaniel P. Berrangegit-submodule-update:
45aef45d51SDaniel P. Berrange	$(call quiet-command, \
46cc84d63aSDaniel P. Berrange          (cd $(SRC_PATH) && GIT="$(GIT)" ./scripts/git-submodule.sh update $(GIT_SUBMODULES)), \
47aef45d51SDaniel P. Berrange          "GIT","$(GIT_SUBMODULES)")
48aef45d51SDaniel P. Berrangeendif
49aef45d51SDaniel P. Berrangeendif
50aef45d51SDaniel P. Berrange
51a5665051SPaolo Bonziniexport NINJA=./ninjatool
52a5665051SPaolo Bonzini
53a5665051SPaolo Bonzini# Running meson regenerates both build.ninja and ninjatool, and that is
54a5665051SPaolo Bonzini# enough to prime the rest of the build.
55a5665051SPaolo Bonzinininjatool: build.ninja
56a5665051SPaolo Bonzini
57a5665051SPaolo Bonzini# Only needed in case Makefile.ninja does not exist.
58a5665051SPaolo Bonzini.PHONY: ninja-clean ninja-distclean clean-ctlist
59a5665051SPaolo Bonziniclean-ctlist:
60a5665051SPaolo Bonzinininja-clean::
61a5665051SPaolo Bonzinininja-distclean::
62a5665051SPaolo Bonzinibuild.ninja: config-host.mak
63a5665051SPaolo Bonzini
64a5665051SPaolo BonziniMakefile.ninja: build.ninja ninjatool
65a5665051SPaolo Bonzini	./ninjatool -t ninja2make --omit clean dist uninstall < $< > $@
66a5665051SPaolo Bonzini-include Makefile.ninja
67a5665051SPaolo Bonzini
68a5665051SPaolo Bonzini${ninja-targets-c_COMPILER} ${ninja-targets-cpp_COMPILER}: .var.command += -MP
69a5665051SPaolo Bonzini
70245dac4aSPaolo Bonzini# If MESON is empty, the rule will be re-evaluated after Makefiles are
71245dac4aSPaolo Bonzini# reread (and MESON won't be empty anymore).
72245dac4aSPaolo Bonziniifneq ($(MESON),)
73245dac4aSPaolo BonziniMakefile.mtest: build.ninja scripts/mtest2make.py
74245dac4aSPaolo Bonzini	$(MESON) introspect --tests | $(PYTHON) scripts/mtest2make.py > $@
75245dac4aSPaolo Bonzini-include Makefile.mtest
76245dac4aSPaolo Bonziniendif
77245dac4aSPaolo Bonzini
7892712822SDaniel P. Berrange.git-submodule-status: git-submodule-update config-host.mak
79aef45d51SDaniel P. Berrange
80d1bd2423SPeter Maydell# Check that we're not trying to do an out-of-tree build from
81d1bd2423SPeter Maydell# a tree that's been used for an in-tree build.
82d1bd2423SPeter Maydellifneq ($(realpath $(SRC_PATH)),$(realpath .))
83d1bd2423SPeter Maydellifneq ($(wildcard $(SRC_PATH)/config-host.mak),)
84d1bd2423SPeter Maydell$(error This is an out of tree build but your source tree ($(SRC_PATH)) \
85d1bd2423SPeter Maydellseems to have been used for an in-tree build. You can fix this by running \
86b98a3baeSPhilippe Mathieu-Daudé"$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source tree)
87d1bd2423SPeter Maydellendif
88d1bd2423SPeter Maydellendif
89d1bd2423SPeter Maydell
902b1f35b9SAlex BennéeCONFIG_SOFTMMU := $(if $(filter %-softmmu,$(TARGET_DIRS)),y)
912b1f35b9SAlex BennéeCONFIG_USER_ONLY := $(if $(filter %-user,$(TARGET_DIRS)),y)
926b827ccaSStefano StabelliniCONFIG_XEN := $(CONFIG_XEN_BACKEND)
93f3aa844bSPaolo BonziniCONFIG_ALL=y
94f3aa844bSPaolo Bonzini-include config-all-devices.mak
95f3aa844bSPaolo Bonzini-include config-all-disas.mak
96f3aa844bSPaolo Bonzini
973a6b016dSMarkus Armbrusterconfig-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
98e5efe7f5SJuan Quintela	@echo $@ is out-of-date, running configure
99a5665051SPaolo Bonzini	@if test -f meson-private/coredata.dat; then \
100a5665051SPaolo Bonzini	  ./config.status --skip-meson; \
101a5665051SPaolo Bonzini	else \
102a5665051SPaolo Bonzini	  ./config.status; \
103a5665051SPaolo Bonzini	fi
10426fffe29SEmilio G. Cota
10526fffe29SEmilio G. Cota# Force configure to re-run if the API symbols are updated
10626fffe29SEmilio G. Cotaifeq ($(CONFIG_PLUGIN),y)
10726fffe29SEmilio G. Cotaconfig-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols
10826fffe29SEmilio G. Cotaendif
10926fffe29SEmilio G. Cota
11055d7e8f6Saurel32else
11155d7e8f6Saurel32config-host.mak:
112eaa2ddbbSFam Zhengifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
11355d7e8f6Saurel32	@echo "Please call configure before running make!"
11455d7e8f6Saurel32	@exit 1
11555d7e8f6Saurel32endif
1167748b8cbSMike Frysingerendif
117766a487aSbellard
118fb57c881SFam Zhenginclude $(SRC_PATH)/rules.mak
119fb57c881SFam Zheng
120c932ce31SPaolo Bonzini# lor is defined in rules.mak
12129de2804SLaurent VivierCONFIG_BLOCK := $(call lor,$(CONFIG_SOFTMMU),$(CONFIG_TOOLS))
12229de2804SLaurent Vivier
1233dff199cSLaurent Viviergenerated-files-y += .git-submodule-status
1240ab8ed18SDaniel P. Berrange
125d9ace8b3SJuan Quintela# Don't try to regenerate Makefile or configure
126d9ace8b3SJuan Quintela# We don't generate any of them
127d9ace8b3SJuan QuintelaMakefile: ;
128d9ace8b3SJuan Quintelaconfigure: ;
129d9ace8b3SJuan Quintela
130acfdaac5SPaolo Bonzini.PHONY: all clean cscope distclean install \
131acfdaac5SPaolo Bonzini	recurse-all dist msi FORCE
1320cb3fb1eSpbrook
133fec90ff0SPaolo Bonzini$(call set-vpath, $(SRC_PATH))
1348c462f8fSpbrook
1353e2e0e6bSJuan QuintelaLIBS+=-lz $(LIBS_TOOLS)
13667c0f08dSJuan Quintela
1378cc357b5SDaniel P. BerrangeSUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet) BUILD_DIR=$(BUILD_DIR)
138a992fe3dSPaul Brook
139992aeb8eSPaolo Bonziniifneq ($(wildcard config-host.mak),)
140992aeb8eSPaolo Bonziniinclude $(SRC_PATH)/Makefile.objs
141ba1183daSFam Zhengendif
142ba1183daSFam Zheng
14346e7b706SFam Zhenginclude $(SRC_PATH)/tests/Makefile.include
144992aeb8eSPaolo Bonzini
145484e2cc7SPaolo Bonziniall: recurse-all
146859aef02SPaolo BonziniMakefile: $(addsuffix /all, $(SUBDIRS))
147b9dea4fbSpbrook
14867953a37SClaudio Fontana# LIBFDT_lib="": avoid breaking existing trees with objects requiring -fPIC
14967953a37SClaudio FontanaDTC_MAKE_ARGS=-I$(SRC_PATH)/dtc VPATH=$(SRC_PATH)/dtc -C dtc V="$(V)" LIBFDT_lib=""
150965f486cSPeter MaydellDTC_CFLAGS=$(CFLAGS) $(QEMU_CFLAGS)
15167953a37SClaudio FontanaDTC_CPPFLAGS=-I$(SRC_PATH)/dtc/libfdt
152a540f158SPeter Crosthwaite
1533b8593eeSMarkus Armbruster.PHONY: dtc/all
15467953a37SClaudio Fontanadtc/all: .git-submodule-status dtc/libfdt
15567953a37SClaudio 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,)
156a540f158SPeter Crosthwaite
15700525864SAaron Lindsaydtc/%: .git-submodule-status
158814e1110SJan Kiszka	@mkdir -p $@
159a540f158SPeter Crosthwaite
160e219c499SRichard Henderson# Overriding CFLAGS causes us to lose defines added in the sub-makefile.
161e219c499SRichard Henderson# Not overriding CFLAGS leads to mis-matches between compilation modes.
162e219c499SRichard Henderson# Therefore we replicate some of the logic in the sub-makefile.
163e219c499SRichard Henderson# Remove all the extra -Warning flags that QEMU uses that Capstone doesn't;
164e219c499SRichard Henderson# no need to annoy QEMU developers with such things.
165e219c499SRichard HendersonCAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS))
166e219c499SRichard HendersonCAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM
167e219c499SRichard HendersonCAP_CFLAGS += -DCAPSTONE_HAS_ARM
168e219c499SRichard HendersonCAP_CFLAGS += -DCAPSTONE_HAS_ARM64
169e219c499SRichard HendersonCAP_CFLAGS += -DCAPSTONE_HAS_POWERPC
170e219c499SRichard HendersonCAP_CFLAGS += -DCAPSTONE_HAS_X86
171e219c499SRichard Henderson
1723b8593eeSMarkus Armbruster.PHONY: capstone/all
1733b8593eeSMarkus Armbrustercapstone/all: .git-submodule-status
1749f81aeb5SAlistair 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))
175e219c499SRichard Henderson
1763b8593eeSMarkus Armbruster.PHONY: slirp/all
1773b8593eeSMarkus Armbrusterslirp/all: .git-submodule-status
178daa79d9aSAlex Bennée	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp		\
179daa79d9aSAlex Bennée		BUILD_DIR="$(BUILD_DIR)/slirp" 			\
180daa79d9aSAlex Bennée		PKG_CONFIG="$(PKG_CONFIG)" 				\
181daa79d9aSAlex Bennée		CC="$(CC)" AR="$(AR)" 	LD="$(LD)" RANLIB="$(RANLIB)"	\
182db5adeaaSPaolo Bonzini		CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)")
183675b9b53SMarc-André Lureau
1843b8593eeSMarkus ArmbrusterROM_DIRS = $(addprefix pc-bios/, $(ROMS))
1851338a4b7SMarkus ArmbrusterROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS)))
186a9c87304SMarc-André Lureau# Only keep -O and -g cflags
1871338a4b7SMarkus Armbruster.PHONY: $(ROM_DIRS_RULES)
1881338a4b7SMarkus Armbruster$(ROM_DIRS_RULES):
189*49b7d744SPaolo Bonzini	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" $(notdir $@),)
190c05ac895SPaul Brook
1915e6d1573SPaolo Bonzini.PHONY: recurse-all recurse-clean
192*49b7d744SPaolo Bonzinirecurse-all: $(addsuffix /all, $(ROM_DIRS))
1935e6d1573SPaolo Bonzinirecurse-clean: $(addsuffix /clean, $(ROM_DIRS))
1944aa42531Spbrook
1953bc2f570SPaolo Bonzini######################################################################
1964fb240a4Sbellard
197a5665051SPaolo Bonziniclean: recurse-clean ninja-clean clean-ctlist
198a5665051SPaolo Bonzini	-test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean
1992d80ae89Sbellard# avoid old build problems by removing potentially incorrect old files
20025be210fSJuan 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
201484e2cc7SPaolo Bonzini	find . \( -name '*.so' -o -name '*.dll' -o -name '*.[oda]' \) -type f \
20223858f40SLaszlo Ersek		! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \
20323858f40SLaszlo Ersek		! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \
20423858f40SLaszlo Ersek		! -path ./roms/edk2/BaseTools/Source/Python/UPT/Dll/sqlite3.dll \
20523858f40SLaszlo Ersek		-exec rm {} +
206c3a0ee84SPaolo Bonzini	rm -f TAGS cscope.* *.pod *~ */*~
207b855f8d1SPaolo Bonzini	rm -f fsdev/*.pod scsi/*.pod
2083dff199cSLaurent Vivier	rm -f $(foreach f,$(generated-files-y),$(f) $(f)-timestamp)
20931e31b8aSbellard
210859aef02SPaolo BonziniVERSION = $(shell cat $(SRC_PATH)/VERSION)
21134bb443eSAnthony Liguori
21234bb443eSAnthony Liguoridist: qemu-$(VERSION).tar.bz2
21334bb443eSAnthony Liguori
21434bb443eSAnthony Liguoriqemu-%.tar.bz2:
21534bb443eSAnthony Liguori	$(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)"
21634bb443eSAnthony Liguori
217a5665051SPaolo Bonzinidistclean: clean ninja-distclean
218a5665051SPaolo Bonzini	-test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean -g
219acfdaac5SPaolo Bonzini	rm -f config-host.mak config-host.h*
2202038f8c8SPaolo Bonzini	rm -f tests/tcg/config-*.mak
2212becc36aSPaolo Bonzini	rm -f config-all-disas.mak config.status
222e8f3bd71SMarc-André Lureau	rm -f tests/qemu-iotests/common.env
223fc8e320eSMagnus Damm	rm -f roms/seabios/config.mak roms/vgabios/config.mak
22426fffe29SEmilio G. Cota	rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols
22564ed6f92SPaolo Bonzini	rm -f *-config-target.h *-config-devices.mak *-config-devices.h
226a5665051SPaolo Bonzini	rm -rf meson-private meson-logs meson-info compile_commands.json
227245dac4aSPaolo Bonzini	rm -f Makefile.ninja ninjatool ninjatool.stamp Makefile.mtest
228793553acSAlexandre Raymond	rm -f config.log
22967ed96f9SPeter Maydell	rm -f linux-headers/asm
230d9840e25STomoki Sekiyama	rm -Rf .sdk
2317d13299dSbellard
232a5665051SPaolo Bonzini# Needed by "meson install"
233a5665051SPaolo Bonziniexport DESTDIR
234612384d7Sbellard
235cb5fc67dSAnthony Liguori# Add a dependency on the generated files, so that they are always
236cb5fc67dSAnthony Liguori# rebuilt before other object files
237428952cfSThomas Huthifneq ($(wildcard config-host.mak),)
238eaa2ddbbSFam Zhengifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
2393dff199cSLaurent VivierMakefile: $(generated-files-y)
2407748b8cbSMike Frysingerendif
241428952cfSThomas Huthendif
242cb5fc67dSAnthony Liguori
2434fb240a4Sbellard# Include automatically generated dependency files
2441435ddb8SPaolo Bonzini# Dependencies in Makefile.objs files come from our recursive subdir rules
2451435ddb8SPaolo Bonzini-include $(wildcard *.d tests/*.d)
246324027c2SFam Zheng
247324027c2SFam Zhenginclude $(SRC_PATH)/tests/docker/Makefile.include
248b1fb9a63SFam Zhenginclude $(SRC_PATH)/tests/vm/Makefile.include
2490d8e065fSMarc-André Lureau
250c355de59SPhilippe Mathieu-Daudéprint-help-run = printf "  %-30s - %s\\n" "$1" "$2"
251c355de59SPhilippe Mathieu-Daudéprint-help = $(quiet-@)$(call print-help-run,$1,$2)
252c355de59SPhilippe Mathieu-Daudé
2530d8e065fSMarc-André Lureau.PHONY: help
2540d8e065fSMarc-André Lureauhelp:
2550d8e065fSMarc-André Lureau	@echo  'Generic targets:'
256c355de59SPhilippe Mathieu-Daudé	$(call print-help,all,Build all)
257c355de59SPhilippe Mathieu-Daudé	$(call print-help,dir/file.o,Build specified target only)
258c355de59SPhilippe Mathieu-Daudé	$(call print-help,install,Install QEMU, documentation and tools)
259c355de59SPhilippe Mathieu-Daudé	$(call print-help,ctags/TAGS,Generate tags file for editors)
260c355de59SPhilippe Mathieu-Daudé	$(call print-help,cscope,Generate cscope index)
261968b4db3SPaolo Bonzini	$(call print-help,sparse,Run sparse on the QEMU source)
2620d8e065fSMarc-André Lureau	@echo  ''
2630d8e065fSMarc-André Lureau	@echo  'Cleaning targets:'
264c355de59SPhilippe Mathieu-Daudé	$(call print-help,clean,Remove most generated files but keep the config)
265c355de59SPhilippe Mathieu-Daudé	$(call print-help,distclean,Remove all generated files)
266c355de59SPhilippe Mathieu-Daudé	$(call print-help,dist,Build a distributable tarball)
2670d8e065fSMarc-André Lureau	@echo  ''
2680d8e065fSMarc-André Lureau	@echo  'Test targets:'
269c355de59SPhilippe Mathieu-Daudé	$(call print-help,check,Run all tests (check-help for details))
270c355de59SPhilippe Mathieu-Daudé	$(call print-help,docker,Help about targets running tests inside containers)
271c355de59SPhilippe Mathieu-Daudé	$(call print-help,vm-help,Help about targets running tests inside VM)
2720d8e065fSMarc-André Lureau	@echo  ''
2730d8e065fSMarc-André Lureau	@echo  'Documentation targets:'
274acfdaac5SPaolo Bonzini	$(call print-help,html info pdf txt man,Build documentation in specified format)
2750d8e065fSMarc-André Lureau	@echo  ''
2760d8e065fSMarc-André Lureauifdef CONFIG_WIN32
2770d8e065fSMarc-André Lureau	@echo  'Windows targets:'
278c355de59SPhilippe Mathieu-Daudé	$(call print-help,installer,Build NSIS-based installer for QEMU)
2790d8e065fSMarc-André Lureauifdef QEMU_GA_MSI_ENABLED
280c355de59SPhilippe Mathieu-Daudé	$(call print-help,msi,Build MSI-based installer for qemu-ga)
2810d8e065fSMarc-André Lureauendif
2820d8e065fSMarc-André Lureau	@echo  ''
2830d8e065fSMarc-André Lureauendif
284c355de59SPhilippe Mathieu-Daudé	$(call print-help,$(MAKE) [targets],(quiet build, default))
285c355de59SPhilippe Mathieu-Daudé	$(call print-help,$(MAKE) V=1 [targets],(verbose build))
286