When .ONESHELL
is not used Makefile executes each shell commands in a separate shell. What is the benefit of this? Why doesn't makefile uses the same shell?
Shell – Makefile and .ONESHELL
gnumakeshell
gnumakeshell
When .ONESHELL
is not used Makefile executes each shell commands in a separate shell. What is the benefit of this? Why doesn't makefile uses the same shell?
Best Answer
One reason is that a failure in one of the recipe commands would not be detected by GNU
make
. Only the final exit status of the shell would be given tomake
. One would have to additionally set.SHELLFLAGS
to-e
to get the shell to terminate early upon errors (this is required for multi-command shell invocations even without.ONESHELL
if they need to fail at the first error).This is all well and good for when
SHELL
is a POSIX shell. A Makefile can also setSHELL
to e.g./usr/bin/perl
or some other command interpreter. It may then be appropriate, or not, to use.ONESHELL
.Making
.ONESHELL
the default behaviour inmake
would potentially break older Makefiles.Even though this is not a question relating to the POSIX standard or the compliance to that standard by GNU
make
, the Rationale of the POSIX specification formake
has this to say about the issue at hand:GNU
make
is POSIX compliant in this respect as it implements the System V behaviour and provides a.ONESHELL
target for enabling the alternative behaviour, if wanted. ... which is another reason for GNUmake
to keep the current behaviour.