为了账号安全,请及时绑定邮箱和手机立即绑定

将参数传递给“ make run”

将参数传递给“ make run”

开心每一天1111 2020-02-04 15:36:02
我使用Makefiles。我有一个run运行该构建目标的目标。简化后,它看起来如下所示:prog: ....  ...run: prog  ./prog坐下来 我知道这很巧妙,但不需要站着鼓掌。现在,我的问题是-有什么方法可以传递参数?以便make run asdf --> ./prog asdfmake run the dog kicked the cat --> ./prog the dog kicked the cat谢谢!
查看完整描述

3 回答

?
哔哔one

TA贡献1854条经验 获得超8个赞

我不知道完全按照自己的意愿做事的方法,但是一种解决方法可能是:


run: ./prog

    ./prog ${ARGS}

然后:


make ARGS="asdf" run


查看完整回答
反对 回复 2020-02-04
?
千巷猫影

TA贡献1829条经验 获得超7个赞

您可以将变量传递给Makefile,如下所示:


run:

    @echo ./prog $$FOO

用法:


$ make run FOO="the dog kicked the cat"

./prog the dog kicked the cat

要么:


$ FOO="the dog kicked the cat" make run

./prog the dog kicked the cat

或者使用Beta提供的解决方案:


run:

    @echo ./prog $(filter-out $@,$(MAKECMDGOALS))

%:

    @:

%:-与任何任务名称匹配的规则; @:-空配方=不执行任何操作


用法:


$ make run the dog kicked the cat

./prog the dog kicked the cat


查看完整回答
反对 回复 2020-02-04
  • 3 回答
  • 0 关注
  • 844 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信