问题描述
我想不出一种方法来为使用make的以下类型的生产定义通用模式规则:
I can't figure out a way to define a generic pattern rule for the following kind of production with make:
通过xyzzy.ext1
从xyzzy.ext0
要求xyzzy-en_US.ext2
.
这有效:
all: xyzzy-en_US.ext2
# to be compiled from xyzzy.ext0
%.ext1 : %.ext0
# produce xyzzy.ext1
%-en_US.ext2 : %.ext1
# produce xyzzy-en_US.ext2
但是如何概括第二条规则的语言环境部分?还是我需要为所有不同的语言环境生成规则?
But how to generalize the locale part of the second rule? Or do I need to generate rules for all different locales?
这些都不起作用:
%-??_??.ext2 : %.ext1
# ...
%.ext2 : $(@,%-??_??.ext2,%.ext1)
# ...
推荐答案
使用Make不能做到这一点(正则表达式的处理在我的愿望清单中很高),但这是一个麻烦.
There is no good way to do this with Make (regex handling is high on my wishlist) but here is a kludge.
您可以为每个区域设置单独的规则,该规则适用于任何事物"(xyzzy或其他).但是,由于您事先不知道将调用哪种语言环境,但是您知道存在ext0文件,因此为每个事物"制定规则可能会更好:
You can have a separate rule for each locale which will work with any "thing" (xyzzy, or whatever). But since you don't know beforehand what locale will be called for, but you do know what ext0 files exist, it might be better to make a rule for every "thing":
THINGS = $(basename $(wildcard *.ext0)) # xyzzy qrssr...
define TEMPLATE
$(1)-%.ext2: $(1).ext1
@echo produce $$@ from $$^ using $$*
endef
$(foreach thing,$(THINGS),$(eval $(call TEMPLATE,$(thing))))
这篇关于Makefile通用模式规则-来自xyzzy.ext0的xyzzy-en_US.ext2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!