[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: subst question
From: |
Danny Boelens |
Subject: |
Re: subst question |
Date: |
Fri, 26 Jan 2007 12:26:36 +0100 |
----- Original Message -----
From: "Brendan Heading" <address@hidden>
To: <address@hidden>
Sent: Friday, January 26, 2007 12:00 PM
Subject: subst question
> All,
>
> Another quick question. Does anyone know a way in GNU Make to filter off
the
> first instance only of a given string.
>
> For example, at the moment I'm doing
>
> $(subst lib,,libfoo.a)
>
> which gives me "foo.a". However if I do :
>
> $(subst lib,,libbarlib.a)
>
> this also gives me "bar.a" even though what I need is "barlib.a".
>
> Any ideas ?
I guess it depends on what you mean with 'the first instance only'. If you
only want to replace the first instance in a word (and do this for every
word) and you're sure the string you want to replace is at the beginning of
a word, you could use the patsubst function: something like $(patsubst
lib%,%,libbarlib.a) will do what you want. A similar thing can be done if
the string is at the end of the word.
If the string can be located anywhere in your word - for instance lib in
'mylibgreatlib.a' and you only want the first lib to be replaced, the only
thing I can think of is using stuff like sed in combination with the shell
function. For instance something like this:
LIBS := mylibgreatlib.a something.a
LIBS := $(shell echo $(LIBS) | sed 's/lib//')
# LIBS now contains 'mygreatlib.a something.a'
I guess that's not a perfect solution, but it works :-)
Hope this helps,
Danny