views:

46

answers:

2

I want to write something like regex:

SRC:="a.dat.1 a.dat.2"    
$(SRC): %.dat.%: (\\1).rlt.(\\2)    
      dat2rlt $^ $@

so that a.dat.1 and a.dat.2 will give a.rlt.1 and a.rlt.2.

In GNU Make info page, it says "the % can be used only once".

Is there some trick to achieve this in GNU Make?

A: 

No, this is missing. A workaround is to add rules dynamically (with eval or include).

See e.g. this related question or this one.

reinierpost
I see. The links are very helpful. Sorry I did not find them before asking.
heroxbd
A: 

For the limited example you gave, you can use a pattern with one %.

SRC := a.dat.1 a.dat.2
${SRC}: a.dat.%: a.rlt.%    
      dat2rlt $^ $@
  1. $* in the recipe will expand to whatever the % matched.
  2. Note that the "s around your original macro are definitely wrong.
  3. Have a look at .SECONDEXPANSION in the manual for more complicated stuff (or over here).
bobbogo