http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49150

           Summary: Preprocessing fortran code with the `-M` flag to
                    automatically resolve dependencies and produce
                    makefile rules rendered useless by requiring .mod
                    files be present
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: zbeek...@gmail.com


Here is some fortran code which can be put in it's own .f90 source file and
compiled into an object file and module file:

MODULE utils
  USE types, ONLY: WP
  IMPLICIT NONE

CONTAINS
  ELEMENTAL FUNCTION initPI() RESULT(PI)
    REAL(WP) :: PI
    PI = ATAN(1.0_WP)*4.0_WP
  END FUNCTION initpi
END MODULE utils

When I run the following command with gfortran 4.6 I get the following error.

$ gfortran -MG -cpp modutils.f90
modutils.f90:2.21:

  USE types, ONLY: WP
                     1
Fatal Error: Can't open module file 'types.mod' for reading at (1): No such
file or directory

This entirely defeats the purpose of having a preprocessor spit out makefile
rules. If I want my dependencies resolved automatically, I should be able to
spit out .d files which are later included in my makefile *in an arbitrary
order.* GENERATION OF MAKEFILE RULES FOR AUTOMATIC DEPENDENCY RESOLUTION MUST
BE ABLE TO BE DONE IN ANY ORDER BY PARSING THE SOURCE. There should not be a
requirement to have .mod files present. These files are part of a separate
source file and contribute zero knowledge to the dependencies of the current
file. The need not be present for preprocessing, or dependency resolution. (But
yes, they are needed for syntax checking.)  With the `-M` feature added to
gfortran one should be able to follow the procedure outlined on the GNUmake
website for automatic dependency generation to build codes with a small set of
pattern rules. See this page for more info.
http://theory.uwinnipeg.ca/localfiles/infofiles/make/make_43.html

If the procedure outlined on that page is attempted, the include statement in
the makefile will cause the makefile to abort because the include statement
tries to build the files in arbitrary order (likely ascii collating sequence by
file name) and the -M flag won't allow this because it aborts if the required
.mod files are not present. The makefile code listed bellow should work but
doesn't because of the eroneously required .mod files:

FC=ifort
GFC = gfortran

%.o: %.f90 %.d
    $(FC) $(FCFLAGS) $(FPPFLAGS) -c $< -o $@


%.d: %.f90
    $(SHELL) -ec "$(GFC) -M -cpp $(FPPFLAGS) $< | sed '1 s/^/$@ /' > $@"

sources:=$(wildcard *.f90)
depends:=$(patsubst %.f90,%.d,$(wildcard *.f90))

include $(depends)

Dependency resolution is the bane of Fortran developers, and a huge headache.
Being able to implement Makefiles like the one listed above instead of
teadiously writing line after line of dependency resolutions by hand will be a
boon for the Fortran community as a whole. Please make it a priority to look
into this in the near future.

Many thanks, and keep up the great work.

I wasn't sure whether this was a fortran issue or a preprocessor issue so I
have more or less duplicated the bug I submitted as a fortran issue here.

Reply via email to