2015-08-25 4 views
0

Хорошо, у меня есть 2 varables в моем файле makefile. Я хочу перебирать файлы в переменной и применять преобразование, как показано ниже.Makefile сменить имя файла в скрытые файлы

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

Как бы я идти о предваряя в . к началу имени файла и изменив расширение зависит от марки? Массив, который я хочу преобразовать, описан ниже.

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] 
Смежные вопросы