Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check dependencies when invoking a sub-make to build when there are changes?

If I have a makefile that calls another makefile, how to I get the master makefile to correctly check if the dependencies of the subordinate makefile have changed?

For example, if I have the rule

server:
     @cd $(SERVERDIR) && $(MAKE)

That invokes make in the subdirectory in which I build an executable "server". However, if I change one of the files that make up server, the parent make doesn't see the changes and refuses to rebuild server - "make: `server' is up to date."

How can I get the master makefile to correctly detect when there's a change in one of the dependent files (something like $(SERVERDIR)/server.c, for example?

like image 409
Zxaos Avatar asked Jan 24 '23 20:01

Zxaos


1 Answers

It looks like you want to use a phony target

.PHONY: server
server:
     @cd $(SERVERDIR) && $(MAKE)

There's a detailed description of the Phony target here, but the short description is you're telling the makefile that there will never be a file that corresponds with this server target, and therefore it won't consider server up to date if there is a file named server in the directory.

like image 198
mbyrne215 Avatar answered May 20 '23 11:05

mbyrne215