如何在运行时创建的 Makefile 文件中使用?

问题描述 投票:0回答:1

我正在使用 make 制作静态站点生成器。

基本上我采用 .RST 文件并创建 .HTML 文件,这很容易。

TARGETS_R = $(shell find . -name '*.rst')
TARGETS_H = $(TARGETS_R:.rst=.html)
regular_files: $(TARGETS_H)
    @echo "Generating HTML files and tag files..."
%.html: %.rst
    @./compile.py $< $@ # create also tags/<tag_name>.tag files as side-effect

问题是,源文件包含标签,所以标签/*.tag 文件只有在处理完所有 .RST 后才能知道。我想制作一个像这样的 navigation.nav 文件

TARGETS_R = $(shell find . -name '*.rst')
TARGETS_H = $(TARGETS_R:.rst=.html)
regular_files: $(TARGETS_H)
    @echo "Generating HTML files and tag files..."
%.html: %.rst
    @./compile.py $< $@ @# create also tags/<tag_name>.tag files as side-effect
# -----------
TAGS = $(shell find . -name '*.tag')
NAVS = $(TAGS:.tag=.nav)
navigation.nav: $(NAVS)
    echo $^ >$@ # some magic here
%.nav: %.tag
    echo $^ >$@ # some magic here

.PHONY: all regular_files

all: regular_files navigation.nav

但它在第一次运行时只制作

.html
.tag
文件然后它需要第二次运行,它从(现在存在的)
.nav
文件制作
.tag
文件

我也想使用 -j24 来使用我所有的核心来处理它。

我怎么能那样做?

makefile gnu-make
1个回答
0
投票

如果 Make 无法预先确定哪些标记文件将存在,那么尝试将它们设为先决条件是没有意义的。

navigation.nav: build_navs
    navs=`find . -name '*.nav'`; echo $$navs # some magic here
build_navs:
    tags=`find . -name '*.tag'`; foreach tag ($$tags) echo $$tag # some magic here
© www.soinside.com 2019 - 2024. All rights reserved.