我对GNU Make 4.2.1有问题。似乎有一些互动我不太了解的static pattern rules和conditional functions的语法之间。
上下文:我有一个由Markdown文件集记录的项目,我想将这些文件呈现为HTML以便对其进行检查本地。目录结构应该看起来像这样:
some_project/
├── README.md # entry page of documentation
├── doc/ # extra docs
│ ├── foo.md
│ ├── bar.md
│ └── ... # and some more
└── doc_html/ # HTML rendering of the docs
├── Makefile # the Makefile I am trying to write
├── index.html # rendered from README.md
├── foo.html # ............. doc/foo.md
├── bar.html # ............. doc/bar.md
└── ... # etc.
没有index.html的特殊情况,我可以写类似:
%.html: ../doc/%.md
some list of commands $< $@
问题是index.html(即../README.md)的先决条件与模式不符。我想处理这个特殊情况无需重复整个命令列表。这就是我所拥有的到目前为止:
DOC_PAGES = $(wildcard ../doc/*.md)
TARGETS = index.html $(patsubst %.md,%.html,$(notdir $(DOC_PAGES)))
# Function to find the source for page $(1)
source = $(if $(findstring index.html,$(1)), \
../README.md, \
$(patsubst %.html,../doc/%.md,$(1)) \
)
all: $(TARGETS)
$(TARGETS): %.html: $(call source,%.html)
@echo some list of commands $< $@
# Check the TARGETS variable and the `source' function
test:
@echo TARGETS = $(TARGETS)
@echo "source(index.html)" = $(call source,index.html)
@echo "source(foo.html)" = $(call source,foo.html)
我的source
函数似乎起作用:
$ make test
TARGETS = index.html bar.html foo.html
source(index.html) = ../README.md
source(foo.html) = ../doc/foo.md
但是,它在静态规则中无法正常运行
$ make
make: *** No rule to make target '../doc/index.md', needed by 'index.html'. Stop.
请注意,如果我从$(TARGETS)
中删除index.html,该规则将起作用。
关于我在做什么错的想法?
我对GNU Make 4.2.1有问题。似乎我不太了解静态模式规则的语法和条件函数之间的相互作用。上下文:我有一个...
此行: