source: LMDZ6/branches/Amaury_dev/tools/fcm/lib/FCM/System/Make/Build/Task/Share.pm @ 5129

Last change on this file since 5129 was 5129, checked in by abarral, 8 weeks ago

Re-add removed by mistake fcm

File size: 2.7 KB
Line 
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# ------------------------------------------------------------------------------
19use strict;
20use warnings;
21
22# ------------------------------------------------------------------------------
23package FCM::System::Make::Build::Task::Share;
24use base qw{Exporter};
25
26use Text::ParseWords qw{shellwords};
27
28our @EXPORT = qw{_props_to_opts};
29
30sub _props_to_opts {
31    # $opt_value should be an sprintf format with one %s.
32    my ($opt_value, @props) = @_;
33    if (!$opt_value) {
34        return;
35    }
36    my @opt_values = shellwords($opt_value);
37    my $index = -1;
38    I:
39    for my $i (0 .. $#opt_values) {
40        if (index($opt_values[$i], '%s') >= 0) {
41            $index = $i;
42            last I;
43        }
44    }
45    if ($index == -1) {
46        return (@opt_values, @props);
47    }
48    my @return;
49    for my $prop (@props) {
50        push(@return, @opt_values[0 .. $index - 1]);
51        push(@return, sprintf($opt_values[$index], $prop));
52        push(@return, @opt_values[$index + 1 .. $#opt_values]);
53    }
54    return @return;
55}
56
57# ------------------------------------------------------------------------------
581;
59__END__
60
61=head1 NAME
62
63FCM::System::Make::Build::Task::Share
64
65=head1 SYNOPSIS
66
67    use FCM::System::Make::Build::Task::Share
68
69=head1 DESCRIPTION
70
71Provides common "local" functions for a make build task.
72
73=head1 FUNCTIONS
74
75The following functions are automatically exported by this module.
76
77=over 4
78
79=item _props_to_opts($opt_value, @props)
80
81Expect $opt_value to be an sprintf format containing one %s, and @props is a
82list of values. Return a list that can be used in a shell command. E.g.:
83
84    _props_to_opts('-D%s', 'HELLO="greetings"', 'WORLD="mars and venus"')
85    # => ('-DHELLO="greetings"', '-DWORLD="mars and venus"')
86   
87    _props_to_opts('-I %s', '/path/1', '/path/2')
88    # => ('-I', '/path/1', '-I', '/path/2')
89
90=head1 COPYRIGHT
91
92Copyright (C) 2006-2021 British Crown (Met Office) & Contributors.
93
94=cut
Note: See TracBrowser for help on using the repository browser.