2015-08-25 24 views
0

好吧我在我的makefile中有2個可變參數。我想遍歷變量中的文件並應用如下的變換。Makefile將文件名更改爲隱藏文件

cmain.cpp   -> .cmain.depend 
src/source.cpp -> src/.source.depend 

我怎麼會去前面加上一個.到文件名的開頭和更改擴展名取決於用make?我想要轉換的數組由下面描述。

ALLSRC=$(shell find . -name '*.cpp') 

回答

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 [email protected] contain the before and after names, so you can do whatever you want to. 
.%.depend : % 
    cp "$<" "[email protected]