Вопрос

In a makefile:

a = d:\wuyu

My purpose is to get the part before :. That's to say, "d" in the example.

Using b = $(patsubst :%,,$(a)) didn't work. Variable "b" is same to variable "a". Using

c = `echo $(a)|sed -e 's/:.*//'`

did work. But it resulted in another problem: *** multiple target patterns. Stop. when doing make since there is : in the sed command. Adding \ in sed didn't work.

Therefore, how can I solve the problem?

Это было полезно?

Решение

The patsubst doesn't work because your pattern is :% which will only match strings that start with a colon; your string doesn't start with a colon so it doesn't match, so no substitution is performed.

You can do this by splitting the string into multiple words:

b = $(firstword $(subst :, ,$(a)))
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top