[Scons-users] Problem with Fortran Dependency Scanner
    Nikolaus Rath 
    nrath at trialphaenergy.com
       
    Mon Apr 27 10:50:46 EDT 2015
    
    
  
Hello,
I have the following tiny test project:
$ find -type f
./src1/foo.f
./src1/bar.F
./src1/bar.mod
./src1/SConstruct
./src2/com.f90
./inc/params.f
$ cat src1/bar.F
      PROGRAM bar
      USE com
      IMPLICIT NONE
      PRINT *, 'Starting bar'
      PRINT *, 'Value of SETTING is', SETTING
      call com_sub
      PRINT *, 'End of bar'
      END
$ cat src2/com.f90
MODULE com
  USE foo
  INTEGER:: com_int=17
CONTAINS
  subroutine com_sub
    PRINT *, 'Starting com_sub'
    CALL foo_sub
    PRINT *, 'End of com_sub'
  end SUBROUTINE com_sub
END MODULE com
$ cat src1/foo.f
      MODULE foo
      IMPLICIT NONE
      INCLUDE 'params.f'
      INTEGER foo_int
      CONTAINS
      subroutine foo_sub
      PRINT *, 'In foo_sub'
      end SUBROUTINE
      END MODULE foo
$ cat inc/params.f
      real,parameter::zero=0,one=1
I'm trying to build it with the following Scons script:
$ cat src1/SConstruct
# Attention, emacs, this is a -*- python -*- file.
import os
opts = Variables(None, ARGUMENTS)
opts.Add(BoolVariable('DEBUG', 'Enable debugging', False))
opts.Add(BoolVariable('SETTING', 'Enable setting', True))
env = DefaultEnvironment(variables = opts,
                         ENV = {'PATH' : os.environ['PATH']})
# Use the same settings for all Fortran dialects
for dialect in ('F77', 'F90', 'F95', 'F03'):
    for var_suffix in ('', 'FLAGS', 'PATH'):
        env['%s%s' % (dialect, var_suffix)] = \
            '${FORTRAN%s}' % var_suffix
opts = Split('-g -Wall')
if env['DEBUG']:
    opts += Split('-O0 -g')
else:
    opts += Split('-O3')
env.Append(FORTRANFLAGS=opts, CPPDEFINES=['SETTING'],
           FORTRANPATH=['#/../inc'])
sources = [ 'bar.F',
            'foo.f',
            '../src2/com.f90' ]
# Object method returns both .mod and .o, so we filter for the latter.
objects = [ x for x in Object(sources) if x.get_suffix() == '.o' ]
Program('test', objects)
However, this fails with:
$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gfortran -o /home/nikratio/tmp/scons-test/src2/com.o -c -g -Wall -O3
-I/home/nikratio/tmp/scons-test/inc
/home/nikratio/tmp/scons-test/src2/com.f90
/home/nikratio/tmp/scons-test/src2/com.f90:2.6:
  USE foo
      1
Fatal Error: Can't open module file 'foo.mod' for reading at (1): No
such file or directory
scons: *** [/home/nikratio/tmp/scons-test/src2/com.o] Error 1
scons: building terminated because of errors.
It seems that Scons did not notice that src2/com.f90 depends on src1/foo.f.
Why is that?
With experimenting, I found out that it helps if I add '.' to
FORTRANPATH - but that seems wrong, because I don't want to include any
files from src1/.
Best,
-Nikolaus
-- 
Nikolaus Rath, Ph.D.
Senior Scientist
Tri Alpha Energy, Inc.
+1 949 830 2117 ext 211
    
    
More information about the Scons-users
mailing list