2014-03-31 35 views
0

我想为每个现有文件*.html创建一个规则。为了从每个html文件创建一个简单的html。makefile中存在%替换的多个源

#Makefile 
destination=dynamic/ 
mysite: $(destination)%.html 

$(destination)%.html: source/%.html 
      #exemple 
      sed -e 's/<h1>/<h2>/' $< > [email protected] 

但我得到的错误:

make: *** No rule to target dynamic/%.html needed by `site'. Stop. 

我想提出mysite的规则取决于每个文件的动态目录。并且每次修改相应的源文件时,重新制作动态目录中的每个文件。

可能吗?

感谢您的帮助。

+0

mysite规则是错误的:它不知道该做什么。您需要列出所有输出文件。 Make确实具有匹配性,并替换您可用于创建此列表的内容。虽然它可能会导致有问题的makefile。 –

+0

你说“我想让mysite规则取决于动态目录中的每个文件”,但是当你启动时,这个目录中没有文件。而且%不能这样工作,它必须匹配目标中的%。 –

+1

第一部分(使mysite规则取决于每个html文件)很容易。但第二个(每次修改源文件时重新制作每个html文件)尚不清楚;当'source/foo.html'被修改时,是否应该重建'dynamic/foo.html',或者所有已经存在于'dynamic /'中的html文件? – Beta

回答

1
destination=dynamic/ 

# this makes a list of all html files in source/ 
SOURCES := $(wildcard source/*.html) 

# this transforms SOURCES into a list of files that belong in dynamic/ 
DESTS := $(patsubst source/%.html,$(destination)%.html, $(SOURCES)) 

.PHONY: mysite # just to let Make know that mysite is not actually a file 
mysite: $(DESTS) 

$(destination)%.html: source/%.html 
    sed -e 's/<h1>/<h2>/' $< > [email protected] or whatever 
0

您可以执行bash脚本并将其标准输出放入变量中。

#Makefile 
my_variable=$(script myScript.sh) 

$(my_variable)%.transformed: $(my_variable)%.original 
     sed -e 's/<h1>/<h2>/' $< > [email protected] or whatever