New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Fortran.pm in vendors/lib/FCM/System/Make/Build/Task/Compile – NEMO

source: vendors/lib/FCM/System/Make/Build/Task/Compile/Fortran.pm @ 10669

Last change on this file since 10669 was 10669, checked in by nicolasmartin, 5 years ago

Import latest FCM release from Github into the repository for testing

File size: 3.4 KB
Line 
1# ------------------------------------------------------------------------------
2# (C) British Crown Copyright 2006-17 Met Office.
3#
4# This file is part of FCM, tools for managing and building source code.
5#
6# FCM is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# FCM is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with FCM. If not, see <http://www.gnu.org/licenses/>.
18# ------------------------------------------------------------------------------
19use strict;
20use warnings;
21# ------------------------------------------------------------------------------
22package FCM::System::Make::Build::Task::Compile::Fortran;
23use base qw{FCM::System::Make::Build::Task::Compile};
24
25our %PROP_NO_PREPROCESS_OF = (
26    'fc'               => 'gfortran',
27    'fc.flags'         => '',
28    'fc.flag-compile'  => '-c',
29    'fc.flag-include'  => '-I%s',
30    'fc.flag-module'   => '',
31    'fc.flag-omp'      => '',
32    'fc.flag-output'   => '-o%s',
33    'fc.include-paths' => '',
34);
35
36our %PROP_OF = (
37    %PROP_NO_PREPROCESS_OF,
38    'fc.defs'          => '',
39    'fc.flag-define'   => '-D%s',
40);
41
42sub new {
43    my ($class, $attrib_ref) = @_;
44    bless(
45        $class->SUPER::new(
46            {name => 'fc', prop_of => \&_prop_of, %{$attrib_ref}},
47        ),
48        $class,
49    );
50}
51
52sub _prop_of {
53    my ($attrib_ref, $target) = @_;
54    if (!defined($target)) {
55        return {%PROP_OF};
56    }
57    my $file_ext = $attrib_ref->{util}->file_ext($target->get_path_of_source());
58    (lc($file_ext) eq $file_ext) ? {%PROP_NO_PREPROCESS_OF} : {%PROP_OF};
59}
60
61# ------------------------------------------------------------------------------
62package FCM::System::Make::Build::Task::Compile::Fortran::Extra;
63use base qw{FCM::Class::CODE};
64
65use FCM::System::Exception;
66use File::Basename qw{basename};
67
68my $E = 'FCM::System::Exception';
69
70our %PROP_OF = %FCM::System::Make::Build::Task::Compile::Fortran::PROP_OF;
71
72__PACKAGE__->class(
73    {prop_of => {isa => '%', default => {%PROP_OF}}},
74    {action_of => {main => \&_main, prop_of => sub {\%PROP_OF}}},
75);
76
77sub _main {
78    my ($attrib_ref, $target) = @_;
79    my ($source, $dest) = (basename($target->get_key()), $target->get_path());
80    if (!-e $source) {
81        return;
82    }
83    rename($source, $dest) || return $E->throw($E->COPY, [$source, $dest], $!);
84    $target;
85}
86
87# ------------------------------------------------------------------------------
881;
89__END__
90
91=head1 NAME
92
93FCM::System::Make::Build::Task::Compile::Fortran
94
95=head1 SYNOPSIS
96
97    use FCM::System::Make::Build::Task::Compile::Fortran;
98    my $task = FCM::System::Make::Build::Task::Compile::Fortran->new(\%attrib);
99    $task->main($target);
100
101=head1 DESCRIPTION
102
103Wraps L<FCM::System::Make::Build::Task::Compile> to compile a Fortran source into
104an object.
105
106The module also provides the
107FCM::System::Make::Build::Task::Compile::Fortran::Extra class to deal with the
108module definition file generated by the compiler in the working directory.
109
110=head1 COPYRIGHT
111
112(C) Crown copyright Met Office. All rights reserved.
113
114=cut
Note: See TracBrowser for help on using the repository browser.