diff mbox series

[RFC,kvm-unit-tests,v1] Makefile: Use 'vpath' for out-of-source builds and not 'VPATH'

Message ID 20250128104141.58693-1-mhartmay@linux.ibm.com (mailing list archive)
State New
Headers show
Series [RFC,kvm-unit-tests,v1] Makefile: Use 'vpath' for out-of-source builds and not 'VPATH' | expand

Commit Message

Marc Hartmayer Jan. 28, 2025, 10:41 a.m. UTC
If VPATH is used, object files are also looked up in the source directory [1],
and this has some disadvantages like a simultaneous in-source build and
out-of-source build is not possible:

  $ cd "$KUT" && ./configure && make -j
  # This command fails
  $ mkdir ../build && cd ../build && "../$KUT/configure" && make -j

Use 'vpath' [2] only for *.c, *.s, and *.S files and not for *.lds files, as
this is not necessary as all *.lds prerequisites already use $(SRCDIR)/*.lds.

[1] https://www.gnu.org/software/make/manual/html_node/General-Search.html
[2] https://www.gnu.org/software/make/manual/html_node/Selective-Search.html

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
--
Note: IMO, in the long run we should try to get rid of vpath completely and use
      OBJDIR/BUILDDIR and SRCDIR instead.
---
 Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)


base-commit: 0ed2cdf3c80ee803b9150898e687e77e4d6f5db2

Comments

Thomas Huth Jan. 31, 2025, 9:53 a.m. UTC | #1
On 28/01/2025 11.41, Marc Hartmayer wrote:
> If VPATH is used, object files are also looked up in the source directory [1],
> and this has some disadvantages like a simultaneous in-source build and
> out-of-source build is not possible:
> 
>    $ cd "$KUT" && ./configure && make -j
>    # This command fails
>    $ mkdir ../build && cd ../build && "../$KUT/configure" && make -j
> 
> Use 'vpath' [2] only for *.c, *.s, and *.S files and not for *.lds files, as
> this is not necessary as all *.lds prerequisites already use $(SRCDIR)/*.lds.
> 
> [1] https://www.gnu.org/software/make/manual/html_node/General-Search.html
> [2] https://www.gnu.org/software/make/manual/html_node/Selective-Search.html
> 
> Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> --
> Note: IMO, in the long run we should try to get rid of vpath completely and use
>        OBJDIR/BUILDDIR and SRCDIR instead.
> ---
>   Makefile | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 7471f7285b78..78352fced9d4 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -6,8 +6,10 @@ endif
>   
>   include config.mak
>   
> -# Set search path for all sources
> -VPATH = $(SRCDIR)
> +# Set search path for %.c %.s and %.S files
> +vpath %.c $(SRCDIR)
> +vpath %.s $(SRCDIR)
> +vpath %.S $(SRCDIR)

Makes sense,
Reviewed-by: Thomas Huth <thuth@redhat.com>

and pushed, thanks!
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 7471f7285b78..78352fced9d4 100644
--- a/Makefile
+++ b/Makefile
@@ -6,8 +6,10 @@  endif
 
 include config.mak
 
-# Set search path for all sources
-VPATH = $(SRCDIR)
+# Set search path for %.c %.s and %.S files
+vpath %.c $(SRCDIR)
+vpath %.s $(SRCDIR)
+vpath %.S $(SRCDIR)
 
 libdirs-get = $(shell [ -d "lib/$(1)" ] && echo "lib/$(1) lib/$(1)/asm")
 ARCH_LIBDIRS := $(call libdirs-get,$(ARCH_LIBDIR)) $(call libdirs-get,$(TEST_DIR))