xref: /openbmc/qemu/Makefile (revision db1015e9)
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
13# Don't use implicit rules or variables
14# we have explicit rules for everything
15MAKEFLAGS += -rR
16
17# Usage: $(call quiet-command,command and args,"NAME","args to print")
18# This will run "command and args", and either:
19#  if V=1 just print the whole command and args
20#  otherwise print the 'quiet' output in the format "  NAME     args to print"
21# NAME should be a short name of the command, 7 letters or fewer.
22# If called with only a single argument, will print nothing in quiet mode.
23quiet-command-run = $(if $(V),,$(if $2,printf "  %-7s %s\n" $2 $3 && ))$1
24quiet-@ = $(if $(V),,@)
25quiet-command = $(quiet-@)$(call quiet-command-run,$1,$2,$3)
26
27UNCHECKED_GOALS := %clean TAGS cscope ctags dist \
28    help check-help print-% \
29    docker docker-% vm-help vm-test vm-build-%
30
31# All following code might depend on configuration variables
32ifneq ($(wildcard config-host.mak),)
33# Put the all: rule here so that config-host.mak can contain dependencies.
34all:
35include config-host.mak
36
37git-submodule-update:
38
39.PHONY: git-submodule-update
40
41git_module_status := $(shell \
42  cd '$(SRC_PATH)' && \
43  GIT="$(GIT)" ./scripts/git-submodule.sh status $(GIT_SUBMODULES); \
44  echo $$?; \
45)
46
47ifeq (1,$(git_module_status))
48ifeq (no,$(GIT_UPDATE))
49git-submodule-update:
50	$(call quiet-command, \
51            echo && \
52            echo "GIT submodule checkout is out of date. Please run" && \
53            echo "  scripts/git-submodule.sh update $(GIT_SUBMODULES)" && \
54            echo "from the source directory checkout $(SRC_PATH)" && \
55            echo && \
56            exit 1)
57else
58git-submodule-update:
59	$(call quiet-command, \
60          (cd $(SRC_PATH) && GIT="$(GIT)" ./scripts/git-submodule.sh update $(GIT_SUBMODULES)), \
61          "GIT","$(GIT_SUBMODULES)")
62endif
63endif
64
65export NINJA=./ninjatool
66
67# Running meson regenerates both build.ninja and ninjatool, and that is
68# enough to prime the rest of the build.
69ninjatool: build.ninja
70
71Makefile.ninja: build.ninja ninjatool
72	./ninjatool -t ninja2make --omit clean dist uninstall cscope TAGS ctags < $< > $@
73-include Makefile.ninja
74
75${ninja-targets-c_COMPILER} ${ninja-targets-cpp_COMPILER}: .var.command += -MP
76
77# If MESON is empty, the rule will be re-evaluated after Makefiles are
78# reread (and MESON won't be empty anymore).
79ifneq ($(MESON),)
80Makefile.mtest: build.ninja scripts/mtest2make.py
81	$(MESON) introspect --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@
82-include Makefile.mtest
83endif
84
85Makefile: .git-submodule-status
86.git-submodule-status: git-submodule-update config-host.mak
87
88# Check that we're not trying to do an out-of-tree build from
89# a tree that's been used for an in-tree build.
90ifneq ($(realpath $(SRC_PATH)),$(realpath .))
91ifneq ($(wildcard $(SRC_PATH)/config-host.mak),)
92$(error This is an out of tree build but your source tree ($(SRC_PATH)) \
93seems to have been used for an in-tree build. You can fix this by running \
94"$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source tree)
95endif
96endif
97
98config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
99	@echo $@ is out-of-date, running configure
100	@if test -f meson-private/coredata.dat; then \
101	  ./config.status --skip-meson; \
102	else \
103	  ./config.status; \
104	fi
105
106# Force configure to re-run if the API symbols are updated
107ifeq ($(CONFIG_PLUGIN),y)
108config-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols
109endif
110
111else
112config-host.mak:
113ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
114	@echo "Please call configure before running make!"
115	@exit 1
116endif
117endif
118
119# Only needed in case Makefile.ninja does not exist.
120.PHONY: ninja-clean ninja-distclean clean-ctlist
121clean-ctlist:
122ninja-clean::
123ninja-distclean::
124build.ninja: config-host.mak
125
126# Don't try to regenerate Makefile or configure
127# We don't generate any of them
128Makefile: ;
129configure: ;
130
131.PHONY: all clean cscope distclean install \
132	recurse-all dist msi FORCE
133
134SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet)
135
136include $(SRC_PATH)/tests/Makefile.include
137
138all: recurse-all
139Makefile: $(addsuffix /all, $(SUBDIRS))
140
141# LIBFDT_lib="": avoid breaking existing trees with objects requiring -fPIC
142DTC_MAKE_ARGS=-I$(SRC_PATH)/dtc VPATH=$(SRC_PATH)/dtc -C dtc V="$(V)" LIBFDT_lib=""
143DTC_CFLAGS=$(CFLAGS) $(QEMU_CFLAGS)
144DTC_CPPFLAGS=-I$(SRC_PATH)/dtc/libfdt
145
146.PHONY: dtc/all
147dtc/all: .git-submodule-status dtc/libfdt
148	$(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,)
149
150dtc/%: .git-submodule-status
151	@mkdir -p $@
152
153# Overriding CFLAGS causes us to lose defines added in the sub-makefile.
154# Not overriding CFLAGS leads to mis-matches between compilation modes.
155# Therefore we replicate some of the logic in the sub-makefile.
156# Remove all the extra -Warning flags that QEMU uses that Capstone doesn't;
157# no need to annoy QEMU developers with such things.
158CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS)
159CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM
160CAP_CFLAGS += -DCAPSTONE_HAS_ARM
161CAP_CFLAGS += -DCAPSTONE_HAS_ARM64
162CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC
163CAP_CFLAGS += -DCAPSTONE_HAS_X86
164
165.PHONY: capstone/all
166capstone/all: .git-submodule-status
167	$(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))
168
169.PHONY: slirp/all
170slirp/all: .git-submodule-status
171	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp		\
172		BUILD_DIR="$(BUILD_DIR)/slirp" 			\
173		PKG_CONFIG="$(PKG_CONFIG)" 				\
174		CC="$(CC)" AR="$(AR)" 	LD="$(LD)" RANLIB="$(RANLIB)"	\
175		CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)")
176
177ROM_DIRS = $(addprefix pc-bios/, $(ROMS))
178ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS)))
179# Only keep -O and -g cflags
180.PHONY: $(ROM_DIRS_RULES)
181$(ROM_DIRS_RULES):
182	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" $(notdir $@),)
183
184.PHONY: recurse-all recurse-clean
185recurse-all: $(addsuffix /all, $(ROM_DIRS))
186recurse-clean: $(addsuffix /clean, $(ROM_DIRS))
187
188######################################################################
189
190clean: recurse-clean ninja-clean clean-ctlist
191	if test -f ninjatool; then ./ninjatool $(if $(V),-v,) -t clean; fi
192# avoid old build problems by removing potentially incorrect old files
193	rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
194	find . \( -name '*.so' -o -name '*.dll' -o -name '*.[oda]' \) -type f \
195		! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \
196		! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \
197		! -path ./roms/edk2/BaseTools/Source/Python/UPT/Dll/sqlite3.dll \
198		-exec rm {} +
199	rm -f TAGS cscope.* *.pod *~ */*~
200	rm -f fsdev/*.pod scsi/*.pod
201
202VERSION = $(shell cat $(SRC_PATH)/VERSION)
203
204dist: qemu-$(VERSION).tar.bz2
205
206qemu-%.tar.bz2:
207	$(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)"
208
209distclean: clean ninja-distclean
210	-test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean -g
211	rm -f config-host.mak config-host.h*
212	rm -f tests/tcg/config-*.mak
213	rm -f config-all-disas.mak config.status
214	rm -f tests/qemu-iotests/common.env
215	rm -f roms/seabios/config.mak roms/vgabios/config.mak
216	rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols
217	rm -f *-config-target.h *-config-devices.mak *-config-devices.h
218	rm -rf meson-private meson-logs meson-info compile_commands.json
219	rm -f Makefile.ninja ninjatool ninjatool.stamp Makefile.mtest
220	rm -f config.log
221	rm -f linux-headers/asm
222	rm -Rf .sdk
223
224.PHONY: ctags
225ctags:
226	rm -f tags
227	find "$(SRC_PATH)" -name '*.[hc]' -exec ctags --append {} +
228
229.PHONY: TAGS
230TAGS:
231	rm -f TAGS
232	find "$(SRC_PATH)" -name '*.[hc]' -exec etags --append {} +
233
234.PHONY: cscope
235cscope:
236	rm -f "$(SRC_PATH)"/cscope.*
237	find "$(SRC_PATH)/" -name "*.[chsS]" -print | sed -e 's,^\./,,' > "$(SRC_PATH)/cscope.files"
238	cscope -b -i"$(SRC_PATH)/cscope.files"
239
240# Needed by "meson install"
241export DESTDIR
242
243include $(SRC_PATH)/tests/docker/Makefile.include
244include $(SRC_PATH)/tests/vm/Makefile.include
245
246print-help-run = printf "  %-30s - %s\\n" "$1" "$2"
247print-help = $(quiet-@)$(call print-help-run,$1,$2)
248
249.PHONY: help
250help:
251	@echo  'Generic targets:'
252	$(call print-help,all,Build all)
253	$(call print-help,dir/file.o,Build specified target only)
254	$(call print-help,install,Install QEMU, documentation and tools)
255	$(call print-help,ctags/TAGS,Generate tags file for editors)
256	$(call print-help,cscope,Generate cscope index)
257	$(call print-help,sparse,Run sparse on the QEMU source)
258	@echo  ''
259	@echo  'Cleaning targets:'
260	$(call print-help,clean,Remove most generated files but keep the config)
261	$(call print-help,distclean,Remove all generated files)
262	$(call print-help,dist,Build a distributable tarball)
263	@echo  ''
264	@echo  'Test targets:'
265	$(call print-help,check,Run all tests (check-help for details))
266	$(call print-help,bench,Run all benchmarks)
267	$(call print-help,docker,Help about targets running tests inside containers)
268	$(call print-help,vm-help,Help about targets running tests inside VM)
269	@echo  ''
270	@echo  'Documentation targets:'
271	$(call print-help,html info pdf txt man,Build documentation in specified format)
272	@echo  ''
273ifdef CONFIG_WIN32
274	@echo  'Windows targets:'
275	$(call print-help,installer,Build NSIS-based installer for QEMU)
276ifdef QEMU_GA_MSI_ENABLED
277	$(call print-help,msi,Build MSI-based installer for qemu-ga)
278endif
279	@echo  ''
280endif
281	$(call print-help,$(MAKE) [targets],(quiet build, default))
282	$(call print-help,$(MAKE) V=1 [targets],(verbose build))
283
284# will delete the target of a rule if commands exit with a nonzero exit status
285.DELETE_ON_ERROR:
286
287print-%:
288	@echo '$*=$($*)'
289