Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 := %clean TAGS cscope ctags dist \
  23. help check-help print-% \
  24. docker docker-% 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. git-submodule-update:
  37. .git-submodule-status: git-submodule-update config-host.mak
  38. Makefile: .git-submodule-status
  39. .PHONY: git-submodule-update
  40. git-submodule-update:
  41. ifneq ($(GIT_SUBMODULES_ACTION),ignore)
  42. $(call quiet-command, \
  43. (GIT="$(GIT)" "$(SRC_PATH)/scripts/git-submodule.sh" $(GIT_SUBMODULES_ACTION) $(GIT_SUBMODULES)), \
  44. "GIT","$(GIT_SUBMODULES)")
  45. endif
  46. # 0. ensure the build tree is okay
  47. # Check that we're not trying to do an out-of-tree build from
  48. # a tree that's been used for an in-tree build.
  49. ifneq ($(realpath $(SRC_PATH)),$(realpath .))
  50. ifneq ($(wildcard $(SRC_PATH)/config-host.mak),)
  51. $(error This is an out of tree build but your source tree ($(SRC_PATH)) \
  52. seems to have been used for an in-tree build. You can fix this by running \
  53. "$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source tree)
  54. endif
  55. endif
  56. # force a rerun of configure if config-host.mak is too old or corrupted
  57. ifeq ($(MESON),)
  58. .PHONY: config-host.mak
  59. x := $(shell rm -rf meson-private meson-info meson-logs)
  60. endif
  61. ifeq ($(NINJA),)
  62. .PHONY: config-host.mak
  63. x := $(shell rm -rf meson-private meson-info meson-logs)
  64. else
  65. export NINJA
  66. endif
  67. ifeq ($(wildcard build.ninja),)
  68. .PHONY: config-host.mak
  69. x := $(shell rm -rf meson-private meson-info meson-logs)
  70. endif
  71. ifeq ($(origin prefix),file)
  72. .PHONY: config-host.mak
  73. x := $(shell rm -rf meson-private meson-info meson-logs)
  74. endif
  75. # 1. ensure config-host.mak is up-to-date
  76. config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/scripts/meson-buildoptions.sh $(SRC_PATH)/VERSION
  77. @echo config-host.mak is out-of-date, running configure
  78. @if test -f meson-private/coredata.dat; then \
  79. ./config.status --skip-meson; \
  80. else \
  81. ./config.status && touch build.ninja.stamp; \
  82. fi
  83. # 2. meson.stamp exists if meson has run at least once (so ninja reconfigure
  84. # works), but otherwise never needs to be updated
  85. meson-private/coredata.dat: meson.stamp
  86. meson.stamp: config-host.mak
  87. @touch meson.stamp
  88. # 3. ensure generated build files are up-to-date
  89. ifneq ($(NINJA),)
  90. Makefile.ninja: build.ninja
  91. $(quiet-@){ \
  92. echo 'ninja-targets = \'; \
  93. $(NINJA) -t targets all | sed 's/:.*//; $$!s/$$/ \\/'; \
  94. echo 'build-files = \'; \
  95. $(NINJA) -t query build.ninja | sed -n '1,/^ input:/d; /^ outputs:/q; s/$$/ \\/p'; \
  96. } > $@.tmp && mv $@.tmp $@
  97. -include Makefile.ninja
  98. # A separate rule is needed for Makefile dependencies to avoid -n
  99. build.ninja: build.ninja.stamp
  100. $(build-files):
  101. build.ninja.stamp: meson.stamp $(build-files)
  102. $(NINJA) $(if $V,-v,) build.ninja && touch $@
  103. endif
  104. ifneq ($(MESON),)
  105. Makefile.mtest: build.ninja scripts/mtest2make.py
  106. $(MESON) introspect --targets --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@
  107. -include Makefile.mtest
  108. .PHONY: update-buildoptions
  109. all update-buildoptions: $(SRC_PATH)/scripts/meson-buildoptions.sh
  110. $(SRC_PATH)/scripts/meson-buildoptions.sh: $(SRC_PATH)/meson_options.txt
  111. $(MESON) introspect --buildoptions $(SRC_PATH)/meson.build | $(PYTHON) \
  112. scripts/meson-buildoptions.py > $@.tmp && mv $@.tmp $@
  113. endif
  114. # 4. Rules to bridge to other makefiles
  115. ifneq ($(NINJA),)
  116. # Filter out long options to avoid flags like --no-print-directory which
  117. # may result in false positive match for MAKE.n
  118. MAKE.n = $(findstring n,$(firstword $(filter-out --%,$(MAKEFLAGS))))
  119. MAKE.k = $(findstring k,$(firstword $(filter-out --%,$(MAKEFLAGS))))
  120. MAKE.q = $(findstring q,$(firstword $(filter-out --%,$(MAKEFLAGS))))
  121. MAKE.nq = $(if $(word 2, $(MAKE.n) $(MAKE.q)),nq)
  122. NINJAFLAGS = $(if $V,-v) $(if $(MAKE.n), -n) $(if $(MAKE.k), -k0) \
  123. $(filter-out -j, $(lastword -j1 $(filter -l% -j%, $(MAKEFLAGS)))) \
  124. -d keepdepfile
  125. ninja-cmd-goals = $(or $(MAKECMDGOALS), all)
  126. ninja-cmd-goals += $(foreach g, $(MAKECMDGOALS), $(.ninja-goals.$g))
  127. makefile-targets := build.ninja ctags TAGS cscope dist clean
  128. # "ninja -t targets" also lists all prerequisites. If build system
  129. # files are marked as PHONY, however, Make will always try to execute
  130. # "ninja build.ninja".
  131. ninja-targets := $(filter-out $(build-files) $(makefile-targets), $(ninja-targets))
  132. .PHONY: $(ninja-targets) run-ninja
  133. $(ninja-targets): run-ninja
  134. # Use "| cat" to give Ninja a more "make-y" output. Use "+" to bypass the
  135. # --output-sync line.
  136. run-ninja: config-host.mak
  137. ifneq ($(filter $(ninja-targets), $(ninja-cmd-goals)),)
  138. +$(if $(MAKE.nq),@:,$(quiet-@)$(NINJA) $(NINJAFLAGS) \
  139. $(sort $(filter $(ninja-targets), $(ninja-cmd-goals))) | cat)
  140. endif
  141. endif
  142. ifeq ($(CONFIG_PLUGIN),y)
  143. .PHONY: plugins
  144. plugins:
  145. $(call quiet-command,\
  146. $(MAKE) $(SUBDIR_MAKEFLAGS) -C contrib/plugins V="$(V)", \
  147. "BUILD", "example plugins")
  148. endif # $(CONFIG_PLUGIN)
  149. else # config-host.mak does not exist
  150. config-host.mak:
  151. ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
  152. @echo "Please call configure before running make!"
  153. @exit 1
  154. endif
  155. endif # config-host.mak does not exist
  156. SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet)
  157. include $(SRC_PATH)/tests/Makefile.include
  158. all: recurse-all
  159. ROMS_RULES=$(foreach t, all clean distclean, $(addsuffix /$(t), $(ROMS)))
  160. .PHONY: $(ROMS_RULES)
  161. $(ROMS_RULES):
  162. $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" $(notdir $@),)
  163. .PHONY: recurse-all recurse-clean
  164. recurse-all: $(addsuffix /all, $(ROMS))
  165. recurse-clean: $(addsuffix /clean, $(ROMS))
  166. recurse-distclean: $(addsuffix /distclean, $(ROMS))
  167. ######################################################################
  168. clean: recurse-clean
  169. -$(quiet-@)test -f build.ninja && $(NINJA) $(NINJAFLAGS) -t clean || :
  170. -$(quiet-@)test -f build.ninja && $(NINJA) $(NINJAFLAGS) clean-ctlist || :
  171. find . \( -name '*.so' -o -name '*.dll' -o \
  172. -name '*.[oda]' -o -name '*.gcno' \) -type f \
  173. ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \
  174. ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \
  175. -exec rm {} +
  176. rm -f TAGS cscope.* *~ */*~
  177. VERSION = $(shell cat $(SRC_PATH)/VERSION)
  178. dist: qemu-$(VERSION).tar.bz2
  179. qemu-%.tar.bz2:
  180. $(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)"
  181. distclean: clean recurse-distclean
  182. -$(quiet-@)test -f build.ninja && $(NINJA) $(NINJAFLAGS) -t clean -g || :
  183. rm -f config-host.mak Makefile.prereqs
  184. rm -f tests/tcg/*/config-target.mak tests/tcg/config-host.mak
  185. rm -f config.status
  186. rm -f roms/seabios/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 Makefile.mtest build.ninja.stamp meson.stamp
  191. rm -f config.log
  192. rm -f linux-headers/asm
  193. rm -Rf .sdk qemu-bundle
  194. find-src-path = find "$(SRC_PATH)" -path "$(SRC_PATH)/meson" -prune -o \
  195. -type l -prune -o \( -name "*.[chsS]" -o -name "*.[ch].inc" \)
  196. .PHONY: ctags
  197. ctags:
  198. $(call quiet-command, \
  199. rm -f "$(SRC_PATH)/"tags, \
  200. "CTAGS", "Remove old tags")
  201. $(call quiet-command, \
  202. $(find-src-path) -exec ctags \
  203. -f "$(SRC_PATH)/"tags --append {} +, \
  204. "CTAGS", "Re-index $(SRC_PATH)")
  205. .PHONY: gtags
  206. gtags:
  207. $(call quiet-command, \
  208. rm -f "$(SRC_PATH)/"GTAGS; \
  209. rm -f "$(SRC_PATH)/"GRTAGS; \
  210. rm -f "$(SRC_PATH)/"GPATH, \
  211. "GTAGS", "Remove old $@ files")
  212. $(call quiet-command, \
  213. (cd $(SRC_PATH) && \
  214. $(find-src-path) -print | gtags -f -), \
  215. "GTAGS", "Re-index $(SRC_PATH)")
  216. .PHONY: TAGS
  217. TAGS:
  218. $(call quiet-command, \
  219. rm -f "$(SRC_PATH)/"TAGS, \
  220. "TAGS", "Remove old $@")
  221. $(call quiet-command, \
  222. $(find-src-path) -exec etags \
  223. -f "$(SRC_PATH)/"TAGS --append {} +, \
  224. "TAGS", "Re-index $(SRC_PATH)")
  225. .PHONY: cscope
  226. cscope:
  227. $(call quiet-command, \
  228. rm -f "$(SRC_PATH)/"cscope.* , \
  229. "cscope", "Remove old $@ files")
  230. $(call quiet-command, \
  231. ($(find-src-path) -print | sed -e 's,^\./,,' \
  232. > "$(SRC_PATH)/cscope.files"), \
  233. "cscope", "Create file list")
  234. $(call quiet-command, \
  235. cscope -b -i"$(SRC_PATH)/cscope.files" \
  236. -f"$(SRC_PATH)"/cscope.out, \
  237. "cscope", "Re-index $(SRC_PATH)")
  238. # Needed by "meson install"
  239. export DESTDIR
  240. include $(SRC_PATH)/tests/lcitool/Makefile.include
  241. include $(SRC_PATH)/tests/docker/Makefile.include
  242. include $(SRC_PATH)/tests/vm/Makefile.include
  243. print-help-run = printf " %-30s - %s\\n" "$1" "$2"
  244. print-help = @$(call print-help-run,$1,$2)
  245. .PHONY: help
  246. help:
  247. @echo 'Generic targets:'
  248. $(call print-help,all,Build all)
  249. $(call print-help,dir/file.o,Build specified target only)
  250. $(call print-help,install,Install QEMU, documentation and tools)
  251. $(call print-help,ctags/gtags/TAGS,Generate tags file for editors)
  252. $(call print-help,cscope,Generate cscope index)
  253. $(call print-help,sparse,Run sparse on the QEMU source)
  254. @echo ''
  255. ifeq ($(CONFIG_PLUGIN),y)
  256. @echo 'Plugin targets:'
  257. $(call print-help,plugins,Build the example TCG plugins)
  258. @echo ''
  259. endif
  260. @echo 'Cleaning targets:'
  261. $(call print-help,clean,Remove most generated files but keep the config)
  262. $(call print-help,distclean,Remove all generated files)
  263. $(call print-help,dist,Build a distributable tarball)
  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. ifdef CONFIG_WIN32
  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 '$*=$($*)'