If my makefile rule changes directories, does it need to change back before finishing?
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 direct开发者_开发知识库ories? In other words, after executing that rule, will subsequent rules be executed in subdir/
instead of where I want them?
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.
精彩评论