List Info

Thread: Lower-casing filenames in pattern rules




Lower-casing filenames in pattern rules
country flaguser name
United States
2008-04-18 21:34:23
To compile Fortran 90 programs, I'd like to use pattern
rules.  Most
Fortran 90 compilers create a .mod file with a base name
that is the
name of the module, all in lower case.  If I've used any
upper-case
letters in the file name, even if it's otherwise identical
(sans
extension) to the module name, I apparently can't use a
pattern rule.

For example, I have a module named foo in a source file
named Foo.f90:

foo.mod Foo.o: Foo.f90
	$(FC) -c $(FOPTS) -o Foo.o Foo.f90 -I MyModuleLibrary

and numerous other files with the same sort of rules.

To avoid compilation cascades I write my inter-module
dependencies in
terms of .mod files, not .o files.  First I save the .mod
file, then I
compile the source file.  Then I compare the new .mod file
to the old
one.  If they're the same, I replace the new one with the
old one, being
careful to preserve its time stamp.

This prevents compiling B.f90 if it accesses a.mod by use
association,
and none of the interfaces in A.f90 have changed.  Of
course, I get a
new .o file.

I tried

%.mod %.o: %.f90
	$(FC) -c $(FOPTS) -o $ $< -I MuModuleLibrary

but "make foo.mod" says

make: *** No rule to make target `foo.mod'.  Stop.

"make Foo.o" works.

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

-- 
Van Snyder                    |  What fraction of Americans
believe 
Van.Snyderjpl.nasa.gov       |  Wrestling is real and NASA is
fake?
Any alleged opinions are my own and have not been approved
or
disapproved by JPL, CalTech, NASA, the President, or anybody
else.



_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Lower-casing filenames in pattern rules
country flaguser name
United States
2008-04-19 01:37:11
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.sourcef
orge.net/>.  Alternatively:
<http://savann
ah.gnu.org/patch/?2823>


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Lower-casing filenames in pattern rules
country flaguser name
United States
2008-04-19 06:14:01
On 2008-04-19 02:34Z, Van Snyder wrote:
> To compile Fortran 90 programs, I'd like to use pattern
rules.  Most
> Fortran 90 compilers create a .mod file with a base
name that is the
> name of the module, all in lower case.  If I've used
any upper-case
> letters in the file name, even if it's otherwise
identical (sans
> extension) to the module name, I apparently can't use a
pattern rule.

I guess it's considered undesirable to avoid the problem by
using only lower-case source file names, so...

> For example, I have a module named foo in a source file
named Foo.f90:
> 
> foo.mod Foo.o: Foo.f90
> 	$(FC) -c $(FOPTS) -o Foo.o Foo.f90 -I MyModuleLibrary
> 
> and numerous other files with the same sort of rules.

Do '.mod' files remain valid if you change the
capitalization
of their names, e.g. with the extra line below? (Sorry, I
don't
know the language.)

> %.mod %.o: %.f90
> 	$(FC) -c $(FOPTS) -o $ $< -I MuModuleLibrary

	mv `echo $*.mod | tr '[:upper:]' '[:lower:]'` $*.mod

or just create an extra dummy file with a mixed-case name,
assuming a case-sensitive file system:

	cp --preserve `echo $*.mod | tr '[:upper:]' '[:lower:]'`
$*.mod
	# 'touch' might work just as well

and write module dependencies in terms of case-preserved
module file names like 'Foo.mod'. But maybe that's worse
than
restricting source file names to lowercase?


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )