On Fri, 2022-11-25 at 15:26 +0100, Patrick Begou wrote: > How can I write a generic rule for building TOTO_M.mod from > toto_m.f90 source and put it in the LIB folder ?
There is no way to do this using "straightforward" pattern rules. Pattern rules always rely on the stem (the "%" part) being an identical string (including case) in the target and prerequisite. That cannot be changed. > Of course,the following lines will not work as the "%" token will be > in uppercase on the right hand side. > > # building only the mod file > LIB/%_M.mod: %_m.f90 > @echo "building $*_M.mod" > touch $@ The only thing I can think of is to use secondary expansion: .SECONDEXPANSION: # building only the mod file LIB/%_M.mod: $$(shell echo $$* | tr A-Z a-z)_m.f90 @echo "building $*_M.mod" touch $@ Note the doubled-"$" here. If this doesn't work then it's not possible to create an implicit rule in your situation and you'll just have to create explicit rules for all your targets. You can use a foreach / eval loop to do it if you don't want to write it all out by hand.