GNU make:ifneq总是评估为true

时间:2014-04-25 20:12:00

标签: makefile

我再次与makefile战斗......我需要一些帮助。

check-fleet:
    LOCAL_VERSION = $(shell fleetctl -version)
    REMOTE_VERSION = $(shell ssh core@$(FLEETCTL_TUNNEL) fleetctl -version)
    ifneq $(strip $(LOCAL_VERSION)) $(strip $(REMOTE_VERSION))
        $(error Your fleetctl client version should match the server. Local version: $(LOCAL_VERSION), server version: $(REMOTE_VERSION). Uninstall your local version and install the latest build from https://github.com/coreos/fleet/releases)
    endif

当执行此操作时,我发现它确实已经脱壳并连接到服务器,但总是会出现错误,即使我手动设置这些变量的值!此外,它们在错误陈述中始终为空白。

即使它们被设置存在问题(即如果它们是空白的),那么至少它们是相等的并且ifneq永远不会被激发。

我想知道这是否是与Makefile的双遍处理相关的问题,但我尝试自己手动将变量设置为相同的已知字符串,并且错误仍然会触发。我没有想法......

1 个答案:

答案 0 :(得分:2)

至关重要的是要理解makefile中不属于配方的行(通常,用TAB缩进)由make解析,而makefile的行是其中的一部分配方(通常用TAB缩进)是由解析为make;它们被传递给shell,shell运行它们。

因此,在配方中添加make变量赋值或创建ifneq之类的命令(使用TAB缩进)是不合法或有效的。

如果您希望命令作为check-fleet目标的一部分运行,则必须在配方中编写 shell脚本,而不是使用make构造。

check-fleet:
        LOCAL_VERSION=`fleetctl -version`; \
        REMOTE_VERSION=`ssh core@$(FLEETCTL_TUNNEL) fleetctl -version`; \
        if [ $$LOCAL_VERSION != $$REMOTE_VERSION ]; then \
            echo "Your fleetctl client version should match the server. Local version: $$LOCAL_VERSION, server version: $$REMOTE_VERSION. Uninstall your local version and install the latest build from https://github.com/coreos/fleet/releases"; exit 1; \
        fi