在makefile内的可变扩展中切碎后缀
如标题所述,如果我需要提供多个后缀(pattern-list)
注意:我在makefile中强制使用bash使用(> shell =/ bin/bash
)
dest_dir
:makefile变量pkg_list
:makefile变量,保留文件夹名称的列表(例如“ packagefsopt1 packageadc packageadc packagememopt2 .....”)。 其中一些名称可能具有OPT1后缀,有些名称则没有。tmp
:现有的文件夹,包含文件夹packagefs,packageadc,packagemem .....
,从tmp到dest copl copting copping的makefile的一部分
for pkg in $(PKG_LIST) ; do \
cd tmp && tar xzf $$pkg-$(MAJOR).$(MINOR).$(TARGET).tar.gz tmp ; \
cp -a tmp/$${pkg%OPT1} $(DEST_DIR) ; \
done
在这里 ”,这意味着Opt1确实是从Packagefsopt1切碎的。 但是我需要的是能够切碎不同的后缀。在这种情况下,
我尝试了此操作:
cp -a tmp/$${pkg%+(OPT1|OPT2)} $(DEST_DIR) ; \
如果直接在控制台中进行测试,但不在makefile内(无法将其切碎=> opt1停留在文件夹名称中,它不存在=> copy Fail)
i这样的某种类型(但导致PKG_STRIPPENT被空了):
pkg_stripped=$(shell echo ${pkg%+(OPT1|OPT2)}) ; \
cp -a tmp/$$pkg_stripped $(DEST_DIR) ; \
有人有一个主意吗?
编辑:解决方案
要么(使用扩展全局)
for pkg in $(PKG_LIST) ; do \
cd tmp && tar xzf $$pkg-$(MAJOR).$(MINOR).$(TARGET).tar.gz tmp ; \
shopt -s extglob ; \
cp -a tmp/$${pkg%+(OPT1|OPT2)} $(DEST_DIR) ; \
done
或(使用SED)
参见 madScientist
As the title states, I have a problem being able to remove suffix from a package name if I need to provide several suffixes (pattern-list)
Note: I have forced bash usage in the Makefile (SHELL=/bin/bash
)
DEST_DIR
: Makefile variablePKG_LIST
: Makefile variable, hold a list of folders names (e.g. "packageFsOPT1 packageAdc packageMemOPT2 .....").
Some of the names might have OPT1 suffix, some other don't.tmp
: folder that is existing and contains the folder packageFs, packageAdc, packageMem.....
Here the part of the Makefile that perform copy from tmp to dest along with the name chopping:
for pkg in $(PKG_LIST) ; do \
cd tmp && tar xzf $pkg-$(MAJOR).$(MINOR).$(TARGET).tar.gz tmp ; \
cp -a tmp/${pkg%OPT1} $(DEST_DIR) ; \
done
This is "working", meaning that OPT1 is indeed chopped from packageFsOPT1.
But what I need is to be able to chop different suffixes. In this case OPT1 or OPT2
I tried this:
cp -a tmp/${pkg%+(OPT1|OPT2)} $(DEST_DIR) ; \
Which is working if tested directly in console but not within the Makefile (not able to chop => OPT1 stays in the folder name, which doesn't exist => copy fail)
I some kind of stuff like this (but lead to pkg_stripped being empty):
pkg_stripped=$(shell echo ${pkg%+(OPT1|OPT2)}) ; \
cp -a tmp/$pkg_stripped $(DEST_DIR) ; \
Does anyone have an idea?
Edit: Solutions
Either (using extended global)
for pkg in $(PKG_LIST) ; do \
cd tmp && tar xzf $pkg-$(MAJOR).$(MINOR).$(TARGET).tar.gz tmp ; \
shopt -s extglob ; \
cp -a tmp/${pkg%+(OPT1|OPT2)} $(DEST_DIR) ; \
done
Or (using sed)
See MadScientist answer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许使用GNU制作功能更简单?类似的事情:
如果您的名字像Fooopt1Opt2(都将被剥离),这将做错事(也许?),但也可以解决。
eta
如果您需要两者,则必须在外壳中进行。您不能在配方中使用
$(shell ...)
:这是一个制造功能,因此在启动外壳之前就通过制造来扩展:它不能在任何外壳的值上操作循环变量当然。我只需为此使用
sed
:Maybe it's simpler to use GNU make functions? Something like this:
This will do the wrong thing (maybe?) if you have names like fooOPT1OPT2 (both will be stripped) but that can be solved as well.
ETA
If you need both you'll have to do it in the shell. You can't use
$(shell ...)
in a recipe: that's a make function so it's expanded by make before the shell is started: it can't operate on the value of any shell for loop variables of course.I would simply use
sed
for this: