Date: Fri, 27 Jan 2012 16:51:27 +0000 From: Chris Rees <utisoft@gmail.com> To: Matthew Seaman <m.seaman@infracaninophile.co.uk> Cc: freebsd-ports <freebsd-ports@freebsd.org> Subject: Re: BSD make -- Malformed conditional Message-ID: <CADLo83-Q9O5AMTReRG9v=U5y1d37NUnK1dGUWe5Yk4ZMbd1Zjw@mail.gmail.com> In-Reply-To: <4F22CB51.6070507@infracaninophile.co.uk> References: <4F22CB51.6070507@infracaninophile.co.uk>
next in thread | previous in thread | raw e-mail | index | archive | help
On 27 Jan 2012 16:06, "Matthew Seaman" <m.seaman@infracaninophile.co.uk> wrote: > > > Dear all, > > Posting this mostly for the archives, but it's probably relevant to some > people here too. > > When hacking on Makefiles, should you wish to match an item in a list, > you might write something like this: > > .for item in ${LIST} > .if ${item} == ${THING} # Ooops! > THING_FOUND= 1 > .endif > .endfor > > This however is a snare and a delusion, and will lead to much weeping > and wailing, and error messages like so: > > % make > "Makefile", line 7: Malformed conditional (foo == ${THING}) > "Makefile", line 9: if-less endif > "Makefile", line 7: Malformed conditional (bar == ${THING}) > "Makefile", line 9: if-less endif > "Makefile", line 7: Malformed conditional (baz == ${THING}) > "Makefile", line 9: if-less endif > "Makefile", line 7: Malformed conditional (blurfl == ${THING}) > "Makefile", line 9: if-less endif > make: fatal errors encountered -- cannot continue > > Instead you should write your loops like this: > > .for item in ${LIST} > .if ${THING} == ${item} > THING_FOUND= 1 > .endif > .endfor > > As the make(1) manual page says on the subject of string comparisons > using == or != : > > An expression may also be a numeric or string comparison: in this case, > the left-hand side must be a variable expansion, whereas the right-hand > side can be a constant or a variable expansion. > > So it seems that despite appearing and behaving almost exactly like one, > the iterator in a .for loop is not actually a variable as such. It also > means that to match a constant string, you can't just write: > > .for item in ${LIST} > .if ${item} == "this" # Ooops You shouldn't use quotes either. Chris
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CADLo83-Q9O5AMTReRG9v=U5y1d37NUnK1dGUWe5Yk4ZMbd1Zjw>