makefile: how to add a prefix to the basename?

烂漫一生 提交于 2019-11-28 21:05:30

Look at Make's addprefix function.

Here is an example we use with addsuffix to place obj files one directory below the source.

SOURCE += MainThread.cpp
SOURCE += Blah.cpp

OBJ=$(join $(addsuffix ../obj/, $(dir $(SOURCE))), $(notdir $(SOURCE:.cpp=.o)))

From the make manual: http://www.gnu.org/software/make/manual/make.html

$(addprefix prefix,names...)

The argument names is regarded as a series of names, separated by whitespace; 
prefix is used as a unit. The value of prefix is prepended to the front of each 
individual name and the resulting larger names are concatenated with single 
spaces between them. For example,

              $(addprefix src/,foo bar)

produces the result `src/foo src/bar'. 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!