我的Makefile
文件如下:
.PHONY: check
check:
ifneq $(shell echo 123), $(shell echo 123)
$(error Not equal)
endif
当我运行时,出现了错误:
$ make
Makefile:3: *** Not equal. Stop.
但这只会在它们不同的情况下才会发生,但它们并不不同。为什么?
我的Makefile
文件如下:
.PHONY: check
check:
ifneq $(shell echo 123), $(shell echo 123)
$(error Not equal)
endif
$ make
Makefile:3: *** Not equal. Stop.
ifneq
不能缩进。按照您编写的方式,它将通过shell命令运行,这意味着$(error)
会先被make命令评估。
我猜想您希望在调用make check
时实际上只运行两个命令,并比较它们的输出。您可以这样做:
.PHONY: check
check:
if [ "`echo 123`" != "`echo 123`" ]; then \
echo "Not equal"; \
exit 1; \
fi
make
在makefile中实际“看到”的内容。
因此,在编译过程中执行条件语句时,应使用shell语法,例如:
SHELL := /bin/bash -e
.PHONY: check
check:
@test "$(shell echo 123)" = "$(shell echo 123)" \
|| { echo Not equal; exit 2; } \
&& { echo Equal; }