0

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?

Michael57
  • 85
  • 7

2 Answers2

1

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))))
Vroomfondel
  • 2,704
  • 1
  • 15
  • 29
1

You could always just remove any suffix, like this:

OBJECTS := $(addsuffix .o,$(basename $(FILES)))
MadScientist
  • 92,819
  • 9
  • 109
  • 136