简体   繁体   English

如何拆分类似路径名的字符串以在Makefile中使用?

[英]How do I split a pathname-like string for use in a Makefile?

I have this Makefile code: 我有这个Makefile代码:

%.spf:
    @echo $@;
    runMe.sh $1 $2 $3 $4 $5;

An example value of the %.spf would be: %.spf的示例值为:

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? 是否可以保留在Makefile中,或者我是否必须创建一个接收$@ Perl脚本并在shell中调用?

但是,这很丑陋,您可能可以对组件1到4进行dir嵌套调用,对基名进行notdir嵌套调用,并可能使用模式匹配来去除最后的斜杠。

Do you really need the path components in a variable or do you just need to offer them to runMe.sh split? 你真的需要变量中的路径组件,还是只需要将它们提供给runMe.sh split? If the latter, then you can get it done with just sed and tr (or just sed ). 如果是后者,那么你可以用sedtr (或者只是sed )完成它。 For example, saying make all with this: 例如,说make all这些:

X=ros_apple/bananas_go_while_197815:123.0/monkey_110_worst_forever/thestar.spf
all:
        @echo `echo $X | sed 's:\.spf$$::' | tr '/' ' '`

produces: 生产:

ros_apple bananas_go_while_197815:123.0 monkey_110_worst_forever thestar

So maybe try this: 所以也许试试这个:

%.spf:
        @echo $@
        runMe.sh `echo $X | sed 's:\.spf$$::' | tr '/' ' '`

If you're dead set on doing it in Perl then you can convert the sed and tr to Perl pretty easily. 如果你已经在Perl中设置了它,那么你可以很容易地将sedtr转换为Perl。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM