Makefile generic pattern rule — xyzzy-en_US.ext2 from xyzzy.ext0

别等时光非礼了梦想. 提交于 2020-01-01 06:54:24

问题


I can't figure out a way to define a generic pattern rule for the following kind of production with make:

require xyzzy-en_US.ext2 from xyzzy.ext0 via xyzzy.ext1.

This works:

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?

Neither of these work:

%-??_??.ext2 : %.ext1
  # ...

%.ext2 : $(@,%-??_??.ext2,%.ext1)
  # ...

回答1:


There is no good way to do this with Make (regex handling is high on my wishlist) but here is a kludge.

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))))


来源:https://stackoverflow.com/questions/3064403/makefile-generic-pattern-rule-xyzzy-en-us-ext2-from-xyzzy-ext0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!