从makefile内部传递命令行参数 [英] Passing a command line argument from inside a makefile

查看:510
本文介绍了从makefile内部传递命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要从其中调用可执行文件的makefile,该可执行文件需要5个参数,我该如何从makefile传递这些参数

I have a makefile from which i am trying to invoke an executable, the executable needs 5 arguments, how do i pass these arguments from makefile

这样做不起作用

run-exe:
  arg1 = "somevalue"
  arg2 = "somevalue"
  arg3 = "somevalue"
  arg4 = "somevalue"
  arg5 = "somevalue"
  $(ExeFolderPath)/Task $(arg1) $(arg2) $(arg3) $(arg4) $(arg5)

参数被忽略了.

推荐答案

run-exe规则的配方中的每一行都在不同的Shell实例中运行.因此,如果在一行中设置一个变量,则该分配对下一行不会有任何影响,因为该下一行在新的Shell实例中运行.

Each line in the recipe of the run-exe rule runs in a different shell instance. So, if you set a variable in one line, that assignment won't have any effect for the next line, because that next line runs in a new shell instance.

但是,您可以通过定义.ONESHELL -target来保持您的方法,以便在单个shell中执行配方的所有行(命令):

You can however keep your approach by defining the .ONESHELL-target in order to get all the lines (commands) of a recipe executed in a single shell:

.ONESHELL:
run-exe:
  arg1="somevalue"
  arg2="somevalue"
  arg3="somevalue"
  arg4="somevalue"
  arg5="somevalue"
  $(ExeFolderPath)/Task $$arg1 $$arg2 $$arg3 $$arg4 $$arg5

请注意,=周围不应有空格,因为这些变量分配是由外壳程序而不是make运行的.

Note that there shouldn't be spaces around the =, since those variable assignment are run by the shell, not make.

还请注意,对于外壳变量,应对$进行转义(即:$$而不是$).

Also note that the $ should be escaped for the shell variables (i.e.: $$ instead of $).

要使用.ONESHELL,您将需要GNU Make 3.82(或更高版本).

You are going to need GNU Make 3.82 (or newer) in order to use .ONESHELL.

这篇关于从makefile内部传递命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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