[comp.unix.wizards] Makefile

rajeevc@mipos2.intel.com (Rajeev Chandrasekhar) (11/10/88)

Is it possible to use the inbuilt commands of the shell
from a makefile ? The shell is csh. I havent tried doing this
before and the docs I have dont mention anything about it.
                 
Rajeev 

Rajeev Chandrasekhar
Intel Corp            >> theres someone in my head, and its not me << 
2625, Walsh Ave MS SC4-59                      (408) 765-4632
Santa Clara, CA 95051  {hplabs,oliveb}!intelca!mipos2!rajeevc                      

guy@auspex.UUCP (Guy Harris) (11/12/88)

>Is it possible to use the inbuilt commands of the shell
>from a makefile ? The shell is csh.

Well, I would suggest you not use "csh", unless you know you're always
going to be on a system that has it, but that's a separate issue.

"make" tends to pass commands containing shell meta-characters to a
shell, rather than running them itself.  This means such commands could
include built-in commands, etc., as long as the command line also
contains such a meta-character.

However, many "make"s always pass them to "/bin/sh".  Others pass them
to the shell specified by the SHELL Makefile variable, which is
generally inherited from the environment.  Thus, while you can usually
guarantee that the Bourne shell will get the commands, you're less
likely to be able to guarantee that the C shell will get them.  (Then
again, with UNIX systems, you can usually guarantee that there's a
Bourne shell available, but you're less likely to be able to guarantee
that there's a C shell available.)

Furthermore, some commands won't do what you expect; e.g., "cd".  If
your Makefile contains

	<commands...>
	cd <directory>;
	<more commands...>

The <more commands> will be executed in the same directory as the
<commands>, the "cd" nonwithstanding; the <commands> will either be
executed directly by "make" or by a subshell, the "cd" will be executed
by a different subshell (the ";" is there to ensure that "make" doesn't
try to execute a program named "cd"), and the <more commands> will
either be executed by "make" (which hasn't changed its current
directory) or by a different subshell run from "make" (which will
inherit "make"s current directory).

Also, "make" passes commands to the shell with the "-c" flag; it passes
a single command line to the shell.  You can put the command on multiple
lines in the Makefile, using backslashes at the end of the lines to
continue the command, so that you can put a Bourne shell construct on
multiple lines:

	for i in $(MAKEVARIABLE); do \
		command $$i; \
	done

which gets passed to the shell as

	/bin/sh -c "for i in <expanded Makevariable>; do command $i; done"

The Bourne shell doesn't mind this; I don't know if the C shell does or
not. 

billd@celerity.UUCP (Bill Davidson) (11/13/88)

In article <438@auspex.UUCP> guy@auspex.UUCP (Guy Harris) writes:
>>Is it possible to use the inbuilt commands of the shell
>>from a makefile ? The shell is csh.

[ useful info on shell's in make deleted ]

>lines in the Makefile, using backslashes at the end of the lines to
>continue the command, so that you can put a Bourne shell construct on
>multiple lines:

>	for i in $(MAKEVARIABLE); do \
>		command $$i; \
>	done

>which gets passed to the shell as

>	/bin/sh -c "for i in <expanded Makevariable>; do command $i; done"

>The Bourne shell doesn't mind this; I don't know if the C shell does or
>not. 

Csh does not like this at all.

     Several keywords ("else","endif" and others), must be the FIRST words
on their input lines.  Others must be the only one on their input lines.
     Since make gives ONE line to the shell, this doesn't work too well.
There MUST be some reason for this but I can't begin to figure out what
it could have been.
     I like csh otherwise, but this problem and the I/O redirection
problems keep me in practice with my bourne shell skills.

	--Bill Davidson

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
....!{ucsd|sdcsvax}!celerity!billd