Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multiple % in Makefile

I have to convert a set of file (let's say format fa) into another format (fb) by a command (fa2fb). Each target fb depends only on one fa file.

Data structure is in a format like this:

source:

./DATA/L1/fa/L1.fa
./DATA/L2/fa/L2.fa
...
./DATA/Ln/fa/Ln.fa

target:

./DATA/L1/fb/L1.fb
./DATA/L2/fb/L2.fb
...
./DATA/Ln/fb/Ln.fb

How can I implement it with make?

I have tried this but of course it did not work:

./DATA/%/fb/%.fb :  ./DATA/%/fa/%.fb

    @fa2fb $< $@

Is there any simple solution without changing the data directories?

Many thanks!

like image 395
gio10 Avatar asked Jul 21 '26 22:07

gio10


1 Answers

Use secondary expansion and the subst function to create a rule where the prerequisites are constructed as a more complex function of the target name:

.SECONDEXPANSION:
DATA/%.fb: $$(subst fb,fa,$$@)
    @fa2fb $< $@

Note that this approach assumes that fb will not occur anywhere else in the filename (which holds true if all of your filenames are of the form DATA/Ln/fb/Ln.fb, for some integer n).

like image 125
Adam Rosenfield Avatar answered Jul 26 '26 07:07

Adam Rosenfield



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!