]>
Commit | Line | Data |
---|---|---|
0cb3fb1e PB |
1 | # Makefile for QEMU. |
2 | ||
4ace32e2 AO |
3 | ifneq ($(words $(subst :, ,$(CURDIR))), 1) |
4 | $(error main directory cannot contain spaces nor colons) | |
5 | endif | |
6 | ||
519e1693 SW |
7 | # Always point to the root of the build tree (needs GNU make). |
8 | BUILD_DIR=$(CURDIR) | |
388d4758 | 9 | |
eaa2ddbb FZ |
10 | # Before including a proper config-host.mak, assume we are in the source tree |
11 | SRC_PATH=. | |
12 | ||
660f7930 PB |
13 | # Don't use implicit rules or variables |
14 | # we have explicit rules for everything | |
15 | MAKEFLAGS += -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. | |
23 | quiet-command-run = $(if $(V),,$(if $2,printf " %-7s %s\n" $2 $3 && ))$1 | |
24 | quiet-@ = $(if $(V),,@) | |
25 | quiet-command = $(quiet-@)$(call quiet-command-run,$1,$2,$3) | |
26 | ||
28fa2927 | 27 | UNCHECKED_GOALS := %clean TAGS cscope ctags dist \ |
de1da442 | 28 | help check-help print-% \ |
4f2f6276 | 29 | docker docker-% vm-help vm-test vm-build-% |
eaa2ddbb | 30 | |
250b086e | 31 | # All following code might depend on configuration variables |
55d7e8f6 | 32 | ifneq ($(wildcard config-host.mak),) |
1ad2134f | 33 | # Put the all: rule here so that config-host.mak can contain dependencies. |
8f67aa82 | 34 | all: |
ad064840 | 35 | include config-host.mak |
d1bd2423 | 36 | |
aef45d51 DB |
37 | git-submodule-update: |
38 | ||
39 | .PHONY: git-submodule-update | |
40 | ||
c4b01c7c DB |
41 | git_module_status := $(shell \ |
42 | cd '$(SRC_PATH)' && \ | |
43 | GIT="$(GIT)" ./scripts/git-submodule.sh status $(GIT_SUBMODULES); \ | |
44 | echo $$?; \ | |
45 | ) | |
aef45d51 DB |
46 | |
47 | ifeq (1,$(git_module_status)) | |
f62bbee5 DB |
48 | ifeq (no,$(GIT_UPDATE)) |
49 | git-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) | |
57 | else | |
aef45d51 DB |
58 | git-submodule-update: |
59 | $(call quiet-command, \ | |
cc84d63a | 60 | (cd $(SRC_PATH) && GIT="$(GIT)" ./scripts/git-submodule.sh update $(GIT_SUBMODULES)), \ |
aef45d51 DB |
61 | "GIT","$(GIT_SUBMODULES)") |
62 | endif | |
63 | endif | |
64 | ||
a5665051 PB |
65 | export NINJA=./ninjatool |
66 | ||
67 | # Running meson regenerates both build.ninja and ninjatool, and that is | |
68 | # enough to prime the rest of the build. | |
69 | ninjatool: build.ninja | |
70 | ||
a5665051 | 71 | Makefile.ninja: build.ninja ninjatool |
d7986405 | 72 | ./ninjatool -t ninja2make --omit clean dist uninstall cscope TAGS ctags < $< > $@ |
a5665051 PB |
73 | -include Makefile.ninja |
74 | ||
75 | ${ninja-targets-c_COMPILER} ${ninja-targets-cpp_COMPILER}: .var.command += -MP | |
76 | ||
245dac4a PB |
77 | # If MESON is empty, the rule will be re-evaluated after Makefiles are |
78 | # reread (and MESON won't be empty anymore). | |
79 | ifneq ($(MESON),) | |
80 | Makefile.mtest: build.ninja scripts/mtest2make.py | |
9ed7247a | 81 | $(MESON) introspect --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@ |
245dac4a PB |
82 | -include Makefile.mtest |
83 | endif | |
84 | ||
660f7930 | 85 | Makefile: .git-submodule-status |
92712822 | 86 | .git-submodule-status: git-submodule-update config-host.mak |
aef45d51 | 87 | |
d1bd2423 PM |
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. | |
90 | ifneq ($(realpath $(SRC_PATH)),$(realpath .)) | |
91 | ifneq ($(wildcard $(SRC_PATH)/config-host.mak),) | |
92 | $(error This is an out of tree build but your source tree ($(SRC_PATH)) \ | |
93 | seems to have been used for an in-tree build. You can fix this by running \ | |
b98a3bae | 94 | "$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source tree) |
d1bd2423 PM |
95 | endif |
96 | endif | |
97 | ||
3a6b016d | 98 | config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION |
e5efe7f5 | 99 | @echo $@ is out-of-date, running configure |
a5665051 PB |
100 | @if test -f meson-private/coredata.dat; then \ |
101 | ./config.status --skip-meson; \ | |
102 | else \ | |
103 | ./config.status; \ | |
104 | fi | |
26fffe29 EC |
105 | |
106 | # Force configure to re-run if the API symbols are updated | |
107 | ifeq ($(CONFIG_PLUGIN),y) | |
108 | config-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols | |
c17a386b AB |
109 | |
110 | .PHONY: plugins | |
111 | plugins: | |
112 | $(call quiet-command,\ | |
113 | $(MAKE) $(SUBDIR_MAKEFLAGS) -C contrib/plugins V="$(V)", \ | |
114 | "BUILD", "example plugins") | |
26fffe29 EC |
115 | endif |
116 | ||
55d7e8f6 AJ |
117 | else |
118 | config-host.mak: | |
eaa2ddbb | 119 | ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail)) |
55d7e8f6 AJ |
120 | @echo "Please call configure before running make!" |
121 | @exit 1 | |
122 | endif | |
7748b8cb | 123 | endif |
766a487a | 124 | |
9f5d9597 GK |
125 | # Only needed in case Makefile.ninja does not exist. |
126 | .PHONY: ninja-clean ninja-distclean clean-ctlist | |
127 | clean-ctlist: | |
128 | ninja-clean:: | |
129 | ninja-distclean:: | |
130 | build.ninja: config-host.mak | |
131 | ||
d9ace8b3 JQ |
132 | # Don't try to regenerate Makefile or configure |
133 | # We don't generate any of them | |
134 | Makefile: ; | |
135 | configure: ; | |
136 | ||
8dc746b2 | 137 | .PHONY: all clean distclean install \ |
acfdaac5 | 138 | recurse-all dist msi FORCE |
0cb3fb1e | 139 | |
660f7930 | 140 | SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet) |
a992fe3d | 141 | |
46e7b706 | 142 | include $(SRC_PATH)/tests/Makefile.include |
992aeb8e | 143 | |
484e2cc7 | 144 | all: recurse-all |
859aef02 | 145 | Makefile: $(addsuffix /all, $(SUBDIRS)) |
b9dea4fb | 146 | |
67953a37 CF |
147 | # LIBFDT_lib="": avoid breaking existing trees with objects requiring -fPIC |
148 | DTC_MAKE_ARGS=-I$(SRC_PATH)/dtc VPATH=$(SRC_PATH)/dtc -C dtc V="$(V)" LIBFDT_lib="" | |
965f486c | 149 | DTC_CFLAGS=$(CFLAGS) $(QEMU_CFLAGS) |
67953a37 | 150 | DTC_CPPFLAGS=-I$(SRC_PATH)/dtc/libfdt |
a540f158 | 151 | |
3b8593ee | 152 | .PHONY: dtc/all |
67953a37 CF |
153 | dtc/all: .git-submodule-status dtc/libfdt |
154 | $(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,) | |
a540f158 | 155 | |
00525864 | 156 | dtc/%: .git-submodule-status |
814e1110 | 157 | @mkdir -p $@ |
a540f158 | 158 | |
e219c499 RH |
159 | # Overriding CFLAGS causes us to lose defines added in the sub-makefile. |
160 | # Not overriding CFLAGS leads to mis-matches between compilation modes. | |
161 | # Therefore we replicate some of the logic in the sub-makefile. | |
162 | # Remove all the extra -Warning flags that QEMU uses that Capstone doesn't; | |
163 | # no need to annoy QEMU developers with such things. | |
feabc71d | 164 | CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS) |
e219c499 RH |
165 | CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM |
166 | CAP_CFLAGS += -DCAPSTONE_HAS_ARM | |
167 | CAP_CFLAGS += -DCAPSTONE_HAS_ARM64 | |
168 | CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC | |
169 | CAP_CFLAGS += -DCAPSTONE_HAS_X86 | |
170 | ||
3b8593ee MA |
171 | .PHONY: capstone/all |
172 | capstone/all: .git-submodule-status | |
9f81aeb5 | 173 | $(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)) |
e219c499 | 174 | |
3b8593ee MA |
175 | .PHONY: slirp/all |
176 | slirp/all: .git-submodule-status | |
daa79d9a AB |
177 | $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp \ |
178 | BUILD_DIR="$(BUILD_DIR)/slirp" \ | |
179 | PKG_CONFIG="$(PKG_CONFIG)" \ | |
180 | CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" \ | |
db5adeaa | 181 | CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)") |
675b9b53 | 182 | |
3b8593ee | 183 | ROM_DIRS = $(addprefix pc-bios/, $(ROMS)) |
1338a4b7 | 184 | ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS))) |
a9c87304 | 185 | # Only keep -O and -g cflags |
1338a4b7 MA |
186 | .PHONY: $(ROM_DIRS_RULES) |
187 | $(ROM_DIRS_RULES): | |
49b7d744 | 188 | $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" $(notdir $@),) |
c05ac895 | 189 | |
5e6d1573 | 190 | .PHONY: recurse-all recurse-clean |
49b7d744 | 191 | recurse-all: $(addsuffix /all, $(ROM_DIRS)) |
5e6d1573 | 192 | recurse-clean: $(addsuffix /clean, $(ROM_DIRS)) |
83f64091 | 193 | |
44dc0ca3 | 194 | ###################################################################### |
4fb240a4 | 195 | |
a5665051 | 196 | clean: recurse-clean ninja-clean clean-ctlist |
9f5d9597 | 197 | if test -f ninjatool; then ./ninjatool $(if $(V),-v,) -t clean; fi |
2d80ae89 | 198 | # avoid old build problems by removing potentially incorrect old files |
25be210f | 199 | 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 | 200 | find . \( -name '*.so' -o -name '*.dll' -o -name '*.[oda]' \) -type f \ |
23858f40 LE |
201 | ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \ |
202 | ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \ | |
23858f40 | 203 | -exec rm {} + |
c3a0ee84 | 204 | rm -f TAGS cscope.* *.pod *~ */*~ |
b855f8d1 | 205 | rm -f fsdev/*.pod scsi/*.pod |
31e31b8a | 206 | |
859aef02 | 207 | VERSION = $(shell cat $(SRC_PATH)/VERSION) |
34bb443e AL |
208 | |
209 | dist: qemu-$(VERSION).tar.bz2 | |
210 | ||
34bb443e AL |
211 | qemu-%.tar.bz2: |
212 | $(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)" | |
213 | ||
a5665051 PB |
214 | distclean: clean ninja-distclean |
215 | -test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean -g | |
acfdaac5 | 216 | rm -f config-host.mak config-host.h* |
2038f8c8 | 217 | rm -f tests/tcg/config-*.mak |
2becc36a | 218 | rm -f config-all-disas.mak config.status |
e8f3bd71 | 219 | rm -f tests/qemu-iotests/common.env |
fc8e320e | 220 | rm -f roms/seabios/config.mak roms/vgabios/config.mak |
26fffe29 | 221 | rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols |
64ed6f92 | 222 | rm -f *-config-target.h *-config-devices.mak *-config-devices.h |
a5665051 | 223 | rm -rf meson-private meson-logs meson-info compile_commands.json |
245dac4a | 224 | rm -f Makefile.ninja ninjatool ninjatool.stamp Makefile.mtest |
793553ac | 225 | rm -f config.log |
67ed96f9 | 226 | rm -f linux-headers/asm |
d9840e25 | 227 | rm -Rf .sdk |
7d13299d | 228 | |
c857f905 GK |
229 | find-src-path = find "$(SRC_PATH)/" -path "$(SRC_PATH)/meson" -prune -o -name "*.[chsS]" |
230 | ||
d7986405 GK |
231 | .PHONY: ctags |
232 | ctags: | |
233 | rm -f tags | |
c857f905 | 234 | $(find-src-path) -exec ctags --append {} + |
d7986405 GK |
235 | |
236 | .PHONY: TAGS | |
237 | TAGS: | |
238 | rm -f TAGS | |
c857f905 | 239 | $(find-src-path) -exec etags --append {} + |
d7986405 GK |
240 | |
241 | .PHONY: cscope | |
242 | cscope: | |
243 | rm -f "$(SRC_PATH)"/cscope.* | |
c857f905 | 244 | $(find-src-path) -print | sed -e 's,^\./,,' > "$(SRC_PATH)/cscope.files" |
d7986405 GK |
245 | cscope -b -i"$(SRC_PATH)/cscope.files" |
246 | ||
a5665051 PB |
247 | # Needed by "meson install" |
248 | export DESTDIR | |
612384d7 | 249 | |
324027c2 | 250 | include $(SRC_PATH)/tests/docker/Makefile.include |
b1fb9a63 | 251 | include $(SRC_PATH)/tests/vm/Makefile.include |
0d8e065f | 252 | |
c355de59 PMD |
253 | print-help-run = printf " %-30s - %s\\n" "$1" "$2" |
254 | print-help = $(quiet-@)$(call print-help-run,$1,$2) | |
255 | ||
0d8e065f MAL |
256 | .PHONY: help |
257 | help: | |
258 | @echo 'Generic targets:' | |
c355de59 | 259 | $(call print-help,all,Build all) |
c355de59 PMD |
260 | $(call print-help,dir/file.o,Build specified target only) |
261 | $(call print-help,install,Install QEMU, documentation and tools) | |
262 | $(call print-help,ctags/TAGS,Generate tags file for editors) | |
263 | $(call print-help,cscope,Generate cscope index) | |
968b4db3 | 264 | $(call print-help,sparse,Run sparse on the QEMU source) |
0d8e065f | 265 | @echo '' |
c17a386b AB |
266 | ifeq ($(CONFIG_PLUGIN),y) |
267 | @echo 'Plugin targets:' | |
268 | $(call print-help,plugins,Build the example TCG plugins) | |
269 | @echo '' | |
270 | endif | |
0d8e065f | 271 | @echo 'Cleaning targets:' |
c355de59 | 272 | $(call print-help,clean,Remove most generated files but keep the config) |
c355de59 PMD |
273 | $(call print-help,distclean,Remove all generated files) |
274 | $(call print-help,dist,Build a distributable tarball) | |
0d8e065f MAL |
275 | @echo '' |
276 | @echo 'Test targets:' | |
c355de59 | 277 | $(call print-help,check,Run all tests (check-help for details)) |
9ed7247a | 278 | $(call print-help,bench,Run all benchmarks) |
c355de59 PMD |
279 | $(call print-help,docker,Help about targets running tests inside containers) |
280 | $(call print-help,vm-help,Help about targets running tests inside VM) | |
0d8e065f MAL |
281 | @echo '' |
282 | @echo 'Documentation targets:' | |
acfdaac5 | 283 | $(call print-help,html info pdf txt man,Build documentation in specified format) |
0d8e065f MAL |
284 | @echo '' |
285 | ifdef CONFIG_WIN32 | |
286 | @echo 'Windows targets:' | |
c355de59 | 287 | $(call print-help,installer,Build NSIS-based installer for QEMU) |
0d8e065f | 288 | ifdef QEMU_GA_MSI_ENABLED |
c355de59 | 289 | $(call print-help,msi,Build MSI-based installer for qemu-ga) |
0d8e065f MAL |
290 | endif |
291 | @echo '' | |
292 | endif | |
c355de59 PMD |
293 | $(call print-help,$(MAKE) [targets],(quiet build, default)) |
294 | $(call print-help,$(MAKE) V=1 [targets],(verbose build)) | |
660f7930 PB |
295 | |
296 | # will delete the target of a rule if commands exit with a nonzero exit status | |
297 | .DELETE_ON_ERROR: | |
298 | ||
299 | print-%: | |
300 | @echo '$*=$($*)' |