Robert S. Barnes
Robert S. Barnes

Reputation: 40558

gnu make: How to concat two strings

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

Answers (6)

PoVa
PoVa

Reputation: 1043

How about this:

STRING1:="foo"
STRING2:="bar"

STRING1:=$(STRING1)$(STRING2)

Obviuosly, you could save the result to a new variable.

Upvotes: 14

Basilevs
Basilevs

Reputation: 23926

GNU make has addsuffix function

Upvotes: 10

Pavel Tumanov
Pavel Tumanov

Reputation: 51

One more way working regardless of extension: ${program_SRCS:=.o}

Upvotes: 3

slowdog
slowdog

Reputation: 6216

Shorter alternative, using a pattern substitution: program_OBJS := ${program_SRCS:%=%.o}

Upvotes: 8

Veger
Veger

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

ur.
ur.

Reputation: 2947

Just a guess program_OBJS := ${program_SRCS:.cpp=.cpp.o}

Upvotes: 1

Related Questions