Can a Gnu Make variable substitution expression match more than one pattern?

118 Views Asked by At

Say I have a list of files with mixed suffixes, e.g. .cpp and .c, and I want to make a list where each .cpp and each .c extension is changed to .o. I realize I could sequentially process my list multiple times, one for each extension of interest. But is there a way to use a variable substitution to do it in one step?

2

There are 2 best solutions below

0
On BEST ANSWER

You could always just remove any suffix, like this:

OBJECTS := $(addsuffix .o,$(basename $(FILES)))
0
On

You can use the usual functional style concatenation by repeated application:

FILES := a.c b.cpp c.cxx
OBJECTS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(patsubst %.cxx,%.o,$(FILES))))