将其命令行参数传递给另一个脚本的 Makefile
在一个项目中,我有一个名为 make.sh 的脚本,它可以构建项目并执行其他一些操作。到目前为止,它运行良好。
然后,出于好奇,我尝试创建一个 Makefile,将其命令行参数传递给该脚本,以便我可以调用它 制作快照 而不是 ./make.sh snapshot
这是我现在正在使用的Makefile
.PHONY: snapshot
%:
./make.sh $@
snapshot:
./make.sh snapshot
但是这种方法有一些问题,我无法将“build”作为参数传递,因为我有一个“Build”目录(由SCons使用),我无法传递要传递给脚本的第二个参数,例如: 上传192.168.1.10 因为 make
将其解释为两个不同的目标...
有没有办法用 Makefile 来做到这一点?
In a project, I have a script called make.sh that builds the project and does some other stuff too. It is working well so far.
Then, just out of curiosity I've tried to create a Makefile that just passed its command-line parameters to this script so I could call it
make snapshot
instead of
./make.sh snapshot
this is the Makefile that I'm using right now
.PHONY: snapshot
%:
./make.sh $@
snapshot:
./make.sh snapshot
But this approach have some problems, I can't pass "build" as a parameter, because I have a "Build" directory (used by SCons), and I can't pass a second parameter to be passed to the script, like:
make upload 192.168.1.10
as make
interprets it as two different targets...
Is there a way I can do this with the Makefile?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你可以做到:
但这是对 Make 的滥用。这个想法是 Make 应该将其参数解释为一组目标,而不是通用参数的有序列表。您可能应该使用不同的工具。
Yes, you can do it:
but this is an abuse of Make. The idea is that Make should interpret its arguments as a set of targets, not an ordered list of general arguments. You should probably use a different tool.