Reputation: 40558
Given the line:
program_OBJS := ${program_SRCS:.cpp=.o}
I would like to append .o
to each filename instead of replacing .cpp
with .o
.
How do I do that?
Upvotes: 12
Views: 57692
Reputation: 1043
How about this:
STRING1:="foo"
STRING2:="bar"
STRING1:=$(STRING1)$(STRING2)
Obviuosly, you could save the result to a new variable.
Upvotes: 14
Reputation: 51
One more way working regardless of extension: ${program_SRCS:=.o}
Upvotes: 3
Reputation: 6216
Shorter alternative, using a pattern substitution: program_OBJS := ${program_SRCS:%=%.o}
Upvotes: 8
Reputation: 37905
To just append something to a list of space separated items you can use:
program_OBJS := $(foreach program,$(program_SRCS),$(program).o)
To use the substitution method (like you show in your question):
program_OBJS := $(program_SRCS:.cpp=.cpp.o)
but for that the list must contain the .cpp suffices, or the substitutions will not occur.
Upvotes: 7