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