I want to describe each submake's dependencies in a file that a top-level Makefile
can include. This is to allows for a recursive make setup (with all of the power of instanced variables and relative pathing) but with all dependencies described in a top-level make to increase compile speed and parallelism.
For instance, let's assume we have a directory tree that looks like this:
project/
|-- lib1
| |-- Makefile
| `-- Makefile.reg
|-- lib2
| |-- Makefile
| `-- Makefile.reg
|-- Makefile
`-- Makefile.reg
The file for project/lib1/Makefile.reg
file may look like this:
REG := lib1
include ../Makefile.reg
The file for project/lib2/Makefile.reg
file may look like this:
REG := lib2
DEP := lib1
include ../Makefile.reg
The file project/Makefile.reg
will look like this:
$(REG)_DIR = ????
$(REG): $(DEP)
$(MAKE) -C $($@_DIR)
And finally, the top-level project/Makefile
would look like this:
include $(shell find . -name "Makefile.reg")
Now, the top-level Makefile
has all of the dependency information for every target and can intelligently call recursive make and utilize full parallelism while keeping the dependency tree intact.
The issue is that I'm not sure how to let project/Makefile.reg
know what the current submake's Makefile.reg
's path is. make
will always be called from the top-level directory, so $(shell pwd)
will always report project/
. One solution would be to include the line from this SO answer, however I would like each Makefile.reg
to only specify a target and an optional dependency list.
Is there a way to include the directory path discovery in the common project/Makefile.reg
rather than putting a new line in every single submake Makefile.reg
? In other words, can an included makefile deduce the parent makefile's directory? I see potential in some different parsing of the MAKEFILE_LIST
variable.