help-make
[Top][All Lists]
Advanced

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

Re: how to filter-out a word sequence?


From: Mike Shal
Subject: Re: how to filter-out a word sequence?
Date: Thu, 4 Jan 2007 20:44:59 -0500

On 1/4/07, Dave Korn <address@hidden> wrote:
On 05 January 2007 01:05, David Boyce wrote:

> My build model has a common link line which contains a number of -z
> options (-z is a way of passing keywords to the linker on Linux and
> Solaris). For instance:
>
>       $(CC) -o program -z combreloc -z noversion -z defs ...
>
>   The problem is that occasionally a target will need one of these
> removed as a special case. But of course using $(filter-out -z
> foo,...) will remove *all* the -z flags, leaving the other keywords
> hanging there alone, while quoting the string like $(filter-out "-z
> foo",...) doesn't match anything. Does anybody know a reasonable way
> to remove a whitespace-containing string? I can think of ways
> involving $(shell) with but would prefer to do it all within the make
> process. Another complication is that, because this needs to be
> compatible with clearmake's GNU-compatibility mode, I'm limited to
> those features available since GNU make 3.76 or so.

  Filter out the word name, then patsubst any "-z -z" sequences into a single
"-z"?

/tmp $ cat foo.mk

LDFLAGS:=-z combreloc -z noversion -z defs

LDFLAGS_LESS_1:=$(filter-out noversion,$(LDFLAGS))
LDFLAGS_LESS:=$(patsubst -z -z,-z,$(LDFLAGS_LESS_1))

all:
        @echo 1 is $(LDFLAGS_LESS_1)
        @echo result is $(LDFLAGS_LESS)
        @echo done

/tmp $ make -f foo.mk
1 is -z combreloc -z -z defs
result is -z combreloc -z defs
done
/tmp $

That doesn't quite work if the flags are interspersed (like "-z foo -r
-z bar"), but if you know all the -z flags are in the same spot that
won't be an issue. Also removing the last flag doesn't work since you
won't have two -z's in a row. You can probably hack around that by
appending a -z flag that you later remove, or something.

You may just be able to use $(subst), since that works on the whole
string instead of each whitespace-separated element. Like:

newflags := $(subst -z foo,,$(LDFLAGS))

Unfortunately this doesn't work if there may be multiple spaces
between the "-z" and "foo".

So to answer the OP, there might not be a "reasonable" way to do what
you want - is there any reason why you absolutely have to add the -z
flags in the first place if you're going to remove them later? Maybe
you can move your conditional logic elsewhere and only add the correct
flags when you need them.

-Mike




reply via email to

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