Makefile

Guy Harris guy at auspex.UUCP
Sat Nov 12 08:14:09 AEST 1988


>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. 



More information about the Comp.unix.wizards mailing list