xref: /openbmc/qemu/Makefile (revision 2b8575bd5fbc8a8880e9ecfb1c7e7990feb1fea6)
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
173bf45835SPaolo BonziniSHELL = /usr/bin/env bash -o pipefail
183bf45835SPaolo Bonzini
19660f7930SPaolo Bonzini# Usage: $(call quiet-command,command and args,"NAME","args to print")
20660f7930SPaolo Bonzini# This will run "command and args", and either:
21660f7930SPaolo Bonzini#  if V=1 just print the whole command and args
22660f7930SPaolo Bonzini#  otherwise print the 'quiet' output in the format "  NAME     args to print"
23660f7930SPaolo Bonzini# NAME should be a short name of the command, 7 letters or fewer.
24660f7930SPaolo Bonzini# If called with only a single argument, will print nothing in quiet mode.
25660f7930SPaolo Bonziniquiet-command-run = $(if $(V),,$(if $2,printf "  %-7s %s\n" $2 $3 && ))$1
26660f7930SPaolo Bonziniquiet-@ = $(if $(V),,@)
27660f7930SPaolo Bonziniquiet-command = $(quiet-@)$(call quiet-command-run,$1,$2,$3)
28660f7930SPaolo Bonzini
2928fa2927SPhilippe Mathieu-DaudéUNCHECKED_GOALS := %clean TAGS cscope ctags dist \
30de1da442SMarc-André Lureau    help check-help print-% \
314f2f6276SPhilippe Mathieu-Daudé    docker docker-% vm-help vm-test vm-build-%
32eaa2ddbbSFam Zheng
33*2b8575bdSPaolo Bonziniall:
34*2b8575bdSPaolo Bonzini.PHONY: all clean distclean recurse-all dist msi FORCE
35*2b8575bdSPaolo Bonzini
36*2b8575bdSPaolo Bonzini# Don't try to regenerate Makefile or configure
37*2b8575bdSPaolo Bonzini# We don't generate any of them
38*2b8575bdSPaolo BonziniMakefile: ;
39*2b8575bdSPaolo Bonziniconfigure: ;
40*2b8575bdSPaolo Bonzini
41250b086eSLluís Vilanova# All following code might depend on configuration variables
4255d7e8f6Saurel32ifneq ($(wildcard config-host.mak),)
43ad064840Spbrookinclude config-host.mak
44d1bd2423SPeter Maydell
45aef45d51SDaniel P. Berrangegit-submodule-update:
46*2b8575bdSPaolo Bonzini.git-submodule-status: git-submodule-update config-host.mak
47*2b8575bdSPaolo BonziniMakefile: .git-submodule-status
48aef45d51SDaniel P. Berrange
49aef45d51SDaniel P. Berrange.PHONY: git-submodule-update
50aef45d51SDaniel P. Berrange
51aef45d51SDaniel P. Berrangegit_module_status := $(shell \
52aef45d51SDaniel P. Berrange  cd '$(SRC_PATH)' && \
53cc84d63aSDaniel P. Berrange  GIT="$(GIT)" ./scripts/git-submodule.sh status $(GIT_SUBMODULES); \
54aef45d51SDaniel P. Berrange  echo $$?; \
55aef45d51SDaniel P. Berrange)
56aef45d51SDaniel P. Berrange
57aef45d51SDaniel P. Berrangeifeq (1,$(git_module_status))
58f62bbee5SDaniel P. Berrangeifeq (no,$(GIT_UPDATE))
59f62bbee5SDaniel P. Berrangegit-submodule-update:
60f62bbee5SDaniel P. Berrange	$(call quiet-command, \
61f62bbee5SDaniel P. Berrange            echo && \
62f62bbee5SDaniel P. Berrange            echo "GIT submodule checkout is out of date. Please run" && \
63f62bbee5SDaniel P. Berrange            echo "  scripts/git-submodule.sh update $(GIT_SUBMODULES)" && \
64f62bbee5SDaniel P. Berrange            echo "from the source directory checkout $(SRC_PATH)" && \
65f62bbee5SDaniel P. Berrange            echo && \
66f62bbee5SDaniel P. Berrange            exit 1)
67f62bbee5SDaniel P. Berrangeelse
68aef45d51SDaniel P. Berrangegit-submodule-update:
69aef45d51SDaniel P. Berrange	$(call quiet-command, \
70cc84d63aSDaniel P. Berrange          (cd $(SRC_PATH) && GIT="$(GIT)" ./scripts/git-submodule.sh update $(GIT_SUBMODULES)), \
71aef45d51SDaniel P. Berrange          "GIT","$(GIT_SUBMODULES)")
72aef45d51SDaniel P. Berrangeendif
73aef45d51SDaniel P. Berrangeendif
74aef45d51SDaniel P. Berrange
75a5665051SPaolo Bonziniexport NINJA=./ninjatool
76a5665051SPaolo Bonzini
77a5665051SPaolo Bonzini# Running meson regenerates both build.ninja and ninjatool, and that is
78a5665051SPaolo Bonzini# enough to prime the rest of the build.
79a5665051SPaolo Bonzinininjatool: build.ninja
80a5665051SPaolo Bonzini
81a5665051SPaolo BonziniMakefile.ninja: build.ninja ninjatool
82d7986405SGreg Kurz	./ninjatool -t ninja2make --omit clean dist uninstall cscope TAGS ctags < $< > $@
83a5665051SPaolo Bonzini-include Makefile.ninja
84a5665051SPaolo Bonzini
85a5665051SPaolo Bonzini${ninja-targets-c_COMPILER} ${ninja-targets-cpp_COMPILER}: .var.command += -MP
86a5665051SPaolo Bonzini
87245dac4aSPaolo Bonzini# If MESON is empty, the rule will be re-evaluated after Makefiles are
88245dac4aSPaolo Bonzini# reread (and MESON won't be empty anymore).
89245dac4aSPaolo Bonziniifneq ($(MESON),)
90245dac4aSPaolo BonziniMakefile.mtest: build.ninja scripts/mtest2make.py
9148a81fd5SPaolo Bonzini	$(MESON) introspect --targets --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@
92245dac4aSPaolo Bonzini-include Makefile.mtest
93245dac4aSPaolo Bonziniendif
94245dac4aSPaolo Bonzini
95*2b8575bdSPaolo Bonzini# Ensure the build tree is okay.
96d1bd2423SPeter Maydell# Check that we're not trying to do an out-of-tree build from
97d1bd2423SPeter Maydell# a tree that's been used for an in-tree build.
98d1bd2423SPeter Maydellifneq ($(realpath $(SRC_PATH)),$(realpath .))
99d1bd2423SPeter Maydellifneq ($(wildcard $(SRC_PATH)/config-host.mak),)
100d1bd2423SPeter Maydell$(error This is an out of tree build but your source tree ($(SRC_PATH)) \
101d1bd2423SPeter Maydellseems to have been used for an in-tree build. You can fix this by running \
102b98a3baeSPhilippe Mathieu-Daudé"$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source tree)
103d1bd2423SPeter Maydellendif
104d1bd2423SPeter Maydellendif
105d1bd2423SPeter Maydell
106*2b8575bdSPaolo Bonzini# force a rerun of configure if config-host.mak is too old or corrupted
107*2b8575bdSPaolo Bonziniifeq ($(MESON),)
108*2b8575bdSPaolo Bonzini.PHONY: config-host.mak
109*2b8575bdSPaolo Bonzinix := $(shell rm -rf meson-private meson-info meson-logs)
110*2b8575bdSPaolo Bonziniendif
111*2b8575bdSPaolo Bonziniifeq ($(NINJA),)
112*2b8575bdSPaolo Bonzini.PHONY: config-host.mak
113*2b8575bdSPaolo Bonzinix := $(shell rm -rf meson-private meson-info meson-logs)
114*2b8575bdSPaolo Bonziniendif
115*2b8575bdSPaolo Bonziniifeq ($(wildcard build.ninja),)
116*2b8575bdSPaolo Bonzini.PHONY: config-host.mak
117*2b8575bdSPaolo Bonzinix := $(shell rm -rf meson-private meson-info meson-logs)
118*2b8575bdSPaolo Bonziniendif
119*2b8575bdSPaolo Bonzini
1203a6b016dSMarkus Armbrusterconfig-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
121e5efe7f5SJuan Quintela	@echo $@ is out-of-date, running configure
122a5665051SPaolo Bonzini	@if test -f meson-private/coredata.dat; then \
123a5665051SPaolo Bonzini	  ./config.status --skip-meson; \
124a5665051SPaolo Bonzini	else \
125a5665051SPaolo Bonzini	  ./config.status; \
126a5665051SPaolo Bonzini	fi
12726fffe29SEmilio G. Cota
12826fffe29SEmilio G. Cota# Force configure to re-run if the API symbols are updated
12926fffe29SEmilio G. Cotaifeq ($(CONFIG_PLUGIN),y)
13026fffe29SEmilio G. Cotaconfig-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols
131c17a386bSAlex Bennée
132c17a386bSAlex Bennée.PHONY: plugins
133c17a386bSAlex Bennéeplugins:
134c17a386bSAlex Bennée	$(call quiet-command,\
135c17a386bSAlex Bennée		$(MAKE) $(SUBDIR_MAKEFLAGS) -C contrib/plugins V="$(V)", \
136c17a386bSAlex Bennée		"BUILD", "example plugins")
137*2b8575bdSPaolo Bonziniendif # $(CONFIG_PLUGIN)
13826fffe29SEmilio G. Cota
139*2b8575bdSPaolo Bonzinielse # config-host.mak does not exist
14055d7e8f6Saurel32config-host.mak:
141eaa2ddbbSFam Zhengifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
14255d7e8f6Saurel32	@echo "Please call configure before running make!"
14355d7e8f6Saurel32	@exit 1
14455d7e8f6Saurel32endif
145*2b8575bdSPaolo Bonziniendif # config-host.mak does not exist
146766a487aSbellard
1479f5d9597SGreg Kurz# Only needed in case Makefile.ninja does not exist.
1489f5d9597SGreg Kurz.PHONY: ninja-clean ninja-distclean clean-ctlist
1499f5d9597SGreg Kurzclean-ctlist:
1509f5d9597SGreg Kurzninja-clean::
1519f5d9597SGreg Kurzninja-distclean::
1529f5d9597SGreg Kurzbuild.ninja: config-host.mak
1539f5d9597SGreg Kurz
154660f7930SPaolo BonziniSUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet)
155a992fe3dSPaul Brook
15646e7b706SFam Zhenginclude $(SRC_PATH)/tests/Makefile.include
157992aeb8eSPaolo Bonzini
158484e2cc7SPaolo Bonziniall: recurse-all
159675b9b53SMarc-André Lureau
1603b8593eeSMarkus ArmbrusterROM_DIRS = $(addprefix pc-bios/, $(ROMS))
1611338a4b7SMarkus ArmbrusterROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS)))
162a9c87304SMarc-André Lureau# Only keep -O and -g cflags
1631338a4b7SMarkus Armbruster.PHONY: $(ROM_DIRS_RULES)
1641338a4b7SMarkus Armbruster$(ROM_DIRS_RULES):
16549b7d744SPaolo Bonzini	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" $(notdir $@),)
166c05ac895SPaul Brook
1675e6d1573SPaolo Bonzini.PHONY: recurse-all recurse-clean
16849b7d744SPaolo Bonzinirecurse-all: $(addsuffix /all, $(ROM_DIRS))
1695e6d1573SPaolo Bonzinirecurse-clean: $(addsuffix /clean, $(ROM_DIRS))
1704aa42531Spbrook
1713bc2f570SPaolo Bonzini######################################################################
1724fb240a4Sbellard
173a5665051SPaolo Bonziniclean: recurse-clean ninja-clean clean-ctlist
1749f5d9597SGreg Kurz	if test -f ninjatool; then ./ninjatool $(if $(V),-v,) -t clean; fi
1752d80ae89Sbellard# avoid old build problems by removing potentially incorrect old files
17625be210fSJuan 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
177484e2cc7SPaolo Bonzini	find . \( -name '*.so' -o -name '*.dll' -o -name '*.[oda]' \) -type f \
17823858f40SLaszlo Ersek		! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \
17923858f40SLaszlo Ersek		! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \
18023858f40SLaszlo Ersek		-exec rm {} +
181c3a0ee84SPaolo Bonzini	rm -f TAGS cscope.* *.pod *~ */*~
182b855f8d1SPaolo Bonzini	rm -f fsdev/*.pod scsi/*.pod
18331e31b8aSbellard
184859aef02SPaolo BonziniVERSION = $(shell cat $(SRC_PATH)/VERSION)
18534bb443eSAnthony Liguori
18634bb443eSAnthony Liguoridist: qemu-$(VERSION).tar.bz2
18734bb443eSAnthony Liguori
18834bb443eSAnthony Liguoriqemu-%.tar.bz2:
18934bb443eSAnthony Liguori	$(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)"
19034bb443eSAnthony Liguori
191a5665051SPaolo Bonzinidistclean: clean ninja-distclean
192a5665051SPaolo Bonzini	-test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean -g
193acfdaac5SPaolo Bonzini	rm -f config-host.mak config-host.h*
1942038f8c8SPaolo Bonzini	rm -f tests/tcg/config-*.mak
1952becc36aSPaolo Bonzini	rm -f config-all-disas.mak config.status
196e8f3bd71SMarc-André Lureau	rm -f tests/qemu-iotests/common.env
197fc8e320eSMagnus Damm	rm -f roms/seabios/config.mak roms/vgabios/config.mak
19826fffe29SEmilio G. Cota	rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols
19964ed6f92SPaolo Bonzini	rm -f *-config-target.h *-config-devices.mak *-config-devices.h
200a5665051SPaolo Bonzini	rm -rf meson-private meson-logs meson-info compile_commands.json
201245dac4aSPaolo Bonzini	rm -f Makefile.ninja ninjatool ninjatool.stamp Makefile.mtest
202793553acSAlexandre Raymond	rm -f config.log
20367ed96f9SPeter Maydell	rm -f linux-headers/asm
204d9840e25STomoki Sekiyama	rm -Rf .sdk
2057d13299dSbellard
206c857f905SGreg Kurzfind-src-path = find "$(SRC_PATH)/" -path "$(SRC_PATH)/meson" -prune -o -name "*.[chsS]"
207c857f905SGreg Kurz
208d7986405SGreg Kurz.PHONY: ctags
209d7986405SGreg Kurzctags:
210e90df5eaSGreg Kurz	rm -f "$(SRC_PATH)/"tags
211e90df5eaSGreg Kurz	$(find-src-path) -exec ctags -f "$(SRC_PATH)/"tags --append {} +
212d7986405SGreg Kurz
213d7986405SGreg Kurz.PHONY: TAGS
214d7986405SGreg KurzTAGS:
215e90df5eaSGreg Kurz	rm -f "$(SRC_PATH)/"TAGS
216e90df5eaSGreg Kurz	$(find-src-path) -exec etags -f "$(SRC_PATH)/"TAGS --append {} +
217d7986405SGreg Kurz
218d7986405SGreg Kurz.PHONY: cscope
219d7986405SGreg Kurzcscope:
220d7986405SGreg Kurz	rm -f "$(SRC_PATH)"/cscope.*
221c857f905SGreg Kurz	$(find-src-path) -print | sed -e 's,^\./,,' > "$(SRC_PATH)/cscope.files"
222e90df5eaSGreg Kurz	cscope -b -i"$(SRC_PATH)/cscope.files" -f"$(SRC_PATH)"/cscope.out
223d7986405SGreg Kurz
224a5665051SPaolo Bonzini# Needed by "meson install"
225a5665051SPaolo Bonziniexport DESTDIR
226612384d7Sbellard
227324027c2SFam Zhenginclude $(SRC_PATH)/tests/docker/Makefile.include
228b1fb9a63SFam Zhenginclude $(SRC_PATH)/tests/vm/Makefile.include
2290d8e065fSMarc-André Lureau
230c355de59SPhilippe Mathieu-Daudéprint-help-run = printf "  %-30s - %s\\n" "$1" "$2"
231c355de59SPhilippe Mathieu-Daudéprint-help = $(quiet-@)$(call print-help-run,$1,$2)
232c355de59SPhilippe Mathieu-Daudé
2330d8e065fSMarc-André Lureau.PHONY: help
2340d8e065fSMarc-André Lureauhelp:
2350d8e065fSMarc-André Lureau	@echo  'Generic targets:'
236c355de59SPhilippe Mathieu-Daudé	$(call print-help,all,Build all)
237c355de59SPhilippe Mathieu-Daudé	$(call print-help,dir/file.o,Build specified target only)
238c355de59SPhilippe Mathieu-Daudé	$(call print-help,install,Install QEMU, documentation and tools)
239c355de59SPhilippe Mathieu-Daudé	$(call print-help,ctags/TAGS,Generate tags file for editors)
240c355de59SPhilippe Mathieu-Daudé	$(call print-help,cscope,Generate cscope index)
241968b4db3SPaolo Bonzini	$(call print-help,sparse,Run sparse on the QEMU source)
2420d8e065fSMarc-André Lureau	@echo  ''
243c17a386bSAlex Bennéeifeq ($(CONFIG_PLUGIN),y)
244c17a386bSAlex Bennée	@echo  'Plugin targets:'
245c17a386bSAlex Bennée	$(call print-help,plugins,Build the example TCG plugins)
246c17a386bSAlex Bennée	@echo  ''
247c17a386bSAlex Bennéeendif
2480d8e065fSMarc-André Lureau	@echo  'Cleaning targets:'
249c355de59SPhilippe Mathieu-Daudé	$(call print-help,clean,Remove most generated files but keep the config)
250c355de59SPhilippe Mathieu-Daudé	$(call print-help,distclean,Remove all generated files)
251c355de59SPhilippe Mathieu-Daudé	$(call print-help,dist,Build a distributable tarball)
2520d8e065fSMarc-André Lureau	@echo  ''
2530d8e065fSMarc-André Lureau	@echo  'Test targets:'
254c355de59SPhilippe Mathieu-Daudé	$(call print-help,check,Run all tests (check-help for details))
2559ed7247aSPaolo Bonzini	$(call print-help,bench,Run all benchmarks)
256c355de59SPhilippe Mathieu-Daudé	$(call print-help,docker,Help about targets running tests inside containers)
257c355de59SPhilippe Mathieu-Daudé	$(call print-help,vm-help,Help about targets running tests inside VM)
2580d8e065fSMarc-André Lureau	@echo  ''
2590d8e065fSMarc-André Lureau	@echo  'Documentation targets:'
2604ac2ee19SPeter Maydell	$(call print-help,html man,Build documentation in specified format)
2610d8e065fSMarc-André Lureau	@echo  ''
2620d8e065fSMarc-André Lureauifdef CONFIG_WIN32
2630d8e065fSMarc-André Lureau	@echo  'Windows targets:'
264c355de59SPhilippe Mathieu-Daudé	$(call print-help,installer,Build NSIS-based installer for QEMU)
2654bad7c3bSStefan Hajnocziifdef CONFIG_QGA_MSI
266c355de59SPhilippe Mathieu-Daudé	$(call print-help,msi,Build MSI-based installer for qemu-ga)
2670d8e065fSMarc-André Lureauendif
2680d8e065fSMarc-André Lureau	@echo  ''
2690d8e065fSMarc-André Lureauendif
270c355de59SPhilippe Mathieu-Daudé	$(call print-help,$(MAKE) [targets],(quiet build, default))
271c355de59SPhilippe Mathieu-Daudé	$(call print-help,$(MAKE) V=1 [targets],(verbose build))
272660f7930SPaolo Bonzini
273660f7930SPaolo Bonzini# will delete the target of a rule if commands exit with a nonzero exit status
274660f7930SPaolo Bonzini.DELETE_ON_ERROR:
275660f7930SPaolo Bonzini
276660f7930SPaolo Bonziniprint-%:
277660f7930SPaolo Bonzini	@echo '$*=$($*)'
278