Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!rpi!batcomputer!cornell!uw-beaver!milton!sumax!thebes!polari!polari.UUCP From: 6sigma2@polari.UUCP (Brian Matthews) Newsgroups: comp.unix.programmer Subject: Problems with tests in make Message-ID: <4378@polari.UUCP> Date: 6 Jun 91 22:30:12 GMT Sender: 6sigma2@polari.UUCP Organization: Seattle Online Public Unix (206) 328-4944 Lines: 44 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@6sceng.UUCP