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 | # ------------------------------------------------------------------------------ |
---|
19 | use strict; |
---|
20 | use warnings; |
---|
21 | |
---|
22 | # ------------------------------------------------------------------------------ |
---|
23 | package FCM::System::Make::Build::FileType::CPP; |
---|
24 | use base qw{FCM::System::Make::Build::FileType}; |
---|
25 | |
---|
26 | use FCM::Context::Make::Build; # for FCM::Context::Make::Build::Target |
---|
27 | use FCM::System::Make::Build::Task::Preprocess::C; |
---|
28 | |
---|
29 | # Dependency types and CODE to extract them |
---|
30 | my %SOURCE_ANALYSE_DEP_OF |
---|
31 | = (include => sub { $_[0] =~ qr{\A\#\s*include\s+"([\w\-+.]+)"}msx }); |
---|
32 | |
---|
33 | # Handler of tasks |
---|
34 | my %TASK_CLASS_OF |
---|
35 | = (process => 'FCM::System::Make::Build::Task::Preprocess::C'); |
---|
36 | |
---|
37 | sub new { |
---|
38 | my ($class, $attrib_ref) = @_; |
---|
39 | bless( |
---|
40 | FCM::System::Make::Build::FileType->new({ |
---|
41 | id => 'cpp', |
---|
42 | file_ext => '.c .m .cc .cp .cxx .cpp .CPP .c++ .C .mm .M', |
---|
43 | source_analyse_dep_of => {%SOURCE_ANALYSE_DEP_OF}, |
---|
44 | source_to_targets => \&_source_to_targets, |
---|
45 | target_file_ext_of => {}, |
---|
46 | task_class_of => {%TASK_CLASS_OF}, |
---|
47 | %{$attrib_ref}, |
---|
48 | }), |
---|
49 | $class, |
---|
50 | ); |
---|
51 | } |
---|
52 | |
---|
53 | # Returns a list of targets for a given build source. |
---|
54 | sub _source_to_targets { |
---|
55 | my ($attrib_ref, $source) = @_; |
---|
56 | my $TARGET = 'FCM::Context::Make::Build::Target'; |
---|
57 | $TARGET->new( |
---|
58 | { category => $TARGET->CT_SRC, |
---|
59 | deps => [@{$source->get_deps()}], |
---|
60 | dep_policy_of => {'include' => $TARGET->POLICY_CAPTURE}, |
---|
61 | info_of => {paths => []}, |
---|
62 | key => $source->get_ns(), |
---|
63 | task => 'process', |
---|
64 | } |
---|
65 | ); |
---|
66 | } |
---|
67 | |
---|
68 | # ------------------------------------------------------------------------------ |
---|
69 | 1; |
---|
70 | __END__ |
---|
71 | |
---|
72 | =head1 NAME |
---|
73 | |
---|
74 | FCM::System::Make::Build::FileType::CPP |
---|
75 | |
---|
76 | =head1 SYNOPSIS |
---|
77 | |
---|
78 | use FCM::System::Make::Build::FileType::CPP; |
---|
79 | my $helper = FCM::System::Make::Build::FileType::CPP->new(); |
---|
80 | $helper->source_analyse($handle); |
---|
81 | |
---|
82 | =head1 DESCRIPTION |
---|
83 | |
---|
84 | A wrapper of |
---|
85 | L<FCM::System::Make::Build::FileType|FCM::System::Make::Build::FileType> with |
---|
86 | configurations to work with C source files for preprocessing. |
---|
87 | |
---|
88 | =head1 COPYRIGHT |
---|
89 | |
---|
90 | (C) Crown copyright Met Office. All rights reserved. |
---|
91 | |
---|
92 | =cut |
---|