在makefile中具有%替换的多个源

时间:2014-03-31 09:36:13

标签: makefile

我想为每个现有文件*.html创建一个规则。为了从每个html文件创建一个简单的html。

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

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

但我收到错误:

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

我想根据动态目录中的每个文件制作mysite规则。每次修改相应的源文件时,重新制作动态目录中的每个文件。

有可能吗?

感谢您的帮助。

2 个答案:

答案 0 :(得分: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>/' $< > $@ or whatever

答案 1 :(得分:0)

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

#Makefile
my_variable=$(script myScript.sh) 

$(my_variable)%.transformed: $(my_variable)%.original
      sed -e 's/<h1>/<h2>/' $< > $@ or whatever
相关问题