Reputation: 303880
There seem to be only a handful of resources on creating a non-recursive make system, and in none of the ones I've found can I figure out how to handle my use case. My hierarchy looks like this:
project/
project/libA/...
project/libB/...
...
project/appA/...
project/appB/...
So maybe project/appA/makefile
depends on libA
and libB
and project/appB/makefile
depends on libA
, libC
, and libF
or something. I want to be able to make
in every directory and have that work. I have a recursive solution for this already.
All the resources always define a root project/makefile
that include
s all the directories above it. But I need that backwards. Are there any examples in the wild for this? I think ideally I want a given library makefile to look like:
include ../../rules.mk
SRC := $(wildcard src/*.cpp)
INCDIR := ./include
$(add_build_target)
... where the base rules.mk would define add_build_target
to append the correct rules for the given SRC
and INCDIR
to build
. Is this the correct approach? And how do I actually write add_build_target
to add the correct targets (.o's for all the .cxx's) - everything I've tried gives me "no rule to make target whatever.o" issues, despite me thinking that I've defined them....
Upvotes: 3
Views: 882
Reputation: 6405
I have implemented and extended ideas from the paper
http://sites.e-advies.nl/nonrecursive-make.html
on multiple occasions in corporate environments, and they work very well, in small or large scale environments. Basically, there is implemented a "directory stack" there and recursive inclusion. Like I said, works well for me. Read this paper, I recommend it.
Upvotes: 2
Reputation: 2079
Have a look at my non-recursive build system implementation called prorab: https://github.com/cppfw/prorab
It allows to achieve exactly what you want. So, you will have independent makefile
in each directory appA, appB, libA, libB,...
and if you cd
to that directory you'll be able to build the project by just typing make
. In that makefile you'll be able to include a makefile from another directory and add a dependency for your app binary on library binary. So, that way if you do some changes to the library code and build the app, it will detect that and rebuild the library.
Then it is also possible to have a top-level makefile
which includes all makefiles from those sub-directories, for building everything.
Let me know if you need help with using prorab.
Upvotes: 0