开发者

Make filtering on rule

开发者 https://www.devze.com 2023-04-13 03:12 出处:网络
I have a make rule like app.o: app.c b.c a.c h.h file.list I am using rule $^to do some action on all dependency.

I have a make rule like

app.o: app.c b.c a.c h.h file.list

I am using rule $^ to do some action on all dependency. But I want to filter based on file e开发者_开发百科xtension on dependency. How can I do that ?

I want a variable

k = (which contain only .c file from dependency list )


If you are using GNU Make, than

$(filter %.c,$^)

will do the trick (filter returns all words matching given pattern from a list, filter-out returns the non-matching ones). If you are using some more primitive make, you'll have to resort to

APP_O_C_DEPS = app.c b.c a.c
APP_O_NONC_DEPS = h.h file.list
app.o: $(APP_O_C_DEPS) $(APP_O_NONC_DEPS)
        ...

Note: The way variables work in Make allows you to say

c_deps = $(filter %.c,$^)
app.o: app.c b.c a.c h.h file.list
    something $(c_deps)

and it will expand to the .c dependencies of current target.

0

精彩评论

暂无评论...
验证码 换一张
取 消