My C++ project has source files organized in nested subdirectories of ./src
. I have a pattern rule in my makefile which compiles all of the .cpp
source files into objects:
$(OBJDIR)/%.o: %.cpp makefile
$(CXX) -c $< -o $@
Since I am using this pattern rather than writing a compilation rule for each source file, I need to tell make
to look recursively through ./src
for these prerequisites. Right now I have:
VPATH := $./src/:./src/folder1:./src/folder2:./src/folder3
This works, but it feels pretty inelegant and also causes bugs when I inevitably forget to add in a new folder.
Hoping someone has a better solution!