我如何获得一个makefile函数来停止当前目标? [英] How do I get a makefile function to stop the current target?
本文介绍了我如何获得一个makefile函数来停止当前目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在makefile中有一个函数,如果文件不存在,或者至少从以下位置执行目标,我想停止整个make运行:
I have a function in a makefile that I want to stop the entire make run if a file doesn't exist, or at least the target it is executed from:
vaultfile = ./vault
$(shell test -f $(1) || exit 1)
define get_token
$(shell test -f $1 && cat $1 || exit 2)
endef
a: token = $(call get_token,$(vaultfile),tokenname)
a:
echo ==== $(token)
.PHONY=a
以上操作无效,文件丢失时会自动失败
The above doesn't work, silently failing when the file is missing
$ rm vault
$ make
echo ====
====
$ echo f > vault
$ make
echo ==== f
==== f
我希望将其包含在函数中,因为大多数目标都不会调用该函数(这显然会执行更多的IRL).
I want this to be in the function, because most targets do not call the function (which obviously does more IRL).
我如何进行这项工作?
推荐答案
谢谢您 MadScientist !
我最终得到的简化版本是:(格式化为易于阅读)
The simplified version of what I ended up with is: (formatted for easier readability)
vaultfile = ./vault
define get_token
$(shell \
$(if $(wildcard $1), \
echo "Decoded $1" \
, \
$(error File $1 does not exist)
)
)
endef
a: token = $(call get_token,$(vaultfile))
a:
echo ==== $(token)
这篇关于我如何获得一个makefile函数来停止当前目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文