[comp.unix.wizards] using /bin/sh in make commands

Leisner.Henr@xerox.com (Marty) (10/18/89)

In making a large system, I stumbled across some interesting behavior I'd
like some help with.

Often people have rules in makefiles of the form:

DIRS=lib src

foo:
	for i in $(DIRS); do \
		(cd $$i; $(MAKE) foo); \
	done

It seems if one of the sub-makes fails, the shell loop  continues.

The Bourne shell has a -e flag to exit immediately on errors.
Unfortunately a line like:
SHELL=/bin/sh -e
doesn't work.  (make tries to exec "/bin/sh -e").

Is there a good way to get the functionality I'm looking for without having
to hack up all the makefiles?


This seems to be somewhat unexpected when making systems (i.e. generally a
make should stop when a command fails).

marty
ARPA:	leisner.henr@xerox.com
GV:  leisner.henr
NS:  leisner:wbst139:xerox
UUCP:	hplabs!arisia!leisner
 

rogerc@sauron.Columbia.NCR.COM (Roger Collins) (10/19/89)

In article <21173@adm.BRL.MIL> Leisner.Henr@xerox.com (Marty) writes:
> 
> DIRS=lib src
> 
> foo:
> 	for i in $(DIRS); do \
> 		(cd $$i; $(MAKE) foo); \
> 	done
> 
> It seems if one of the sub-makes fails, the shell loop  continues.

Try this instead:

----------------------------------------
DIRS=lib src

foo:		$(DIRS)

$(DIRS)::
		cd $@; $(MAKE) foo
----------------------------------------

--
	Roger Collins
	NCR - Engineering & Manufacturing Columbia
	Domain:	rogerc@ncrcae.Columbia.NCR.COM
	Uucp:	(ncrsd | ncrlnk)!ncrcae!rogerc

david@indetech.com (David Kuder) (10/19/89)

In article <21173@adm.BRL.MIL> Leisner.Henr@xerox.com (Marty) writes:
>Often people have rules in makefiles of the form:
foo:
	for i in $(DIRS); do \
		(cd $$i; $(MAKE) foo); \
	done

>It seems if one of the sub-makes fails, the shell loop  continues.
>The Bourne shell has a -e flag to exit immediately on errors.
>Unfortunately a line like:
SHELL=/bin/sh -e
>doesn't work.  (make tries to exec "/bin/sh -e").
>Is there a good way to get the functionality I'm looking for without having
>to hack up all the makefiles?


Which make are you using?  There are way too many of these beasts.
However, on the three that I have at hand, SunOS4, Sys5.3, UCB4.3 (the
last two are Pyramid versions), a "make foo" stops as soon as one of
the sub makes fails.

If you must avoid changing the makefile (arguably broken) if you run
the make under a Bourne in which a 'set -e' has been done then the
shells started by the make will inherit it.  I can't test this but
it may work.
-- 
David A. Kuder                              Comp.lang.perl, the time is now!
415 438-2003  david@indetech.com  {uunet,sun,sharkey,pacbell}!indetech!david