Skip to contentSkip to conversation

Makefile: Use 'vpath' for out-of-source builds and not 'VPATH'

RFC PATCH In review Marc Hartmayer 2 participants 2 messages Jan 28, 2025 – Jan 31, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Makefile: Use 'vpath' for out-of-source builds and not 'VPATH'

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

--
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(-)
Makefile +4 -2
index 7471f7285b78..78352fced9d4 100644
@@ -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))

base-commit: 0ed2cdf3c80ee803b9150898e687e77e4d6f5db2

Signature · 1 line
2.48.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Marc Hartmayer

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

--
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(-)
Makefile +0 -0
index 7471f7285b78..78352fced9d4 100644

Makefile endif · line 12

Quoted 9 lines
Makefile +4 -2
@@ -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,

and pushed, thanks!