我有这个 Makefile
:
TMP_DIR := tmp
RUN_OR_NOT := $(shell date '+%y%m%d%H%M')
all: version
version:
ifeq ($(shell test -d ${TMP_DIR} && echo -n "yes";),yes)
$(shell echo ${TMP_DIR} already exists ...)
else
$(shell mkdir -p ${TMP_DIR})
endif
我想先检查目录 tmp
是否存在,如果不存在则创建它。这有效,但有一个奇怪的错误:
ifeq (yes,yes)
/bin/sh: 1: Syntax error: word unexpected (expecting ")")
Makefile:7: die Regel für Ziel „version“ scheiterte
make: *** [version] Fehler 2
为什么会出现这个奇怪的/bin/sh: 1: Syntax error: word unexpected (expecting ")")
错误?以及如何解决这个问题?
最佳答案
在 makefile 中,配方是一个 shell 脚本。您正在尝试将诸如 ifeq
之类的 make 结构放入您的配方中。 Make 会将这些传递给 shell,而 shell 会抛出此错误,因为它不理解 makefile 语法。
您应该使用 shell 脚本而不是 makefile 语法来编写您的食谱:
version:
if test -d ${TMP_DIR}; then \
echo ${TMP_DIR} already exists ...; \
else \
mkdir -p ${TMP_DIR}; \
fi
虽然我不知道你为什么关心目录是否已经存在;我个人只会使用:
version:
mkdir -p ${TMP_DIR}
关于makefile -/bin/sh : 1: Syntax error: word unexpected (expecting ")"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44373872/