Problems with tests in make

Chris Torek torek at elf.ee.lbl.gov
Fri Jun 7 21:35:12 AEST 1991


In article <4378 at polari.UUCP> 6sigma2 at 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 at ee.lbl.gov



More information about the Comp.unix.programmer mailing list