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 | # ------------------------------------------------------------------------------ |
---|
23 | package FCM::System::Make::Build::Task::Share; |
---|
24 | use base qw{Exporter}; |
---|
25 | |
---|
26 | use Text::ParseWords qw{shellwords}; |
---|
27 | |
---|
28 | our @EXPORT = qw{_props_to_opts}; |
---|
29 | |
---|
30 | sub _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 | # ------------------------------------------------------------------------------ |
---|
58 | 1; |
---|
59 | __END__ |
---|
60 | |
---|
61 | =head1 NAME |
---|
62 | |
---|
63 | FCM::System::Make::Build::Task::Share |
---|
64 | |
---|
65 | =head1 SYNOPSIS |
---|
66 | |
---|
67 | use FCM::System::Make::Build::Task::Share |
---|
68 | |
---|
69 | =head1 DESCRIPTION |
---|
70 | |
---|
71 | Provides common "local" functions for a make build task. |
---|
72 | |
---|
73 | =head1 FUNCTIONS |
---|
74 | |
---|
75 | The following functions are automatically exported by this module. |
---|
76 | |
---|
77 | =over 4 |
---|
78 | |
---|
79 | =item _props_to_opts($opt_value, @props) |
---|
80 | |
---|
81 | Expect $opt_value to be an sprintf format containing one %s, and @props is a |
---|
82 | list 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 | |
---|
92 | Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
93 | |
---|
94 | =cut |
---|