|
From: | Patrick Begou |
Subject: | Re: Help needed for writing a rule |
Date: | Fri, 25 Nov 2022 17:12:42 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 |
Hi Paul many thanks for your quick answer.Indeed, I've found a solution. Since my email: as nothing was working for a while, I dive again and again in the documentation and then decide to remove all my complex and not working syntax to try to build a functional Makefile. And I think I have a solution. The small test below is working. The modified Makefile of one of my folders from my large application seams to work too.
Seams that it could be as simple as this Makefile: 1 2 .SUFFIXES: 3 4 # building only the mod file 5 %_M.mod: 6 @echo "building $@ from $<" 7 touch $@ 8 9 %_m.o: %_m.f90 10 @echo "building $@ module from $<" 11 touch $@ 12 13 %.o: %.f90 14 @echo "building $@ from $<" 15 touch $@ 16 17 all: toto.o 18 19 clean: 20 rm -f *.mod *.o LIB/* 21 22 toto.o : toto.f90 LIB/TITI_M.mod titi_m.o 23 titi_m.o LIB/TITI_M.mod: titi_m.f90 Just run: touch titi_m.f90 toto.f90 mkdir LIB makeOf course this works because I am building a ".depends" file with all dependencies dynamically too for my application. In the provided Makefile example, dependencies are added at the end of the makefile. May be this could have side effects I do not see, but seams to work on the computer (RHEL8). I should try on other linux flavor as it must be portable.
Patrick Le 25/11/2022 à 16:30, Paul Smith a écrit :
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.
[Prev in Thread] | Current Thread | [Next in Thread] |