On Thu, 14 May 2026 13:04:44 -0300
Jason Gunthorpe <[email protected]> wrote:
> The test programs are compiled via a static pattern rule that requires
> intermediate .o files:
>
> $(TEST_GEN_PROGS): %: %.o $(LIBVFIO_O)
>
> After lib.mk prefixes TEST_GEN_PROGS with $(OUTPUT), this creates
> dependencies on .o files in the output directory (e.g.
> $(OUTPUT)/vfio_dma_mapping_test.o). However, there is no rule to compile
> these .o files from the source directory .c files when OUTPUT differs
> from the source directory.
>
> Add an explicit chain of pattern rules:
> $(OUTPUT)/% -> $(OUTPUT)/%.o -> %.c
>
> Following the same pattern already used in libvfio.mk for the library
> objects.
>
> Fixes: 19faf6fd969c ("vfio: selftests: Add a helper library for VFIO
> selftests")
> Reviewed-by: David Matlack <[email protected]>
> Signed-off-by: Jason Gunthorpe <[email protected]>
> ---
> tools/testing/selftests/vfio/Makefile | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> v2: Fix the typo
>
> diff --git a/tools/testing/selftests/vfio/Makefile
> b/tools/testing/selftests/vfio/Makefile
> index 40165d087a0bc4..0a4cfd1a6c7ed6 100644
> --- a/tools/testing/selftests/vfio/Makefile
> +++ b/tools/testing/selftests/vfio/Makefile
> @@ -27,10 +27,13 @@ CFLAGS += $(EXTRA_CFLAGS)
>
> LDFLAGS += -pthread
>
> -$(TEST_GEN_PROGS): %: %.o $(LIBVFIO_O)
> +$(TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(LIBVFIO_O)
> $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< $(LIBVFIO_O) $(LDLIBS) -o $@
>
> TEST_GEN_PROGS_O = $(patsubst %, %.o, $(TEST_GEN_PROGS))
> +$(TEST_GEN_PROGS_O): $(OUTPUT)/%.o: %.c
> + $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
> +
> TEST_DEP_FILES = $(patsubst %.o, %.d, $(TEST_GEN_PROGS_O) $(LIBVFIO_O))
> -include $(TEST_DEP_FILES)
>
>
> base-commit: b5953f774781f0b489ae1f34d49eb08fefe176a6
Applied to vfio next branch for v7.2. Thanks,
Alex