【问题标题】:Makefile if conditional function inside foreachMakefile if foreach 中的条件函数
【发布时间】:2022-01-08 10:42:13
【问题描述】:

我正在尝试在 makefile 中运行类似的东西,而我是编写 makefile 的新手。

EXECUTABLES = emcc em++ emcmake emconfigure emmake

K := $(foreach exec,$(EXECUTABLES),\
        $(if $(shell which $(exec)), \
        @echo "Emsdk binaries are already added to path", \
        $(if [! -d "${HOME}/.wasm/emsdk"]), \
        @echo "Emsdk is not installed consider running bash install_requirements first",\
        @source "${HOME}/.wasm/emsdk/emsdk_env.sh"))

但它会抛出类似 insufficient number of arguments (1) to function `if'. Stop. 这样的错误。我错过了什么吗?

【问题讨论】:

    标签: if-statement foreach makefile emscripten


    【解决方案1】:

    我不确定你的这部分作业是什么意思:

        $(if [! -d "${HOME}/.wasm/emsdk"]), \
    

    但这绝对是不正确的语法。你已经用一个参数关闭了 if 函数,它至少需要两个参数。

    也许你真的想在这里使用$(shell ...)?但我不明白这会做什么; make 的 if 函数不查看退出代码。

    【讨论】:

    • 缩进检查路径下的文件夹是否不存在
    • 我不明白你的评论。我不是在谈论缩进。我是说您看到此错误的原因是因为 $(if [! -d "${HOME}/.wasm/emsdk"]) 不是有效的 make if 函数构造。 Make 的 if 函数具有 $(if <cond>,<true>[,<false>]) 形式,而您的版本没有 ,<true> 部分。
    • 另外提一下,[! -d "${HOME}/.wasm/emsdk"] 也不是一个有效的 shell 测试:你必须在 [[]] 结束之前有空格: [ ! -d "${HOME}/.wasm/emsdk" ]
    • 感谢@MadScientist,您的 cmets 有助于更好地理解 makefile 中的 if 函数并解决此问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    • 1970-01-01
    • 2021-11-10
    • 2020-12-02
    • 2014-08-08
    相关资源
    最近更新 更多