开发者

gnu make: How to concat two strings

开发者 https://www.devze.com 2023-01-03 23:40 出处:网络
Given the line: program_OBJS :开发者_Python百科= ${program_SRCS:.cpp=.o} I would like to append .o to each filename instead of replacing .cpp with .o.

Given the line:

program_OBJS :开发者_Python百科= ${program_SRCS:.cpp=.o}

I would like to append .o to each filename instead of replacing .cpp with .o.

How do I do that?


GNU make has addsuffix function


How about this:

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

STRING1:=$(STRING1)$(STRING2)

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


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.


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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消