Edit

kc3-lang/automake/lib/Automake/VarDef.pm

Branch :

  • Show log

    Commit

  • Author : Alexandre Duret-Lutz
    Date : 2003-05-25 20:05:50
    Hash : fde42f14
    Message : * lib/Automake/Variable.pm, lib/Automake/VarDef.pm: New files. * lib/Automake/Makefile.am (dist_perllib_DATA): Add Variable.pm and VarDef.pm. * automake.in: Use Automake::Variable and Automake::VarDef. (MACRO_PATTERN): Delete. Now Automake::Variable::_MACRO_PATTERN. (am_macro_for_var): Delete. Now Automake::Variable::_am_macro_for_var. (ac_macro_for_var): Delete. Now Automake::Variable::_ac_macro_for_var. (silent_variable_override): Delete. Now Automake::Variable::_silent_variable_override. (var_value, var_location, var_comment, var_type, var_owner, var_pretty, content_seen): Delete. This functionality is now offered by Automake::Variable and Automake::VarDef. (VAR_AUTOMAKE, VAR_CONFIGURE, VAR_MAKEFILE, VAR_ASIS, VAR_PRETTY): Delete. Now defined in Automake::VarDef. (var_order): Delete. Now Automake::Variable::_var_order. (appendvar): Delete. Now Automake::Variable::_appendvar. (var_SUFFIX_trigger): Register using Automake::Variable::hook. (initialize_per_input): Call Automake::Variable::reset. (err_var, msg_cond_var, msg_var, reject_var): Delete. Now defined in Automake::Variable. (generate_makefile, process_option_list, handle_languages) (traverse_variable_recursively_worker) (transform_variable_recursively, handle_compile) (handle_libraries, handle_ltlibraries) (check_typos, handle_dist, handle_subdirs, scan_autoconf_files): Adjust to use Automake::Variable functions. (check_ambiguous_condition): Delete. Now Automake::Variable::_check_ambiguous_condition. (condition_ambiguous_p): Delete. Now Automake::Variable::condition_ambiguous_p. (variable_not_always_defined_in_cond): Delete. Now Automake::Variable::not_always_defined_in_cond. (macro_define): Delete. Now Automake::Variable::define. (macro_delete): Delete. Now Automake::Variable::variable_delete. (macro_dump): Delete. Now Automake::Variable::variable_dump. (macros_dump): Delete. Now Automake::Variable::variables_dump. (variable_defined): Delete. Now Automake::Variable::variable_defined, with the target check temporarily disabled. (variable_assert): Delete. Now Automake::Variable::variable_assert. (examine_variable): Delete. Now Automake::Variable::examine_variable. (variable_conditions): Delete. Now Automake::Variable::conditions. (scan_variable_expansions): Delete. Now Automake::Variable::scan_variable_expansions. (check_variable_expansions): Delete. Now Automake::Variable::check_variable_expansions. (check_variable_defined_unconditionally): Delete. Now Automake::Variable::check_defined_unconditionally. (variable_value): Delete. Now Automake::Variable::variable_value. (variable_value_as_list): Delete. Now Automake::Variable::variable_value_as_list. (variable_value_as_list_recursive_worker): Adjust to use Automake::Variable functions. (variable_output): Delete. Now Automake::Variable::output. (define_pretty_variable, define_configure_variable, read_am_file) (define_standard_variables, read_main_am_file): Adjust to use Automake::Variable functions. (handle_variables): Delete. Now Automake::Variable::output_variables. (file_contents_internal, am_primary_prefixes, am_install_var) (require_file_with_macro, require_conf_file_with_macro) (push_dist_common): : Adjust to use Automake::Variable functions. (require_variables): Delete. Now Automake::Variable::require_variables. (require_variables_for_macro): Delete. Now Automake::Variable::require_variables_for_variable. * tests/Makefile.am (XFAIL_TESTS): Add target.test.

  • lib/Automake/VarDef.pm
  • # Copyright (C) 2003  Free Software Foundation, Inc.
    
    # 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, 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, write to the Free Software
    # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    # 02111-1307, USA.
    
    package Automake::VarDef;
    use strict;
    use Carp;
    use Automake::ChannelDefs;
    
    require Exporter;
    use vars '@ISA', '@EXPORT';
    @ISA = qw/Exporter/;
    @EXPORT = qw (&VAR_AUTOMAKE &VAR_CONFIGURE &VAR_MAKEFILE
    	      &VAR_ASIS &VAR_PRETTY &VAR_SILENT);
    
    =head1 NAME
    
    Automake::VarDef - a class for variable definitions
    
    =head1 SYNOPSIS
    
      use Automake::VarDef;
      use Automake::Location;
    
      # Create a VarDef for a definition such as
      # | # any comment
      # | foo = bar
      # in Makefile.am
      my $loc = new Automake::Location 'Makefile.am:2';
      my $def = new Automake::VarDef ('foo', 'bar', '# any comment',
                                      $loc, '', VAR_MAKEFILE, VAR_ASIS);
    
      # Appending to a definition.
      $def->append ('value to append', 'comment to append');
    
      # Accessors.
      my $value    = $def->value;
      my $comment  = $def->comment;
      my $location = $def->location;
      my $type     = $def->type;
      my $owner    = $def->owner;
      my $pretty   = $def->pretty;
    
      # Changing owner.
      $def->set_owner (VAR_CONFIGURE,
                       new Automake::Location 'configure.ac:15');
    
      # Marking examined definitions.
      $def->set_seen;
      my $seen_p = $def->seen;
    
      # Printing a variable for debugging.
      print STDERR $def->dump;
    
    =head1 DESCRIPTION
    
    This class gather data related to one Makefile-variable definition.
    
    =head2 Constants
    
    =over 4
    
    =item C<VAR_AUTOMAKE>, C<VAR_CONFIGURE>, C<VAR_MAKEFILE>
    
    Possible owners for variables.  A variable can be defined
    by Automake, in F<configure.ac> (using C<AC_SUBST>), or in
    the user's F<Makefile.am>.
    
    =cut
    
    # Defined so that the owner of a variable can only be increased (e.g
    # Automake should not override a configure or Makefile variable).
    use constant VAR_AUTOMAKE => 0; # Variable defined by Automake.
    use constant VAR_CONFIGURE => 1;# Variable defined in configure.ac.
    use constant VAR_MAKEFILE => 2; # Variable defined in Makefile.am.
    
    =item C<VAR_ASIS>, C<VAR_PRETTY>, C<VAR_SILENT>
    
    Possible print styles.  C<VAR_ASIS> variable should be output as-is.
    C<VAR_PRETTY> variable are wrapped on multiple lines if they cannot
    fit on one.  Finally, C<VAR_SILENT> variable are not output at all.
    
    C<VAR_SILENT> variables can also be overridden silently (unlike the
    other kinds of variables whose overridding may sometimes produce
    warnings).
    
    =cut
    
    # Possible values for pretty.
    use constant VAR_ASIS => 0;	# Output as-is.
    use constant VAR_PRETTY => 1;	# Pretty printed on output.
    use constant VAR_SILENT => 2;	# Not output.  (Can also be
    				# overridden silently.)
    
    =back
    
    =head2 Methods
    
    =over 4
    
    =item C<my $def = Automake::new ($varname, $value, $comment, $location, $type, $owner, $pretty)>
    
    Create a new Makefile-variable definition.  C<$varname> is the name of
    the variable being defined and C<$value> its value.
    
    C<$comment> is any comment preceding the definition.  (Because
    Automake reorders variable definitions in the output, it also tries to
    carry comments around.)
    
    C<$location> is the place where the definition occured, it should be
    an instance of L<Automake::Location>.
    
    C<$type> should be C<''> for definitions made with C<=>, and C<':'>
    for those made with C<:=>.
    
    C<$owner> specifies who owns the variables, it can be one of
    C<VAR_AUTOMAKE>, C<VAR_CONFIGURE>, or C<VAR_MAKEFILE> (see these
    definitions).
    
    Finally, C<$pretty> tells how the variable should be output, and can
    be one of C<VAR_ASIS>, C<VAR_PRETTY>, or C<VAR_SILENT> (see these
    definitions).
    
    =cut
    
    sub new ($$$$$$$$)
    {
      my ($class, $var, $value, $comment, $location, $type, $owner, $pretty) = @_;
    
      # A user variable must be set by either `=' or `:=', and later
      # promoted to `+='.
      if ($owner != VAR_AUTOMAKE && $type eq '+')
        {
          error $location, "$var must be set with `=' before using `+='";
        }
    
      my $self = {
        value => $value,
        comment => $comment,
        location => $location,
        type => $type,
        owner => $owner,
        pretty => $pretty,
        seen => 0,
      };
      bless $self, $class;
    
      return $self;
    }
    
    =item C<$def-E<gt>append ($value, $comment)>
    
    Append C<$value> and <$comment> to the exisiting value and comment of
    C<$def>.  This is normally called on C<+=> definitions.
    
    =cut
    
    sub append ($$$)
    {
      my ($self, $value, $comment) = @_;
      $self->{'comment'} .= $comment;
    
      my $val = $self->{'value'};
      if (chomp $val)
        {
          # Insert a backslash before a trailing newline.
          $val .= "\\\n";
        }
      elsif ($val)
        {
          # Insert a separator.
          $val .= ' ';
        }
      $self->{'value'} = $val . $value;
    }
    
    =item C<$def-E<gt>value>
    
    =item C<$def-E<gt>comment>
    
    =item C<$def-E<gt>location>
    
    =item C<$def-E<gt>type>
    
    =item C<$def-E<gt>owner>
    
    =item C<$def-E<gt>pretty>
    
    Accessors to the various constituents of a C<VarDef>.  See the
    documentation of C<new>'s arguments for a description of these.
    
    =cut
    
    sub value ($)
    {
      my ($self) = @_;
      return $self->{'value'};
    }
    
    sub comment ($)
    {
      my ($self) = @_;
      return $self->{'comment'};
    }
    
    sub location ($)
    {
      my ($self) = @_;
      return $self->{'location'};
    }
    
    sub type ($)
    {
      my ($self) = @_;
      return $self->{'type'};
    }
    
    sub owner ($)
    {
      my ($self) = @_;
      return $self->{'owner'};
    }
    
    sub pretty ($)
    {
      my ($self) = @_;
      return $self->{'pretty'};
    }
    
    =item C<$def-E<gt>set_owner ($owner, $location)>
    
    Change the owner of a definition.  This usually happens because
    the user used C<+=> on an Automake variable, so (s)he now owns
    the content.  C<$location> should be an instance of L<Automake::Location>
    indicating where the change took place.
    
    =cut
    
    sub set_owner ($$$)
    {
      my ($self, $owner, $location) = @_;
      # We always adjust the location when the owner changes (even for
      # `+=' statements).  The risk otherwise is to warn about
      # a VAR_MAKEFILE variable and locate it in configure.ac...
      $self->{'owner'} = $owner;
      $self->{'location'} = $location;
    }
    
    =item C<$def-E<gt>set_seen>
    
    =item C<$bool = $def-E<gt>seen>
    
    These function allows Automake to mark (C<set_seen>) variable that
    it has examined in some way, and latter check (using C<seen>) for
    unused variables.  Unused variables usually indicate typos.
    
    =cut
    
    sub set_seen ($)
    {
      my ($self) = @_;
      $self->{'seen'} = 1;
    }
    
    sub seen ($)
    {
      my ($self) = @_;
      return $self->{'seen'};
    }
    
    =item C<$str = $def-E<gt>dump>
    
    Format the contents of C<$def> as a human-readable string,
    for debugging.
    
    =cut
    
    sub dump ($)
    {
      my ($self) = @_;
      my $owner = $self->owner;
    
      if ($owner == VAR_AUTOMAKE)
        {
          $owner = 'Automake';
        }
      elsif ($owner == VAR_CONFIGURE)
        {
          $owner = 'Configure';
        }
      elsif ($owner == VAR_MAKEFILE)
        {
          $owner = 'Makefile';
        }
      else
        {
          prog_error ("unexpected owner");
        }
    
      my $where = $self->location->dump;
      my $comment = $self->comment;
      my $value = $self->value;
      my $type = $self->type;
    
      return "{
          type: $type=
          where: $where      comment: $comment
          value: $value
          owner: $owner
        }\n";
    }
    
    =back
    
    =head1 SEE ALSO
    
    L<Automake::Variable>.
    
    =cut
    
    1;
    
    ### Setup "GNU" style for perl-mode and cperl-mode.
    ## Local Variables:
    ## perl-indent-level: 2
    ## perl-continued-statement-offset: 2
    ## perl-continued-brace-offset: 0
    ## perl-brace-offset: 0
    ## perl-brace-imaginary-offset: 0
    ## perl-label-offset: -2
    ## cperl-indent-level: 2
    ## cperl-brace-offset: 0
    ## cperl-continued-brace-offset: 0
    ## cperl-label-offset: -2
    ## cperl-extra-newline-before-brace: t
    ## cperl-merge-trailing-else: nil
    ## cperl-continued-statement-offset: 2
    ## End: