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