From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Havard Skinnemoen <hskinnemoen@gmail.com>
Subject: [PULL 08/17] Makefile: separate meson rerun from the rest of the ninja invocation
Date: Mon, 26 Oct 2020 09:51:22 -0400 [thread overview]
Message-ID: <20201026135131.3006712-9-pbonzini@redhat.com> (raw)
In-Reply-To: <20201026135131.3006712-1-pbonzini@redhat.com>
The rules to build Makefile.mtest are suffering from the "tunnel vision"
problem that is common with recursive makefiles. Makefile.mtest depends
on build.ninja, but Make does not know when build.ninja needs to be
rebuilt before creating Makefile.mtest.
To fix this, separate the ninja invocation into the "regenerate build
files" phase and the QEMU build phase. Sentinel files such as
meson-private/coredata.dat or build.ninja are used to figure out the
phases that haven't run yet; however, because those files' timestamps
are not guaranteed to be touched, the usual makefile stamp-file trick
is used on top.
Reported-by: Havard Skinnemoen <hskinnemoen@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
Makefile | 40 +++++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/Makefile b/Makefile
index 18f026eac3..5236464d1f 100644
--- a/Makefile
+++ b/Makefile
@@ -92,6 +92,8 @@ endif
ifeq ($(NINJA),)
.PHONY: config-host.mak
x := $(shell rm -rf meson-private meson-info meson-logs)
+else
+export NINJA
endif
ifeq ($(wildcard build.ninja),)
.PHONY: config-host.mak
@@ -100,31 +102,44 @@ endif
# 1. ensure config-host.mak is up-to-date
config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
- @echo $@ is out-of-date, running configure
+ @echo config-host.mak is out-of-date, running configure
@if test -f meson-private/coredata.dat; then \
./config.status --skip-meson; \
else \
- ./config.status; \
+ ./config.status && touch build.ninja.stamp; \
fi
-# 2. ensure generated build files are up-to-date
+# 2. meson.stamp exists if meson has run at least once (so ninja reconfigure
+# works), but otherwise never needs to be updated
+meson-private/coredata.dat: meson.stamp
+meson.stamp: config-host.mak
+ @touch meson.stamp
+
+# 3. ensure generated build files are up-to-date
ifneq ($(NINJA),)
-# A separate rule is needed for Makefile dependencies to avoid -n
-export NINJA
Makefile.ninja: build.ninja
- $(quiet-@){ echo 'ninja-targets = \'; $(NINJA) -t targets all | sed 's/:.*//; $$!s/$$/ \\/'; } > $@
+ $(quiet-@){ \
+ echo 'ninja-targets = \'; \
+ $(NINJA) -t targets all | sed 's/:.*//; $$!s/$$/ \\/'; \
+ echo 'build-files = \'; \
+ $(NINJA) -t query build.ninja | sed -n '1,/^ input:/d; /^ outputs:/q; s/$$/ \\/p'; \
+ } > $@.tmp && mv $@.tmp $@
-include Makefile.ninja
+
+# A separate rule is needed for Makefile dependencies to avoid -n
+build.ninja: build.ninja.stamp
+build.ninja.stamp: meson.stamp $(build-files)
+ $(NINJA) $(if $V,-v,) build.ninja && touch $@
endif
ifneq ($(MESON),)
-# The dependency on config-host.mak ensures that meson has run
-Makefile.mtest: build.ninja scripts/mtest2make.py config-host.mak
+Makefile.mtest: build.ninja scripts/mtest2make.py
$(MESON) introspect --targets --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@
-include Makefile.mtest
endif
-# 3. Rules to bridge to other makefiles
+# 4. Rules to bridge to other makefiles
ifneq ($(NINJA),)
NINJAFLAGS = $(if $V,-v,) \
@@ -135,7 +150,10 @@ ninja-cmd-goals = $(or $(MAKECMDGOALS), all)
ninja-cmd-goals += $(foreach t, $(.tests), $(.test.deps.$t))
makefile-targets := build.ninja ctags TAGS cscope dist clean uninstall
-ninja-targets := $(filter-out $(makefile-targets), $(ninja-targets))
+# "ninja -t targets" also lists all prerequisites. If build system
+# files are marked as PHONY, however, Make will always try to execute
+# "ninja build.ninja".
+ninja-targets := $(filter-out $(build-files) $(makefile-targets), $(ninja-targets))
.PHONY: $(ninja-targets) run-ninja
$(ninja-targets): run-ninja
@@ -214,7 +232,7 @@ distclean: clean
rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols
rm -f *-config-target.h *-config-devices.mak *-config-devices.h
rm -rf meson-private meson-logs meson-info compile_commands.json
- rm -f Makefile.ninja Makefile.mtest
+ rm -f Makefile.ninja Makefile.mtest build.ninja.stamp meson.stamp
rm -f config.log
rm -f linux-headers/asm
rm -Rf .sdk
--
2.26.2
next prev parent reply other threads:[~2020-10-26 13:54 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-26 13:51 [PULL 00/17] Build system changes and misc fixes for QEMU 5.2 soft freeze Paolo Bonzini
2020-10-26 13:51 ` [PULL 01/17] build: fix macOS --enable-modules build Paolo Bonzini
2020-10-27 9:27 ` Philippe Mathieu-Daudé
2020-10-27 13:27 ` Paolo Bonzini
2020-10-27 15:21 ` Gerd Hoffmann
2020-10-27 15:33 ` Gerd Hoffmann
2020-10-26 13:51 ` [PULL 02/17] meson: rewrite curses/iconv test Paolo Bonzini
2020-10-26 13:51 ` [PULL 03/17] do not use colons in test names Paolo Bonzini
2020-10-26 13:51 ` [PULL 04/17] hw/core/qdev-clock: add a reference on aliased clocks Paolo Bonzini
2020-10-26 13:51 ` [PULL 05/17] qtest: unbreak non-TCG builds in bios-tables-test Paolo Bonzini
2020-10-26 13:51 ` [PULL 06/17] replay: do not build if TCG is not available Paolo Bonzini
2020-10-26 13:51 ` [PULL 07/17] Remove deprecated -no-kvm option Paolo Bonzini
2020-10-26 13:51 ` Paolo Bonzini [this message]
2020-10-26 13:51 ` [PULL 09/17] configure: allow configuring localedir Paolo Bonzini
2020-10-26 13:51 ` [PULL 10/17] configure: move directory options from config-host.mak to meson Paolo Bonzini
2020-10-26 13:51 ` [PULL 11/17] configure: remove unused variable from config-host.mak Paolo Bonzini
2020-10-26 13:51 ` [PULL 12/17] configure: move install_blobs from configure to meson Paolo Bonzini
2020-10-26 13:51 ` [PULL 13/17] WHPX: Fix WHPX build break Paolo Bonzini
2020-10-26 13:51 ` [PULL 14/17] win32: boot broken when bind & data dir are the same Paolo Bonzini
2020-10-26 13:51 ` [PULL 15/17] machine: remove deprecated -machine enforce-config-section option Paolo Bonzini
2020-10-26 13:51 ` [PULL 16/17] machine: move UP defaults to class_base_init Paolo Bonzini
2020-10-26 13:51 ` [PULL 17/17] machine: move SMP initialization from vl.c Paolo Bonzini
2020-10-26 17:18 ` [PULL 00/17] Build system changes and misc fixes for QEMU 5.2 soft freeze Peter Maydell
2020-10-26 18:59 ` 罗勇刚(Yonggang Luo)
2020-10-26 20:58 ` Paolo Bonzini
2020-10-26 21:04 ` 罗勇刚(Yonggang Luo)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201026135131.3006712-9-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=hskinnemoen@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).