1 # Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010 Free Software
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 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, except
75 # for 'ansi2knr' whose value is a pair [filename, Location].
76 use vars '%_options'; # From AUTOMAKE_OPTIONS
77 use vars '%_global_options'; # from AM_INIT_AUTOMAKE or the command line.
89 Strictness constants used as values for C<$strictness>.
95 # Constants to define the "strictness" level.
96 use constant FOREIGN => 0;
97 use constant GNU => 1;
98 use constant GNITS => 2;
106 The current strictness. One of C<FOREIGN>, C<GNU>, or C<GNITS>.
108 =item C<$strictness_name>
110 The current strictness name. One of C<'foreign'>, C<'gnu'>, or C<'gnits'>.
117 use vars qw ($strictness $strictness_name);
119 # Strictness level as set on command line.
120 use vars qw ($_default_strictness $_default_strictness_name);
127 =item C<Automake::Options::reset>
129 Reset the options variables for the next F<Makefile.am>.
131 In other words, this gets rid of all local options in use by the
132 previous F<Makefile.am>.
138 %_options = %_global_options;
139 # The first time we are run,
140 # remember the current setting as the default.
141 if (defined $_default_strictness)
143 $strictness = $_default_strictness;
144 $strictness_name = $_default_strictness_name;
148 $_default_strictness = $strictness;
149 $_default_strictness_name = $strictness_name;
153 =item C<$value = option ($name)>
155 =item C<$value = global_option ($name)>
157 Query the state of an option. If the option is unset, this
158 returns the empty list. Otherwise it returns the option's value,
159 as set by C<set_option> or C<set_global_option>.
161 Note that C<global_option> should be used only when it is
162 important to make sure an option hasn't been set locally.
163 Otherwise C<option> should be the standard function to
164 check for options (be they global or local).
171 return () unless defined $_options{$name};
172 return $_options{$name};
175 sub global_option ($)
178 return () unless defined $_global_options{$name};
179 return $_global_options{$name};
182 =item C<set_option ($name, $value)>
184 =item C<set_global_option ($name, $value)>
186 Set an option. By convention, C<$value> is usually the location
187 of the option definition.
193 my ($name, $value) = @_;
194 $_options{$name} = $value;
197 sub set_global_option ($$)
199 my ($name, $value) = @_;
200 $_global_options{$name} = $value;
204 =item C<unset_option ($name)>
206 =item C<unset_global_option ($name)>
215 delete $_options{$name};
218 sub unset_global_option ($)
221 delete $_global_options{$name};
225 =item C<process_option_list ($where, @options)>
227 =item C<process_global_option_list ($where, @options)>
229 Process Automake's option lists. C<@options> should be a list of
230 words, as they occur in C<AUTOMAKE_OPTIONS> or C<AM_INIT_AUTOMAKE>.
232 Return 1 on error, 0 otherwise.
237 # _process_option_list (\%OPTIONS, $WHERE, @OPTIONS)
238 # --------------------------------------------------
239 # Process a list of options. Return 1 on error, 0 otherwise.
240 # \%OPTIONS is the hash to fill with options data, $WHERE is
241 # the location where @OPTIONS occurred.
242 sub _process_option_list (\%$@)
244 my ($options, $where, @list) = @_;
248 $options->{$_} = $where;
249 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
253 elsif (/^(.*\/)?ansi2knr$/)
255 # An option like "../lib/ansi2knr" is allowed. With no
256 # path prefix, we assume the required programs are in this
257 # directory. We save the actual option for later.
258 $options->{'ansi2knr'} = [$_, $where];
260 elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
261 || $_ eq 'dist-shar' || $_ eq 'dist-zip'
262 || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
263 || $_ eq 'dist-lzip' || $_ eq 'dist-lzma' || $_ eq 'dist-xz'
264 || $_ eq 'no-dist-gzip' || $_ eq 'no-dist'
265 || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
266 || $_ eq 'readme-alpha' || $_ eq 'check-news'
267 || $_ eq 'subdir-objects' || $_ eq 'nostdinc'
268 || $_ eq 'no-exeext' || $_ eq 'no-define'
269 || $_ eq 'std-options'
270 || $_ eq 'color-tests' || $_ eq 'parallel-tests'
271 || $_ eq 'cygnus' || $_ eq 'no-dependencies')
273 # Explicitly recognize these.
275 elsif ($_ =~ /^filename-length-max=(\d+)$/)
277 delete $options->{$_};
278 $options->{'filename-length-max'} = [$_, $1];
280 elsif ($_ eq 'silent-rules')
283 "option `$_' can only be used as argument to AM_INIT_AUTOMAKE\n"
284 . "but not in AUTOMAKE_OPTIONS makefile statements")
285 if $where->get !~ /^configure\./;
287 elsif ($_ eq 'tar-v7' || $_ eq 'tar-ustar' || $_ eq 'tar-pax')
290 "option `$_' can only be used as argument to AM_INIT_AUTOMAKE\n"
291 . "but not in AUTOMAKE_OPTIONS makefile statements")
292 if $where->get !~ /^configure\./;
293 for my $opt ('tar-v7', 'tar-ustar', 'tar-pax')
296 if (exists $options->{$opt})
299 "options `$_' and `$opt' are mutually exclusive");
304 elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/)
306 # Got a version number.
307 if (Automake::Version::check ($VERSION, $&))
309 error ($where, "require Automake $_, but have $VERSION",
310 uniq_scope => US_GLOBAL);
314 elsif (/^(?:--warnings=|-W)(.*)$/)
316 foreach my $cat (split (',', $1))
318 msg 'unsupported', $where, "unknown warning category `$cat'"
319 if switch_warning $cat;
324 error ($where, "option `$_' not recognized",
325 uniq_scope => US_GLOBAL);
332 sub process_option_list ($@)
334 my ($where, @list) = @_;
335 return _process_option_list (%_options, $where, @list);
338 sub process_global_option_list ($@)
340 my ($where, @list) = @_;
341 return _process_option_list (%_global_options, $where, @list);
344 =item C<set_strictness ($name)>
346 Set the current strictness level.
347 C<$name> should be one of C<'foreign'>, C<'gnu'>, or C<'gnits'>.
352 sub set_strictness ($)
354 $strictness_name = $_[0];
356 Automake::ChannelDefs::set_strictness ($strictness_name);
358 if ($strictness_name eq 'gnu')
362 elsif ($strictness_name eq 'gnits')
366 elsif ($strictness_name eq 'foreign')
368 $strictness = FOREIGN;
372 prog_error "level `$strictness_name' not recognized";
378 ### Setup "GNU" style for perl-mode and cperl-mode.
380 ## perl-indent-level: 2
381 ## perl-continued-statement-offset: 2
382 ## perl-continued-brace-offset: 0
383 ## perl-brace-offset: 0
384 ## perl-brace-imaginary-offset: 0
385 ## perl-label-offset: -2
386 ## cperl-indent-level: 2
387 ## cperl-brace-offset: 0
388 ## cperl-continued-brace-offset: 0
389 ## cperl-label-offset: -2
390 ## cperl-extra-newline-before-brace: t
391 ## cperl-merge-trailing-else: nil
392 ## cperl-continued-statement-offset: 2