makefilegnugnu-make

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?


Solution

  • 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.