[LTP] [PATCH v3 2/3] build: Build shared libs once on subtree make

Li Wang li.wang@linux.dev
Mon Nov 2 04:39:17 CET 2026


On Wed, Oct 21, 2026 at 10:11:29AM +0200, Andrea Cervesato wrote:
> From: Andrea Cervesato <andrea.cervesato@suse.com>
> 
> When make is invoked directly in a trunk subdirectory (MAKELEVEL == 0),
> build shared prerequisites (libltp.a, libs, and libkerntest.a) once
> via MAKE_DEPS before launching parallel subdirectory builds.
> 
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  include/mk/generic_trunk_target.inc | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/include/mk/generic_trunk_target.inc b/include/mk/generic_trunk_target.inc
> index f9db7896a..aa8e500e1 100644
> --- a/include/mk/generic_trunk_target.inc
> +++ b/include/mk/generic_trunk_target.inc
> @@ -36,6 +36,29 @@ RECURSIVE_TARGETS		?= all install check
>  
>  $(eval $(get_make_dirs))
>  
> +ifeq ($(MAKELEVEL),0)
> +ifneq ($(filter $(abs_top_builddir)/testcases%,$(CURDIR)),)
> +MAKE_DEPS += $(abs_top_builddir)/lib/libltp.a $(abs_top_builddir)/libs-all
> +
> +$(abs_top_builddir)/lib/libltp.a:
> +	mkdir -m 00755 -p "$(abs_top_builddir)/lib"
> +	$(MAKE) -C "$(abs_top_builddir)/lib" -f "$(abs_top_srcdir)/lib/Makefile" all
> +
> +.PHONY: $(abs_top_builddir)/libs-all
> +$(abs_top_builddir)/libs-all: $(LTPLIBS_FILES)
> +	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/kernel/%,$(CURDIR)),)
> +MAKE_DEPS += $(abs_top_builddir)/testcases/kernel/lib/libkerntest.a
> +
> +$(abs_top_builddir)/testcases/kernel/lib/libkerntest.a:
> +	mkdir -m 00755 -p "$(abs_top_builddir)/testcases/kernel/lib"
> +	$(MAKE) -C "$(abs_top_builddir)/testcases/kernel/lib" -f "$(abs_top_srcdir)/testcases/kernel/lib/Makefile" all
> +endif
> +endif
> +
>  .PHONY: $(RECURSIVE_TARGETS) $(addprefix trunk-,$(RECURSIVE_TARGETS))
>  
>  $(SUBDIRS): %:

This code works but isn't elegant. How about refactoring it as follows:

-------------------

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

$(abs_top_builddir)/lib/libltp.a:
	$(MKDIR_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)
	$(MKDIR_P) "$(@D)"
	$(MAKE) -C "$(@D)" -f "$(abs_top_srcdir)/libs/Makefile" all

endif

ifneq ($(filter $(abs_top_builddir)/testcases/kernel/%,$(CURDIR)),)

MAKE_DEPS += $(abs_top_builddir)/testcases/kernel/lib/libkerntest.a

$(abs_top_builddir)/testcases/kernel/lib/libkerntest.a:
	$(MKDIR_P) "$(@D)"
	$(MAKE) -C "$(@D)" -f "$(abs_top_srcdir)/testcases/kernel/lib/Makefile" all

endif

endif

-- 
Regards,
Li Wang


More information about the ltp mailing list