help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Odd effects from setting SHELL?


From: Christian Convey
Subject: Re: Odd effects from setting SHELL?
Date: Fri, 22 Jun 2007 10:23:43 -0400

Thanks for the help Philip.  Responses below...

On 6/21/07, Philip Guenther <address@hidden> wrote:
On 6/21/07, Christian Convey <address@hidden> wrote:
...
> When I just do this:
>    cd /lib_foo; make all
> everything works just fine.
>
> But when I do *this*:
>    cd /lib_foo; make SHELL=/bin/csh all
> things *don't* work fine:

This is, in general, a Bad Idea.  Makefiles should always be written
with /bin/sh syntax for portability and avoid the limitations in csh
syntax.  (For example, a makefile rule written in csh can't loop using
csh's 'foreach', as that requires a real newline.  sh's 'for' doesn't
have that problem.)


> The "%.o: %.cpp" rule in make_lib.mk invokes gcc.  When I don't
> explicitly set SHELL, gcc's current working directory is /src/lib_foo
> (which is what I want.)  When I *do* set SHELL, gcc's working
> directory is my home directory, /home/cjc/.  gcc is then unable to
> find the source code files, and fails.

Your .cshrc (or .tcshrc) is doing 'cd $HOME' or just 'cd'.  "Don't do that".


Good catch - you were right.  Suppose I switch to SHELL=/bin/sh.  Is
there some accepted way to prevent *other* people using my makefiles
from having the same problem I experienced?

For example, Joe Programmer checks out my whole project, and Joe's
~/.bashrc file has a "cd" or "cd ~" line, just like I had/have in my
~/.cshrc file.  Is there a convention to help him avoid the trap I
fell into?

Or is it just not a problem with bourne-compatible shells? :

If bash is invoked as "sh", it automatically applies its "--norc"
feature to avoid reading configuration files.

I know Ubuntu has /bin/sh --> dash, and I *think* from dash's man
pages that the only time it ever reads a configuration file at all is,
if you're using it as a login shell, it reads ~/.profile.  So 'dash'
might be safe from this "cd" or "cd ~" problem as well.

So maybe bourne-based shells just don't have this as an issue at all?


> P.S. The reason I'm setting SHELL at all is that some of the commands
> within the makefiles need to redirect both stdout and stderr to
> /dev/null.  tcsh and bash have different ways of doing this, so I was
> trying to force the use of some particular shell by our makefiles.

And you reason for not just using the portable /bin/sh syntax is....?

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 naively assumed the best solution was to just force everything to
[t]csh, since that worked for this other guy.  I didn't understand
what a can of worms I was opening.  I plan to use /bin/sh from now on.

Thanks again for the help.

- Christian




reply via email to

[Prev in Thread] Current Thread [Next in Thread]