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
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é
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?
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.
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é
>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
--
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 =]
>>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
--