Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GNU Make: replace spaces with commas

8,143 views
Skip to first unread message

Tristan Miller

unread,
Jan 12, 2004, 9:48:29 AM1/12/04
to
Greetings.

I have a Makefile which needs to construct a command line for the program
curl. Curl takes its filename arguments as a strictly comma-delimited list
(i.e., no spaces unless they're part of the filename). In my case I need
to convert the contents of the $? variable from a space-delimited list into
such a comma-delimited list. I can't figure out how to do this using
Make-internal string commands, though.

The $(subst) command is the obvious solution, but I can't figure out how to
escape the space and the comma so that they're recognized by Make. That
is, $(subst \ ,\,,$?) (and variations thereof I've tried) don't work.

$(foreach f,$?,$f,) is not an option as it inserts extraneous space which
confuses curl.

Any solutions besides resorting to $(shell tr)?

Regards,
Tristan

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you

René Larsen

unread,
Jan 12, 2004, 2:04:14 PM1/12/04
to
In article <1104342.j...@ID-187157.news.dfncis.de>, Tristan Miller
wrote:

>
> Greetings.
>
> I have a Makefile which needs to construct a command line for the program
> curl. Curl takes its filename arguments as a strictly comma-delimited list
> (i.e., no spaces unless they're part of the filename). In my case I need
> to convert the contents of the $? variable from a space-delimited list into
> such a comma-delimited list. I can't figure out how to do this using
> Make-internal string commands, though.
>
> The $(subst) command is the obvious solution, but I can't figure out how to
> escape the space and the comma so that they're recognized by Make. That
> is, $(subst \ ,\,,$?) (and variations thereof I've tried) don't work.
>
> $(foreach f,$?,$f,) is not an option as it inserts extraneous space which
> confuses curl.

When I try "info make" and follow the links "Functions" -> "Syntax of
Functions", I get the following example at the end:

comma:= ,
empty:=
space:= $(empty) $(empty)
foo:= a b c
bar:= $(subst $(space),$(comma),$(foo))
# bar is now `a,b,c'.

It looks like just what you wanted ;-)

Regards, René

Derk Gwen

unread,
Jan 12, 2004, 5:53:58 PM1/12/04
to
Tristan Miller <psych...@nothingisreal.com> wrote:
# Greetings.
#
# I have a Makefile which needs to construct a command line for the program
# curl. Curl takes its filename arguments as a strictly comma-delimited list
# (i.e., no spaces unless they're part of the filename). In my case I need
# to convert the contents of the $? variable from a space-delimited list into
# such a comma-delimited list. I can't figure out how to do this using
# Make-internal string commands, though.

Do you mean something like

# Q=$(sep=""; L=""
for f in "a b c" "def" "gh i"
do
L=$L$sep$f; sep=,
done
echo $L)
# echo $Q
a b c,def,gh i

--
Derk Gwen http://derkgwen.250free.com/html/index.html
Who's leading this mob?

Tristan Miller

unread,
Jan 13, 2004, 5:12:19 AM1/13/04
to
Greetings.

In article <VA.0000000...@spamfilter.dk>, René Larsen wrote:
> When I try "info make" and follow the links "Functions" -> "Syntax of
> Functions", I get the following example at the end:
>
> comma:= ,
> empty:=
> space:= $(empty) $(empty)
> foo:= a b c
> bar:= $(subst $(space),$(comma),$(foo))
> # bar is now `a,b,c'.
>
> It looks like just what you wanted ;-)

It does look that way, but this doesn't work for me. Here is the example
copy-and-pasted into a minimal Makefile:

[psy@port-3106 /tmp]$ cat Makefile


comma:= ,
empty:=
space:= $(empty) $(empty)
foo:= a b c
bar:= $(subst $(space),$(comma),$(foo))

all:
echo "$(bar)"

[psy@port-3106 /tmp]$ make
echo " "
 
[psy@port-3106 /tmp]$

Is there something exceedingly obvious I'm overlooking or is there a bug in
GNU Make (or the GNU Make documentation)? I am running version 3.80.

René Larsen

unread,
Jan 14, 2004, 5:34:56 AM1/14/04
to
In article <2707018.Y...@ID-187157.news.dfncis.de>, Tristan Miller
wrote:

>
> It does look that way, but this doesn't work for me. Here is the example
> copy-and-pasted into a minimal Makefile:
>
> [psy@port-3106 /tmp]$ cat Makefile
> comma:= ,
> empty:=
> space:= $(empty) $(empty)
> foo:= a b c
> bar:= $(subst $(space),$(comma),$(foo))
>
> all:
> echo "$(bar)"
>
> [psy@port-3106 /tmp]$ make
> echo " "
>  
> [psy@port-3106 /tmp]$
>
> Is there something exceedingly obvious I'm overlooking or is there a bug in
> GNU Make (or the GNU Make documentation)? I am running version 3.80.

To be really sure I just copy-and-pasted your code into a minimal GNUmakefile
and got the following output:

echo "a,b,c"
"a,b,c"

"make -v" gives:
GNU Make version 3.79.1, by Richard Stallman and Roland McGrath.
Built for i386-pc-msdosdjgpp

I don't know where the problem is. Perhaps Derk Gwen's example works?

Regards, René

Walter Harms

unread,
Jan 14, 2004, 12:33:32 PM1/14/04
to
Tristan Miller <psych...@nothingisreal.com> writes:

>Greetings.

>I have a Makefile which needs to construct a command line for the program
>curl. Curl takes its filename arguments as a strictly comma-delimited list
>(i.e., no spaces unless they're part of the filename). In my case I need
>to convert the contents of the $? variable from a space-delimited list into
>such a comma-delimited list. I can't figure out how to do this using
>Make-internal string commands, though.

>The $(subst) command is the obvious solution, but I can't figure out how to
>escape the space and the comma so that they're recognized by Make. That
>is, $(subst \ ,\,,$?) (and variations thereof I've tried) don't work.

>$(foreach f,$?,$f,) is not an option as it inserts extraneous space which
>confuses curl.

>Any solutions besides resorting to $(shell tr)?


i did try it but:
you can define a funktion via define and then use $(call funktion arglist).
call will replace any $1 with the first argument, etc.

i would use 'tr' if $(subst) does not work.

walter
--

Richard Dawe

unread,
Jan 14, 2004, 6:31:39 PM1/14/04
to
Hello.

Ah, there's the problem. DJGPP's port of make tries to avoid calling the
shell, if it all possible. So it does some things internally, whereas
make on Unix/Linux would call the shell.

The problem that you're hitting is DJGPP's make defaults to using
command.com. Put a line like this in your Makefile and it should work
better:

SHELL=/bin/sh

If that fails, try this:

SHELL=/dev/env/DJDIR/bin/bash.exe

The /bin/sh solution should be preferred, since that's more portable.

Incidentally it's worth reading the README.DOS (or README.DJGPP - I
forget which) file for DJGPP's make. It's in $DJDIR/gnu/make-3.791 in
this case, I think.

Hope that helps, regards, Rich =]

Walter Harms

unread,
Jan 15, 2004, 11:28:50 AM1/15/04
to

>>I have a Makefile which needs to construct a command line for the program
>>curl. Curl takes its filename arguments as a strictly comma-delimited list
>>(i.e., no spaces unless they're part of the filename). In my case I need
>>to convert the contents of the $? variable from a space-delimited list into
>>such a comma-delimited list. I can't figure out how to do this using
>>Make-internal string commands, though.

>>The $(subst) command is the obvious solution, but I can't figure out how to
>>escape the space and the comma so that they're recognized by Make. That
>>is, $(subst \ ,\,,$?) (and variations thereof I've tried) don't work.

>>$(foreach f,$?,$f,) is not an option as it inserts extraneous space which
>>confuses curl.

i found that example in the make docs:


comma:= ,
empty:=
space:= $(empty) $(empty)

foo: foo.c bar.c
/bin/echo "xx" $(subst $(space),$(comma),$^)

walter
--

0 new messages