make: Recursion

1 
1 5.7 Recursive Use of 'make'
1 ===========================
1 
1 Recursive use of 'make' means using 'make' as a command in a makefile.
1 This technique is useful when you want separate makefiles for various
1 subsystems that compose a larger system.  For example, suppose you have
1 a sub-directory 'subdir' which has its own makefile, and you would like
1 the containing directory's makefile to run 'make' on the sub-directory.
1 You can do it by writing this:
1 
1      subsystem:
1              cd subdir && $(MAKE)
1 
1 or, equivalently, this (⇒Summary of Options Options Summary.):
1 
1      subsystem:
1              $(MAKE) -C subdir
1 
1    You can write recursive 'make' commands just by copying this example,
1 but there are many things to know about how they work and why, and about
1 how the sub-'make' relates to the top-level 'make'.  You may also find
1 it useful to declare targets that invoke recursive 'make' commands as
11 '.PHONY' (for more discussion on when this is useful, see ⇒Phony
 Targets).
1 
1    For your convenience, when GNU 'make' starts (after it has processed
1 any '-C' options) it sets the variable 'CURDIR' to the pathname of the
1 current working directory.  This value is never touched by 'make' again:
1 in particular note that if you include files from other directories the
1 value of 'CURDIR' does not change.  The value has the same precedence it
1 would have if it were set in the makefile (by default, an environment
1 variable 'CURDIR' will not override this value).  Note that setting this
1 variable has no impact on the operation of 'make' (it does not cause
1 'make' to change its working directory, for example).
1 

Menu