1 | # ------------------------------------------------------------------------------ |
---|
2 | # Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
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 | # ------------------------------------------------------------------------------ |
---|
19 | use strict; |
---|
20 | use warnings; |
---|
21 | # ------------------------------------------------------------------------------ |
---|
22 | package FCM::System::Make::Build::Task::Compile::Fortran; |
---|
23 | use base qw{FCM::System::Make::Build::Task::Compile}; |
---|
24 | |
---|
25 | our %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 | |
---|
36 | our %PROP_OF = ( |
---|
37 | %PROP_NO_PREPROCESS_OF, |
---|
38 | 'fc.defs' => '', |
---|
39 | 'fc.flag-define' => '-D%s', |
---|
40 | ); |
---|
41 | |
---|
42 | sub 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 | |
---|
52 | sub _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 | # ------------------------------------------------------------------------------ |
---|
62 | package FCM::System::Make::Build::Task::Compile::Fortran::Extra; |
---|
63 | use base qw{FCM::Class::CODE}; |
---|
64 | |
---|
65 | use FCM::System::Exception; |
---|
66 | use File::Basename qw{basename}; |
---|
67 | |
---|
68 | my $E = 'FCM::System::Exception'; |
---|
69 | |
---|
70 | our %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 | |
---|
77 | sub _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 | # ------------------------------------------------------------------------------ |
---|
88 | 1; |
---|
89 | __END__ |
---|
90 | |
---|
91 | =head1 NAME |
---|
92 | |
---|
93 | FCM::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 | |
---|
103 | Wraps L<FCM::System::Make::Build::Task::Compile> to compile a Fortran source into |
---|
104 | an object. |
---|
105 | |
---|
106 | The module also provides the |
---|
107 | FCM::System::Make::Build::Task::Compile::Fortran::Extra class to deal with the |
---|
108 | module definition file generated by the compiler in the working directory. |
---|
109 | |
---|
110 | =head1 COPYRIGHT |
---|
111 | |
---|
112 | Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
113 | |
---|
114 | =cut |
---|