[Scons-users] Problem with Fortran Dependency Scanner

Damien damien at khubla.com
Mon Apr 27 11:10:21 EDT 2015


Try adding this to your flags:

env['FORTRANMODDIRPREFIX'] = '-J'
env['FORTRANMODDIR'] = '${TARGET.dir}'

Modules and directories can be a bit of a pain...

Damien

On 2015-04-27 8:50 AM, Nikolaus Rath wrote:
> 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
>



More information about the Scons-users mailing list