【问题标题】:Makefile change filename into hidden filesMakefile 将文件名更改为隐藏文件
【发布时间】:2015-08-25 19:32:13
【问题描述】:
好吧,我的 makefile 中有 2 个变量。我想遍历变量中的文件并应用如下转换。
cmain.cpp -> .cmain.depend
src/source.cpp -> src/.source.depend
如何在文件名的开头添加. 并将扩展名更改为依赖于make?我要转换的数组如下所述。
ALLSRC=$(shell find . -name '*.cpp')
【问题讨论】:
标签:
string
makefile
gnu-make
【解决方案1】:
ALLSRC := $(shell find . -name '*.cpp')
#Get the filenames without the directory so we prepend the . to the right thing
FNAME := $(notdir $(ALLSRC))
#Add the .
FNAME := $(FNAME:%=.%)
#Put the directory names back
HIDDEN := $(join $(dir $(ALLSRC)),$(FNAME))
HIDDEN := $(HIDDEN:%=%.depend)
#Equivalent one liner
HIDDEN2 := $(patsubst %,%.depend,$(join $(dir $(ALLSRC)),$(patsubst %,.%,$(notdir $(ALLSRC)))))
.PHONY: all
all: $(HIDDEN)
# Copies the file in this example, but $< and $@ contain the before and after names, so you can do whatever you want to.
.%.depend : %
cp "$<" "$@