]> Git Repo - qemu.git/blob - Makefile
build: cleanups to Makefile
[qemu.git] / Makefile
1 # Makefile for QEMU.
2
3 ifneq ($(words $(subst :, ,$(CURDIR))), 1)
4   $(error main directory cannot contain spaces nor colons)
5 endif
6
7 # Always point to the root of the build tree (needs GNU make).
8 BUILD_DIR=$(CURDIR)
9
10 # Before including a proper config-host.mak, assume we are in the source tree
11 SRC_PATH=.
12
13 # Don't use implicit rules or variables
14 # we have explicit rules for everything
15 MAKEFLAGS += -rR
16
17 SHELL = /usr/bin/env bash -o pipefail
18
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.
25 quiet-command-run = $(if $(V),,$(if $2,printf "  %-7s %s\n" $2 $3 && ))$1
26 quiet-@ = $(if $(V),,@)
27 quiet-command = $(quiet-@)$(call quiet-command-run,$1,$2,$3)
28
29 UNCHECKED_GOALS := %clean TAGS cscope ctags dist \
30     help check-help print-% \
31     docker docker-% vm-help vm-test vm-build-%
32
33 all:
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
38 Makefile: ;
39 configure: ;
40
41 # All following code might depend on configuration variables
42 ifneq ($(wildcard config-host.mak),)
43 include config-host.mak
44
45 git-submodule-update:
46 .git-submodule-status: git-submodule-update config-host.mak
47 Makefile: .git-submodule-status
48
49 .PHONY: git-submodule-update
50
51 git_module_status := $(shell \
52   cd '$(SRC_PATH)' && \
53   GIT="$(GIT)" ./scripts/git-submodule.sh status $(GIT_SUBMODULES); \
54   echo $$?; \
55 )
56
57 ifeq (1,$(git_module_status))
58 ifeq (no,$(GIT_UPDATE))
59 git-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)
67 else
68 git-submodule-update:
69         $(call quiet-command, \
70           (cd $(SRC_PATH) && GIT="$(GIT)" ./scripts/git-submodule.sh update $(GIT_SUBMODULES)), \
71           "GIT","$(GIT_SUBMODULES)")
72 endif
73 endif
74
75 export NINJA=./ninjatool
76
77 # Running meson regenerates both build.ninja and ninjatool, and that is
78 # enough to prime the rest of the build.
79 ninjatool: build.ninja
80
81 Makefile.ninja: build.ninja ninjatool
82         ./ninjatool -t ninja2make --omit clean dist uninstall cscope TAGS ctags < $< > $@
83 -include Makefile.ninja
84
85 ${ninja-targets-c_COMPILER} ${ninja-targets-cpp_COMPILER}: .var.command += -MP
86
87 # If MESON is empty, the rule will be re-evaluated after Makefiles are
88 # reread (and MESON won't be empty anymore).
89 ifneq ($(MESON),)
90 Makefile.mtest: build.ninja scripts/mtest2make.py
91         $(MESON) introspect --targets --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@
92 -include Makefile.mtest
93 endif
94
95 # Ensure the build tree is okay.
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.
98 ifneq ($(realpath $(SRC_PATH)),$(realpath .))
99 ifneq ($(wildcard $(SRC_PATH)/config-host.mak),)
100 $(error This is an out of tree build but your source tree ($(SRC_PATH)) \
101 seems to have been used for an in-tree build. You can fix this by running \
102 "$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source tree)
103 endif
104 endif
105
106 # force a rerun of configure if config-host.mak is too old or corrupted
107 ifeq ($(MESON),)
108 .PHONY: config-host.mak
109 x := $(shell rm -rf meson-private meson-info meson-logs)
110 endif
111 ifeq ($(NINJA),)
112 .PHONY: config-host.mak
113 x := $(shell rm -rf meson-private meson-info meson-logs)
114 endif
115 ifeq ($(wildcard build.ninja),)
116 .PHONY: config-host.mak
117 x := $(shell rm -rf meson-private meson-info meson-logs)
118 endif
119
120 config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
121         @echo $@ is out-of-date, running configure
122         @if test -f meson-private/coredata.dat; then \
123           ./config.status --skip-meson; \
124         else \
125           ./config.status; \
126         fi
127
128 # Force configure to re-run if the API symbols are updated
129 ifeq ($(CONFIG_PLUGIN),y)
130 config-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols
131
132 .PHONY: plugins
133 plugins:
134         $(call quiet-command,\
135                 $(MAKE) $(SUBDIR_MAKEFLAGS) -C contrib/plugins V="$(V)", \
136                 "BUILD", "example plugins")
137 endif # $(CONFIG_PLUGIN)
138
139 else # config-host.mak does not exist
140 config-host.mak:
141 ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
142         @echo "Please call configure before running make!"
143         @exit 1
144 endif
145 endif # config-host.mak does not exist
146
147 # Only needed in case Makefile.ninja does not exist.
148 .PHONY: ninja-clean ninja-distclean clean-ctlist
149 clean-ctlist:
150 ninja-clean::
151 ninja-distclean::
152 build.ninja: config-host.mak
153
154 SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet)
155
156 include $(SRC_PATH)/tests/Makefile.include
157
158 all: recurse-all
159
160 ROM_DIRS = $(addprefix pc-bios/, $(ROMS))
161 ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS)))
162 # Only keep -O and -g cflags
163 .PHONY: $(ROM_DIRS_RULES)
164 $(ROM_DIRS_RULES):
165         $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" $(notdir $@),)
166
167 .PHONY: recurse-all recurse-clean
168 recurse-all: $(addsuffix /all, $(ROM_DIRS))
169 recurse-clean: $(addsuffix /clean, $(ROM_DIRS))
170
171 ######################################################################
172
173 clean: recurse-clean ninja-clean clean-ctlist
174         if test -f ninjatool; then ./ninjatool $(if $(V),-v,) -t clean; fi
175 # avoid old build problems by removing potentially incorrect old files
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
177         find . \( -name '*.so' -o -name '*.dll' -o -name '*.[oda]' \) -type f \
178                 ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \
179                 ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \
180                 -exec rm {} +
181         rm -f TAGS cscope.* *.pod *~ */*~
182         rm -f fsdev/*.pod scsi/*.pod
183
184 VERSION = $(shell cat $(SRC_PATH)/VERSION)
185
186 dist: qemu-$(VERSION).tar.bz2
187
188 qemu-%.tar.bz2:
189         $(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)"
190
191 distclean: clean ninja-distclean
192         -test -f ninjatool && ./ninjatool $(if $(V),-v,) -t clean -g
193         rm -f config-host.mak config-host.h*
194         rm -f tests/tcg/config-*.mak
195         rm -f config-all-disas.mak config.status
196         rm -f tests/qemu-iotests/common.env
197         rm -f roms/seabios/config.mak roms/vgabios/config.mak
198         rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols
199         rm -f *-config-target.h *-config-devices.mak *-config-devices.h
200         rm -rf meson-private meson-logs meson-info compile_commands.json
201         rm -f Makefile.ninja ninjatool ninjatool.stamp Makefile.mtest
202         rm -f config.log
203         rm -f linux-headers/asm
204         rm -Rf .sdk
205
206 find-src-path = find "$(SRC_PATH)/" -path "$(SRC_PATH)/meson" -prune -o -name "*.[chsS]"
207
208 .PHONY: ctags
209 ctags:
210         rm -f "$(SRC_PATH)/"tags
211         $(find-src-path) -exec ctags -f "$(SRC_PATH)/"tags --append {} +
212
213 .PHONY: TAGS
214 TAGS:
215         rm -f "$(SRC_PATH)/"TAGS
216         $(find-src-path) -exec etags -f "$(SRC_PATH)/"TAGS --append {} +
217
218 .PHONY: cscope
219 cscope:
220         rm -f "$(SRC_PATH)"/cscope.*
221         $(find-src-path) -print | sed -e 's,^\./,,' > "$(SRC_PATH)/cscope.files"
222         cscope -b -i"$(SRC_PATH)/cscope.files" -f"$(SRC_PATH)"/cscope.out
223
224 # Needed by "meson install"
225 export DESTDIR
226
227 include $(SRC_PATH)/tests/docker/Makefile.include
228 include $(SRC_PATH)/tests/vm/Makefile.include
229
230 print-help-run = printf "  %-30s - %s\\n" "$1" "$2"
231 print-help = $(quiet-@)$(call print-help-run,$1,$2)
232
233 .PHONY: help
234 help:
235         @echo  'Generic targets:'
236         $(call print-help,all,Build all)
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)
241         $(call print-help,sparse,Run sparse on the QEMU source)
242         @echo  ''
243 ifeq ($(CONFIG_PLUGIN),y)
244         @echo  'Plugin targets:'
245         $(call print-help,plugins,Build the example TCG plugins)
246         @echo  ''
247 endif
248         @echo  'Cleaning targets:'
249         $(call print-help,clean,Remove most generated files but keep the config)
250         $(call print-help,distclean,Remove all generated files)
251         $(call print-help,dist,Build a distributable tarball)
252         @echo  ''
253         @echo  'Test targets:'
254         $(call print-help,check,Run all tests (check-help for details))
255         $(call print-help,bench,Run all benchmarks)
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)
258         @echo  ''
259         @echo  'Documentation targets:'
260         $(call print-help,html man,Build documentation in specified format)
261         @echo  ''
262 ifdef CONFIG_WIN32
263         @echo  'Windows targets:'
264         $(call print-help,installer,Build NSIS-based installer for QEMU)
265 ifdef CONFIG_QGA_MSI
266         $(call print-help,msi,Build MSI-based installer for qemu-ga)
267 endif
268         @echo  ''
269 endif
270         $(call print-help,$(MAKE) [targets],(quiet build, default))
271         $(call print-help,$(MAKE) V=1 [targets],(verbose build))
272
273 # will delete the target of a rule if commands exit with a nonzero exit status
274 .DELETE_ON_ERROR:
275
276 print-%:
277         @echo '$*=$($*)'
This page took 0.038758 seconds and 4 git commands to generate.