* [PATCH] vfio: selftests: Fix out-of-tree build with make O=
@ 2026-04-27 23:07 Jason Gunthorpe
2026-04-27 23:15 ` Jason Gunthorpe
2026-04-28 18:27 ` David Matlack
0 siblings, 2 replies; 5+ messages in thread
From: Jason Gunthorpe @ 2026-04-27 23:07 UTC (permalink / raw)
To: Alex Williamson, kvm, linux-kselftest, Shuah Khan
Cc: Alex Williamson, David Matlack, patches, Shuah Khan
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")
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
tools/testing/selftests/vfio/Makefile | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/vfio/Makefile b/tools/testing/selftests/vfio/Makefile
index 40165d087a0bc4..81c3be8298fdc2 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: 681b35420592a2e072d9759254185e72d2e914c8
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] vfio: selftests: Fix out-of-tree build with make O=
2026-04-27 23:07 [PATCH] vfio: selftests: Fix out-of-tree build with make O= Jason Gunthorpe
@ 2026-04-27 23:15 ` Jason Gunthorpe
2026-04-28 18:27 ` David Matlack
1 sibling, 0 replies; 5+ messages in thread
From: Jason Gunthorpe @ 2026-04-27 23:15 UTC (permalink / raw)
To: Alex Williamson, kvm, linux-kselftest, Shuah Khan
Cc: Alex Williamson, David Matlack, patches, Shuah Khan
On Mon, Apr 27, 2026 at 08:07:37PM -0300, Jason Gunthorpe wrote:
> -$(TEST_GEN_PROGS): %: %.o $(LIBVFIO_O)
> +$(TEST_GEN_PROGS): $(OUTPUT)/%: %(OUTPUT)/%.o $(LIBVFIO_O)
I grabbed the wrong version of this, it should be:
v
+$(TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(LIBVFIO_O)
Sorry,
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] vfio: selftests: Fix out-of-tree build with make O=
2026-04-27 23:07 [PATCH] vfio: selftests: Fix out-of-tree build with make O= Jason Gunthorpe
2026-04-27 23:15 ` Jason Gunthorpe
@ 2026-04-28 18:27 ` David Matlack
2026-04-28 19:04 ` Jason Gunthorpe
1 sibling, 1 reply; 5+ messages in thread
From: David Matlack @ 2026-04-28 18:27 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Alex Williamson, kvm, linux-kselftest, Shuah Khan,
Alex Williamson, patches, Shuah Khan
On 2026-04-27 08:07 PM, Jason Gunthorpe 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")
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
> tools/testing/selftests/vfio/Makefile | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/vfio/Makefile b/tools/testing/selftests/vfio/Makefile
> index 40165d087a0bc4..81c3be8298fdc2 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)
Changing this line (with the fix you replied with) is not actually
needed right? I tried the following without it and was able to build:
$ make OUTPUT=/tmp -C tools/testing/selftests/vfio
$(TEST_GEN_PROGS) has already been prefixed with $(OUTPUT), so %
in the original pattern already included $(OUTPUT).
Is this for readability?
> $(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 $@
Looking at this commit made me confused how this was even working before
and I learned that make has built-in rules to build .o files that
assumes the .c is in the same directory. I see now that we were reying
on those built-in rules to build $(TEST_GEN_PROGS_O). It makes sense to
have an explicit rule to handle the directory mismatch between .c and
.o.
This also got me thinking it might be a nice cleanup to use the
predefined macros $(COMPILE.c) and $(LINK.c) in these rules instead of
$(CC) $(CFLAGS) ... etc. No need to attach that to this fix though.
> +
> TEST_DEP_FILES = $(patsubst %.o, %.d, $(TEST_GEN_PROGS_O) $(LIBVFIO_O))
> -include $(TEST_DEP_FILES)
>
>
> base-commit: 681b35420592a2e072d9759254185e72d2e914c8
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] vfio: selftests: Fix out-of-tree build with make O=
2026-04-28 18:27 ` David Matlack
@ 2026-04-28 19:04 ` Jason Gunthorpe
2026-04-28 20:16 ` David Matlack
0 siblings, 1 reply; 5+ messages in thread
From: Jason Gunthorpe @ 2026-04-28 19:04 UTC (permalink / raw)
To: David Matlack
Cc: Alex Williamson, kvm, linux-kselftest, Shuah Khan,
Alex Williamson, patches, Shuah Khan
On Tue, Apr 28, 2026 at 06:27:06PM +0000, David Matlack wrote:
> On 2026-04-27 08:07 PM, Jason Gunthorpe 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")
> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> > ---
> > tools/testing/selftests/vfio/Makefile | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/vfio/Makefile b/tools/testing/selftests/vfio/Makefile
> > index 40165d087a0bc4..81c3be8298fdc2 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)
>
> Changing this line (with the fix you replied with) is not actually
> needed right? I tried the following without it and was able to build:
>
> $ make OUTPUT=/tmp -C tools/testing/selftests/vfio
>
> $(TEST_GEN_PROGS) has already been prefixed with $(OUTPUT), so %
> in the original pattern already included $(OUTPUT).
>
> Is this for readability?
Yes, it makes more sense to explicitly match the stems through the
flow than to have the implicit $(TEST_GEN_PROGS) == XXX/$(OUTPUT)
> > $(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 $@
>
> Looking at this commit made me confused how this was even working before
> and I learned that make has built-in rules to build .o files that
> assumes the .c is in the same directory.
Yes
> I see now that we were reying
> on those built-in rules to build $(TEST_GEN_PROGS_O). It makes sense to
> have an explicit rule to handle the directory mismatch between .c and
> .o.
Hmm now that I think about it, I wonder if it used the right flags..
> This also got me thinking it might be a nice cleanup to use the
> predefined macros $(COMPILE.c) and $(LINK.c) in these rules instead of
> $(CC) $(CFLAGS) ... etc. No need to attach that to this fix though.
Yeah probably
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] vfio: selftests: Fix out-of-tree build with make O=
2026-04-28 19:04 ` Jason Gunthorpe
@ 2026-04-28 20:16 ` David Matlack
0 siblings, 0 replies; 5+ messages in thread
From: David Matlack @ 2026-04-28 20:16 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Alex Williamson, kvm, linux-kselftest, Shuah Khan,
Alex Williamson, patches, Shuah Khan
On 2026-04-28 04:04 PM, Jason Gunthorpe wrote:
> On Tue, Apr 28, 2026 at 06:27:06PM +0000, David Matlack wrote:
> > On 2026-04-27 08:07 PM, Jason Gunthorpe 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")
> > > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
With the fix applied from your reply,
Reviewed-by: David Matlack <dmatlack@google.com>
> > > ---
> > > tools/testing/selftests/vfio/Makefile | 5 ++++-
> > > 1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/tools/testing/selftests/vfio/Makefile b/tools/testing/selftests/vfio/Makefile
> > > index 40165d087a0bc4..81c3be8298fdc2 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)
> >
> > Changing this line (with the fix you replied with) is not actually
> > needed right? I tried the following without it and was able to build:
> >
> > $ make OUTPUT=/tmp -C tools/testing/selftests/vfio
> >
> > $(TEST_GEN_PROGS) has already been prefixed with $(OUTPUT), so %
> > in the original pattern already included $(OUTPUT).
> >
> > Is this for readability?
>
> Yes, it makes more sense to explicitly match the stems through the
> flow than to have the implicit $(TEST_GEN_PROGS) == XXX/$(OUTPUT)
Sounds good.
>
> > > $(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 $@
> >
> > Looking at this commit made me confused how this was even working before
> > and I learned that make has built-in rules to build .o files that
> > assumes the .c is in the same directory.
>
> Yes
>
> > I see now that we were reying
> > on those built-in rules to build $(TEST_GEN_PROGS_O). It makes sense to
> > have an explicit rule to handle the directory mismatch between .c and
> > .o.
>
> Hmm now that I think about it, I wonder if it used the right flags..
It looks like it used the same command that we will be using after this
patch, just with the wrong path to the .c file.
$ make -p -f /dev/null
...
COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
...
OUTPUT_OPTION = -o $@
...
%.o: %.c
# recipe to execute (built-in):
$(COMPILE.c) $(OUTPUT_OPTION) $<
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-28 20:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-27 23:07 [PATCH] vfio: selftests: Fix out-of-tree build with make O= Jason Gunthorpe
2026-04-27 23:15 ` Jason Gunthorpe
2026-04-28 18:27 ` David Matlack
2026-04-28 19:04 ` Jason Gunthorpe
2026-04-28 20:16 ` David Matlack
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox