Subject: Re: New make modifiers: :C///W, :tW, and :[]
To: Alan Barrett <apb@cequrux.com>
From: Simon J. Gerraty <sjg@crufty.net>
List: tech-userlevel
Date: 07/31/2003 09:52:30
>of share/mk/bsd.endian.mk, Luke Mewburn addressed this problem using
>something like

>	.if exists(${CC:ts::C/:.*$//})

>Here, the ":ts:" converts the spaces to colons, and then :C/// sees only
>one word.  It's debatable whether this should even have worked (perhaps

No, its well defined that it should have worked ;-)
But ${CC:[1]} is neater.

>It would sometimes be useful to address individual words in a variable
>expansion.  We could add a :[] modifier to do this, and it could even
>subsume the functionality of :tW and :tw, as follows:

>	:[1]   first word
>	:[2]   second word
>	:[-1]  last word
>	:[0]   entire string as a single word
>		    (equivalent to :tW)
>	:[*]   entire string as separate words
>		    (reverses the effect of :[0]; equivalent to :tw)


Personally I think :[] or :t[] is best, and I'd suggest implementing it such
that you can do:  ${VAR:[2 .. 4]} or ${VAR:[-1 .. -3]}, ie. support the notion
of a start and end index, and treat them the same in the case of :[1] etc.

>NetBSD/FreeBSD/OpenBSD.  I think that the risk of another BSD using :[

Sadly the support of the old sysV :old=new can make any new modifier break
something, but that's life.  I think :[] (or :t[] would be good.

>for an incompatible purpose is low enough not to matter, and we could
>even discuss it with the other BSDs before implementing.

Worth pinging them at least.

--sjg