Make & csh

Paul Fox fox at marlow.uucp
Mon Sep 12 08:13:34 AEST 1988


The following is a summary of the responses to
my earlier question about the problems I have been
having with make and csh. Just to recap, in
case you missed my question --

Why does the c-shell print its prompt when I alias
'cd' in my .cshrc to th following:

   alias cd cd  \!\* \; set prompt = '\(`whoami`@alice\)$cwd$DEPTH\ '

Thanks very much for the many responses - some were
on the right track, and have fixed this annoyance
for me. But some of you seemed to miss the real problem.

I use the C-shell all the time, and setenv SHELL to /bin/csh
on my uport 386 system (and my sun and my xenix 386 etc...).
If I do not set the SHELL variable in my makefile, then
something like this in a makefile works fine.

fred:
	date

If the command after label 'fred' is a 'complex' command, then
make handles it differently:

fred:
	pwd ; date

The original problem is that I had a line like this in my
makefile:

fred:
	cd dir ; cshell-script-name

this was causing me problems, because the cshell would keep
printing its prompt in between the 'cd' and the 'script' execution.
So I tried putting 'SHELL=/bin/sh' in the makefile to let
the Bourne shell quietly fork-off the script. However, since the
script is written in C-shell, I would get syntax errors from the
Bourne Shell.

I believe my latter problem to be the inability of the cshell and
Bourne shell to interpret the '#!/..' string at the start of scripts.
--------------
From: Greg Woods <woods at gpu.utcs.toronto.edu>
Organization: G. A. W. Consulting


If I understand your problem correctly...

The C-Shell does not set the prompt variable when not in interactive
mode.  Therefore, if the .cshrc scrip checks to see if the prompt variable
is set, it is possible to avoid having csh print a prompt when it is
used to run a sub-command or script.

The problem I have is with ISC's port of csh insisting that stdin be a
terminal when not interactive.

-- 
From: Amos Shapir <amos%taux01 at nsc.uucp>
Organization: National Semiconductor (IC) Ltd, Israel Home of the 32532

Most makefiles assume commands are for /bin/sh, not csh. On some systems
(probably on sun's and sysV) make uses the env variable SHELL to know
what shell to run. Some csh's (probably the one you use) default to
SHELL=/bin/csh. Simply setenv SHELL=/bin/sh  to fix it.

   [[ This is not sufficient in my case because of the reason
      given above -- paul]]

-- 
From: Paul Hite <paul at prcrs.uucp>

Hi Paul,

I expect that you should be having a great deal of trouble with csh. For
example create a simple 1 line file called qqqqq1 and get into vi.  Try
":r qqqqq*".  Do you read in the file or get a "too many file name" 
message?  I suspect that you will get the latter.

A non-interactive csh must *never* have the prompt variable set.  If you
insist on putting all that stuff in your .cshrc at least use:
if ($?prompt) then
	alias cd...
endif

You might consider moving some of the stuff that you have in .cshrc to .login.
.login is only sourced for the login shell.  Remember that your .cshrc file
is sourced each time that you invoke a shell for any purpose.  csh is not
known for its quick initialization under the best of circumstances.

Take a look at your environment variables.  Use env or printenv depending
on your system.  You will find that "SHELL=/usr/ucb/csh" or something.
When the System V make runs, all environment variables become macros.
It is like you had put "SHELL=/usr/ucb/csh" in your makefile.  The macro
SHELL is special.  It tells make to use the mentioned shell to process 
each command in the makefile.  After you correct your .cshrc, your symptom
will disappear.  But you will still be using csh to execute the commands
in your makefile.  You can use the quicker Bourne shell by putting a line
"SHELL=/bin/sh" in your makefile.

Paul Hite    uunet!prcrs!paul

--
From: Steve Dempsey <dempsey at handel.uucp>
Organization: Colorado State University, Ft. Collins CO 80526

In article <452 at alice.marlow.uucp> you write:
>I have a problem with make and the c-shell. My login shell is the
>cshell and here is a copy of my .cshrc:

>------------------------------------------
>if (! $?DEPTH) setenv DEPTH ""
>setenv DEPTH ":$DEPTH"
>set history=150
>set path = ( . /usr/bin /bin /etc /usr/local/bin /usr/games /usr/lib /usr/lbin /usr/dbin )
etc.....

I believe your problem to lie in the DEPTH check.  I assume you want to
ignore much of the .cshrc file if the new shell is NOT interactive.
Such is the case when using make.  I test for the $prompt variable in my
own .cshrc file:
-----------------------------------------------------------------------------
# preliminary stuff runs for all new shells
set path = ( whatever )
if ($?prompt) then
# this part runs for interactive shells only
set prompt = "$cwd % "
endif

# possibly more stuff also to run in every shell
-----------------------------------------------------------------------------

The $prompt variable should be set (or not) automatically for you.
Those .cshrc files can be a major *pain* to tweak until you get it just
right.  I hope this helps.

--
From: Andrew Ernest <andrew at ramona.uucp>

csh and make do not mix well (at least on non-BSD systems).  At the
beginning of all your make files, include:

SHELL=/bin/sh

The funny extraneous prompts should go away.

Andrew (uunet!ramona!andrew)

--
From: Chih-Cheng Ho <ho at cs.utah.edu>
Organization: University of Utah CS Dept

Three solutions:

1. Change your shell variable $SHELL from /bin/csh to /bin/sh:

	setenv SHELL /bin/sh		(add in your .login)

  [[ Not sufficient - I want SHELL to be /bin/csh ! -- paul]]

2. Change the $SHELL variable at the beginning of your makefile:

	SHELL = /bin/sh
	.... (whatever you have in your makefile now)

3. Add a $prompt check in your .cshrc:

	if ($?prompt) then
		.... (whatever you have in your .cshrc now)
	endif


Why only Xenix?

Xenix's (and System V) make uses the $SHELL environment variable to decide
which shell to use for command execution.  BSD's (SunOS maybe) make always
uses /bin/sh.  I recommand you do both 2 and 3.


=====================
     //        o      All opinions are my own.
   (O)        ( )     The powers that be ...
  /    \_____( )
 o  \         |
    /\____\__/        Tel: +44 628 891313 x. 212
  _/_/   _/_/         UUCP:     fox at marlow.uucp



More information about the Comp.unix.wizards mailing list