Discussion:
New make modifiers: :C///W, :tW, and :[]
Alan Barrett
2003-07-31 17:58:56 UTC
Permalink
I propose adding a new :[] modifier to make(1) in NetBSD,
and possibly also adding some other modifiers.

":[]" will allow you to extract a single word from a space-separated list,
like this:

CC= /usr/bin/gcc -Wall
.if exists(${CC:[1]})
...

See http://mail-index.netbsd.org/tech-userlevel/2003/07/31/0000.html
for a post to NetBSD's tech-userlevel list where I discusssed the
problem and several proposed solutions. See other nearby messages
linked from http://mail-index.netbsd.org/tech-userlevel/2003/07/
for responses.

Briefly, the proposals are

:tW Set a flag that causes subsequent modifiers to treat the
value as a single entity instead of as a space-separated
list.

Why ":tW"? We already have :tu and :tl to convert to
upper or lower case, so starting with "t" is natural.
"tW" is supposed to suggest "convert to one big word".

:tw Undo the effect of :tW. "tw" is supposed to suggest
"convert to small words".

:C///W A "one big word" variant of the existing :C/// regular
expression substitution modifier. Unlike the usual
:C/// (which works separately on each space-separated
word), this would work on the entire string all at once,
so it would be able to match teh spaces between words.

:S///W A "one big word" variant of the existing :S/// simple
string substitution operator.

:[N] Select the Nth word, where N is a positive integer.
:[1] selects the first word.
:[-N] Select the Nth word from the end. :[-1] selects the
last word.
:[0] Select the entire string, but treat it as one big word.
(Equivalent to :tw.)
:[*] Select the entire string, treating it as a sequence of
space-separated words. (Undoes the effects of :[0];
equivalent to :tw.)


There seems to be support for adding :[] to NetBSD's make(1). :tW/:tw
and :C///W are not really necessary if you have :[0] and :[*], but they
might nevertheless be useful enough to add.

Would other BSDs be likely to pick up these features, or at least
not use the same modifier characters with incompatible meanings?

--apb (Alan Barrett)

---------------------------------------------------------------------
The BSD APIs Discussion Mailing List
To unsubscribe:
send "unsubscribe bsd-api-discuss" to majordomo-of7zbby7T3pWk0Htik3J/***@public.gmane.org
Garance A Drosihn
2003-08-03 02:12:42 UTC
Permalink
Post by Alan Barrett
I propose adding a new :[] modifier to make(1) in NetBSD,
and possibly also adding some other modifiers.
":[]" will allow you to extract a single word from a
CC= /usr/bin/gcc -Wall
.if exists(${CC:[1]})
...
Of course, this assumes that the filename path does not have any
blanks in *it*... :-)
(yes, I have written some scripts for MacOS 10, why do you ask?)

The following are just my own opinions. I do not pretend
to be speaking for "the FreeBSD project"...
Post by Alan Barrett
Briefly, the proposals are
:tW Set a flag that causes subsequent ...
:tw Undo the effect of :tW.
I think we could skip with these two. Given the other proposed
options, all this gives us more stuff to document. (IMO)
Post by Alan Barrett
:C///W A "one big word" variant...
:S///W A "one big word" variant...
These are also redundant, but I think they serve a useful
purpose in reminding people the significance of blanks
with the standard C/// and S///. Also, it's more intuitive
than having to reference ':[0]' before doing the C or S.
Post by Alan Barrett
:[N] Select the Nth word, where N is a positive
integer. :[1] selects the first word.
:[-N] Select the Nth word from the end. :[-1]
selects the last word.
:[0] Select the entire string, but treat it as
one big word. (Equivalent to :tw.)
I expect that you mean ':tW' here!
Post by Alan Barrett
:[*] Select the entire string, treating it as a
sequence of space-separated words. (Undoes
the effects of :[0]; equivalent to :tw.)
Some of the replies to your message also suggested various
additional options. I liked the idea of ':[#]' to give the
number of words, and I liked the idea of having some way to
specify a range. If a person wants to do something special
with word #1, then they might also want to do something
special with word#2->last_word. I don't particularly care
what syntax is used for a range, though I would like it to
include a way to say "to the last word" without having to
dig up the # value. Probably just ':[N..-M]', with M==1
would include everything up to the last word.

If other freebsd developers do not object to the *idea* of
these changes, I would be willing to look at installing
similar changes to FreeBSD, after NetBSD has worked with
them for a little while.
--
Garance Alistair Drosehn = gad-AvF0vkkS99i66gPnRoyaY/***@public.gmane.org
Senior Systems Programmer or gad-h+***@public.gmane.org
Rensselaer Polytechnic Institute or drosih-***@public.gmane.org

---------------------------------------------------------------------
The BSD APIs Discussion Mailing List
To unsubscribe:
send "unsubscribe bsd-api-discuss" to majordomo-of7zbby7T3pWk0Htik3J/***@public.gmane.org
Alan Barrett
2003-08-03 09:31:27 UTC
Permalink
Post by Garance A Drosihn
Some of the replies to your message also suggested various
additional options. I liked the idea of ':[#]' to give the
number of words, and I liked the idea of having some way to
specify a range.
I have added ranges to my implementation. ":[2..-1]" means "everything
except the first word".

:[#] seems like a reasonable idea.

--apb (Alan Barrett)

---------------------------------------------------------------------
The BSD APIs Discussion Mailing List
To unsubscribe:
send "unsubscribe bsd-api-discuss" to majordomo-of7zbby7T3pWk0Htik3J/***@public.gmane.org
Garance A Drosihn
2003-08-03 02:21:45 UTC
Permalink
Comments? If so, please forward them to the
Warner
Date: Thu, 31 Jul 2003 19:58:56 +0200
Subject: New make modifiers: :C///W, :tW, and :[]
I propose adding a new :[] modifier to make(1) in NetBSD,
and possibly also adding some other modifiers.
Just a note. In my reply on that list, I made the
following offer:

If other freebsd developers do not object to the *idea*
of these changes, I would be willing to look at installing
similar changes to FreeBSD, after NetBSD has worked with
them for a little while.

So, speak up if the proposal strikes you as a bad idea.
(also note that I'm perfectly happy for someone else to
do this work on freebsd's make, if anyone wants to)
--
Garance Alistair Drosehn = gad-AvF0vkkS99i66gPnRoyaY/***@public.gmane.org
Senior Systems Programmer or gad-h+***@public.gmane.org
Rensselaer Polytechnic Institute or drosih-***@public.gmane.org

---------------------------------------------------------------------
The BSD APIs Discussion Mailing List
To unsubscribe:
send "unsubscribe bsd-api-discuss" to majordomo-of7zbby7T3pWk0Htik3J/***@public.gmane.org
Alan Barrett
2003-08-04 11:29:24 UTC
Permalink
Post by Alan Barrett
:[0] Select the entire string, but treat it as one big word.
(Equivalent to :tw.)
:[*] Select the entire string, treating it as a sequence of
space-separated words. (Undoes the effects of :[0];
equivalent to :tw.)
Somebody suggested in private email that, by analogy with "$*" and "$@"
in /bin/sh, it would make more sense for :[*] to mean the entire string
as one big word, and for :[@] to mean the entire string as several
separate words.

--apb (Alan Barrett)

---------------------------------------------------------------------
The BSD APIs Discussion Mailing List
To unsubscribe:
send "unsubscribe bsd-api-discuss" to majordomo-of7zbby7T3pWk0Htik3J/***@public.gmane.org
Loading...