File Coverage

File:/usr/local/share/automake-1.11/Automake/Options.pm
Coverage:28.9%

linestmtbrancondsubpodtimecode
1# Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2, or (at your option)
6# any later version.
7
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16package Automake::Options;
17
18
1
1
1
4
1
4
use strict;
19
1
1
1
5
6
3
use Exporter;
20
1
1
1
3
1
6
use Automake::Config;
21
1
1
1
3
2
2
use Automake::ChannelDefs;
22
1
1
1
4
1
3
use Automake::Channels;
23
1
1
1
11
1
8
use Automake::Version;
24
25
1
1
1
4
1
3
use vars qw (@ISA @EXPORT);
26
27@ISA = qw (Exporter);
28@EXPORT = qw (option global_option
29              set_option set_global_option
30              unset_option unset_global_option
31              process_option_list process_global_option_list
32              set_strictness $strictness $strictness_name
33              &FOREIGN &GNU &GNITS);
34
35 - 71
=head1 NAME

Automake::Options - keep track of Automake options

=head1 SYNOPSIS

  use Automake::Options;

  # Option lookup and setting.
  $opt = option 'name';
  $opt = global_option 'name';
  set_option 'name', 'value';
  set_global_option 'name', 'value';
  unset_option 'name';
  unset_global_option 'name';

  # Batch option setting.
  process_option_list $location, @names;
  process_global_option_list $location, @names;

  # Strictness lookup and setting.
  set_strictness 'foreign';
  set_strictness 'gnu';
  set_strictness 'gnits';
  if ($strictness >= GNU) { ... }
  print "$strictness_name\n";

=head1 DESCRIPTION

This packages manages Automake's options and strictness settings.
Options can be either local or global.  Local options are set using an
C<AUTOMAKE_OPTIONS> variable in a F<Makefile.am> and apply only to
this F<Makefile.am>.  Global options are set from the command line or
passed as an argument to C<AM_INIT_AUTOMAKE>, they apply to all
F<Makefile.am>s.

=cut
72
73# Values are the Automake::Location of the definition, except
74# for 'ansi2knr' whose value is a pair [filename, Location].
75
1
1
1
4
1
3
use vars '%_options'; # From AUTOMAKE_OPTIONS
76
1
1
1
3
1
2
use vars '%_global_options'; # from AM_INIT_AUTOMAKE or the command line.
77
78 - 92
=head2 Constants

=over 4

=item FOREIGN

=item GNU

=item GNITS

Strictness constants used as values for C<$strictness>.

=back

=cut
93
94# Constants to define the "strictness" level.
95
1
1
1
3
1
3
use constant FOREIGN => 0;
96
1
1
1
3
1
6
use constant GNU => 1;
97
1
1
1
4
1
6
use constant GNITS => 2;
98
99 - 113
=head2 Variables

=over 4

=item C<$strictness>

The current strictness.  One of C<FOREIGN>, C<GNU>, or C<GNITS>.

=item C<$strictness_name>

The current strictness name.  One of C<'foreign'>, C<'gnu'>, or C<'gnits'>.

=back

=cut
114
115# Strictness levels.
116
1
1
1
4
1
3
use vars qw ($strictness $strictness_name);
117
118# Strictness level as set on command line.
119
1
1
1
3
1
8
use vars qw ($_default_strictness $_default_strictness_name);
120
121
122 - 133
=head2 Functions

=over 4

=item C<Automake::Options::reset>

Reset the options variables for the next F<Makefile.am>.

In other words, this gets rid of all local options in use by the
previous F<Makefile.am>.

=cut
134
135sub reset ()
136{
137
0
1
0
  %_options = %_global_options;
138  # The first time we are run,
139  # remember the current setting as the default.
140
0
0
  if (defined $_default_strictness)
141    {
142
0
0
      $strictness = $_default_strictness;
143
0
0
      $strictness_name = $_default_strictness_name;
144    }
145  else
146    {
147
0
0
      $_default_strictness = $strictness;
148
0
0
      $_default_strictness_name = $strictness_name;
149    }
150}
151
152 - 165
=item C<$value = option ($name)>

=item C<$value = global_option ($name)>

Query the state of an option.  If the option is unset, this
returns the empty list.  Otherwise it returns the option's value,
as set by C<set_option> or C<set_global_option>.

Note that C<global_option> should be used only when it is
important to make sure an option hasn't been set locally.
Otherwise C<option> should be the standard function to
check for options (be they global or local).

=cut
166
167sub option ($)
168{
169
0
1
0
  my ($name) = @_;
170
0
0
  return () unless defined $_options{$name};
171
0
0
  return $_options{$name};
172}
173
174sub global_option ($)
175{
176
0
1
0
  my ($name) = @_;
177
0
0
  return () unless defined $_global_options{$name};
178
0
0
  return $_global_options{$name};
179}
180
181 - 188
=item C<set_option ($name, $value)>

=item C<set_global_option ($name, $value)>

Set an option.  By convention, C<$value> is usually the location
of the option definition.

=cut
189
190sub set_option ($$)
191{
192
0
1
0
  my ($name, $value) = @_;
193
0
0
  $_options{$name} = $value;
194}
195
196sub set_global_option ($$)
197{
198
0
1
0
  my ($name, $value) = @_;
199
0
0
  $_global_options{$name} = $value;
200}
201
202
203 - 209
=item C<unset_option ($name)>

=item C<unset_global_option ($name)>

Unset an option.

=cut
210
211sub unset_option ($)
212{
213
0
1
0
  my ($name) = @_;
214
0
0
  delete $_options{$name};
215}
216
217sub unset_global_option ($)
218{
219
0
1
0
  my ($name) = @_;
220
0
0
  delete $_global_options{$name};
221}
222
223
224 - 233
=item C<process_option_list ($where, @options)>

=item C<process_global_option_list ($where, @options)>

Process Automake's option lists.  C<@options> should be a list of
words, as they occur in C<AUTOMAKE_OPTIONS> or C<AM_INIT_AUTOMAKE>.

Return 1 on error, 0 otherwise.

=cut
234
235# $BOOL
236# _process_option_list (\%OPTIONS, $WHERE, @OPTIONS)
237# -------------------------------------------------
238# Process a list of options. Return 1 on error, 0 otherwise.
239# \%OPTIONS is the hash to fill with options data, $WHERE is
240# the location where @OPTIONS occurred.
241sub _process_option_list (\%$@)
242{
243
0
0
  my ($options, $where, @list) = @_;
244
245
0
0
  foreach (@list)
246    {
247
0
0
      $options->{$_} = $where;
248
0
0
      if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
249        {
250
0
0
          set_strictness ($_);
251        }
252      elsif (/^(.*\/)?ansi2knr$/)
253        {
254          # An option like "../lib/ansi2knr" is allowed. With no
255          # path prefix, we assume the required programs are in this
256          # directory. We save the actual option for later.
257
0
0
          $options->{'ansi2knr'} = [$_, $where];
258        }
259      elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
260             || $_ eq 'dist-shar' || $_ eq 'dist-zip'
261             || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
262             || $_ eq 'dist-lzma' || $_ eq 'dist-xz'
263             || $_ eq 'no-dist-gzip' || $_ eq 'no-dist'
264             || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
265             || $_ eq 'readme-alpha' || $_ eq 'check-news'
266             || $_ eq 'subdir-objects' || $_ eq 'nostdinc'
267             || $_ eq 'no-exeext' || $_ eq 'no-define'
268             || $_ eq 'std-options'
269             || $_ eq 'color-tests' || $_ eq 'parallel-tests'
270             || $_ eq 'cygnus' || $_ eq 'no-dependencies')
271        {
272          # Explicitly recognize these.
273        }
274      elsif ($_ =~ /^filename-length-max=(\d+)$/)
275        {
276
0
0
          delete $options->{$_};
277
0
0
          $options->{'filename-length-max'} = [$_, $1];
278        }
279      elsif ($_ eq 'silent-rules')
280        {
281
0
0
          error ($where,
282                 "option `$_' can only be used as argument to AM_INIT_AUTOMAKE\n"
283                 . "but not in AUTOMAKE_OPTIONS makefile statements")
284            if $where->get !~ /^configure\./;
285        }
286      elsif ($_ eq 'tar-v7' || $_ eq 'tar-ustar' || $_ eq 'tar-pax')
287        {
288
0
0
          error ($where,
289                 "option `$_' can only be used as argument to AM_INIT_AUTOMAKE\n"
290                 . "but not in AUTOMAKE_OPTIONS makefile statements")
291            if $where->get !~ /^configure\./;
292
0
0
          for my $opt ('tar-v7', 'tar-ustar', 'tar-pax')
293            {
294
0
0
              next if $opt eq $_;
295
0
0
              if (exists $options->{$opt})
296                {
297
0
0
                  error ($where,
298                         "options `$_' and `$opt' are mutually exclusive");
299
0
0
                  last;
300                }
301            }
302        }
303      elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/)
304        {
305          # Got a version number.
306
0
0
          if (Automake::Version::check ($VERSION, $&))
307            {
308
0
0
              error ($where, "require Automake $_, but have $VERSION",
309                     uniq_scope => US_GLOBAL);
310
0
0
              return 1;
311            }
312        }
313      elsif (/^(?:--warnings=|-W)(.*)$/)
314        {
315
0
0
          foreach my $cat (split (',', $1))
316            {
317
0
0
              msg 'unsupported', $where, "unknown warning category `$cat'"
318                if switch_warning $cat;
319            }
320        }
321      else
322        {
323
0
0
          error ($where, "option `$_' not recognized",
324                 uniq_scope => US_GLOBAL);
325
0
0
          return 1;
326        }
327    }
328
0
0
  return 0;
329}
330
331sub process_option_list ($@)
332{
333
0
1
0
  my ($where, @list) = @_;
334
0
0
  return _process_option_list (%_options, $where, @list);
335}
336
337sub process_global_option_list ($@)
338{
339
0
1
0
  my ($where, @list) = @_;
340
0
0
  return _process_option_list (%_global_options, $where, @list);
341}
342
343 - 348
=item C<set_strictness ($name)>

Set the current strictness level.
C<$name> should be one of C<'foreign'>, C<'gnu'>, or C<'gnits'>.

=cut
349
350# Set strictness.
351sub set_strictness ($)
352{
353
1
1
6
  $strictness_name = $_[0];
354
355
1
4
  Automake::ChannelDefs::set_strictness ($strictness_name);
356
357
1
3
  if ($strictness_name eq 'gnu')
358    {
359
1
3
      $strictness = GNU;
360    }
361  elsif ($strictness_name eq 'gnits')
362    {
363
0
      $strictness = GNITS;
364    }
365  elsif ($strictness_name eq 'foreign')
366    {
367
0
      $strictness = FOREIGN;
368    }
369  else
370    {
371
0
      prog_error "level `$strictness_name' not recognized\n";
372    }
373}
374
3751;
376
377### Setup "GNU" style for perl-mode and cperl-mode.
378## Local Variables:
379## perl-indent-level: 2
380## perl-continued-statement-offset: 2
381## perl-continued-brace-offset: 0
382## perl-brace-offset: 0
383## perl-brace-imaginary-offset: 0
384## perl-label-offset: -2
385## cperl-indent-level: 2
386## cperl-brace-offset: 0
387## cperl-continued-brace-offset: 0
388## cperl-label-offset: -2
389## cperl-extra-newline-before-brace: t
390## cperl-merge-trailing-else: nil
391## cperl-continued-statement-offset: 2
392## End: