From d622098bce7f7210d6d54417d863e1b66433e587 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 4 Sep 2023 02:02:01 +0000 Subject: [PATCH] Added logic to properly initilize SCons to use gfortran if tool gfortran is loaded. Also initialize FORTRAN properly to use -fPIC as it does for F77, F90,.... Patch initially from discord user maiphi --- SCons/Tool/gfortran.py | 13 +++++++++---- test/Fortran/F03.py | 7 +++---- test/Fortran/fixture/SConstruct_gfortran_shared | 3 +++ test/Fortran/fixture/gfortran_shared.f | 3 +++ test/Fortran/gfortran.py | 15 +++++++++++---- 5 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 test/Fortran/fixture/SConstruct_gfortran_shared create mode 100644 test/Fortran/fixture/gfortran_shared.f diff --git a/SCons/Tool/gfortran.py b/SCons/Tool/gfortran.py index cb55ad602..f438b9171 100644 --- a/SCons/Tool/gfortran.py +++ b/SCons/Tool/gfortran.py @@ -30,19 +30,24 @@ selection method. """ from SCons.Util import CLVar +from SCons.Tool.FortranCommon import add_all_to_env, add_fortran_to_env -from . import fortran +compilers = ['gfortran'] def generate(env) -> None: """Add Builders and construction variables for gfortran.""" - fortran.generate(env) + + add_all_to_env(env) + add_fortran_to_env(env) + + compiler = env.Detect(compilers) or 'gfortran' # fill in other dialects (FORTRAN dialect set by fortran.generate(), # but don't overwrite if they have been set manually. - for dialect in ['F77', 'F90', 'F95', 'F03', 'F08']: + for dialect in ['FORTRAN', 'F77', 'F90', 'F95', 'F03', 'F08']: if dialect not in env: - env[f'{dialect}'] = 'gfortran' + env[f'{dialect}'] = compiler if f'SH{dialect}' not in env: env[f'SH{dialect}'] = f'${dialect}' diff --git a/test/Fortran/F03.py b/test/Fortran/F03.py index ce56cc30b..0d4b9461c 100644 --- a/test/Fortran/F03.py +++ b/test/Fortran/F03.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import TestSCons diff --git a/test/Fortran/fixture/SConstruct_gfortran_shared b/test/Fortran/fixture/SConstruct_gfortran_shared new file mode 100644 index 000000000..a063af860 --- /dev/null +++ b/test/Fortran/fixture/SConstruct_gfortran_shared @@ -0,0 +1,3 @@ +DefaultEnvironment(tools=[]) +env = Environment(tools = ['gfortran', 'gnulink']) +env.SharedLibrary('gfortran_shared', ['gfortran_shared.f']) diff --git a/test/Fortran/fixture/gfortran_shared.f b/test/Fortran/fixture/gfortran_shared.f new file mode 100644 index 000000000..6efd8ffeb --- /dev/null +++ b/test/Fortran/fixture/gfortran_shared.f @@ -0,0 +1,3 @@ + SUBROUTINE gfortran_shared + WRITE(*,*) "Hi from subroutine gfortran_shared!" + END SUBROUTINE gfortran_shared \ No newline at end of file diff --git a/test/Fortran/gfortran.py b/test/Fortran/gfortran.py index c3dec97fe..8d9b73129 100644 --- a/test/Fortran/gfortran.py +++ b/test/Fortran/gfortran.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Verify that the gfortran tool compiles a .f90 file to an executable, @@ -98,6 +97,14 @@ test.must_exist(['modules', 'test2mod.mod']) test.up_to_date(arguments = '.') + +# Now test if shared library build works. +test.file_fixture('fixture/gfortran_shared.f') +test.file_fixture('fixture/SConstruct_gfortran_shared') +test.run(arguments = '-f SConstruct_gfortran_shared') +test.fail_test('gfortran ' not in test.stdout(), message="SCons didn't use gfortran") + + test.pass_test() # Local Variables: -- 2.11.4.GIT