File: | /tmp/automake/lib/Automake/Options.pm |
Coverage: | 95.2% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | # Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010 Free Software | ||||||
2 | # Foundation, Inc. | ||||||
3 | |||||||
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) | ||||||
7 | # any later version. | ||||||
8 | |||||||
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. | ||||||
13 | |||||||
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/>. | ||||||
16 | |||||||
17 | package Automake::Options; | ||||||
18 | |||||||
19 | 1159 1159 1159 | 3134 983 3186 | use strict; | ||||
20 | 1159 1159 1159 | 4010 1153 2741 | use Exporter; | ||||
21 | 1159 1159 1159 | 4477 1128 6517 | use Automake::Config; | ||||
22 | 1159 1159 1159 | 4387 1146 3617 | use Automake::ChannelDefs; | ||||
23 | 1159 1159 1159 | 4637 1150 3174 | use Automake::Channels; | ||||
24 | 1159 1159 1159 | 9535 1565 8614 | use Automake::Version; | ||||
25 | |||||||
26 | 1159 1159 1159 | 4259 1114 4283 | use vars qw (@ISA @EXPORT); | ||||
27 | |||||||
28 | @ISA = qw (Exporter); | ||||||
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); | ||||||
35 | |||||||
36 - 72 | =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 | ||||||
73 | |||||||
74 | # Values are the Automake::Location of the definition, except | ||||||
75 | # for 'ansi2knr' whose value is a pair [filename, Location]. | ||||||
76 | 1159 1159 1159 | 4408 1162 2652 | use vars '%_options'; # From AUTOMAKE_OPTIONS | ||||
77 | 1159 1159 1159 | 4371 2654 2848 | use vars '%_global_options'; # from AM_INIT_AUTOMAKE or the command line. | ||||
78 | |||||||
79 - 93 | =head2 Constants =over 4 =item FOREIGN =item GNU =item GNITS Strictness constants used as values for C<$strictness>. =back =cut | ||||||
94 | |||||||
95 | # Constants to define the "strictness" level. | ||||||
96 | 1159 1159 1159 | 4319 1160 3626 | use constant FOREIGN => 0; | ||||
97 | 1159 1159 1159 | 4317 1101 2792 | use constant GNU => 1; | ||||
98 | 1159 1159 1159 | 4137 1162 2778 | use constant GNITS => 2; | ||||
99 | |||||||
100 - 114 | =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 | ||||||
115 | |||||||
116 | # Strictness levels. | ||||||
117 | 1159 1159 1159 | 4167 1121 2771 | use vars qw ($strictness $strictness_name); | ||||
118 | |||||||
119 | # Strictness level as set on command line. | ||||||
120 | 1159 1159 1159 | 4024 1104 2935 | use vars qw ($_default_strictness $_default_strictness_name); | ||||
121 | |||||||
122 | |||||||
123 - 134 | =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 | ||||||
135 | |||||||
136 | sub reset () | ||||||
137 | { | ||||||
138 | 1322 | 1 | 5961 | %_options = %_global_options; | |||
139 | # The first time we are run, | ||||||
140 | # remember the current setting as the default. | ||||||
141 | 1322 | 4294 | if (defined $_default_strictness) | ||||
142 | { | ||||||
143 | 203 | 426 | $strictness = $_default_strictness; | ||||
144 | 203 | 551 | $strictness_name = $_default_strictness_name; | ||||
145 | } | ||||||
146 | else | ||||||
147 | { | ||||||
148 | 1119 | 2442 | $_default_strictness = $strictness; | ||||
149 | 1119 | 3327 | $_default_strictness_name = $strictness_name; | ||||
150 | } | ||||||
151 | } | ||||||
152 | |||||||
153 - 166 | =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 | ||||||
167 | |||||||
168 | sub option ($) | ||||||
169 | { | ||||||
170 | 248342 | 1 | 332775 | my ($name) = @_; | |||
171 | 248342 | 902740 | return () unless defined $_options{$name}; | ||||
172 | 1843 | 7753 | return $_options{$name}; | ||||
173 | } | ||||||
174 | |||||||
175 | sub global_option ($) | ||||||
176 | { | ||||||
177 | 2638 | 1 | 5469 | my ($name) = @_; | |||
178 | 2638 | 16554 | return () unless defined $_global_options{$name}; | ||||
179 | 14 | 68 | return $_global_options{$name}; | ||||
180 | } | ||||||
181 | |||||||
182 - 189 | =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 | ||||||
190 | |||||||
191 | sub set_option ($$) | ||||||
192 | { | ||||||
193 | 63 | 1 | 109 | my ($name, $value) = @_; | |||
194 | 63 | 150 | $_options{$name} = $value; | ||||
195 | } | ||||||
196 | |||||||
197 | sub set_global_option ($$) | ||||||
198 | { | ||||||
199 | 31 | 1 | 90 | my ($name, $value) = @_; | |||
200 | 31 | 192 | $_global_options{$name} = $value; | ||||
201 | } | ||||||
202 | |||||||
203 | |||||||
204 - 210 | =item C<unset_option ($name)> =item C<unset_global_option ($name)> Unset an option. =cut | ||||||
211 | |||||||
212 | sub unset_option ($) | ||||||
213 | { | ||||||
214 | 0 | 1 | 0 | my ($name) = @_; | |||
215 | 0 | 0 | delete $_options{$name}; | ||||
216 | } | ||||||
217 | |||||||
218 | sub unset_global_option ($) | ||||||
219 | { | ||||||
220 | 6 | 1 | 14 | my ($name) = @_; | |||
221 | 6 | 17 | delete $_global_options{$name}; | ||||
222 | } | ||||||
223 | |||||||
224 | |||||||
225 - 234 | =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 | ||||||
235 | |||||||
236 | # $BOOL | ||||||
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 (\%$@) | ||||||
243 | { | ||||||
244 | 200 | 620 | my ($options, $where, @list) = @_; | ||||
245 | |||||||
246 | 200 | 557 | foreach (@list) | ||||
247 | { | ||||||
248 | 206 | 679 | $options->{$_} = $where; | ||||
249 | 206 | 19872 | if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign') | ||||
250 | { | ||||||
251 | 9 | 40 | set_strictness ($_); | ||||
252 | } | ||||||
253 | elsif (/^(.*\/)?ansi2knr$/) | ||||||
254 | { | ||||||
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 | 14 | 66 | $options->{'ansi2knr'} = [$_, $where]; | ||||
259 | } | ||||||
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') | ||||||
272 | { | ||||||
273 | # Explicitly recognize these. | ||||||
274 | } | ||||||
275 | elsif ($_ =~ /^filename-length-max=(\d+)$/) | ||||||
276 | { | ||||||
277 | 3 | 11 | delete $options->{$_}; | ||||
278 | 3 | 17 | $options->{'filename-length-max'} = [$_, $1]; | ||||
279 | } | ||||||
280 | elsif ($_ eq 'silent-rules') | ||||||
281 | { | ||||||
282 | 3 | 14 | error ($where, | ||||
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\./; | ||||||
286 | } | ||||||
287 | elsif ($_ eq 'tar-v7' || $_ eq 'tar-ustar' || $_ eq 'tar-pax') | ||||||
288 | { | ||||||
289 | 5 | 29 | error ($where, | ||||
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 | 5 | 19 | for my $opt ('tar-v7', 'tar-ustar', 'tar-pax') | ||||
294 | { | ||||||
295 | 15 | 38 | next if $opt eq $_; | ||||
296 | 10 | 28 | if (exists $options->{$opt}) | ||||
297 | { | ||||||
298 | 1 | 10 | error ($where, | ||||
299 | "options `$_' and `$opt' are mutually exclusive"); | ||||||
300 | 1 | 4 | last; | ||||
301 | } | ||||||
302 | } | ||||||
303 | } | ||||||
304 | elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/) | ||||||
305 | { | ||||||
306 | # Got a version number. | ||||||
307 | 3 | 24 | if (Automake::Version::check ($VERSION, $&)) | ||||
308 | { | ||||||
309 | 1 | 7 | error ($where, "require Automake $_, but have $VERSION", | ||||
310 | uniq_scope => US_GLOBAL); | ||||||
311 | 1 | 8 | return 1; | ||||
312 | } | ||||||
313 | } | ||||||
314 | elsif (/^(?:--warnings=|-W)(.*)$/) | ||||||
315 | { | ||||||
316 | 19 | 138 | foreach my $cat (split (',', $1)) | ||||
317 | { | ||||||
318 | 19 | 115 | msg 'unsupported', $where, "unknown warning category `$cat'" | ||||
319 | if switch_warning $cat, $where; | ||||||
320 | } | ||||||
321 | } | ||||||
322 | else | ||||||
323 | { | ||||||
324 | 2 | 18 | error ($where, "option `$_' not recognized", | ||||
325 | uniq_scope => US_GLOBAL); | ||||||
326 | 2 | 15 | return 1; | ||||
327 | } | ||||||
328 | } | ||||||
329 | 197 | 1268 | return 0; | ||||
330 | } | ||||||
331 | |||||||
332 | sub process_option_list ($@) | ||||||
333 | { | ||||||
334 | 131 | 1 | 401 | my ($where, @list) = @_; | |||
335 | 131 | 732 | return _process_option_list (%_options, $where, @list); | ||||
336 | } | ||||||
337 | |||||||
338 | sub process_global_option_list ($@) | ||||||
339 | { | ||||||
340 | 69 | 1 | 223 | my ($where, @list) = @_; | |||
341 | 69 | 575 | return _process_option_list (%_global_options, $where, @list); | ||||
342 | } | ||||||
343 | |||||||
344 - 349 | =item C<set_strictness ($name)> Set the current strictness level. C<$name> should be one of C<'foreign'>, C<'gnu'>, or C<'gnits'>. =cut | ||||||
350 | |||||||
351 | # Set strictness. | ||||||
352 | sub set_strictness ($) | ||||||
353 | { | ||||||
354 | 2339 | 1 | 4838 | $strictness_name = $_[0]; | |||
355 | |||||||
356 | 2339 | 6857 | Automake::ChannelDefs::set_strictness ($strictness_name); | ||||
357 | |||||||
358 | 2339 | 10389 | if ($strictness_name eq 'gnu') | ||||
359 | { | ||||||
360 | 1177 | 3021 | $strictness = GNU; | ||||
361 | } | ||||||
362 | elsif ($strictness_name eq 'gnits') | ||||||
363 | { | ||||||
364 | 11 | 30 | $strictness = GNITS; | ||||
365 | } | ||||||
366 | elsif ($strictness_name eq 'foreign') | ||||||
367 | { | ||||||
368 | 1151 | 3416 | $strictness = FOREIGN; | ||||
369 | } | ||||||
370 | else | ||||||
371 | { | ||||||
372 | 0 | prog_error "level `$strictness_name' not recognized"; | |||||
373 | } | ||||||
374 | } | ||||||
375 | |||||||
376 | 1; | ||||||
377 | |||||||
378 | ### Setup "GNU" style for perl-mode and cperl-mode. | ||||||
379 | ## Local Variables: | ||||||
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 | ||||||
393 | ## End: |