make: Execution

1 
1 5.3 Recipe Execution
1 ====================
1 
1 When it is time to execute recipes to update a target, they are executed
1 by invoking a new sub-shell for each line of the recipe, unless the
11 '.ONESHELL' special target is in effect (⇒Using One Shell One
 Shell.) (In practice, 'make' may take shortcuts that do not affect the
1 results.)
1 
1    *Please note:* this implies that setting shell variables and invoking
1 shell commands such as 'cd' that set a context local to each process
1 will not affect the following lines in the recipe.(1)  If you want to
1 use 'cd' to affect the next statement, put both statements in a single
1 recipe line.  Then 'make' will invoke one shell to run the entire line,
1 and the shell will execute the statements in sequence.  For example:
1 
1      foo : bar/lose
1              cd $(@D) && gobble $(@F) > ../$@
1 
1 Here we use the shell AND operator ('&&') so that if the 'cd' command
1 fails, the script will fail without trying to invoke the 'gobble'
1 command in the wrong directory, which could cause problems (in this case
1 it would certainly cause '../foo' to be truncated, at least).
1 

Menu