【问题标题】:Makefile: Passing command line arguments to file inside MakefileMakefile:将命令行参数传递给 Makefile 中的文件
【发布时间】:2013-03-08 04:04:08
【问题描述】:

在我的 Makfile 中,我有以下内容,

smktestrun: smktest
    @../projects/test.sh

我称之为:

Make smktestrun

但有时我需要与此文件 (test.sh) 一起传递参数/参数

所以基本上我想:

test.sh -abc

但是,如果我只是在 Makefile 本身中传递参数,则该参数不会被视为简单地执行了 sheel 脚本。

那么有没有一种方法可以在 Makefile 中指定需要与该文件一起传递的参数?

谢谢。

【问题讨论】:

    标签: shell makefile command-line-arguments


    【解决方案1】:

    你可以在 Makefile 中定义一个变量。

    smktestrun: smktest
        @../projects/test.sh ${ARG}
    

    那么make的命令行就是:

    make smktestrun ARG="something"
    

    【讨论】:

    • 谢谢,你写了 {} @chepner 用 () 写了同样的东西。两个都可以用吗?
    • 没有区别——它们的意思完全相同(在 GNU Make 和 POSIX make 中)。 stackoverflow.com/questions/25185607/…
    【解决方案2】:

    类似

    smktestrun: smktest
            @../projects/test.sh $(TESTARGS)
    

    然后调用 Makefile 与

    $ make smktestrun TESTARGS="-abc"
    

    【讨论】:

    • 非常感谢。一个插件?如果我只是调用:make smktestrun,它会抱怨我也需要 TESTARGS 吗?
    • 我不认为应该这样做,但如果是这样,您可以在 Makefile 中使用 TESTARGS:= 分配一个默认的空值
    猜你喜欢
    • 2011-09-10
    • 2020-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-10
    相关资源
    最近更新 更多