Reputation: 67
I have the following issue: I got one folder, let's say /trunk/modules/mymodule which contains my project that I must build using a buildsystem and I have the /trunk/libs/mylib folder with it's own .cpp and .h files.
My module will need to use the library that I am building in /libs/mylib, but that library will also be used by other projects. So I want whenever I build my project I also check if the library is updated(and rebuild it is there are changes), but I want the makefiles in the library to be able to be run independently, so someone can just update the library or use it with another module.
I have 2 Makefiles.in, i connect them by calling include ../../lib/mylib/Makefile in the first one and use -L same path -lmylib when linking my project which will also be a .so library.
I logically get warning: overriding recipe for target 'distclean'
and
warning: overriding recipe for target 'clean'
for the clean and make distclean which are defined in both makefiles.
How do I get around that? And is it even possible?
Upvotes: 0
Views: 357
Reputation: 2079
Non-recursive way: If you control all the makefiles and can rewrite those completely, then I'd suggest you to look at https://github.com/cppfw/prorab
It allows having independent makefiles for neighbor projects and also including one makefile into another and adding the compilation dependency. See WIKI in the github repo.
Basically, you add the dependency of your executable on some libmylib.so
and also include the makefile which builds that library.
Upvotes: 0
Reputation: 9875
Instead of including your library Makefile lib/mylib/Makefile
you can use recursive MAKE by running
$(MAKE) -C ../../lib/mylib/Makefile
from your main module's Makefile modules/mymodule/Makefile
.
You could use a similar solutions for targets clean
or distclean
You could use a phony target mylib
like this:
.PHONY: mylib all clean
LIBDIR=../../lib/mylib
all: mymodule
mymodule: mylib
...
mylib:
$(MAKE) -C $(LIBDIR)
clean:
$(MAKE) -C $(LIBDIR) $@
...
Note: If you copy code from this example to a Makefile
, change the indentation to use a tab instead of spaces.
You might also consider using a top level Makefile
in trunk
that recursively calls make
in lib/mylib
and modules/mymodule
.
See also https://www.gnu.org/software/make/manual/make.html#Recursion
Some consider recursive make as harmful, but this depends on how exactly you use it.
Upvotes: 0