views:

26

answers:

1

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  A: 

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