make: Choosing the Shell

1 
1 5.3.2 Choosing the Shell
1 ------------------------
1 
1 The program used as the shell is taken from the variable 'SHELL'.  If
1 this variable is not set in your makefile, the program '/bin/sh' is used
1 as the shell.  The argument(s) passed to the shell are taken from the
1 variable '.SHELLFLAGS'.  The default value of '.SHELLFLAGS' is '-c'
1 normally, or '-ec' in POSIX-conforming mode.
1 
1    Unlike most variables, the variable 'SHELL' is never set from the
1 environment.  This is because the 'SHELL' environment variable is used
1 to specify your personal choice of shell program for interactive use.
1 It would be very bad for personal choices like this to affect the
11 functioning of makefiles.  ⇒Variables from the Environment
 Environment.
1 
1    Furthermore, when you do set 'SHELL' in your makefile that value is
1 _not_ exported in the environment to recipe lines that 'make' invokes.
1 Instead, the value inherited from the user's environment, if any, is
1 exported.  You can override this behavior by explicitly exporting
11 'SHELL' (⇒Communicating Variables to a Sub-'make'
 Variables/Recursion.), forcing it to be passed in the environment to
1 recipe lines.
1 
1    However, on MS-DOS and MS-Windows the value of 'SHELL' in the
1 environment *is* used, since on those systems most users do not set this
1 variable, and therefore it is most likely set specifically to be used by
1 'make'.  On MS-DOS, if the setting of 'SHELL' is not suitable for
1 'make', you can set the variable 'MAKESHELL' to the shell that 'make'
1 should use; if set it will be used as the shell instead of the value of
1 'SHELL'.
1 
1 Choosing a Shell in DOS and Windows
1 ...................................
1 
1 Choosing a shell in MS-DOS and MS-Windows is much more complex than on
1 other systems.
1 
1    On MS-DOS, if 'SHELL' is not set, the value of the variable 'COMSPEC'
1 (which is always set) is used instead.
1 
1    The processing of lines that set the variable 'SHELL' in Makefiles is
1 different on MS-DOS. The stock shell, 'command.com', is ridiculously
1 limited in its functionality and many users of 'make' tend to install a
1 replacement shell.  Therefore, on MS-DOS, 'make' examines the value of
1 'SHELL', and changes its behavior based on whether it points to a
1 Unix-style or DOS-style shell.  This allows reasonable functionality
1 even if 'SHELL' points to 'command.com'.
1 
1    If 'SHELL' points to a Unix-style shell, 'make' on MS-DOS
1 additionally checks whether that shell can indeed be found; if not, it
1 ignores the line that sets 'SHELL'.  In MS-DOS, GNU 'make' searches for
1 the shell in the following places:
1 
1   1. In the precise place pointed to by the value of 'SHELL'.  For
1      example, if the makefile specifies 'SHELL = /bin/sh', 'make' will
1      look in the directory '/bin' on the current drive.
1 
1   2. In the current directory.
1 
1   3. In each of the directories in the 'PATH' variable, in order.
1 
1    In every directory it examines, 'make' will first look for the
1 specific file ('sh' in the example above).  If this is not found, it
1 will also look in that directory for that file with one of the known
1 extensions which identify executable files.  For example '.exe', '.com',
1 '.bat', '.btm', '.sh', and some others.
1 
1    If any of these attempts is successful, the value of 'SHELL' will be
1 set to the full pathname of the shell as found.  However, if none of
1 these is found, the value of 'SHELL' will not be changed, and thus the
1 line that sets it will be effectively ignored.  This is so 'make' will
1 only support features specific to a Unix-style shell if such a shell is
1 actually installed on the system where 'make' runs.
1 
1    Note that this extended search for the shell is limited to the cases
1 where 'SHELL' is set from the Makefile; if it is set in the environment
1 or command line, you are expected to set it to the full pathname of the
1 shell, exactly as things are on Unix.
1 
1    The effect of the above DOS-specific processing is that a Makefile
1 that contains 'SHELL = /bin/sh' (as many Unix makefiles do), will work
1 on MS-DOS unaltered if you have e.g. 'sh.exe' installed in some
1 directory along your 'PATH'.
1