1 | # Copyright (C) 2003, 2004 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, write to the Free Software
|
---|
15 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
---|
16 | # 02110-1301, USA.
|
---|
17 |
|
---|
18 | package Automake::Options;
|
---|
19 |
|
---|
20 | use strict;
|
---|
21 | use Exporter;
|
---|
22 | use Automake::Config;
|
---|
23 | use Automake::ChannelDefs;
|
---|
24 | use Automake::Channels;
|
---|
25 | use Automake::Version;
|
---|
26 |
|
---|
27 | use vars qw (@ISA @EXPORT);
|
---|
28 |
|
---|
29 | @ISA = qw (Exporter);
|
---|
30 | @EXPORT = qw (option global_option
|
---|
31 | set_option set_global_option
|
---|
32 | unset_option unset_global_option
|
---|
33 | process_option_list process_global_option_list
|
---|
34 | set_strictness $strictness $strictness_name
|
---|
35 | &FOREIGN &GNU &GNITS);
|
---|
36 |
|
---|
37 | =head1 NAME
|
---|
38 |
|
---|
39 | Automake::Options - keep track of Automake options
|
---|
40 |
|
---|
41 | =head1 SYNOPSIS
|
---|
42 |
|
---|
43 | use Automake::Options;
|
---|
44 |
|
---|
45 | # Option lookup and setting.
|
---|
46 | $opt = option 'name';
|
---|
47 | $opt = global_option 'name';
|
---|
48 | set_option 'name', 'value';
|
---|
49 | set_global_option 'name', 'value';
|
---|
50 | unset_option 'name';
|
---|
51 | unset_global_option 'name';
|
---|
52 |
|
---|
53 | # Batch option setting.
|
---|
54 | process_option_list $location, @names;
|
---|
55 | process_global_option_list $location, @names;
|
---|
56 |
|
---|
57 | # Strictness lookup and setting.
|
---|
58 | set_strictness 'foreign';
|
---|
59 | set_strictness 'gnu';
|
---|
60 | set_strictness 'gnits';
|
---|
61 | if ($strictness >= GNU) { ... }
|
---|
62 | print "$strictness_name\n";
|
---|
63 |
|
---|
64 | =head1 DESCRIPTION
|
---|
65 |
|
---|
66 | This packages manages Automake's options and strictness settings.
|
---|
67 | Options can be either local or global. Local options are set using an
|
---|
68 | C<AUTOMAKE_OPTIONS> variable in a F<Makefile.am> and apply only to
|
---|
69 | this F<Makefile.am>. Global options are set from the command line or
|
---|
70 | passed as an argument to C<AM_INIT_AUTOMAKE>, they apply to all
|
---|
71 | F<Makefile.am>s.
|
---|
72 |
|
---|
73 | =cut
|
---|
74 |
|
---|
75 | # Values are the Automake::Location of the definition, except
|
---|
76 | # for 'ansi2knr' whose value is a pair [filename, Location].
|
---|
77 | use vars '%_options'; # From AUTOMAKE_OPTIONS
|
---|
78 | use vars '%_global_options'; # from AM_INIT_AUTOMAKE or the command line.
|
---|
79 |
|
---|
80 | =head2 Constants
|
---|
81 |
|
---|
82 | =over 4
|
---|
83 |
|
---|
84 | =item FOREIGN
|
---|
85 |
|
---|
86 | =item GNU
|
---|
87 |
|
---|
88 | =item GNITS
|
---|
89 |
|
---|
90 | Strictness constants used as values for C<$strictness>.
|
---|
91 |
|
---|
92 | =back
|
---|
93 |
|
---|
94 | =cut
|
---|
95 |
|
---|
96 | # Constants to define the "strictness" level.
|
---|
97 | use constant FOREIGN => 0;
|
---|
98 | use constant GNU => 1;
|
---|
99 | use constant GNITS => 2;
|
---|
100 |
|
---|
101 | =head2 Variables
|
---|
102 |
|
---|
103 | =over 4
|
---|
104 |
|
---|
105 | =item C<$strictness>
|
---|
106 |
|
---|
107 | The current stricness. One of C<FOREIGN>, C<GNU>, or C<GNITS>.
|
---|
108 |
|
---|
109 | =item C<$strictness_name>
|
---|
110 |
|
---|
111 | The current stricness name. One of C<'foreign'>, C<'gnu'>, or C<'gnits'>.
|
---|
112 |
|
---|
113 | =back
|
---|
114 |
|
---|
115 | =cut
|
---|
116 |
|
---|
117 | # Strictness levels.
|
---|
118 | use vars qw ($strictness $strictness_name);
|
---|
119 |
|
---|
120 | # Strictness level as set on command line.
|
---|
121 | use vars qw ($_default_strictness $_default_strictness_name);
|
---|
122 |
|
---|
123 |
|
---|
124 | =head2 Functions
|
---|
125 |
|
---|
126 | =over 4
|
---|
127 |
|
---|
128 | =item C<Automake::Options::reset>
|
---|
129 |
|
---|
130 | Reset the options variables for the next F<Makefile.am>.
|
---|
131 |
|
---|
132 | In other words, this gets rid of all local options in use by the
|
---|
133 | previous F<Makefile.am>.
|
---|
134 |
|
---|
135 | =cut
|
---|
136 |
|
---|
137 | sub reset ()
|
---|
138 | {
|
---|
139 | %_options = %_global_options;
|
---|
140 | # The first time we are run,
|
---|
141 | # remember the current setting as the default.
|
---|
142 | if (defined $_default_strictness)
|
---|
143 | {
|
---|
144 | $strictness = $_default_strictness;
|
---|
145 | $strictness_name = $_default_strictness_name;
|
---|
146 | }
|
---|
147 | else
|
---|
148 | {
|
---|
149 | $_default_strictness = $strictness;
|
---|
150 | $_default_strictness_name = $strictness_name;
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | =item C<$value = option ($name)>
|
---|
155 |
|
---|
156 | =item C<$value = global_option ($name)>
|
---|
157 |
|
---|
158 | Query the state of an option. If the option is unset, this
|
---|
159 | returns the empty list. Otherwise it returns the option's value,
|
---|
160 | as set by C<set_option> or C<set_global_option>.
|
---|
161 |
|
---|
162 | Not that C<global_option> should be used only when it is
|
---|
163 | important to make sure an option hasn't been set locally.
|
---|
164 | Otherwise C<option> should be the standard function to
|
---|
165 | check for options (be they global or local).
|
---|
166 |
|
---|
167 | =cut
|
---|
168 |
|
---|
169 | sub option ($)
|
---|
170 | {
|
---|
171 | my ($name) = @_;
|
---|
172 | return () unless defined $_options{$name};
|
---|
173 | return $_options{$name};
|
---|
174 | }
|
---|
175 |
|
---|
176 | sub global_option ($)
|
---|
177 | {
|
---|
178 | my ($name) = @_;
|
---|
179 | return () unless defined $_global_options{$name};
|
---|
180 | return $_global_options{$name};
|
---|
181 | }
|
---|
182 |
|
---|
183 | =item C<set_option ($name, $value)>
|
---|
184 |
|
---|
185 | =item C<set_global_option ($name, $value)>
|
---|
186 |
|
---|
187 | Set an option. By convention, C<$value> is usually the location
|
---|
188 | of the option definition.
|
---|
189 |
|
---|
190 | =cut
|
---|
191 |
|
---|
192 | sub set_option ($$)
|
---|
193 | {
|
---|
194 | my ($name, $value) = @_;
|
---|
195 | $_options{$name} = $value;
|
---|
196 | }
|
---|
197 |
|
---|
198 | sub set_global_option ($$)
|
---|
199 | {
|
---|
200 | my ($name, $value) = @_;
|
---|
201 | $_global_options{$name} = $value;
|
---|
202 | }
|
---|
203 |
|
---|
204 |
|
---|
205 | =item C<unset_option ($name)>
|
---|
206 |
|
---|
207 | =item C<unset_global_option ($name)>
|
---|
208 |
|
---|
209 | Unset an option.
|
---|
210 |
|
---|
211 | =cut
|
---|
212 |
|
---|
213 | sub unset_option ($)
|
---|
214 | {
|
---|
215 | my ($name) = @_;
|
---|
216 | delete $_options{$name};
|
---|
217 | }
|
---|
218 |
|
---|
219 | sub unset_global_option ($)
|
---|
220 | {
|
---|
221 | my ($name) = @_;
|
---|
222 | delete $_global_options{$name};
|
---|
223 | }
|
---|
224 |
|
---|
225 |
|
---|
226 | =item C<process_option_list ($where, @options)>
|
---|
227 |
|
---|
228 | =item C<process_global_option_list ($where, @options)>
|
---|
229 |
|
---|
230 | Process Automake's option lists. C<@options> should be a list of
|
---|
231 | words, as they occur in C<AUTOMAKE_OPTIONS> or C<AM_INIT_AUTOMAKE>.
|
---|
232 |
|
---|
233 | Return 1 on error, 0 otherwise.
|
---|
234 |
|
---|
235 | =cut
|
---|
236 |
|
---|
237 | # $BOOL
|
---|
238 | # _process_option_list (\%OPTIONS, $WHERE, @OPTIONS)
|
---|
239 | # -------------------------------------------------
|
---|
240 | # Process a list of options. Return 1 on error, 0 otherwise.
|
---|
241 | # \%OPTIONS is the hash to fill with options data, $WHERE is
|
---|
242 | # the location where @OPTIONS occured.
|
---|
243 | sub _process_option_list (\%$@)
|
---|
244 | {
|
---|
245 | my ($options, $where, @list) = @_;
|
---|
246 |
|
---|
247 | foreach (@list)
|
---|
248 | {
|
---|
249 | $options->{$_} = $where;
|
---|
250 | if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
|
---|
251 | {
|
---|
252 | set_strictness ($_);
|
---|
253 | }
|
---|
254 | elsif (/^(.*\/)?ansi2knr$/)
|
---|
255 | {
|
---|
256 | # An option like "../lib/ansi2knr" is allowed. With no
|
---|
257 | # path prefix, we assume the required programs are in this
|
---|
258 | # directory. We save the actual option for later.
|
---|
259 | $options->{'ansi2knr'} = [$_, $where];
|
---|
260 | }
|
---|
261 | elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
|
---|
262 | || $_ eq 'dist-shar' || $_ eq 'dist-zip'
|
---|
263 | || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
|
---|
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 'cygnus' || $_ eq 'no-dependencies')
|
---|
271 | {
|
---|
272 | # Explicitly recognize these.
|
---|
273 | }
|
---|
274 | elsif ($_ =~ /^filename-length-max=(\d+)$/)
|
---|
275 | {
|
---|
276 | delete $options->{$_};
|
---|
277 | $options->{'filename-length-max'} = [$_, $1];
|
---|
278 | }
|
---|
279 | elsif ($_ eq 'tar-v7' || $_ eq 'tar-ustar' || $_ eq 'tar-pax')
|
---|
280 | {
|
---|
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')
|
---|
285 | {
|
---|
286 | next if $opt eq $_;
|
---|
287 | if (exists $options->{$opt})
|
---|
288 | {
|
---|
289 | error ($where,
|
---|
290 | "options `$_' and `$opt' are mutually exclusive");
|
---|
291 | last;
|
---|
292 | }
|
---|
293 | }
|
---|
294 | }
|
---|
295 | elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/)
|
---|
296 | {
|
---|
297 | # Got a version number.
|
---|
298 | if (Automake::Version::check ($VERSION, $&))
|
---|
299 | {
|
---|
300 | error ($where, "require Automake $_, but have $VERSION",
|
---|
301 | uniq_scope => US_GLOBAL);
|
---|
302 | return 1;
|
---|
303 | }
|
---|
304 | }
|
---|
305 | elsif (/^(?:--warnings=|-W)(.*)$/)
|
---|
306 | {
|
---|
307 | foreach my $cat (split (',', $1))
|
---|
308 | {
|
---|
309 | msg 'unsupported', $where, "unknown warning category `$cat'"
|
---|
310 | if switch_warning $cat;
|
---|
311 | }
|
---|
312 | }
|
---|
313 | else
|
---|
314 | {
|
---|
315 | error ($where, "option `$_' not recognized",
|
---|
316 | uniq_scope => US_GLOBAL);
|
---|
317 | return 1;
|
---|
318 | }
|
---|
319 | }
|
---|
320 | return 0;
|
---|
321 | }
|
---|
322 |
|
---|
323 | sub process_option_list ($@)
|
---|
324 | {
|
---|
325 | my ($where, @list) = @_;
|
---|
326 | return _process_option_list (%_options, $where, @list);
|
---|
327 | }
|
---|
328 |
|
---|
329 | sub process_global_option_list ($@)
|
---|
330 | {
|
---|
331 | my ($where, @list) = @_;
|
---|
332 | return _process_option_list (%_global_options, $where, @list);
|
---|
333 | }
|
---|
334 |
|
---|
335 | =item C<set_strictness ($name)>
|
---|
336 |
|
---|
337 | Set the current strictness level.
|
---|
338 | C<$name> should be one of C<'foreign'>, C<'gnu'>, or C<'gnits'>.
|
---|
339 |
|
---|
340 | =cut
|
---|
341 |
|
---|
342 | # Set strictness.
|
---|
343 | sub set_strictness ($)
|
---|
344 | {
|
---|
345 | $strictness_name = $_[0];
|
---|
346 |
|
---|
347 | Automake::ChannelDefs::set_strictness ($strictness_name);
|
---|
348 |
|
---|
349 | if ($strictness_name eq 'gnu')
|
---|
350 | {
|
---|
351 | $strictness = GNU;
|
---|
352 | }
|
---|
353 | elsif ($strictness_name eq 'gnits')
|
---|
354 | {
|
---|
355 | $strictness = GNITS;
|
---|
356 | }
|
---|
357 | elsif ($strictness_name eq 'foreign')
|
---|
358 | {
|
---|
359 | $strictness = FOREIGN;
|
---|
360 | }
|
---|
361 | else
|
---|
362 | {
|
---|
363 | prog_error "level `$strictness_name' not recognized\n";
|
---|
364 | }
|
---|
365 | }
|
---|
366 |
|
---|
367 | 1;
|
---|
368 |
|
---|
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:
|
---|