]> Git Repo - qemu.git/blame - Makefile
add ninja to dockerfiles, CI configurations and test VMs
[qemu.git] / Makefile
CommitLineData
0cb3fb1e
PB
1# Makefile for QEMU.
2
4ace32e2
AO
3ifneq ($(words $(subst :, ,$(CURDIR))), 1)
4 $(error main directory cannot contain spaces nor colons)
5endif
6
519e1693
SW
7# Always point to the root of the build tree (needs GNU make).
8BUILD_DIR=$(CURDIR)
388d4758 9
eaa2ddbb
FZ
10# Before including a proper config-host.mak, assume we are in the source tree
11SRC_PATH=.
12
660f7930
PB
13# Don't use implicit rules or variables
14# we have explicit rules for everything
15MAKEFLAGS += -rR
16
3bf45835
PB
17SHELL = /usr/bin/env bash -o pipefail
18
660f7930
PB
19# Usage: $(call quiet-command,command and args,"NAME","args to print")
20# This will run "command and args", and either:
21# if V=1 just print the whole command and args
22# otherwise print the 'quiet' output in the format " NAME args to print"
23# NAME should be a short name of the command, 7 letters or fewer.
24# If called with only a single argument, will print nothing in quiet mode.
25quiet-command-run = $(if $(V),,$(if $2,printf " %-7s %s\n" $2 $3 && ))$1
26quiet-@ = $(if $(V),,@)
27quiet-command = $(quiet-@)$(call quiet-command-run,$1,$2,$3)
28
28fa2927 29UNCHECKED_GOALS := %clean TAGS cscope ctags dist \
de1da442 30 help check-help print-% \
4f2f6276 31 docker docker-% vm-help vm-test vm-build-%
eaa2ddbb 32
250b086e 33# All following code might depend on configuration variables
55d7e8f6 34ifneq ($(wildcard config-host.mak),)
1ad2134f 35# Put the all: rule here so that config-host.mak can contain dependencies.
8f67aa82 36all:
ad064840 37include config-host.mak
d1bd2423 38
aef45d51
DB
39git-submodule-update:
40
41.PHONY: git-submodule-update
42
c4b01c7c
DB
43git_module_status := $(shell \
44 cd '$(SRC_PATH)' && \
45 GIT="$(GIT)" ./scripts/git-submodule.sh status $(GIT_SUBMODULES); \
46 echo $$?; \
47)
aef45d51
DB
48
49ifeq (1,$(git_module_status))
f62bbee5
DB
50ifeq (no,$(GIT_UPDATE))
51git-submodule-update:
52 $(call quiet-command, \
53 echo && \
54 echo "GIT submodule checkout is out of date. Please run" && \
55 echo " scripts/git-submodule.sh update $(GIT_SUBMODULES)" && \
56 echo "from the source directory checkout $(SRC_PATH)" && \
57 echo && \
58 exit 1)
59else
aef45d51
DB
60git-submodule-update:
61 $(call quiet-command, \
cc84d63a 62 (cd $(SRC_PATH) && GIT="$(GIT)" ./scripts/git-submodule.sh update $(GIT_SUBMODULES)), \
aef45d51
DB
63 "GIT","$(GIT_SUBMODULES)")
64endif
65endif
66
a5665051
PB
67export NINJA=./ninjatool
68
69# Running meson regenerates both build.ninja and ninjatool, and that is
70# enough to prime the rest of the build.
71ninjatool: build.ninja
72
a5665051 73Makefile.ninja: build.ninja ninjatool
d7986405 74 ./ninjatool -t ninja2make --omit clean dist uninstall cscope TAGS ctags < $< > $@
a5665051
PB
75-include Makefile.ninja
76
77${ninja-targets-c_COMPILER} ${ninja-targets-cpp_COMPILER}: .var.command += -MP
78
245dac4a
PB
79# If MESON is empty, the rule will be re-evaluated after Makefiles are
80# reread (and MESON won't be empty anymore).
81ifneq ($(MESON),)
82Makefile.mtest: build.ninja scripts/mtest2make.py
48a81fd5 83 $(MESON) introspect --targets --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@
245dac4a
PB
84-include Makefile.mtest
85endif
86
660f7930 87Makefile: .git-submodule-status
92712822 88.git-submodule-status: git-submodule-update config-host.mak
aef45d51 89
d1bd2423
PM
90# Check that we're not trying to do an out-of-tree build from
91# a tree that's been used for an in-tree build.
92ifneq ($(realpath $(SRC_PATH)),$(realpath .))
93ifneq ($(wildcard $(SRC_PATH)/config-host.mak),)
94$(error This is an out of tree build but your source tree ($(SRC_PATH)) \
95seems to have been used for an in-tree build. You can fix this by running \
b98a3bae 96"$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source tree)
d1bd2423
PM
97endif
98endif
99
3a6b016d 100config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
e5efe7f5 101 @echo $@ is out-of-date, running configure
a5665051
PB
102 @if test -f meson-private/coredata.dat; then \
103 ./config.status --skip-meson; \
104 else \
105 ./config.status; \
106 fi
26fffe29
EC
107
108# Force configure to re-run if the API symbols are updated
109ifeq ($(CONFIG_PLUGIN),y)
110config-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols
c17a386b
AB
111
112.PHONY: plugins
113plugins:
114 $(call quiet-command,\
115 $(MAKE) $(SUBDIR_MAKEFLAGS) -C contrib/plugins V="$(V)", \
116 "BUILD", "example plugins")
26fffe29
EC
117endif
118
55d7e8f6
AJ
119else
120config-host.mak:
eaa2ddbb 121ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
55d7e8f6
AJ
122 @echo "Please call configure before running make!"
123 @exit 1
124endif
7748b8cb 125endif
766a487a 126
9f5d9597
GK
127# Only needed in case Makefile.ninja does not exist.
128.PHONY: ninja-clean ninja-distclean clean-ctlist
129clean-ctlist:
130ninja-clean::
131ninja-distclean::
132build.ninja: config-host.mak
133
d9ace8b3
JQ
134# Don't try to regenerate Makefile or configure
135# We don't generate any of them
136Makefile: ;
137configure: ;
138
8dc746b2 139.PHONY: all clean distclean install \
acfdaac5 140 recurse-all dist msi FORCE
0cb3fb1e 141
660f7930 142SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet)
a992fe3d 143
46e7b706 144include $(SRC_PATH)/tests/Makefile.include
992aeb8e 145
484e2cc7 146all: recurse-all
fbb4121d 147Makefile:
675b9b53 148
3b8593ee 149ROM_DIRS = $(addprefix pc-bios/, $(ROMS))
1338a4b7 150ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS)))
a9c87304 151# Only keep -O and -g cflags
1338a4b7
MA
152.PHONY: $(ROM_DIRS_RULES)
153$(ROM_DIRS_RULES):
49b7d744 154 $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" $(notdir $@),)
c05ac895 155
5e6d1573 156.PHONY: recurse-all recurse-clean
49b7d744 157recurse-all: $(addsuffix /all, $(ROM_DIRS))
5e6d1573 158recurse-clean: $(addsuffix /clean, $(ROM_DIRS))
83f64091 159
44dc0ca3 160######################################################################
4fb240a4 161
a5665051 162clean: recurse-clean ninja-clean clean-ctlist
9f5d9597 163 if test -f ninjatool; then ./ninjatool $(if $(V),-v,) -t clean; fi
2d80ae89 164# avoid old build problems by removing potentially incorrect old files
25be210f 165 rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
484e2cc7 166 find . \( -name '*.so' -o -name '*.dll' -o -name '*.[oda]' \) -type f \
23858f40
LE
167 ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \
168 ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \
23858f40 169 -exec rm {} +
c3a0ee84 170 rm -f TAGS cscope.* *.pod *~ */*~
b855f8d1 171 rm -f fsdev/*.pod scsi/*.pod
31e31b8a 172
859aef02 173VERSION = $(shell cat $(SRC_PATH)/VERSION)
34bb443e
AL
174
175dist: qemu-$(VERSION).tar.bz2
176
34bb443e
AL
177qemu-%.tar.bz2:
178 $(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)"
179
a5665051
PB
180distclean: clean ninja-distclean
181 -test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean -g
acfdaac5 182 rm -f config-host.mak config-host.h*
2038f8c8 183 rm -f tests/tcg/config-*.mak
2becc36a 184 rm -f config-all-disas.mak config.status
e8f3bd71 185 rm -f tests/qemu-iotests/common.env
fc8e320e 186 rm -f roms/seabios/config.mak roms/vgabios/config.mak
26fffe29 187 rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols
64ed6f92 188 rm -f *-config-target.h *-config-devices.mak *-config-devices.h
a5665051 189 rm -rf meson-private meson-logs meson-info compile_commands.json
245dac4a 190 rm -f Makefile.ninja ninjatool ninjatool.stamp Makefile.mtest
793553ac 191 rm -f config.log
67ed96f9 192 rm -f linux-headers/asm
d9840e25 193 rm -Rf .sdk
7d13299d 194
c857f905
GK
195find-src-path = find "$(SRC_PATH)/" -path "$(SRC_PATH)/meson" -prune -o -name "*.[chsS]"
196
d7986405
GK
197.PHONY: ctags
198ctags:
e90df5ea
GK
199 rm -f "$(SRC_PATH)/"tags
200 $(find-src-path) -exec ctags -f "$(SRC_PATH)/"tags --append {} +
d7986405
GK
201
202.PHONY: TAGS
203TAGS:
e90df5ea
GK
204 rm -f "$(SRC_PATH)/"TAGS
205 $(find-src-path) -exec etags -f "$(SRC_PATH)/"TAGS --append {} +
d7986405
GK
206
207.PHONY: cscope
208cscope:
209 rm -f "$(SRC_PATH)"/cscope.*
c857f905 210 $(find-src-path) -print | sed -e 's,^\./,,' > "$(SRC_PATH)/cscope.files"
e90df5ea 211 cscope -b -i"$(SRC_PATH)/cscope.files" -f"$(SRC_PATH)"/cscope.out
d7986405 212
a5665051
PB
213# Needed by "meson install"
214export DESTDIR
612384d7 215
324027c2 216include $(SRC_PATH)/tests/docker/Makefile.include
b1fb9a63 217include $(SRC_PATH)/tests/vm/Makefile.include
0d8e065f 218
c355de59
PMD
219print-help-run = printf " %-30s - %s\\n" "$1" "$2"
220print-help = $(quiet-@)$(call print-help-run,$1,$2)
221
0d8e065f
MAL
222.PHONY: help
223help:
224 @echo 'Generic targets:'
c355de59 225 $(call print-help,all,Build all)
c355de59
PMD
226 $(call print-help,dir/file.o,Build specified target only)
227 $(call print-help,install,Install QEMU, documentation and tools)
228 $(call print-help,ctags/TAGS,Generate tags file for editors)
229 $(call print-help,cscope,Generate cscope index)
968b4db3 230 $(call print-help,sparse,Run sparse on the QEMU source)
0d8e065f 231 @echo ''
c17a386b
AB
232ifeq ($(CONFIG_PLUGIN),y)
233 @echo 'Plugin targets:'
234 $(call print-help,plugins,Build the example TCG plugins)
235 @echo ''
236endif
0d8e065f 237 @echo 'Cleaning targets:'
c355de59 238 $(call print-help,clean,Remove most generated files but keep the config)
c355de59
PMD
239 $(call print-help,distclean,Remove all generated files)
240 $(call print-help,dist,Build a distributable tarball)
0d8e065f
MAL
241 @echo ''
242 @echo 'Test targets:'
c355de59 243 $(call print-help,check,Run all tests (check-help for details))
9ed7247a 244 $(call print-help,bench,Run all benchmarks)
c355de59
PMD
245 $(call print-help,docker,Help about targets running tests inside containers)
246 $(call print-help,vm-help,Help about targets running tests inside VM)
0d8e065f
MAL
247 @echo ''
248 @echo 'Documentation targets:'
4ac2ee19 249 $(call print-help,html man,Build documentation in specified format)
0d8e065f
MAL
250 @echo ''
251ifdef CONFIG_WIN32
252 @echo 'Windows targets:'
c355de59 253 $(call print-help,installer,Build NSIS-based installer for QEMU)
4bad7c3b 254ifdef CONFIG_QGA_MSI
c355de59 255 $(call print-help,msi,Build MSI-based installer for qemu-ga)
0d8e065f
MAL
256endif
257 @echo ''
258endif
c355de59
PMD
259 $(call print-help,$(MAKE) [targets],(quiet build, default))
260 $(call print-help,$(MAKE) V=1 [targets],(verbose build))
660f7930
PB
261
262# will delete the target of a rule if commands exit with a nonzero exit status
263.DELETE_ON_ERROR:
264
265print-%:
266 @echo '$*=$($*)'
This page took 0.80926 seconds and 4 git commands to generate.