3 ms·
One thing I've never figured out a good solution for in make, is multiple-pattern rules. Say I have LANGS=nob sme sma smj POS=V N A and want to run som
by unhammer 12y ago
One thing I've never figured out a good solution for in make, is multiple-pattern rules. Say I have
LANGS=nob sme sma smj
POS=V N A
and want to run something on all combinations of these, like
./something --pos=V --f1=nob.f --f2=sme.f nob.txt sme.txt > nob-sme.V
– how can I make a pattern goal for that? I invariably end up with some redundancy, where e.g. only the "V" in the example above turns into my % (and $ * ), e.g.
nob-sme.%: nob.f sme.f nob.txt sme.txt pos/%
./something --pos=$* --f1=nob.f --f2=sme.f nob.txt sme.txt > $@
Fortunately I haven't yet had to do this for anything too large to just copy-paste stuff, but it feels like something someone would have solved at some point, I've just never seen examples like that in any of the make-alternatives I've looked at.
- the_why_of_y 12y agoYou can't have more than 1 pattern variable but if they are all of the same form you can generate all these rules via $(eval); first define a function that generates one rule, then invoke it for all combinations. Unfortunately this sort of thing is not very readable because make function parameters are numbered, not named. define genrule $(1)-$(2).$(3): $(1).f $(2).f $(1).txt $(2).txt pos/$(3) ./something --pos=$(3) --f1=$(1).f --f2=$(2).f $(1).txt $(2).txt > $$@ endef $(foreach lang1,$(LANGS),\ $(foreach lang2,$(filter-out $(lang1),$(LANGS)),\ $(foreach pos,$(POS),\ $(eval $(call genrule,$(lang1),$(lang2),$(pos))))))
- unhammer 12y agoWow. I had no idea you could have that kind of meta-rules in make, nor am I sure I really want to :-) but that's still pretty neat.