[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.6 Recursive Use of make

Recursive use of make means using make as a command in a makefile. This technique is useful when you want separate makefiles for various subsystems that compose a larger system. For example, suppose you have a subdirectory `subdir' which has its own makefile, and you would like the containing directory's makefile to run make on the subdirectory. You can do it by writing this:

        cd subdir && $(MAKE)

or, equivalently, this (see section Summary of Options):

        $(MAKE) -C subdir

You can write recursive make commands just by copying this example, but there are many things to know about how they work and why, and about how the sub-make relates to the top-level make. You may also find it useful to declare targets that invoke recursive make commands as `.PHONY' (for more discussion on when this is useful, see 4.6 Phony Targets).

For your convenience, GNU make sets the variable CURDIR to the pathname of the current working directory for you. If -C is in effect, it will contain the path of the new directory, not the original. The value has the same precedence it would have if it were set in the makefile (by default, an environment variable CURDIR will not override this value). Note that setting this variable has no effect on the operation of make

5.6.1 How the MAKE Variable Works  The special effects of using `$(MAKE)'.
5.6.2 Communicating Variables to a Sub-make  How to communicate variables to a sub-make.
5.6.3 Communicating Options to a Sub-make  How to communicate options to a sub-make.
5.6.4 The `--print-directory' Option  How the `-w' or `--print-directory' option helps debug use of recursive make commands.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Jeff Bailey on December, 25 2002 using texi2html