summaryrefslogtreecommitdiff
path: root/lib/Automake/VarAppend.pm
blob: 8f114cfef7f0c28895cf3566f701ccd242c3b8c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Copyright (C) 2018  Matthias Paulmier

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

package Automake::VarAppend;

use strict;
use 5.006;

use Automake::Channels;
use Automake::Condition qw (TRUE FALSE);
use Automake::Item;
use Automake::VarDef;
use Exporter;

use vars '@ISA', '@EXPORT';

@ISA = qw (Automake::Item Exporter);

@EXPORT = qw (append_var_cur_cond first_assign_var am_check_definitions);

=head1 NAME

Automake::VarAppend - Helper methods for appending to variables

=head1 DESCRIPTION

This package provides methods for appending values to variables.

It is used by the C<Automake::Variable> class in its C<define> function.

=head2 Functions

=item C<append_var_cur_cond ($self, $var, $owner, $where, $def, $value,
$comment)>

Append $value to an existing $var defined for the current condition.  This is
only used in the define method of this file.

=cut

sub append_var_cur_cond ($$$$$$$)
{
  my ($self, $var, $owner, $where, $def, $value, $comment) = @_;
  $def->append ($value, $comment);
  $self->{'last-append'} = [];

  # Only increase owners.  A VAR_CONFIGURE variable augmented in a
  # Makefile.am becomes a VAR_MAKEFILE variable.
  $def->set_owner ($owner, $where->clone)
      if $owner > $def->owner;
}


=item C<first_assign_var ($sefl, $var, $cond, $owner, $where, $def, $value, $pretty, $comment, $new_var, $type)>

Method that assign a value to a variable for the first time or for total
redefinition of an Automake variable or an AC_SUBST variable for an existing
condition.

=cut

sub first_assign_var ($$$$$$$$$$$)
{
  my ($self, $var, $cond, $owner, $where, $def, $value, $pretty, $comment, $new_var, $type) = @_;

  # Never decrease an owner.
  $owner = $def->owner
    if ! $new_var && $owner < $def->owner;

  # Assignments to a macro set its location.  We don't adjust
  # locations for '+='.  Ideally I suppose we would associate
  # line numbers with random bits of text.
  $def = new Automake::VarDef ($var, $value, $comment, $where->clone,
			       $type, $owner, $pretty);
  $self->set ($cond, $def);
}


=item am_check_definitions ($var, $cond, $def, $type, $where)

Additional checks for Automake definitions

=cut

sub am_check_definitions ($$$$$)
{
  my ($var, $cond, $def, $type, $where) = @_;
  # An Automake variable must be consistently defined with the same
  # sign by Automake.
  if ($def->type ne $type && $def->owner == VAR_AUTOMAKE)
    {
      error ($def->location,
             "Automake variable '$var' was set with '"
             . $def->type . "=' here ...", partial => 1);
      error ($where, "... and is now set with '$type=' here.");
      prog_error ("Automake variable assignments should be consistently\n"
                  . "defined with the same sign");
    }
}


=back

=head1 SEE ALSO

L<Automake::VarDef>, L<Automake::Variable>,
L<Automake::Condition>, L<Automake::Item>,
L<Automake::Channels>.

=cut

1;