views:

14

answers:

1

If I have a rule in my makefile like this:

subdir/object:
    cd subdir && do_stuff_to_build_object

Do I need to add && cd .. to the end of the rule, so that make ends up in the same directory at the end of running it as it started? Or does make run the rule in a subshell or otherwise shield itself from things like changing directories? In other words, after executing that rule, will subsequent rules be executed in subdir/ instead of where I want them?

+1  A: 

Not on Unix-based systems.

The action is performed by a shell (or, at least, a sub-process) run by make, and any cd operations that it performs do not affect the parent make process.

Jonathan Leffler
Well, I have to wait 12 more minutes before accepting. Heh.
Ryan Thompson