Reword the copyright notices to match what's suggested in GPLv3.
[automake/plouj.git] / lib / Automake / Options.pm
blob1705981b97d9b313aa5ed00a57941c200e314c60
1 # Copyright (C) 2003, 2004, 2006, 2007 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 3, or (at your option)
6 # any later version.
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;
18 use strict;
19 use Exporter;
20 use Automake::Config;
21 use Automake::ChannelDefs;
22 use Automake::Channels;
23 use Automake::Version;
25 use vars qw (@ISA @EXPORT);
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);
35 =head1 NAME
37 Automake::Options - keep track of Automake options
39 =head1 SYNOPSIS
41 use Automake::Options;
43 # Option lookup and setting.
44 $opt = option 'name';
45 $opt = global_option 'name';
46 set_option 'name', 'value';
47 set_global_option 'name', 'value';
48 unset_option 'name';
49 unset_global_option 'name';
51 # Batch option setting.
52 process_option_list $location, @names;
53 process_global_option_list $location, @names;
55 # Strictness lookup and setting.
56 set_strictness 'foreign';
57 set_strictness 'gnu';
58 set_strictness 'gnits';
59 if ($strictness >= GNU) { ... }
60 print "$strictness_name\n";
62 =head1 DESCRIPTION
64 This packages manages Automake's options and strictness settings.
65 Options can be either local or global. Local options are set using an
66 C<AUTOMAKE_OPTIONS> variable in a F<Makefile.am> and apply only to
67 this F<Makefile.am>. Global options are set from the command line or
68 passed as an argument to C<AM_INIT_AUTOMAKE>, they apply to all
69 F<Makefile.am>s.
71 =cut
73 # Values are the Automake::Location of the definition, except
74 # for 'ansi2knr' whose value is a pair [filename, Location].
75 use vars '%_options'; # From AUTOMAKE_OPTIONS
76 use vars '%_global_options'; # from AM_INIT_AUTOMAKE or the command line.
78 =head2 Constants
80 =over 4
82 =item FOREIGN
84 =item GNU
86 =item GNITS
88 Strictness constants used as values for C<$strictness>.
90 =back
92 =cut
94 # Constants to define the "strictness" level.
95 use constant FOREIGN => 0;
96 use constant GNU => 1;
97 use constant GNITS => 2;
99 =head2 Variables
101 =over 4
103 =item C<$strictness>
105 The current strictness. One of C<FOREIGN>, C<GNU>, or C<GNITS>.
107 =item C<$strictness_name>
109 The current strictness name. One of C<'foreign'>, C<'gnu'>, or C<'gnits'>.
111 =back
113 =cut
115 # Strictness levels.
116 use vars qw ($strictness $strictness_name);
118 # Strictness level as set on command line.
119 use vars qw ($_default_strictness $_default_strictness_name);
122 =head2 Functions
124 =over 4
126 =item C<Automake::Options::reset>
128 Reset the options variables for the next F<Makefile.am>.
130 In other words, this gets rid of all local options in use by the
131 previous F<Makefile.am>.
133 =cut
135 sub reset ()
137 %_options = %_global_options;
138 # The first time we are run,
139 # remember the current setting as the default.
140 if (defined $_default_strictness)
142 $strictness = $_default_strictness;
143 $strictness_name = $_default_strictness_name;
145 else
147 $_default_strictness = $strictness;
148 $_default_strictness_name = $strictness_name;
152 =item C<$value = option ($name)>
154 =item C<$value = global_option ($name)>
156 Query the state of an option. If the option is unset, this
157 returns the empty list. Otherwise it returns the option's value,
158 as set by C<set_option> or C<set_global_option>.
160 Note that C<global_option> should be used only when it is
161 important to make sure an option hasn't been set locally.
162 Otherwise C<option> should be the standard function to
163 check for options (be they global or local).
165 =cut
167 sub option ($)
169 my ($name) = @_;
170 return () unless defined $_options{$name};
171 return $_options{$name};
174 sub global_option ($)
176 my ($name) = @_;
177 return () unless defined $_global_options{$name};
178 return $_global_options{$name};
181 =item C<set_option ($name, $value)>
183 =item C<set_global_option ($name, $value)>
185 Set an option. By convention, C<$value> is usually the location
186 of the option definition.
188 =cut
190 sub set_option ($$)
192 my ($name, $value) = @_;
193 $_options{$name} = $value;
196 sub set_global_option ($$)
198 my ($name, $value) = @_;
199 $_global_options{$name} = $value;
203 =item C<unset_option ($name)>
205 =item C<unset_global_option ($name)>
207 Unset an option.
209 =cut
211 sub unset_option ($)
213 my ($name) = @_;
214 delete $_options{$name};
217 sub unset_global_option ($)
219 my ($name) = @_;
220 delete $_global_options{$name};
224 =item C<process_option_list ($where, @options)>
226 =item C<process_global_option_list ($where, @options)>
228 Process Automake's option lists. C<@options> should be a list of
229 words, as they occur in C<AUTOMAKE_OPTIONS> or C<AM_INIT_AUTOMAKE>.
231 Return 1 on error, 0 otherwise.
233 =cut
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.
241 sub _process_option_list (\%$@)
243 my ($options, $where, @list) = @_;
245 foreach (@list)
247 $options->{$_} = $where;
248 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
250 set_strictness ($_);
252 elsif (/^(.*\/)?ansi2knr$/)
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 $options->{'ansi2knr'} = [$_, $where];
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'
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'
270 || $_ eq 'cygnus' || $_ eq 'no-dependencies')
272 # Explicitly recognize these.
274 elsif ($_ =~ /^filename-length-max=(\d+)$/)
276 delete $options->{$_};
277 $options->{'filename-length-max'} = [$_, $1];
279 elsif ($_ eq 'tar-v7' || $_ eq 'tar-ustar' || $_ eq 'tar-pax')
281 error ($where,
282 "option `$_' must be an argument of AM_INIT_AUTOMAKE")
283 if $where->get !~ /^configure\./;
284 for my $opt ('tar-v7', 'tar-ustar', 'tar-pax')
286 next if $opt eq $_;
287 if (exists $options->{$opt})
289 error ($where,
290 "options `$_' and `$opt' are mutually exclusive");
291 last;
295 elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/)
297 # Got a version number.
298 if (Automake::Version::check ($VERSION, $&))
300 error ($where, "require Automake $_, but have $VERSION",
301 uniq_scope => US_GLOBAL);
302 return 1;
305 elsif (/^(?:--warnings=|-W)(.*)$/)
307 foreach my $cat (split (',', $1))
309 msg 'unsupported', $where, "unknown warning category `$cat'"
310 if switch_warning $cat;
313 else
315 error ($where, "option `$_' not recognized",
316 uniq_scope => US_GLOBAL);
317 return 1;
320 return 0;
323 sub process_option_list ($@)
325 my ($where, @list) = @_;
326 return _process_option_list (%_options, $where, @list);
329 sub process_global_option_list ($@)
331 my ($where, @list) = @_;
332 return _process_option_list (%_global_options, $where, @list);
335 =item C<set_strictness ($name)>
337 Set the current strictness level.
338 C<$name> should be one of C<'foreign'>, C<'gnu'>, or C<'gnits'>.
340 =cut
342 # Set strictness.
343 sub set_strictness ($)
345 $strictness_name = $_[0];
347 Automake::ChannelDefs::set_strictness ($strictness_name);
349 if ($strictness_name eq 'gnu')
351 $strictness = GNU;
353 elsif ($strictness_name eq 'gnits')
355 $strictness = GNITS;
357 elsif ($strictness_name eq 'foreign')
359 $strictness = FOREIGN;
361 else
363 prog_error "level `$strictness_name' not recognized\n";
369 ### Setup "GNU" style for perl-mode and cperl-mode.
370 ## Local Variables:
371 ## perl-indent-level: 2
372 ## perl-continued-statement-offset: 2
373 ## perl-continued-brace-offset: 0
374 ## perl-brace-offset: 0
375 ## perl-brace-imaginary-offset: 0
376 ## perl-label-offset: -2
377 ## cperl-indent-level: 2
378 ## cperl-brace-offset: 0
379 ## cperl-continued-brace-offset: 0
380 ## cperl-label-offset: -2
381 ## cperl-extra-newline-before-brace: t
382 ## cperl-merge-trailing-else: nil
383 ## cperl-continued-statement-offset: 2
384 ## End: