# Copyright (C) 2003, 2004 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. package Automake::Options; use strict; use Exporter; use Automake::Config; use Automake::ChannelDefs; use Automake::Channels; use Automake::Version; use vars qw (@ISA @EXPORT); @ISA = qw (Exporter); @EXPORT = qw (option global_option set_option set_global_option unset_option unset_global_option process_option_list process_global_option_list set_strictness $strictness $strictness_name &FOREIGN &GNU &GNITS); =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 variable in a F and apply only to this F. Global options are set from the command line or passed as an argument to C, they apply to all Fs. =cut # Values are the Automake::Location of the definition, except # for 'ansi2knr' whose value is a pair [filename, Location]. use vars '%_options'; # From AUTOMAKE_OPTIONS use vars '%_global_options'; # from AM_INIT_AUTOMAKE or the command line. =head2 Constants =over 4 =item FOREIGN =item GNU =item GNITS Strictness constants used as values for C<$strictness>. =back =cut # Constants to define the "strictness" level. use constant FOREIGN => 0; use constant GNU => 1; use constant GNITS => 2; =head2 Variables =over 4 =item C<$strictness> The current stricness. One of C, C, or C. =item C<$strictness_name> The current stricness name. One of C<'foreign'>, C<'gnu'>, or C<'gnits'>. =back =cut # Strictness levels. use vars qw ($strictness $strictness_name); # Strictness level as set on command line. use vars qw ($_default_strictness $_default_strictness_name); =head2 Functions =over 4 =item C Reset the options variables for the next F. In other words, this gets rid of all local options in use by the previous F. =cut sub reset () { %_options = %_global_options; # The first time we are run, # remember the current setting as the default. if (defined $_default_strictness) { $strictness = $_default_strictness; $strictness_name = $_default_strictness_name; } else { $_default_strictness = $strictness; $_default_strictness_name = $strictness_name; } } =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 or C. Not that C should be used only when it is important to make sure an option hasn't been set locally. Otherwise C