help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Lower-casing filenames in pattern rules


From: Brian Dessent
Subject: Re: Lower-casing filenames in pattern rules
Date: Fri, 18 Apr 2008 23:37:11 -0700

Van Snyder wrote:

> %.mod %.o: %.f90
>         $(FC) -c $(FOPTS) -o $@ $< -I MuModuleLibrary
> 
> but "make foo.mod" says
> 
> make: *** No rule to make target `foo.mod'.  Stop.

Right, that doesn't work because in order for the pattern rule to match,
there would have to be a file 'foo.f90'.

> Is there a way to lower-case a filename as it works its way into or
> through a pattern rule?

I don't know how you'd do this with just pattern rules.  However,
GMSL[1] contains a 'lc' function which computes lowercase, and combined
with foreach/eval you can do something like this:

include gmsl

define modrule
$(call lc,$(1)).mod $(1).o: $(1).f90
        $$(FC) -c $$(FOPTS) -o $$@ $$< -I MuModuleLibrary
endef

SOURCES = Foo.f90 Bar.f90 Baz.f90

$(foreach f,$(SOURCES),$(eval $(call modrule,$(basename $(f)))))

I'm not sure this will be satisfactory though, because it no longer uses
a pattern rule and so you lose the feature of pattern rules with
multiple targets being interpreted by make as a single recipe that
generates multiple outputs.  Instead this will be equivalent to having
written:

foo.mod: Foo.f90
        $(FC) -c $(FOPTS) -o $@ $< -I MuModuleLibrary
Foo.o: Foo.f90
        $(FC) -c $(FOPTS) -o $@ $< -I MuModuleLibrary
bar.mod: Bar.f90
        $(FC) -c $(FOPTS) -o $@ $< -I MuModuleLibrary
Bar.o: Bar.f90
        $(FC) -c $(FOPTS) -o $@ $< -I MuModuleLibrary
baz.mod: Baz.f90
        $(FC) -c $(FOPTS) -o $@ $< -I MuModuleLibrary
Baz.o: Baz.f90
        $(FC) -c $(FOPTS) -o $@ $< -I MuModuleLibrary

That's obviously not parallel-make safe since make isn't aware that both
the .mod and .o are generated from the one recipe.  Maybe you could make
each one an individual pattern rule e.g.

define modrule
$(call lc,$(1)).mod %.o: %.f90
        $$(FC) -c $$(FOPTS) -o $$@ $$< -I MuModuleLibrary
endef

I'm not sure if this is valid or not.

Brian

[1] <http://gmsl.sourceforge.net/>.  Alternatively:
<http://savannah.gnu.org/patch/?2823>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]