From: "Li Wang (Hieco)" <li.wang@linux.dev>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 2/3] build: Build shared libraries once when make runs in testcases/
Date: Tue, 24 Nov 2026 17:06:32 +0800 [thread overview]
Message-ID: <20261124090633.840656-3-li.wang@linux.dev> (raw)
In-Reply-To: <20261124090633.840656-1-li.wang@linux.dev>
From: Andrea Cervesato <andrea.cervesato@suse.com>
Running make directly under testcases/ (for example
"make -C testcases/kernel/syscalls -j8") can start many sub-makes in
parallel. Each leaf can then reach the $(LIBLTP) rule in
testcases.mk and call "$(MAKE) -C lib" at the same time. This builds
the same library more than once, and parallel builds can race on
libltp.a. libkerntest.a and the libs/ libraries have the same
problem.
Add include/mk/generic_lib_deps.inc and include it from both the
generic leaf and trunk targets. When make is started inside
testcases/ (MAKELEVEL == 0), the file adds libltp.a, the libs/
libraries and, for testcases/ and testcases/kernel/*, libkerntest.a
to MAKE_DEPS. Leaf targets and trunk subdirectories depend on
MAKE_DEPS as order-only prerequisites. As a result, the libraries
are built once, in the top-level make process, before any
subdirectory is entered.
The library targets are .PHONY, so lib/, libs/ and
testcases/kernel/lib/ are always entered and their own Makefiles
decide what to rebuild. A change to the library sources is therefore
picked up. Because the prerequisites are order-only, tests that are
already linked are not relinked.
Remove the old $(LIBLTP) rule and "MAKE_DEPS := $(LIBLTP)" from
include/mk/testcases.mk, which the new file replaces. Builds started
from the top-level directory are not affected.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Li Wang (Hieco) <li.wang@linux.dev>
---
include/mk/generic_leaf_target.inc | 2 ++
include/mk/generic_lib_deps.inc | 34 +++++++++++++++++++++++++++++
include/mk/generic_trunk_target.inc | 8 +++++++
include/mk/testcases.mk | 5 +----
testcases/kernel/include/lib.mk | 2 ++
5 files changed, 47 insertions(+), 4 deletions(-)
create mode 100644 include/mk/generic_lib_deps.inc
diff --git a/include/mk/generic_leaf_target.inc b/include/mk/generic_leaf_target.inc
index 7c685fea7..533381b9f 100644
--- a/include/mk/generic_leaf_target.inc
+++ b/include/mk/generic_leaf_target.inc
@@ -76,6 +76,8 @@
# INSTALL_DIR := $(libdir)
#
+include $(top_srcdir)/include/mk/generic_lib_deps.inc
+
.PHONY: all clean install check
ifneq ($(strip $(MAKE_TARGETS)),)
diff --git a/include/mk/generic_lib_deps.inc b/include/mk/generic_lib_deps.inc
new file mode 100644
index 000000000..666b3f9ef
--- /dev/null
+++ b/include/mk/generic_lib_deps.inc
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) Linux Test Project, 2026
+
+ifeq ($(MAKELEVEL),0)
+
+ifneq ($(filter $(abs_top_builddir)/testcases%,$(CURDIR)),)
+
+MAKE_DEPS += $(abs_top_builddir)/lib/libltp.a
+MAKE_DEPS += $(abs_top_builddir)/libs-all
+
+.PHONY: $(abs_top_builddir)/lib/libltp.a
+$(abs_top_builddir)/lib/libltp.a:
+ mkdir -m 00755 -p "$(@D)"
+ $(MAKE) -C "$(@D)" -f "$(abs_top_srcdir)/lib/Makefile" all
+
+.PHONY: $(abs_top_builddir)/libs-all
+$(abs_top_builddir)/libs-all: $(LTPLIBS_FILES) | $(abs_top_builddir)/lib/libltp.a
+ mkdir -m 00755 -p "$(abs_top_builddir)/libs"
+ $(MAKE) -C "$(abs_top_builddir)/libs" -f "$(abs_top_srcdir)/libs/Makefile" all
+
+endif
+
+ifneq ($(filter $(abs_top_builddir)/testcases $(abs_top_builddir)/testcases/kernel%,$(filter-out $(abs_top_builddir)/testcases/kernel/lib,$(CURDIR))),)
+
+MAKE_DEPS += $(abs_top_builddir)/testcases/kernel/lib/libkerntest.a
+
+.PHONY: $(abs_top_builddir)/testcases/kernel/lib/libkerntest.a
+$(abs_top_builddir)/testcases/kernel/lib/libkerntest.a: | $(abs_top_builddir)/lib/libltp.a
+ mkdir -m 00755 -p "$(@D)"
+ $(MAKE) -C "$(@D)" -f "$(abs_top_srcdir)/testcases/kernel/lib/Makefile" all
+
+endif
+
+endif
diff --git a/include/mk/generic_trunk_target.inc b/include/mk/generic_trunk_target.inc
index f9db7896a..4186ee9d9 100644
--- a/include/mk/generic_trunk_target.inc
+++ b/include/mk/generic_trunk_target.inc
@@ -36,6 +36,8 @@ RECURSIVE_TARGETS ?= all install check
$(eval $(get_make_dirs))
+include $(top_srcdir)/include/mk/generic_lib_deps.inc
+
.PHONY: $(RECURSIVE_TARGETS) $(addprefix trunk-,$(RECURSIVE_TARGETS))
$(SUBDIRS): %:
@@ -78,6 +80,12 @@ endif
install: trunk-install
+ifneq ($(strip $(MAKE_DEPS)),)
+ifneq ($(strip $(filter all install,$(RECURSIVE_TARGETS))),)
+$(filter all install,$(RECURSIVE_TARGETS)): | $(MAKE_DEPS)
+endif
+endif
+
# Print out CURDIR to check for a recursion issue.
ifeq ($(strip $(SUBDIRS)),)
$(warning CURDIR is: $(CURDIR))
diff --git a/include/mk/testcases.mk b/include/mk/testcases.mk
index 5960d7485..f9ff93928 100644
--- a/include/mk/testcases.mk
+++ b/include/mk/testcases.mk
@@ -15,10 +15,7 @@ LIBLTP := $(LIBLTP_DIR)/libltp.a
$(APICMDS_DIR)/tst_kvercmp: | $(APICMDS_DIR)
$(MAKE) -C "$(APICMDS_DIR)" -f "$(abs_top_srcdir)/tools/apicmds/Makefile" all
-$(LIBLTP): | $(LIBLTP_DIR)
- $(MAKE) -C "$(LIBLTP_DIR)" -f "$(abs_top_srcdir)/lib/Makefile" all
-
-MAKE_DEPS := $(LIBLTP)
+MAKE_DEPS :=
INSTALL_DIR := testcases/bin
diff --git a/testcases/kernel/include/lib.mk b/testcases/kernel/include/lib.mk
index c1a0c6d52..8f1ec5313 100644
--- a/testcases/kernel/include/lib.mk
+++ b/testcases/kernel/include/lib.mk
@@ -29,8 +29,10 @@ LDFLAGS += -L$(LIBKERNTEST_DIR)
$(LIBKERNTEST_DIR):
mkdir -p "$@"
+ifneq ($(MAKELEVEL),0)
$(LIBKERNTEST): | $(LIBKERNTEST_DIR)
$(MAKE) -C "$(LIBKERNTEST_DIR)" -f "$(LIBKERNTEST_SRCDIR)/Makefile" all
+endif
MAKE_DEPS += $(LIBKERNTEST)
--
2.56.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-11-24 9:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 9:06 [LTP] [PATCH v4 0/3] Speedup LTP compile time by ~20% on multi-machine Li Wang (Hieco)
2026-11-24 9:06 ` [LTP] [PATCH v4 1/3] build: Fix library prerequisites in testcases.mk Li Wang (Hieco)
2026-11-24 9:06 ` Li Wang (Hieco) [this message]
2026-11-24 9:06 ` [LTP] [PATCH v4 3/3] build: Recurse into trunk subdirectories in parallel Li Wang (Hieco)
2026-11-24 11:32 ` [LTP] [PATCH v4 0/3] Speedup LTP compile time by ~20% on multi-machine Cyril Hrubis
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=20261124090633.840656-3-li.wang@linux.dev \
--to=li.wang@linux.dev \
--cc=ltp@lists.linux.it \
/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