Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Jan 2012 16:05:37 +0000
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        freebsd-ports <freebsd-ports@FreeBSD.org>
Subject:   BSD make -- Malformed conditional
Message-ID:  <4F22CB51.6070507@infracaninophile.co.uk>

next in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig7FB8387BD1D0D244C3619B35
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable


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:

=2Efor item in ${LIST}
=2Eif ${item} =3D=3D ${THING}  # Ooops!
THING_FOUND=3D	1
=2Eendif
=2Eendfor

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 =3D=3D ${THING})
"Makefile", line 9: if-less endif
"Makefile", line 7: Malformed conditional (bar =3D=3D ${THING})
"Makefile", line 9: if-less endif
"Makefile", line 7: Malformed conditional (baz =3D=3D ${THING})
"Makefile", line 9: if-less endif
"Makefile", line 7: Malformed conditional (blurfl =3D=3D ${THING})
"Makefile", line 9: if-less endif
make: fatal errors encountered -- cannot continue

Instead you should write your loops like this:

=2Efor item in ${LIST}
=2Eif ${THING} =3D=3D ${item}
THING_FOUND=3D    1
=2Eendif
=2Eendfor

As the make(1) manual page says on the subject of string comparisons
using =3D=3D or !=3D :

     An expression may also be a numeric or string comparison: in this ca=
se,
     the left-hand side must be a variable expansion, whereas the right-h=
and
     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:

=2Efor item in ${LIST}
=2Eif ${item} =3D=3D "this"  # Ooops
THIS_FOUND=3D1
=2Eendif
=2Eendfor

but have to assign the text "this" to a variable somewhere, and use the
second form.

Yes, you can use ${LIST:Mthis} instead, but using this construct can be
a bit tricky in itself...

% cat Makefile

LIST=3D	foo bar baz blurfl

THING=3D	baz

all:
	@echo "OK     \$${LIST:Mfoo} =3D ${LIST:Mfoo}"
	@echo "Not OK \$${LIST:M\$${THING}} =3D ${LIST:M${THING}}"
% make
OK     ${LIST:Mfoo} =3D foo
Not OK ${LIST:M${THING}} =3D }

	Cheers,

	Matthew

--=20
Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey     Ramsgate
JID: matthew@infracaninophile.co.uk               Kent, CT11 9PW


--------------enig7FB8387BD1D0D244C3619B35
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.16 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8iy1oACgkQ8Mjk52CukIw1EgCeNrwfvkTHm5L8q1bqKhSR4Swv
wHIAninG/eNaxfBHO5ajQO8Gzbh1URl4
=bTiN
-----END PGP SIGNATURE-----

--------------enig7FB8387BD1D0D244C3619B35--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4F22CB51.6070507>