Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

11.9 The Make Macro 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

 
 
  Published under the terms of the GNU General Public License Design by Interspire