我使用Makefiles。
我有一个名为run的目标,它运行构建目标。简化后,如下图所示:
prog: ....
...
run: prog
./prog
有传递参数的方法吗?这
make run asdf --> ./prog asdf
make run the dog kicked the cat --> ./prog the dog kicked the cat
我使用Makefiles。
我有一个名为run的目标,它运行构建目标。简化后,如下图所示:
prog: ....
...
run: prog
./prog
有传递参数的方法吗?这
make run asdf --> ./prog asdf
make run the dog kicked the cat --> ./prog the dog kicked the cat
当前回答
Run: ./prog看起来有点奇怪,因为正确的部分应该是一个先决条件,所以Run: prog看起来更好。
我的建议很简单:
.PHONY: run
run:
prog $(arg1)
我想补充一点,可以传递参数:
作为参数:使arg1="asdf"运行 或者定义为environment: arg1="asdf" make run
其他回答
我不知道怎么做你想要的,但一个变通的方法可能是:
run: ./prog
./prog $(ARGS)
然后:
make ARGS="asdf" run
# or
make run ARGS="asdf"
不是很自豪,但我不想传递环境变量,所以我把运行罐装命令的方式颠倒了:
run:
@echo command-you-want
这将打印你想要运行的命令,所以只需要在subshell中求值即可:
$(make run) args to my command
你可以像下面这样将变量传递给Makefile:
run:
@echo ./prog $$FOO
用法:
$ make run FOO="the dog kicked the cat"
./prog the dog kicked the cat
or:
$ 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
我使用的另一个技巧是-n标志,它告诉make做一个演练。例如,
$ make install -n
# Outputs the string: helm install stable/airflow --name airflow -f values.yaml
$ eval $(make install -n) --dry-run --debug
# Runs: helm install stable/airflow --name airflow -f values.yaml --dry-run --debug
Run: ./prog看起来有点奇怪,因为正确的部分应该是一个先决条件,所以Run: prog看起来更好。
我的建议很简单:
.PHONY: run
run:
prog $(arg1)
我想补充一点,可以传递参数:
作为参数:使arg1="asdf"运行 或者定义为environment: arg1="asdf" make run