Next: Comments in Make Rules, Previous: The Make Macro MAKEFLAGS, Up: Portable Make
SHELL
Posix-compliant make internally uses the $(SHELL)
macro to spawn shell processes and execute Make rules. This
is a builtin macro supplied by make, but it can be modified
by a makefile or by a command-line argument.
Not all make implementations define this SHELL
macro.
OSF/Tru64
make is an example; this implementation always uses
/bin/sh
. So it's a good idea to always define SHELL
in
your makefiles. If you use Autoconf, do
SHELL = @SHELL@
Do not force SHELL = /bin/sh
because that is not correct
everywhere. For instance DJGPP lacks /bin/sh
, and when
its GNU make
port sees such a setting it enters a special
emulation mode where features like pipes and redirections are emulated
on top of DOS's command.com. Unfortunately this emulation is
incomplete; for instance it does not handle command substitutions.
On DJGPP SHELL
should point to Bash.
Posix-compliant make should never acquire the value of
$(SHELL) from the environment, even when make -e
is used
(otherwise, think about what would happen to your rules if
SHELL=/bin/tcsh
).
However not all make implementations have this exception.
For instance it's not surprising that OSF/Tru64 make doesn't
protect SHELL
, since it doesn't use it.
$ cat Makefile SHELL = /bin/sh FOO = foo all: @echo $(SHELL) @echo $(FOO) $ env SHELL=/bin/tcsh FOO=bar make -e # OSF1 V4.0 Make /bin/tcsh bar $ env SHELL=/bin/tcsh FOO=bar gmake -e # GNU make /bin/sh bar