如何拆分类似路径名的字符串以在 Makefile 中使用?
我有这个 Makefile 代码:
%.spf:
@echo $@;
runMe.sh $1 $2 $3 $4 $5;
%.spf
的示例值是:
ros_apple/bananas_go_while_197815:123.0/monkey_110_worst_forever/thestar.spf
如何将文件名的参数提取到变量中?
$1 = ros_apple
$2 = bananas_go_while_197815:123.0
$3 = worst
$4 = 110
$5 = thestar
是否可以保留在 Makefile 中,或者我是否必须创建一些 Perl 脚本来接收 $@
并在其中进行 shell 调用?
I have this Makefile code:
%.spf:
@echo $@;
runMe.sh $1 $2 $3 $4 $5;
An example value of the %.spf
would be:
ros_apple/bananas_go_while_197815:123.0/monkey_110_worst_forever/thestar.spf
How would I go about extracting the arguments of the filename into variables?
$1 = ros_apple
$2 = bananas_go_while_197815:123.0
$3 = worst
$4 = 110
$5 = thestar
Is it possible to stay within the Makefile or do I have to create some Perl script that takes in the $@
and does the shell calling within?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确实需要变量中的路径组件,还是只需要将它们提供给
runMe.sh
split ?如果是后者,那么您只需使用sed
和tr
(或仅使用sed
)即可完成。例如,使用以下内容说make all
会产生:
所以也许可以尝试一下:
如果您决心在 Perl 中执行此操作,那么您可以将
sed
和tr
到 Perl 非常容易。Do you really need the path components in a variable or do you just need to offer them to
runMe.sh
split? If the latter, then you can get it done with justsed
andtr
(or justsed
). For example, sayingmake all
with this:produces:
So maybe try this:
If you're dead set on doing it in Perl then you can convert the
sed
andtr
to Perl pretty easily.无论这有多丑陋,您都可以对 dir 进行嵌套调用 表示组件 1 到 4,
notdir
表示基本名称,并且可能使用模式匹配来去掉最后的斜杠。However ugly this is, you can probably do nested calls to dir for components 1 through 4, and
notdir
for the basename, and possibly use a pattern match to strip off the final slash.