[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [GNU-make] Tricky problem filtering out commas from a string.
From: |
Rakesh Sharma |
Subject: |
RE: [GNU-make] Tricky problem filtering out commas from a string. |
Date: |
Tue, 21 Jul 2015 22:10:21 -0700 |
Hello DaveK,
I was going though the GNU Make mailing list & somehow stumbled upon a
very-oldquery that you had posted on this list.
You were reporting a problem due to comma variables. But actually the problemis
not that, rather it is the age-old problem of make allowing the use of
undefinedvariables to collapse into an empty string!
The culprit is on line #10 and 11.On line-11, the variable
`LIST2_WITHOUT_COMMAS' is used whereas a line beforeon line-10,
`LIST_WITHOUT_COMMAS' is initialized. Due to which an empty stringis output.
We could prevent such issues by not resorting to creating new variables for
intermediateresults, like as,
> 10 LIST_WITHOUT_COMMAS:=$(filter-out $(IMMCOMMA),$(LIST_WITH_COMMAS))>
> 11 $(warning $(LIST2_WITHOUT_COMMAS))
$(warning $(filter-out $(IMMCOMMA),$(LIST_WITH_COMMAS)))
Or, with a newer version of GNU make, there is an option
"--warn-undefined-variables"which when run on your makefile "comma.mk" will
blurt out:
$ make --warn-undefined-variables -f comma.mk
comma.mk: 11: warning: undefined variable 'LIST2_WITH_COMMAS'
With regards, Rakesh S.
P.S.: By any chance, are you the David Korn of the Kornshell ?
>On 19 April 2007 14:06, Paul Smith wrote:>>> On Thu, 2007-04-19 at 13:15
>+0100, Dave Korn wrote:>>>>> The obvious first approach - escape the comma so
>that filter-out doesn't>>> think it's the separator between its two arguments
>- just doesn't work. I>>> can't quite see how to achieve this in make....>>>>
>Using backslashes as an escape character in make is pretty ad hoc; it>>
>definitely does not work everywhere you expect it to (unfortunately).>> I
>wondered if that might be the case.>>> However, you should be able to do it
>with variables:>>>> COMMA = ,>> LIST_WITHOUT_COMMAS:=$(filter-out
>$(COMMA),$(LIST_WITH_COMMAS))>> Doesn't actually work in practice: as Danny
>pointed out, filter-out only>matches entire words, but using a variable
>enabled subst to work.>>/tmp $ cat -n comma.mk> 1> 2
>LIST_WITH_COMMAS:= foo, bar, baz, quux> 3> 4 COMMA = ,> 5
>IMMCOMMA:= ,> 6> 7 LIST_WITHOUT_COMMAS:=$(filter-out
>$(COMMA),$(LIST_WITH_COMMAS))> 8 $(warning $(LIST_WITHOUT_COMMAS))>
>9> 10 LIST_WITHOUT_COMMAS:=$(filter-out $(IMMCOMMA),$(LIST_WITH_COMMAS))>
> 11 $(warning $(LIST2_WITHOUT_COMMAS))> 12> 13
>LIST3_WITHOUT_COMMAS:=$(subst $(COMMA), ,$(LIST_WITH_COMMAS))> 14
>$(warning $(LIST3_WITHOUT_COMMAS))> 15> 16
>LIST4_WITHOUT_COMMAS:=$(subst $(IMMCOMMA), ,$(LIST_WITH_COMMAS))> 17
>$(warning $(LIST4_WITHOUT_COMMAS))> 18> 19> 20> 21 all:> 22
> @>/tmp $ /bin/make -f comma.mk>comma.mk:8: foo, bar, baz,
>quux>comma.mk:11:>comma.mk:14: foo bar baz quux>comma.mk:17: foo bar baz
>quux>make: `all' is up to date.>> Thanks to all :)>> cheers,>
>DaveK>-->Can't think of a witty .sigline today....
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- RE: [GNU-make] Tricky problem filtering out commas from a string.,
Rakesh Sharma <=