1 # Copyright (C) 2003-2013 Free Software Foundation, Inc.
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)
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.
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/>.
16 package Automake::Options;
22 use Automake::ChannelDefs;
23 use Automake::Channels;
24 use Automake::Version;
26 use vars qw (@ISA @EXPORT);
29 @EXPORT = qw (option global_option
30 set_option set_global_option
31 unset_option unset_global_option
32 process_option_list process_global_option_list
33 set_strictness $strictness $strictness_name
34 &FOREIGN &GNU &GNITS);
38 Automake::Options - keep track of Automake options
42 use Automake::Options;
44 # Option lookup and setting.
46 $opt = global_option 'name';
47 set_option 'name', 'value';
48 set_global_option 'name', 'value';
50 unset_global_option 'name';
52 # Batch option setting.
53 process_option_list $location, @names;
54 process_global_option_list $location, @names;
56 # Strictness lookup and setting.
57 set_strictness 'foreign';
59 set_strictness 'gnits';
60 if ($strictness >= GNU) { ... }
61 print "$strictness_name\n";
65 This packages manages Automake's options and strictness settings.
66 Options can be either local or global. Local options are set using an
67 C<AUTOMAKE_OPTIONS> variable in a F<Makefile.am> and apply only to
68 this F<Makefile.am>. Global options are set from the command line or
69 passed as an argument to C<AM_INIT_AUTOMAKE>, they apply to all
74 # Values are the Automake::Location of the definition.
75 use vars '%_options'; # From AUTOMAKE_OPTIONS
76 use vars '%_global_options'; # From AM_INIT_AUTOMAKE or the command line.
78 # Whether process_option_list has already been called for the current
80 use vars '$_options_processed';
81 # Whether process_global_option_list has already been called.
82 use vars '$_global_options_processed';
94 Strictness constants used as values for C<$strictness>.
100 # Constants to define the "strictness" level.
101 use constant FOREIGN => 0;
102 use constant GNU => 1;
103 use constant GNITS => 2;
111 The current strictness. One of C<FOREIGN>, C<GNU>, or C<GNITS>.
113 =item C<$strictness_name>
115 The current strictness name. One of C<'foreign'>, C<'gnu'>, or C<'gnits'>.
122 use vars qw ($strictness $strictness_name);
124 # Strictness level as set on command line.
125 use vars qw ($_default_strictness $_default_strictness_name);
132 =item C<Automake::Options::reset>
134 Reset the options variables for the next F<Makefile.am>.
136 In other words, this gets rid of all local options in use by the
137 previous F<Makefile.am>.
143 $_options_processed = 0;
144 %_options = %_global_options;
145 # The first time we are run,
146 # remember the current setting as the default.
147 if (defined $_default_strictness)
149 $strictness = $_default_strictness;
150 $strictness_name = $_default_strictness_name;
154 $_default_strictness = $strictness;
155 $_default_strictness_name = $strictness_name;
159 =item C<$value = option ($name)>
161 =item C<$value = global_option ($name)>
163 Query the state of an option. If the option is unset, this
164 returns the empty list. Otherwise it returns the option's value,
165 as set by C<set_option> or C<set_global_option>.
167 Note that C<global_option> should be used only when it is
168 important to make sure an option hasn't been set locally.
169 Otherwise C<option> should be the standard function to
170 check for options (be they global or local).
177 return () unless defined $_options{$name};
178 return $_options{$name};
181 sub global_option ($)
184 return () unless defined $_global_options{$name};
185 return $_global_options{$name};
188 =item C<set_option ($name, $value)>
190 =item C<set_global_option ($name, $value)>
192 Set an option. By convention, C<$value> is usually the location
193 of the option definition.
199 my ($name, $value) = @_;
200 $_options{$name} = $value;
203 sub set_global_option ($$)
205 my ($name, $value) = @_;
206 $_global_options{$name} = $value;
210 =item C<unset_option ($name)>
212 =item C<unset_global_option ($name)>
221 delete $_options{$name};
224 sub unset_global_option ($)
227 delete $_global_options{$name};
231 =item C<process_option_list (@list)>
233 =item C<process_global_option_list (@list)>
235 Process Automake's option lists. C<@list> should be a list of hash
236 references with keys C<option> and C<where>, where C<option> is an
237 option as they occur in C<AUTOMAKE_OPTIONS> or C<AM_INIT_AUTOMAKE>,
238 and C<where> is the location where that option occurred.
240 These functions should be called at most once for each set of options
241 having the same precedence; i.e., do not call it twice for two options
242 from C<AM_INIT_AUTOMAKE>.
244 Return 1 on error, 0 otherwise.
248 # _option_must_be_from_configure ($OPTION, $WHERE)
249 # ----------------------------------------------
250 # Check that the $OPTION given in location $WHERE is specified with
251 # AM_INIT_AUTOMAKE, not with AUTOMAKE_OPTIONS.
252 sub _option_must_be_from_configure ($$)
254 my ($opt, $where)= @_;
256 if $where->get =~ /^configure\./;
258 "option '$opt' can only be used as argument to AM_INIT_AUTOMAKE\n" .
259 "but not in AUTOMAKE_OPTIONS makefile statements";
262 # _is_valid_easy_option ($OPTION)
263 # -------------------------------
264 # Explicitly recognize valid automake options that require no
265 # special handling by '_process_option_list' below.
266 sub _is_valid_easy_option ($)
269 return scalar grep { $opt eq $_ } qw(
298 # _process_option_list (\%OPTIONS, @LIST)
299 # ------------------------------------------
300 # Process a list of options. \%OPTIONS is the hash to fill with options
301 # data. @LIST is a list of options as get passed to public subroutines
302 # process_option_list() and process_global_option_list() (see POD
303 # documentation above).
304 sub _process_option_list (\%@)
306 my ($options, @list) = @_;
309 foreach my $h (@list)
311 local $_ = $h->{'option'};
312 my $where = $h->{'where'};
313 $options->{$_} = $where;
314 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
318 # TODO: Remove this special check in Automake 1.14 or 1.15.
319 elsif (/^(.*\/)?ansi2knr$/)
321 # Obsolete (and now removed) de-ANSI-fication support.
323 "automatic de-ANSI-fication support has been removed");
325 # TODO: Remove this special check in Automake 1.15.
326 elsif ($_ eq 'cygnus')
328 error $where, "support for Cygnus-style trees has been removed";
330 # TODO: Remove this special check in Automake 1.14 or 1.15.
331 elsif ($_ eq 'dist-lzma')
333 error ($where, "support for lzma-compressed distribution " .
334 "archives has been removed");
336 elsif (/^filename-length-max=(\d+)$/)
338 delete $options->{$_};
339 $options->{'filename-length-max'} = [$_, $1];
341 elsif ($_ eq 'tar-v7' || $_ eq 'tar-ustar' || $_ eq 'tar-pax')
343 _option_must_be_from_configure ($_, $where);
344 for my $opt ('tar-v7', 'tar-ustar', 'tar-pax')
347 if $opt eq $_ or ! exists $options->{$opt};
349 "options '$_' and '$opt' are mutually exclusive");
353 elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/)
355 # Got a version number.
356 if (Automake::Version::check ($VERSION, $&))
358 error ($where, "require Automake $_, but have $VERSION",
359 uniq_scope => US_GLOBAL);
363 elsif (/^(?:--warnings=|-W)(.*)$/)
365 my @w = map { { cat => $_, loc => $where} } split (',', $1);
368 elsif (! _is_valid_easy_option $_)
370 error ($where, "option '$_' not recognized",
371 uniq_scope => US_GLOBAL);
375 # We process warnings here, so that any explicitly-given warning setting
376 # will take precedence over warning settings defined implicitly by the
378 foreach my $w (@warnings)
380 msg 'unsupported', $w->{'loc'},
381 "unknown warning category '$w->{'cat'}'"
382 if switch_warning $w->{cat};
387 sub process_option_list (@)
389 prog_error "local options already processed"
390 if $_options_processed;
391 return _process_option_list (%_options, @_);
392 $_options_processed = 1;
395 sub process_global_option_list (@)
397 prog_error "global options already processed"
398 if $_global_options_processed;
399 return _process_option_list (%_global_options, @_);
400 $_global_options_processed = 1;
403 =item C<set_strictness ($name)>
405 Set the current strictness level.
406 C<$name> should be one of C<'foreign'>, C<'gnu'>, or C<'gnits'>.
411 sub set_strictness ($)
413 $strictness_name = $_[0];
415 Automake::ChannelDefs::set_strictness ($strictness_name);
417 if ($strictness_name eq 'gnu')
421 elsif ($strictness_name eq 'gnits')
425 elsif ($strictness_name eq 'foreign')
427 $strictness = FOREIGN;
431 prog_error "level '$strictness_name' not recognized";
437 ### Setup "GNU" style for perl-mode and cperl-mode.
439 ## perl-indent-level: 2
440 ## perl-continued-statement-offset: 2
441 ## perl-continued-brace-offset: 0
442 ## perl-brace-offset: 0
443 ## perl-brace-imaginary-offset: 0
444 ## perl-label-offset: -2
445 ## cperl-indent-level: 2
446 ## cperl-brace-offset: 0
447 ## cperl-continued-brace-offset: 0
448 ## cperl-label-offset: -2
449 ## cperl-extra-newline-before-brace: t
450 ## cperl-merge-trailing-else: nil
451 ## cperl-continued-statement-offset: 2