Christian Convey wrote: > >>Didn't know about the reasons for preferring /bin/sh. The guy who > >>originally wrote the makefiles wasn't setting SHELL at all, and his > >>default shell is tcsh. When I tried to build (my default is bash), > >>the code wouldn't run. > > > >I think you may still be a little confused on this point. No make > >program, including GNU make, EVER pays attention to the user's > >default shell. If you don't override it explicitly on the command > >line or within the makefile, it will use the system shell, period. > > > >-David Boyce > > > > > > Hmm. I believe you, but that sounds pretty different about what I was > originally observing. But I checked what you said and I concede that > it does appear to always be /bin/sh that gets run.
Your question is a very interesting one because it involves a lot of changes over time. The make program has had a long and rich history and has evolved from the early days to the present. Feldman introduced make in 1978 with "Make - A Program for Maintaining Computer Programs" in an AT&T Technical Report. It is still available and interesting reading but mostly I mention it to show how long make has been around. In different decades the default behavior has changed and improved. This is from my imperfect memory but as I recall the default SHELL variable for make depended upon the system type. AT&T based Unix systems defaulted to /bin/sh while BSD based Unix systems defaulted to /bin/csh. This was configurable and the person building for the local environment could choose and configure this. Therefore the different system's defaults reflected the belief of the person building it as to the best shell to use. Opposite coasts used opposite values. (You see, even today some things never change. :-) In that type of environment it is necessary to always specify the SHELL variable to be one or the other. Because otherwise when running on the other system your shell would be incorrect. Note that in the simple case it does not matter. If all of the shell commands are very simple shell commands then they work with both shells. > Does that mean that there's no reason at all to put "SHELL=/bin/sh" in > the top of some/all of my makefiles? Not with GNU make nor a modern POSIX make. However some other more traditional make programs that is true. The GNU make manual says: Variables in `make' can come from the environment in which `make' is run. Every environment variable that `make' sees when it starts up is transformed into a `make' variable with the same name and value. But an explicit assignment in the makefile, or with a command argument, overrides the environment. (If the `-e' flag is specified, then values from the environment override assignments in the makefile. But this is not recommended practice.) Summary: In general the environment is available to use in a Makefile. Other use of variables from the environment is not recommended. It is not wise for makefiles to depend for their functioning on environment variables set up outside their control, since this would cause different users to get different results from the same makefile. This is against the whole purpose of most makefiles. Such problems would be especially likely with the variable `SHELL', which is normally present in the environment to specify the user's choice of interactive shell. It would be very undesirable for this choice to affect `make'. So `make' ignores the environment value of `SHELL' (except on MS-DOS and MS-Windows, where `SHELL' is usually not set.) POSIX has also specified that this behavior is required. In the online docs: http://www.opengroup.org/onlinepubs/009695399/utilities/make.html The SHELL macro shall be treated specially. It shall be provided by make and set to the pathname of the shell command language interpreter (see sh). The SHELL environment variable shall not affect the value of the SHELL macro. If SHELL is defined in the makefile or is specified on the command line, it shall replace the original value of the SHELL macro, but shall not affect the SHELL environment variable. Other effects of defining SHELL in the makefile or on the command line are implementation-defined. Summary: The exception in make to the above general rule of environment variables being available inside of makefiles is the SHELL variable. Because the SHELL variable would cause problems it is specifically excepted. Therefore with today's make what you say is true. There is no reason to say 'SHELL = /bin/sh' since that is the default and the environment will not override it. However if you were trying to be portable to some other historical make implementations then it may be of value. > (O'Reilly's "Managing Projects with make", p. 64, middle of page, does > recommend putting "SHELL=/bin/sh" in the top of every makefile.) My copy of O'Reilly's "Managing Projects with make" by Steve Talbott copyright 1986-1988 is a slim book and has only 77 pages in total. I assume you must have a newer edition. :-) This copy only mentions SHELL once in passing on page 64 where it indicates that the default value is /bin/csh. I infer from this that Steve was using what I assume to be a BSD version of make. Bob _______________________________________________ Help-make mailing list Help-make@gnu.org http://lists.gnu.org/mailman/listinfo/help-make