Recursive use of make means using make as a command within a makefile. This technique is useful when a large project contains sub-directories, each having their respective makefiles. The following example will help understand advantage of using .PHONY with recursive make.
/main |_ Makefile |_ /foo |_ Makefile |_ ... // other files |_ /bar |_ Makefile |_ ... // other files |_ /koo |_ Makefile |_ ... // other files
To run sub-directory's makefile from within the makefile of main, the main's makefile would have looping as shown below (there are other ways in which this can be achieved, but that is out of scope of the current topic)
SUBDIRS = foo bar koo subdirs: for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir; \ done
However, there are pitfalls with this method.
By declaring the sub-directories as .PHONY targets (you must do this as the sub-directory obviously always exists; otherwise it won’t be built) these problems can be overcome.
SUBDIRS = foo bar koo .PHONY: subdirs $(SUBDIRS) subdirs: $(SUBDIRS) $(SUBDIRS): $(MAKE) -C $@