我可以使makefile在规则之外中止吗? [英] Can I make a makefile abort outside of a rule?

查看:127
本文介绍了我可以使makefile在规则之外中止吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Makefile的顶部,在任何规则之前,我都有以下内容:

ifeq ($(ENVIRONMENT),LOCAL)
    TARGET := local_target
else
    TARGET := hello
endif

如果未设置ENVIRONMENT环境变量,或者将其设置为LOCAL以外的值,而不是将TARGET设置为hello,我希望makefile停止并以-1退出. /p>

我可以这样做吗?当我将TARGET := hello更改为exit -1时,出现以下错误:

Makefile:4: *** missing separator.  Stop.

我怎么做这项工作?

解决方案

exit是shell命令,因此您可以使用 解决方案

exit is a shell command, so you could use the shell assignment operator (i.e.: !=) inside the Makefile to call exit:

TARGET != exit -1

This would be actually equivalent to:

TARGET := $(shell exit -1)

Note again that this calls a shell that in turns runs the shell's exit built-in, i.e.: it does not exit make. The typical approach for exiting while processing a makefile is to call GNU Make's error built-in function instead:

$(error Error-message-here)

Putting everything together:

ifeq ($(ENVIRONMENT),LOCAL)
 TARGET := local_target
else # indent with spaces, not a tab
 $(error ENVIRONMENT not set to LOCAL)
endif

这篇关于我可以使makefile在规则之外中止吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆