Problems with tests in make

Brian Matthews 6sigma2 at polari.UUCP
Fri Jun 7 08:30:12 AEST 1991


I'm trying to write some make rules that use test to conditionally
execute different shell commands.  For instance, if a certain
make variable has one value, I want to do one thing, otherwise something
else.

The obvious solution is to do something like this:

	if $(VAR) = val1; then command1; else command2; fi

If VAR happens to contain val1, or I'm using a System V-like make,
everything works fine.  However, if VAR doesn't contain val1, BSD-like
makes seem to bail out as soon as the test fails - the else command2
isn't executed, and the make fails.

For a concrete example, put:
SHELL=/bin/sh

a:	b c
	@echo a made

b:
	@if test x = x; then echo b made;fi

c:
	@if test x = y; then echo c not made;else echo c made;fi

In a file called Makefile and do a make.  I would expect to see:
b made
c made
a made
but when using BSD-like makes (on BSD 4.3 or Ultrix for example) 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.  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.

Any ideas?
-- 
Brian L. Matthews
blm at 6sceng.UUCP



More information about the Comp.unix.programmer mailing list