help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Tricky problem filtering out commas from a string.


From: Dave Korn
Subject: RE: Tricky problem filtering out commas from a string.
Date: Thu, 19 Apr 2007 14:18:46 +0100

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....





reply via email to

[Prev in Thread] Current Thread [Next in Thread]