Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. # Makefile for QEMU.
  2. ifneq ($(words $(subst :, ,$(CURDIR))), 1)
  3. $(error main directory cannot contain spaces nor colons)
  4. endif
  5. # Always point to the root of the build tree (needs GNU make).
  6. BUILD_DIR=$(CURDIR)
  7. # Before including a proper config-host.mak, assume we are in the source tree
  8. SRC_PATH=.
  9. # Don't use implicit rules or variables
  10. # we have explicit rules for everything
  11. MAKEFLAGS += -rR
  12. SHELL = bash -o pipefail
  13. # Usage: $(call quiet-command,command and args,"NAME","args to print")
  14. # This will run "command and args", and either:
  15. # if V=1 just print the whole command and args
  16. # otherwise print the 'quiet' output in the format " NAME args to print"
  17. # NAME should be a short name of the command, 7 letters or fewer.
  18. # If called with only a single argument, will print nothing in quiet mode.
  19. quiet-command-run = $(if $(V),,$(if $2,printf " %-7s %s\n" $2 $3 && ))$1
  20. quiet-@ = $(if $(V),,@)
  21. quiet-command = $(quiet-@)$(call quiet-command-run,$1,$2,$3)
  22. UNCHECKED_GOALS := TAGS gtags cscope ctags dist \
  23. help check-help print-% \
  24. docker docker-% lcitool-refresh vm-help vm-test vm-build-%
  25. all:
  26. .PHONY: all clean distclean recurse-all dist msi FORCE
  27. # Don't try to regenerate Makefile or configure
  28. # We don't generate any of them
  29. Makefile: ;
  30. configure: ;
  31. # All following code might depend on configuration variables
  32. ifneq ($(wildcard config-host.mak),)
  33. include config-host.mak
  34. include Makefile.prereqs
  35. Makefile.prereqs: config-host.mak
  36. # 0. ensure the build tree is okay
  37. # Check that we're not trying to do an out-of-tree build from
  38. # a tree that's been used for an in-tree build.
  39. ifneq ($(realpath $(SRC_PATH)),$(realpath .))
  40. ifneq ($(wildcard $(SRC_PATH)/config-host.mak),)
  41. $(error This is an out of tree build but your source tree ($(SRC_PATH)) \
  42. seems to have been used for an in-tree build. You can fix this by running \
  43. "$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source tree)
  44. endif
  45. endif
  46. # force a rerun of configure if config-host.mak is too old or corrupted
  47. ifeq ($(MESON),)
  48. .PHONY: config-host.mak
  49. x := $(shell rm -rf meson-private meson-info meson-logs)
  50. endif
  51. ifeq ($(NINJA),)
  52. .PHONY: config-host.mak
  53. x := $(shell rm -rf meson-private meson-info meson-logs)
  54. else
  55. export NINJA
  56. endif
  57. ifeq ($(wildcard build.ninja),)
  58. .PHONY: config-host.mak
  59. x := $(shell rm -rf meson-private meson-info meson-logs)
  60. endif
  61. ifeq ($(origin prefix),file)
  62. .PHONY: config-host.mak
  63. x := $(shell rm -rf meson-private meson-info meson-logs)
  64. endif
  65. # 1. ensure config-host.mak is up-to-date
  66. config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/scripts/meson-buildoptions.sh \
  67. $(SRC_PATH)/pythondeps.toml $(SRC_PATH)/VERSION
  68. @echo config-host.mak is out-of-date, running configure
  69. @if test -f meson-private/coredata.dat; then \
  70. ./config.status --skip-meson; \
  71. else \
  72. ./config.status; \
  73. fi
  74. # 2. meson.stamp exists if meson has run at least once (so ninja reconfigure
  75. # works), but otherwise never needs to be updated
  76. meson-private/coredata.dat: meson.stamp
  77. meson.stamp: config-host.mak
  78. @touch meson.stamp
  79. # 3. ensure meson-generated build files are up-to-date
  80. ifneq ($(NINJA),)
  81. Makefile.ninja: build.ninja
  82. $(quiet-@){ \
  83. echo 'ninja-targets = \'; \
  84. $(NINJA) -t targets all | sed 's/:.*//; $$!s/$$/ \\/'; \
  85. echo 'build-files = \'; \
  86. $(NINJA) -t query build.ninja | sed -n '1,/^ input:/d; /^ outputs:/q; s/$$/ \\/p'; \
  87. } > $@.tmp && mv $@.tmp $@
  88. -include Makefile.ninja
  89. endif
  90. ifneq ($(MESON),)
  91. # The path to meson always points to pyvenv/bin/meson, but the absolute
  92. # paths could change. In that case, force a regeneration of build.ninja.
  93. # Note that this invocation of $(NINJA), just like when Make rebuilds
  94. # Makefiles, does not include -n.
  95. build.ninja: build.ninja.stamp
  96. $(build-files):
  97. build.ninja.stamp: meson.stamp $(build-files)
  98. @if test "$$(cat build.ninja.stamp)" = "$(MESON)" && test -n "$(NINJA)"; then \
  99. $(NINJA) build.ninja; \
  100. else \
  101. echo "$(MESON) setup --reconfigure $(SRC_PATH)"; \
  102. $(MESON) setup --reconfigure $(SRC_PATH); \
  103. fi && echo "$(MESON)" > $@
  104. Makefile.mtest: build.ninja scripts/mtest2make.py
  105. $(MESON) introspect --targets --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@
  106. -include Makefile.mtest
  107. .PHONY: update-buildoptions
  108. all update-buildoptions: $(SRC_PATH)/scripts/meson-buildoptions.sh
  109. $(SRC_PATH)/scripts/meson-buildoptions.sh: $(SRC_PATH)/meson_options.txt
  110. $(MESON) introspect --buildoptions $(SRC_PATH)/meson.build | $(PYTHON) \
  111. scripts/meson-buildoptions.py > $@.tmp && mv $@.tmp $@
  112. endif
  113. # 4. Rules to bridge to other makefiles
  114. ifneq ($(NINJA),)
  115. # Filter out long options to avoid flags like --no-print-directory which
  116. # may result in false positive match for MAKE.n
  117. MAKE.n = $(findstring n,$(firstword $(filter-out --%,$(MAKEFLAGS))))
  118. MAKE.k = $(findstring k,$(firstword $(filter-out --%,$(MAKEFLAGS))))
  119. MAKE.q = $(findstring q,$(firstword $(filter-out --%,$(MAKEFLAGS))))
  120. MAKE.nq = $(if $(word 2, $(MAKE.n) $(MAKE.q)),nq)
  121. NINJAFLAGS = \
  122. $(if $V,-v) \
  123. $(if $(MAKE.n), -n) \
  124. $(if $(MAKE.k), -k0) \
  125. $(filter-out -j, \
  126. $(or $(filter -l% -j%, $(MAKEFLAGS)), \
  127. $(if $(filter --jobserver-auth=%, $(MAKEFLAGS)),, -j1))) \
  128. -d keepdepfile
  129. ninja-cmd-goals = $(or $(MAKECMDGOALS), all)
  130. ninja-cmd-goals += $(foreach g, $(MAKECMDGOALS), $(.ninja-goals.$g))
  131. makefile-targets := build.ninja ctags TAGS cscope dist clean
  132. # "ninja -t targets" also lists all prerequisites. If build system
  133. # files are marked as PHONY, however, Make will always try to execute
  134. # "ninja build.ninja".
  135. ninja-targets := $(filter-out $(build-files) $(makefile-targets), $(ninja-targets))
  136. .PHONY: $(ninja-targets) run-ninja
  137. $(ninja-targets): run-ninja
  138. # Use "| cat" to give Ninja a more "make-y" output. Use "+" to bypass the
  139. # --output-sync line.
  140. run-ninja: config-host.mak
  141. ifneq ($(filter $(ninja-targets), $(ninja-cmd-goals)),)
  142. +$(if $(MAKE.nq),@:,$(quiet-@)$(NINJA) $(NINJAFLAGS) \
  143. $(sort $(filter $(ninja-targets), $(ninja-cmd-goals))) | cat)
  144. endif
  145. endif
  146. else # config-host.mak does not exist
  147. ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
  148. $(error Please call configure before running make)
  149. endif
  150. endif # config-host.mak does not exist
  151. SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet)
  152. include $(SRC_PATH)/tests/Makefile.include
  153. all: recurse-all
  154. SUBDIR_RULES=$(foreach t, all clean distclean, $(addsuffix /$(t), $(SUBDIRS)))
  155. .PHONY: $(SUBDIR_RULES)
  156. $(SUBDIR_RULES):
  157. $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" $(notdir $@),)
  158. .PHONY: recurse-all recurse-clean
  159. recurse-all: $(addsuffix /all, $(SUBDIRS))
  160. recurse-clean: $(addsuffix /clean, $(SUBDIRS))
  161. recurse-distclean: $(addsuffix /distclean, $(SUBDIRS))
  162. ######################################################################
  163. clean: recurse-clean
  164. -$(quiet-@)test -f build.ninja && $(NINJA) $(NINJAFLAGS) -t clean || :
  165. -$(quiet-@)test -f build.ninja && $(NINJA) $(NINJAFLAGS) clean-ctlist || :
  166. find . \( -name '*.so' -o -name '*.dll' -o \
  167. -name '*.[oda]' -o -name '*.gcno' \) -type f \
  168. ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \
  169. ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \
  170. -exec rm {} +
  171. rm -f TAGS cscope.* *~ */*~
  172. @$(MAKE) -Ctests/qemu-iotests clean
  173. VERSION = $(shell cat $(SRC_PATH)/VERSION)
  174. dist: qemu-$(VERSION).tar.xz
  175. qemu-%.tar.xz:
  176. $(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.xz,%,$@)"
  177. distclean: clean recurse-distclean
  178. -$(quiet-@)test -f build.ninja && $(NINJA) $(NINJAFLAGS) -t clean -g || :
  179. rm -f config-host.mak Makefile.prereqs
  180. rm -f tests/tcg/*/config-target.mak tests/tcg/config-host.mak
  181. rm -f config.status
  182. rm -f roms/seabios/config.mak
  183. rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols
  184. rm -f *-config-target.h *-config-devices.mak *-config-devices.h
  185. rm -rf meson-private meson-logs meson-info compile_commands.json
  186. rm -f Makefile.ninja Makefile.mtest build.ninja.stamp meson.stamp
  187. rm -f config.log
  188. rm -f linux-headers/asm
  189. rm -Rf .sdk qemu-bundle
  190. find-src-path = find "$(SRC_PATH)" -path "$(SRC_PATH)/meson" -prune -o \
  191. -type l -prune -o \( -name "*.[chsS]" -o -name "*.[ch].inc" \)
  192. .PHONY: ctags
  193. ctags:
  194. $(call quiet-command, \
  195. rm -f "$(SRC_PATH)/"tags, \
  196. "CTAGS", "Remove old tags")
  197. $(call quiet-command, \
  198. $(find-src-path) -exec ctags \
  199. -f "$(SRC_PATH)/"tags --append {} +, \
  200. "CTAGS", "Re-index $(SRC_PATH)")
  201. .PHONY: gtags
  202. gtags:
  203. $(call quiet-command, \
  204. rm -f "$(SRC_PATH)/"GTAGS; \
  205. rm -f "$(SRC_PATH)/"GRTAGS; \
  206. rm -f "$(SRC_PATH)/"GPATH, \
  207. "GTAGS", "Remove old $@ files")
  208. $(call quiet-command, \
  209. (cd $(SRC_PATH) && \
  210. $(find-src-path) -print | gtags -f -), \
  211. "GTAGS", "Re-index $(SRC_PATH)")
  212. .PHONY: TAGS
  213. TAGS:
  214. $(call quiet-command, \
  215. rm -f "$(SRC_PATH)/"TAGS, \
  216. "TAGS", "Remove old $@")
  217. $(call quiet-command, \
  218. $(find-src-path) -exec etags \
  219. -f "$(SRC_PATH)/"TAGS --append {} +, \
  220. "TAGS", "Re-index $(SRC_PATH)")
  221. .PHONY: cscope
  222. cscope:
  223. $(call quiet-command, \
  224. rm -f "$(SRC_PATH)/"cscope.* , \
  225. "cscope", "Remove old $@ files")
  226. $(call quiet-command, \
  227. ($(find-src-path) -print | sed -e 's,^\./,,' \
  228. > "$(SRC_PATH)/cscope.files"), \
  229. "cscope", "Create file list")
  230. $(call quiet-command, \
  231. cscope -b -i"$(SRC_PATH)/cscope.files" \
  232. -f"$(SRC_PATH)"/cscope.out, \
  233. "cscope", "Re-index $(SRC_PATH)")
  234. # Needed by "meson install"
  235. export DESTDIR
  236. include $(SRC_PATH)/tests/lcitool/Makefile.include
  237. include $(SRC_PATH)/tests/docker/Makefile.include
  238. include $(SRC_PATH)/tests/vm/Makefile.include
  239. print-help-run = printf " %-30s - %s\\n" "$1" "$2"
  240. print-help = @$(call print-help-run,$1,$2)
  241. .PHONY: update-linux-vdso
  242. update-linux-vdso:
  243. @for m in $(SRC_PATH)/linux-user/*/Makefile.vdso; do \
  244. $(MAKE) $(SUBDIR_MAKEFLAGS) -C $$(dirname $$m) -f Makefile.vdso \
  245. SRC_PATH=$(SRC_PATH) BUILD_DIR=$(BUILD_DIR); \
  246. done
  247. .PHONY: help
  248. help:
  249. @echo 'Generic targets:'
  250. $(call print-help,all,Build all)
  251. $(call print-help,dir/file.o,Build specified target only)
  252. $(call print-help,install,Install QEMU, documentation and tools)
  253. $(call print-help,ctags/gtags/TAGS,Generate tags file for editors)
  254. $(call print-help,cscope,Generate cscope index)
  255. $(call print-help,sparse,Run sparse on the QEMU source)
  256. @echo ''
  257. @echo 'Cleaning targets:'
  258. $(call print-help,clean,Remove most generated files but keep the config)
  259. $(call print-help,distclean,Remove all generated files)
  260. $(call print-help,dist,Build a distributable tarball)
  261. @echo ''
  262. @echo 'Linux-user targets:'
  263. $(call print-help,update-linux-vdso,Build linux-user vdso images)
  264. @echo ''
  265. @echo 'Test targets:'
  266. $(call print-help,check,Run all tests (check-help for details))
  267. $(call print-help,bench,Run all benchmarks)
  268. $(call print-help,lcitool-help,Help about targets for managing build environment manifests)
  269. $(call print-help,docker-help,Help about targets running tests inside containers)
  270. $(call print-help,vm-help,Help about targets running tests inside VM)
  271. @echo ''
  272. @echo 'Documentation targets:'
  273. $(call print-help,html man,Build documentation in specified format)
  274. @echo ''
  275. ifneq ($(filter msi, $(ninja-targets)),)
  276. @echo 'Windows targets:'
  277. $(call print-help,installer,Build NSIS-based installer for QEMU)
  278. $(call print-help,msi,Build MSI-based installer for qemu-ga)
  279. @echo ''
  280. endif
  281. $(call print-help,$(MAKE) [targets],(quiet build, default))
  282. $(call print-help,$(MAKE) V=1 [targets],(verbose build))
  283. # will delete the target of a rule if commands exit with a nonzero exit status
  284. .DELETE_ON_ERROR:
  285. print-%:
  286. @echo '$*=$($*)'