Makefile 中依赖项的动态评估

标签 dynamic latex makefile

我正在为 LaTex 文档编写 Makefile。作为 makefile 的一部分,我只想在相应的 BIB 文件更改或(如果使用书目样式)当 bibliographystyle.bst 文件更改时制作 BBL 文件。

为了跟踪文件更改,我使用了 MD5 哈希(我在使用时间戳时遇到了问题)。

我正在尝试使用以下代码从 AUX 文件中检索所需的 BST 文件:

# Get the BST dependencies from an AUX file
get-bibstyle = $(foreach bst, $(shell sed -n 's/\\bibstyle{\(.*\)}/\1/p' $1 | tr '\n' ' '), $(addsuffix .bst, $(bst)))

然后,我使用以下代码创建 BBL 文件:
# bbl: Bibtex produces .aux files from .aux files.
#      Also depends on .bst files (if they appear in the aux file).
%.bbl: $(call to-md5,%.aux) $(call to-md5, $(call get-bibstyle,$*.aux))
ifneq ($(strip $(BIB_SRC)),)
    $(IGNORE_RESULT)$(MUTE)$(VERBOSE) $(ECHO) "Building target: $@"
#   $(IGNORE_RESULT)$(MUTE)$(MOVE_TO_COL)
    $(IGNORE_RESULT)$(MUTE)$(SETCOLOUR_RED)
    $(IGNORE_RESULT)$(MUTE)$(ECHO) "===========================BIBTEX PASS================================"
    $(BIBTEX) $(*F)
    $(IGNORE_RESULT)$(MUTE)$(SETCOLOUR_LIGHTRED)
    $(IGNORE_RESULT)$(MUTE)$(ECHO) "===========================BIBTEX/LaTeX PASS================================"
    $(TEX) $(*F)
    $(IGNORE_RESULT)$(MUTE)$(RESTORE_COLOUR)
endif

to-md5 函数只是将 .md5 附加到其输入。 to-md5 = $(patsubst %,%.md5,$1)
我希望 xyz.bbl 的依赖项是 xyz.bib 并且通过在 xyz.aux 文件上运行 sed 表达式返回的所有 bst 文件。我知道这必须通过 eval 和 call 的组合来完成,但我一直无法弄清楚。

目前,我的输出如下。
sed: can't read .aux: No such file or directory
make: `xyz.bbl' is up to date.

最佳答案

这种方法的问题

%.bbl: $(call to-md5,%.aux) $(call to-md5, $(call get-bibstyle,$*.aux))

是 Make 在构建依赖树之前扩展了 preqs(即,不知道 % 是什么)。所以第一个 preq,$(call to-md5,%.aux)变成 %.aux.md5这将工作得很好,但在第二个 preq $(call get-bibstyle,$*.aux)失败,因为 $*评估结果为零,并且没有 .aux 这样的文件扫描。 (您会遇到与 %$$* 或其他类似的问题,只是无法提取名称。)

可以办到。我能想到的最少的 Rube-Goldbergian 方法是递归使用 Make:
-include Makefile.inc

# If there's no exact rule for this target, add it to the list, note its preqs
# and start over.
%.bbl:  
    @echo KNOWN_BBL += $@ > Makefile.inc
    @echo $@: $(call to-md5,$*.aux) $(call to-md5, $(call get-bibstyle,$*.aux)) >> Makefile.inc
    @$(MAKE) -s $@

$(KNOWN_BBL):
ifneq ($(strip $(BIB_SRC)),)
    $(IGNORE_RESULT)$(MUTE)$(VERBOSE) $(ECHO) "Building target: $@ from $^"
    ...

请注意,这将为每个 BBL 重新运行 Make,如果您想构建很多 BBL,这可能不是很有效。我认为有一种方法可以只执行一次,但需要更多思考......

关于Makefile 中依赖项的动态评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10409748/

相关文章:

jquery - 如何更改/添加 css 到动态生成的复选框类

javascript - 如何从动态创建的表中删除信息

latex - 如何修复 "Underfull\hbox (badness 10000)"警告?

javascript - MathJax 的公式呈现不正确

java - 包中包含 .java 文件的 Eclipse JNI

Makefile:是否可以有带斜杠的词干?

Java 动态加载一个类

使用 C# 和 SQL Server 数据库进行 jQuery 自动完成

r - 由于更新,knitr 中出现不需要的清理(逃逸)

android - 为什么 Android.mk 文件中的 $(call my-dir) 返回了错误的路径?