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.
H.pm in vendors/FCM-2017.10.0/lib/FCM/System/Make/Build/FileType – NEMO

source: vendors/FCM-2017.10.0/lib/FCM/System/Make/Build/FileType/H.pm @ 10672

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

Reimport latest FCM release

File size: 4.1 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
22# ------------------------------------------------------------------------------
23package FCM::System::Make::Build::FileType::H;
24use base qw{FCM::System::Make::Build::FileType};
25
26use FCM::Context::Make::Build;    # for FCM::Context::Make::Build::Target
27use FCM::System::Make::Build::Task::Install;
28use File::Basename qw{basename};
29
30# RE: file (base) name
31my $RE_FILE = qr{[\w\-+.]+}imsx;
32
33# Dependency types and CODE to extract them
34my %SOURCE_ANALYSE_DEP_OF = (
35    include => sub { $_[0] =~ qr{\A\#\s*include\s+"($RE_FILE)"}msx },
36
37    # Note: handle ! as a comment, for *.h files containing Fortran source
38    o => sub {
39        $_[0] =~ qr{\A\s*(?:!|/\*)\s*depends\s*on\s*:\s*($RE_FILE)}imsx;
40    },
41);
42
43# Alias
44my $TARGET = 'FCM::Context::Make::Build::Target';
45
46# Handler of tasks
47my %TASK_CLASS_OF = (install => 'FCM::System::Make::Build::Task::Install');
48
49# Property suffices of output file extensions
50my %TARGET_EXT_OF = ('o' => '.o');
51
52sub new {
53    my ($class, $attrib_ref) = @_;
54    bless(
55        FCM::System::Make::Build::FileType->new({
56            id                    => 'h',
57            file_ext              => '.h',
58            source_analyse_dep_of => {%SOURCE_ANALYSE_DEP_OF},
59            source_to_targets     => \&_source_to_targets,
60            target_file_ext_of    => {%TARGET_EXT_OF},
61            task_class_of         => {%TASK_CLASS_OF},
62            %{$attrib_ref},
63        }),
64        $class,
65    );
66}
67
68# Returns a list of targets for a given build source.
69sub _source_to_targets {
70    my ($attrib_ref, $source, $prop_hash_ref) = @_;
71    my %dot = %{$prop_hash_ref};
72    my $key = basename($source->get_path());
73    my @deps = map {
74        my $ext = $attrib_ref->{util}->file_ext($_->[0]);
75        $_->[1] eq 'o' && !$ext ? [lc($_->[0]) . $dot{o}, $_->[1]] : $_;
76    } @{$source->get_deps()};
77    $TARGET->new(
78        {   category => $TARGET->CT_INCLUDE,
79            deps     => [@deps],
80            dep_policy_of => {'include' => $TARGET->POLICY_CAPTURE},
81            key      => $key,
82            status_of=> {'include' => $TARGET->ST_UNKNOWN},
83            task     => 'install',
84        }
85    );
86}
87
88# ------------------------------------------------------------------------------
89package FCM::System::Make::Build::FileType::HPP;
90use base qw{FCM::System::Make::Build::FileType::H};
91
92sub new {
93    my ($class, $attrib_ref) = @_;
94    bless(
95        FCM::System::Make::Build::FileType::H->new({
96            source_analyse_dep_of => {include => $SOURCE_ANALYSE_DEP_OF{include}},
97            target_file_ext_of    => {},
98            %{$attrib_ref},
99        }),
100        $class,
101    );
102}
103
104# ------------------------------------------------------------------------------
1051;
106__END__
107
108=head1 NAME
109
110FCM::System::Make::Build::FileType::H
111
112=head1 SYNOPSIS
113
114    use FCM::System::Make::Build::FileType::H;
115    my $helper = FCM::System::Make::Build::FileType::H->new();
116    $helper->source_analyse($handle);
117
118    my $helper = FCM::System::Make::Build::FileType::HPP->new();
119    $helper->source_analyse($handle);
120
121=head1 DESCRIPTION
122
123A wrapper of
124L<FCM::System::Make::Build::FileType|FCM::System::Make::Build::FileType> with
125configurations to work with C or Fortran preprocessor header files.
126
127=head1 COPYRIGHT
128
129(C) Crown copyright Met Office. All rights reserved.
130
131=cut
Note: See TracBrowser for help on using the repository browser.