我想为 LaTeX 文档创建一个 makefile(在这个最小的 例子)。当没有文件“makeindexstyle.ist”时,应该创建它(通过 运行 make makeindexstyle.ist) 并用于格式化索引。规则为
%.pdf
反映了这一点。但是,它还没有工作,我收到错误
ifneq (, ) {
/bin/sh: 1: Syntax error: word unexpected (expecting ")")
make: *** [master.pdf] Error 2
怎么了?
Parts from Makefile:
MASTER = master
TEX = slave
TEXI = texi2dvi -p
all: $(MASTER:=.pdf)
%.pdf: %.tex $(TEX:=.tex)
ifneq ($(wildcard makeindexstyle.ist), ) { # if makeindexstyle.ist exists, compile and build index
$(TEXI) $<
make makeindexstyle.ist
makeindex -c -s makeindexstyle.ist $(MASTER:=.idx)
}
endif
$(TEXI) $<
makeindexstyle.ist:
@(echo "...") > makeindexstyle.ist
更新: 我试图让它尽可能简单,看看错误来自哪里。除其他事项外(例如引用),我尝试了以下操作:
%.pdf: %.tex $(TEX:=.tex)
exist := $(wildcard "absolute-path-to-makeindexstyle.ist")
ifneq ($strip $(exist)),)
echo "foo"
endif
$(TEXI) $<
但结果是
exists :=
make: exists: Command not found
make: *** [book.pdf] Error 127
同时,我可以在shell端解决它:
IDX = "makeindexstyle.ist"
%.pdf: %.tex $(TEX:=.tex)
@if test -f $(IDX); then \
echo "foo"; \
fi
$(TEXI) $<
我正在为所有像我一样遇到此错误的人回答这个问题。 这个网站是我在这篇文章之后偶然发现的,它解释了这是缩进的问题。
此代码导致错误
target : dependencies
ifneq (condition)
body1
else
body2
endif
但是这段代码的功能符合预期
target : dependecies
ifneq (condition)
body1
else
body2
endif
Makefile 很奇怪。
这听起来像是如何检查 Makefile 中是否存在文件?或如何通过测试文件是否存在来有条件地设置 Makefile 变量。
尝试
ifneq ($(wildcard makeindexstyle.ist),)
没有空间。或者,在参数周围添加
""
?