Chris Smith
Chris Smith

Reputation: 3012

Makefile prepend and append all elements in array

I'm writing a Makefile, I have a list of all the files (without src/ or .cpp), and I want to convert those to build/*.o. Here's what I've tried already:

FILES=icxxabi list memory string
OBJECTS=$(echo ("${build/$$FILES[@].o}")[@])

So for the input a dir/b c, it should output:

build/a.o build/dir/b.o build/c.o

Upvotes: 27

Views: 19110

Answers (2)

melpomene
melpomene

Reputation: 85827

Take a look at the make file name functions:

OBJECTS = $(addprefix build/,$(addsuffix .o,$(FILES)))

Upvotes: 24

ccorn
ccorn

Reputation: 534

With GNU Make, you could try

OBJECTS=$(patsubst %, build/%.o, $(FILES))

Upvotes: 30

Related Questions