I've visited many links including Peter Miller's PDF about non recursive make but I still can't find a simple example on how to implement it.
I've googled for hours but many of them seem to be over-complicated and hard to tell the flow of things.
Can somebody show an example of a couple of directories? I'd like to see how the makefile scales as more directories are added.
Maybe for something like:
/src/
|->main.cc
|->dirA/a.cc
|->dirA/module.mk
|->dirB/b.cc
|->dirB/module.mk
/include/
|->main.h
|->a.h
|->b.h
Then have main.o require a.o and b.o to be compiled into one executable.
Thanks for any tips and guidance in advance!
You haven't said much about what you want this system to do. Here's a crude but effective solution:
/src/Makefile:
vpath %.h include
main: main.o
$(CXX) $^ -o $@
%.o: %.cc
$(CXX) -c -Iinclude $< -o $@ # not the best way, but maybe the clearest
include dirA/module.mk
include dirB/module.mk
/src/dirA/module.mk:
main: dirA/a.o
dirA/a.o: a.h
/src/dirB/module.mk:
main: dirB/b.o
dirB/b.o: b.h
There is more you can do, once you have this much working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With