Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!agate!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.unix.programmer Subject: Re: Problems with tests in make Message-ID: <14016@dog.ee.lbl.gov> Date: 7 Jun 91 11:35:12 GMT Article-I.D.: dog.14016 References: <4378@polari.UUCP> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 44 X-Local-Date: Fri, 7 Jun 91 04:35:12 PDT In article <4378@polari.UUCP> 6sigma2@polari.UUCP (Brian Matthews) writes: >I'm trying to write some make rules that use test to conditionally >execute different shell commands. ... BSD-like makes seem to bail out >as soon as the test fails ... >c: > @if test x = y; then echo c not made;else echo c made;fi >... make fails with exit code 1 after outputting b made. > >I've tried all sort of different things, including prefixing the if >with set +e (thinking the shell was bailing out when test exited with >a 1), running in a subshell and doing an exit 0, etc. You were on the right track. The problem is a bug in the BSD Bourne shell; under -e, it improperly exits for *all* nonzero subprocess exits, rather than only those which are tested. The bug is partially fixed in 4.3BSD-tahoe: I fixed the if foo; then bar; else baz; fi case but forgot to hit up the foo && bar || baz cases (I got thoroughly sick of working on sh in just the few minutes it took to fix if, while, and until: Bourne's pseudo-Algol is a nightmare). The reason `set +e' did not help is that the BSD Bourne shell was so old that it did not have `set +' for turning off options. Once -e is set in such a shell, you cannot get rid of it. >I can put a - before the @if, but I'd rather not, because I would >like the make to stop if the command executed as a consequence of >the test result fails. Unfortunately, unless you have source, you are stuck with that. I had a version of the BSD Bourne shell which I had deBourned and then fixed this and a number of other bugs, but it has fallen by the wayside; BSD now uses a Bourne-shell clone based on Kenneth Almquist's `ash' as /bin/sh. -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov