Path: utzoo!telly!eci386!ecicrl!clewis From: clewis@ferret.ocunix.on.ca (Chris Lewis) Newsgroups: comp.unix.programmer Subject: Re: Problems with tests in make Message-ID: <2126@ecicrl.ocunix.on.ca> Date: 8 Jun 91 06:11:54 GMT References: <4378@polari.UUCP> Organization: Elegant Communications Inc., Ottawa, Canada Lines: 59 In article <4378@polari.UUCP> 6sigma2@polari.UUCP (Brian Matthews) writes: Hi Brian, long time no see. >I'm trying to write some make rules that use test to conditionally >execute different shell commands. >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. This is a bug in the BSD shell. To-wit, make starts the shell script with "-e" set, and the test's failure causes the shell script to terminate immediately rather than processing thru the else clause. You can test this yourself with the following shell script: set -e if test x = y then echo wha? else echo "worked properly" fi On non-SYSV shells this won't print anything. I think this botch was even in V7. What I usually do is this: # comment out on System V. IGNORESH = set +e ; all: $(IGNORESH) if .... \ then ... Unfortunately, you have to check the returns of each subcommand individually (as you would do in a normal script), and on error execute "exit 1". Psroff has this in its makefiles, and even a way of testing whether you need it commented out or not. BTW: go multi line on your shell scripts, it makes them a lot easier to read even if you have to put backslashes on the ends of all of the lines... If it wasn't for this stupid botch in BSD, set -e and trap 0's would make error recovery in shell scripts easy and portable... Grrr! -- Chris Lewis, Phone: (613) 832-0541, Domain: clewis@ferret.ocunix.on.ca UUCP: ...!cunews!latour!ecicrl!clewis; Ferret Mailing List: ferret-request@eci386; Psroff (not Adobe Transcript) enquiries: psroff-request@eci386 or Canada 416-832-0541. Psroff 3.0 in c.s.u soon!