automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Automake::Options


From: Alexandre Duret-Lutz
Subject: Automake::Options
Date: Thu, 07 Aug 2003 01:23:20 +0200
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux)

>>> "adl" == Alexandre Duret-Lutz <address@hidden> writes:

 adl> I'm (slowly) working on getting the %target_* machinery in
 adl> its own packages, Automake::Rule/Automake::RuleDef, like
 adl> Automake::Variable/Automake::VarDef.  (both share a few
 adl> functions via Automake::Item/Automake::ItemDef base
 adl> classes, suggestion for better names are welcome).

 adl> Doing this, I've discovered that the current
 adl> implementation of &rule_define (which should become
 adl> Automake::Rule::define) checks for $options{'no-exeext'}.
 adl> Ooops, %options need to be available to packages.

 adl> In a second tree I'm therefore working on getting all the
 adl> %options machinery in its own Automake::Options package.
 adl> This includes functions such as process_option_list.

Here is a patch for this.  make check is running.

2003-08-07  Alexandre Duret-Lutz  <address@hidden>

        * lib/Automake/Options.pm: New file.
        * lib/Automake/Makefile.am (dist_perllib_DATA): Add Options.pm.
        * automake.in (FOREIGN, GNU, GNITS, $default_strictness)
        ($default_strictness_name, $strictness, $strictness_name)
        (%options, %global_options, process_option_list)
        (set_strictness): Remove, now in Options.pm.
        (initialize_per_input): Call Automake::Options::reset.
        (handle_options, get_object_extension, get_object_extension)
        (handle_languages, handle_single_transform_list, handle_compile)
        (handle_texinfo_helper, handle_man_pages, handle_dist)
        (handle_configure, do_check_merge_target)
        (handle_factored_dependencies, handle_tests)
        (handle_minor_options, scan_autoconf_traces, check_cygnus)
        (lang_sub_obj, lang_c_rewrite, lang_c_finish, rule_define)
        (make_paragraphs, am_install_var, parse_arguments): Adjust
        to set and read options via the new interface.

Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1494
diff -u -r1.1494 automake.in
--- automake.in 6 Aug 2003 21:20:15 -0000       1.1494
+++ automake.in 6 Aug 2003 23:21:24 -0000
@@ -131,6 +131,7 @@
 use Automake::Location;
 use Automake::Condition qw/TRUE FALSE/;
 use Automake::DisjConditions;
+use Automake::Options;
 use Automake::Version;
 use Automake::Variable;
 use Automake::VarDef;
@@ -193,11 +194,6 @@
 my $EXEC_DIR_PATTERN =
   '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)' . "\$";
 
-# Constants to define the "strictness" level.
-use constant FOREIGN => 0;
-use constant GNU     => 1;
-use constant GNITS   => 2;
-
 # Values for AC_CANONICAL_*
 use constant AC_CANONICAL_HOST   => 1;
 use constant AC_CANONICAL_SYSTEM => 2;
@@ -276,12 +272,6 @@
 # TRUE if we should always generate Makefile.in.
 my $force_generation = 1;
 
-# Strictness level as set on command line.
-my $default_strictness = GNU;
-
-# Name of strictness level, as set on command line.
-my $default_strictness_name = 'gnu';
-
 # From the Perl manual.
 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
 
@@ -557,16 +547,6 @@
 # All .P files.
 my %dep_files;
 
-# Strictness levels.
-my $strictness;
-my $strictness_name;
-
-# Automake options.
-# Values are the Automake::Location of the definition, except
-# for 'ansi2knr' whose value is a pair [filename, Location].
-my %options;                   # From AUTOMAKE_OPTIONS
-my %global_options;            # From AM_INIT_AUTOMAKE or the command line.
-
 # This is a list of all targets to run during "make dist".
 my @dist_targets;
 
@@ -693,7 +673,8 @@
 
     @suffixes = ();
 
-    Automake::Variable::reset ();
+    Automake::Options::reset;
+    Automake::Variable::reset;
 
     %targets = ();
     %target_source = ();
@@ -768,11 +749,6 @@
 
     %dep_files = ();
 
-    $strictness = $default_strictness;
-    $strictness_name = $default_strictness_name;
-
-    %options = ();
-
     @dist_targets = ();
 
     %de_ansi_files = ();
@@ -1154,81 +1130,15 @@
 
 ################################################################
 
-# $BOOL
-# process_option_list (\%OPTIONS, $WHERE, @OPTIONS)
-# -------------------------------------------------
-# Process a list of options.  Return 1 on error, 0 otherwise.
-# \%OPTIONS is the hash to fill with options data, $WHERE is
-# the location where @OPTIONS occured.
-sub process_option_list (\%$@)
-{
-  my ($options, $where, @list) = @_;
-
-  foreach (@list)
-    {
-      $options->{$_} = $where;
-      if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
-       {
-         &set_strictness ($_);
-       }
-      elsif (/^(.*\/)?ansi2knr$/)
-       {
-         # An option like "../lib/ansi2knr" is allowed.  With no
-         # path prefix, we assume the required programs are in this
-         # directory.  We save the actual option for later.
-         $options->{'ansi2knr'} = [$_, $where];
-       }
-      elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
-            || $_ eq 'dist-shar' || $_ eq 'dist-zip'
-            || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
-            || $_ eq 'no-dist-gzip'
-            || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
-            || $_ eq 'readme-alpha' || $_ eq 'check-news'
-            || $_ eq 'subdir-objects' || $_ eq 'nostdinc'
-            || $_ eq 'no-exeext' || $_ eq 'no-define'
-            || $_ eq 'std-options'
-            || $_ eq 'cygnus' || $_ eq 'no-dependencies')
-       {
-         # Explicitly recognize these.
-       }
-      elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/)
-       {
-         # Got a version number.
-         if (Automake::Version::check ($VERSION, $&))
-           {
-             error ($where, "require Automake $_, but have $VERSION",
-                    uniq_scope => US_GLOBAL);
-               return 1;
-           }
-       }
-      elsif (/^(?:--warnings=|-W)(.*)$/)
-       {
-         foreach my $cat (split (',', $1))
-           {
-             msg 'unsupported', $where, "unknown warning category `$cat'"
-               if switch_warning $cat;
-           }
-       }
-      else
-       {
-         error ($where, "option `$_' not recognized",
-                uniq_scope => US_GLOBAL);
-         return 1;
-       }
-    }
-}
 
 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
 sub handle_options
 {
-  %options = %global_options;
-
   my $var = var ('AUTOMAKE_OPTIONS');
   if ($var)
     {
       # FIXME: We should disallow conditional definitions of AUTOMAKE_OPTIONS.
-      if (process_option_list (%options,
-                              $var->rdef (TRUE)->location,
+      if (process_option_list ($var->rdef (TRUE)->location,
                               $var->value_as_list_recursive (TRUE)))
        {
          return 1;
@@ -1237,9 +1147,9 @@
 
   if ($strictness == GNITS)
     {
-      $options{'readme-alpha'} = 1;
-      $options{'std-options'} = 1;
-      $options{'check-news'} = 1;
+      set_option ('readme-alpha', INTERNAL);
+      set_option ('std-options', INTERNAL);
+      set_option ('check-news', INTERNAL);
     }
 
   return 0;
@@ -1260,7 +1170,7 @@
 
     # Check for automatic de-ANSI-fication.
     $extension = '$U' . $extension
-      if $options{'ansi2knr'};
+      if option 'ansi2knr';
 
     $get_object_extension_was_run = 1;
 
@@ -1271,7 +1181,7 @@
 # Call finish function for each language that was used.
 sub handle_languages
 {
-    if (! $options{'no-dependencies'})
+    if (! option 'no-dependencies')
     {
        # Include auto-dep code.  Don't include it if DEP_FILES would
        # be empty.
@@ -1339,7 +1249,7 @@
        my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
 
        my ($AMDEP, $FASTDEP) =
-         ($options{'no-dependencies'} || $lang->autodep eq 'no')
+         (option 'no-dependencies' || $lang->autodep eq 'no')
          ? ('FALSE', 'FALSE') : ('AMDEP', "am__fastdep$fpfx");
 
        my %transform = ('EXT'     => $ext,
@@ -1352,7 +1262,7 @@
                                   => (count_files_for_language ($lang->name) > 
1));
 
        # Generate the appropriate rules for this extension.
-       if (((! $options{'no-dependencies'}) && $lang->autodep ne 'no')
+       if (((! option 'no-dependencies') && $lang->autodep ne 'no')
            || defined $lang->compile)
        {
            # Some C compilers don't support -c -o.  Use it only if really
@@ -1361,7 +1271,7 @@
            $output_flag = '-o'
              if (! $output_flag
                  && $lang->name eq 'c'
-                 && $options{'subdir-objects'});
+                 && option 'subdir-objects');
 
            # Compute a possible derived extension.
            # This is not used by depend2.am.
@@ -1823,7 +1733,7 @@
                 my $obj_sans_ext = substr ($object, 0,
                                           - length ($this_obj_ext));
                my $full_ansi = $full;
-               if ($lang->ansi && $options{'ansi2knr'})
+               if ($lang->ansi && option 'ansi2knr')
                  {
                    $full_ansi =~ s/$KNOWN_EXTENSIONS_PATTERN$/\$U$&/;
                    $obj_sans_ext .= '$U';
@@ -1956,7 +1866,7 @@
                 # .deps directory is created.
                push (@dep_list,
                      require_build_directory ($directory . '/$(DEPDIR)'))
-                 unless $options{'no-dependencies'};
+                 unless option 'no-dependencies';
             }
 
             &pretty_print_rule ($object . ':', "\t", @dep_list)
@@ -2287,7 +2197,7 @@
 
     # Boilerplate.
     my $default_includes = '';
-    if (! $options{'nostdinc'})
+    if (! option 'nostdinc')
       {
        $default_includes = ' -I. -I$(srcdir)';
 
@@ -2328,9 +2238,9 @@
     $output_rules .= "$coms$rules";
 
     # Check for automatic de-ANSI-fication.
-    if ($options{'ansi2knr'})
+    if (option 'ansi2knr')
       {
-       my ($ansi2knr_filename, $ansi2knr_where) = @{$options{'ansi2knr'}};
+       my ($ansi2knr_filename, $ansi2knr_where) = @{option 'ansi2knr'};
        my $ansi2knr_dir = '';
 
        require_variables ($ansi2knr_where, "option `ansi2knr' is used",
@@ -3065,7 +2975,7 @@
       $texinfodir = ('$(srcdir)/'
                     . dirname (variable_value ('TEXINFO_TEX')));
     }
-  elsif ($options{'cygnus'})
+  elsif (option 'cygnus')
     {
       $texinfodir = '$(top_srcdir)/../texinfo';
       define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex", INTERNAL);
@@ -3085,7 +2995,7 @@
 
   push (@dist_targets, 'dist-info');
 
-  if (! $options{'no-installinfo'})
+  if (! option 'no-installinfo')
     {
       # Make sure documentation is made and installed first.  Use
       # $(INFO_DEPS), not 'info', because otherwise recursive makes
@@ -3107,7 +3017,7 @@
   # Do some error checking.  Note that this file is not required
   # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
   # up above.
-  if ($need_texi_file && ! $options{'no-texinfo.tex'})
+  if ($need_texi_file && ! option 'no-texinfo.tex')
     {
       if ($need_texi_file > 1)
        {
@@ -3212,7 +3122,7 @@
                                 MANS => "@mans");
 
   push (@all, '$(MANS)')
-    unless $options{'no-installman'};
+    unless option 'no-installman';
 }
 
 # Handle DATA variables.
@@ -3332,15 +3242,15 @@
 
   # `make dist' isn't used in a Cygnus-style tree.
   # Omit the rules so that people don't try to use them.
-  return if $options{'cygnus'};
+  return if option 'cygnus';
 
   # At least one of the archive formats must be enabled.
   if ($relative_dir eq '.')
     {
-      my $archive_defined = $options{'no-dist-gzip'} ? 0 : 1;
+      my $archive_defined = option 'no-dist-gzip' ? 0 : 1;
       $archive_defined ||=
-       grep { $options{"dist-$_"} } ('shar', 'zip', 'tarZ', 'bzip2');
-      error ($options{'no-dist-gzip'},
+       grep { option "dist-$_" } ('shar', 'zip', 'tarZ', 'bzip2');
+      error (option 'no-dist-gzip',
             "no-dist-gzip specified but no dist-* specified, "
             . "at least one archive format must be enabled")
        unless $archive_defined;
@@ -3672,9 +3582,9 @@
      'MAKEFILE-IN'         => $infile,
      'MAKEFILE-IN-DEPS'    => "@include_stack",
      'MAKEFILE-AM'         => $amfile,
-     STRICTNESS            => $global_options{'cygnus'}
+     STRICTNESS            => global_option 'cygnus'
                                 ? 'cygnus' : $strictness_name,
-     'USE-DEPS'            => $global_options{'no-dependencies'}
+     'USE-DEPS'            => global_option 'no-dependencies'
                                 ? ' --ignore-deps' : '',
      'MAKEFILE-AM-SOURCES' =>  "$input$colon_infile",
      'REGEN-ACLOCAL-M4'    => $regen_aclocal_m4,
@@ -4134,7 +4044,7 @@
     }
 
   # In --cygnus mode, check doesn't depend on all.
-  if ($options{'cygnus'})
+  if (option 'cygnus')
     {
       # Just run the local check rules.
       pretty_print_rule ('check-am:', "\t\t", @check);
@@ -4246,7 +4156,7 @@
   reject_target ('install-info-local',
                 "`install-info-local' target defined but "
                 . "`no-installinfo' option not in use")
-    unless $options{'no-installinfo'};
+    unless option 'no-installinfo';
 
   # Install the -local hooks.
   foreach (keys %dependencies)
@@ -4321,7 +4231,7 @@
 # Handle TESTS variable and other checks.
 sub handle_tests
 {
-  if ($options{'dejagnu'})
+  if (option 'dejagnu')
     {
       &handle_tests_dejagnu;
     }
@@ -4416,7 +4326,7 @@
 # Handle some of the minor options.
 sub handle_minor_options
 {
-  if ($options{'readme-alpha'})
+  if (option 'readme-alpha')
     {
       if ($relative_dir eq '.')
        {
@@ -4644,8 +4554,8 @@
          elsif (defined $args[1])
            {
              exit $exit_code
-               if (process_option_list (%global_options, $where,
-                                        split (' ', $args[1])));
+               if (process_global_option_list ($where,
+                                               split (' ', $args[1])));
            }
        }
       elsif ($macro eq 'AM_MAINTAINER_MODE')
@@ -4744,11 +4654,12 @@
 # Set up for Cygnus mode.
 sub check_cygnus
 {
-  return unless $options{'cygnus'};
+  my $cygnus = option 'cygnus';
+  return unless $cygnus;
 
-  &set_strictness ('foreign');
-  $options{'no-installinfo'} = $options{'cygnus'};
-  $options{'no-dependencies'} = $options{'cygnus'};
+  set_strictness ('foreign');
+  set_option ('no-installinfo', $cygnus);
+  set_option ('no-dependencies', $cygnus);
 
   err_ac "`AM_MAINTAINER_MODE' required when --cygnus specified"
     if !$seen_maint_mode;
@@ -4773,9 +4684,9 @@
 
   for my $opt ('no-installman', 'no-installinfo')
     {
-      msg ('error-gnu', $options{$opt},
+      msg ('error-gnu', option $opt,
           "option `$opt' disallowed by GNU standards")
-       if $options{$opt};
+       if option $opt;
     }
 }
 
@@ -4808,7 +4719,7 @@
 # when a subdir object should be used.
 sub lang_sub_obj
 {
-    return $options{'subdir-objects'} ? LANG_SUBDIR : LANG_PROCESS;
+    return option 'subdir-objects' ? LANG_SUBDIR : LANG_PROCESS;
 }
 
 # Rewrite a single C source file.
@@ -4816,14 +4727,14 @@
 {
   my ($directory, $base, $ext) = @_;
 
-  if ($options{'ansi2knr'} && $base =~ /_$/)
+  if (option 'ansi2knr' && $base =~ /_$/)
     {
       # FIXME: include line number in error.
       err_am "C source file `$base.c' would be deleted by ansi2knr rules";
     }
 
   my $r = LANG_PROCESS;
-  if ($options{'subdir-objects'})
+  if (option 'subdir-objects')
     {
       $r = LANG_SUBDIR;
       $base = $directory . '/' . $base
@@ -4957,7 +4868,7 @@
        }
     }
 
-    if ($options{'ansi2knr'} && keys %de_ansi_files)
+    if (option 'ansi2knr' && keys %de_ansi_files)
     {
        # Make all _.c files depend on their corresponding .c files.
        my @objects;
@@ -5570,7 +5481,7 @@
       && $target_name{$noexe}{$cond} ne $target)
     {
       # The no-exeext option enables this feature.
-      if (! $options{'no-exeext'})
+      if (! option 'no-exeext')
        {
          msg ('obsolete', $targets{$noexe}{$cond},
               "deprecated feature: target `$noexe' overrides "
@@ -6169,19 +6080,19 @@
   my $command =
     "s/$IGNORE_PATTERN//gm;"
     . transform (%transform,
-                'CYGNUS'      => defined $options{'cygnus'},
+                'CYGNUS'      => !! option 'cygnus',
                 'MAINTAINER-MODE'
                 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
 
-                'BZIP2'       => $options{'dist-bzip2'} || 0,
-                'COMPRESS'    => $options{'dist-tarZ'} || 0,
-                'GZIP'        => $options{'no-dist-gzip'} ? 0 : 1,
-                'SHAR'        => $options{'dist-shar'} || 0,
-                'ZIP'         => $options{'dist-zip'} || 0,
-
-                'INSTALL-INFO' => !$options{'no-installinfo'},
-                'INSTALL-MAN'  => !$options{'no-installman'},
-                'CK-NEWS'      => $options{'check-news'} || 0,
+                'BZIP2'       => !! option 'dist-bzip2',
+                'COMPRESS'    => !! option 'dist-tarZ',
+                'GZIP'        =>  ! option 'no-dist-gzip',
+                'SHAR'        => !! option 'dist-shar',
+                'ZIP'         => !! option 'dist-zip',
+
+                'INSTALL-INFO' =>  ! option 'no-installinfo',
+                'INSTALL-MAN'  =>  ! option 'no-installman',
+                'CK-NEWS'      => !! option 'check-news',
 
                 'SUBDIRS'      => !! var ('SUBDIRS'),
                 'TOPDIR'       => backname ($relative_dir),
@@ -6736,8 +6647,7 @@
       # If so, with install-exec? (or install-data?).
       my $exec_p = ($nodir_name =~ /$EXEC_DIR_PATTERN/o);
 
-      my $check_options_p = $install_p
-       && defined $options{'std-options'};
+      my $check_options_p = $install_p && !! option 'std-options';
 
       # Use the location of the currently processed variable as context.
       $where->push_context ("while processing `$one_name'");
@@ -7296,30 +7206,6 @@
 ################################################################
 
 
-# Set strictness.
-sub set_strictness
-{
-  $strictness_name = $_[0];
-
-  Automake::ChannelDefs::set_strictness ($strictness_name);
-
-  if ($strictness_name eq 'gnu')
-    {
-      $strictness = GNU;
-    }
-  elsif ($strictness_name eq 'gnits')
-    {
-      $strictness = GNITS;
-    }
-  elsif ($strictness_name eq 'foreign')
-    {
-      $strictness = FOREIGN;
-    }
-  else
-    {
-      prog_error "level `$strictness_name' not recognized\n";
-    }
-}
 
 
 ################################################################
@@ -7441,11 +7327,11 @@
      'libdir:s'        => \$libdir,
      'gnu'             => sub { set_strictness ('gnu'); },
      'gnits'           => sub { set_strictness ('gnits'); },
-     'cygnus'          => sub { $global_options{'cygnus'} = $cli_where; },
+     'cygnus'          => sub { set_global_option ('cygnus', $cli_where); },
      'foreign'          => sub { set_strictness ('foreign'); },
-     'include-deps'    => sub { delete $global_options{'no-dependencies'}; },
-     'i|ignore-deps'   => sub { $global_options{'no-dependencies'}
-                                = $cli_where; },
+     'include-deps'    => sub { unset_global_option ('no-dependencies'); },
+     'i|ignore-deps'   => sub { set_global_option ('no-dependencies',
+                                                   $cli_where); },
      'no-force'        => sub { $force_generation = 0; },
      'f|force-missing'  => \$force_missing,
      'o|output-dir:s'  => \$output_directory,
@@ -7522,10 +7408,6 @@
       push (@input_files, $input);
       $output_files{$input} = join (':', ($local, @rest));
     }
-
-  # Take global strictness from whatever we currently have set.
-  $default_strictness = $strictness;
-  $default_strictness_name = $strictness_name;
 }
 
 ################################################################
Index: lib/Automake/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/Makefile.am,v
retrieving revision 1.16
diff -u -r1.16 Makefile.am
--- lib/Automake/Makefile.am    6 Aug 2003 21:20:15 -0000       1.16
+++ lib/Automake/Makefile.am    6 Aug 2003 23:21:24 -0000
@@ -29,6 +29,7 @@
   FileUtils.pm \
   General.pm \
   Location.pm \
+  Options.pm \
   Struct.pm \
   Variable.pm \
   VarDef.pm \
Index: lib/Automake/Options.pm
===================================================================
RCS file: lib/Automake/Options.pm
diff -N lib/Automake/Options.pm
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/Automake/Options.pm     6 Aug 2003 23:21:25 -0000
@@ -0,0 +1,363 @@
+# Copyright (C) 2003  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);
+
address@hidden = qw (Exporter);
address@hidden = 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<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
+
+# 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<FOREIGN>, C<GNU>, or C<GNITS>.
+
+=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<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
+
+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<set_option> or C<set_global_option>.
+
+Not 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
+
+sub option ($)
+{
+  my ($name) = @_;
+  return () unless defined $_options{$name};
+  return $_options{$name};
+}
+
+sub global_option ($)
+{
+  my ($name) = @_;
+  return () unless defined $_global_options{$name};
+  return $_global_options{$name};
+}
+
+=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
+
+sub set_option ($$)
+{
+  my ($name, $value) = @_;
+  $_options{$name} = $value;
+}
+
+sub set_global_option ($$)
+{
+  my ($name, $value) = @_;
+  $_global_options{$name} = $value;
+}
+
+
+=item C<unset_option ($name)>
+
+=item C<unset_global_option ($name)>
+
+Unset an option.
+
+=cut
+
+sub unset_option ($)
+{
+  my ($name) = @_;
+  delete $_options{$name};
+}
+
+sub unset_global_option ($)
+{
+  my ($name) = @_;
+  delete $_global_options{$name};
+}
+
+
+=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
+
+# $BOOL
+# _process_option_list (\%OPTIONS, $WHERE, @OPTIONS)
+# -------------------------------------------------
+# Process a list of options.  Return 1 on error, 0 otherwise.
+# \%OPTIONS is the hash to fill with options data, $WHERE is
+# the location where @OPTIONS occured.
+sub _process_option_list (\%$@)
+{
+  my ($options, $where, @list) = @_;
+
+  foreach (@list)
+    {
+      $options->{$_} = $where;
+      if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
+       {
+         set_strictness ($_);
+       }
+      elsif (/^(.*\/)?ansi2knr$/)
+       {
+         # An option like "../lib/ansi2knr" is allowed.  With no
+         # path prefix, we assume the required programs are in this
+         # directory.  We save the actual option for later.
+         $options->{'ansi2knr'} = [$_, $where];
+       }
+      elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
+            || $_ eq 'dist-shar' || $_ eq 'dist-zip'
+            || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
+            || $_ eq 'no-dist-gzip'
+            || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
+            || $_ eq 'readme-alpha' || $_ eq 'check-news'
+            || $_ eq 'subdir-objects' || $_ eq 'nostdinc'
+            || $_ eq 'no-exeext' || $_ eq 'no-define'
+            || $_ eq 'std-options'
+            || $_ eq 'cygnus' || $_ eq 'no-dependencies')
+       {
+         # Explicitly recognize these.
+       }
+      elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/)
+       {
+         # Got a version number.
+         if (Automake::Version::check ($VERSION, $&))
+           {
+             error ($where, "require Automake $_, but have $VERSION",
+                    uniq_scope => US_GLOBAL);
+             return 1;
+           }
+       }
+      elsif (/^(?:--warnings=|-W)(.*)$/)
+       {
+         foreach my $cat (split (',', $1))
+           {
+             msg 'unsupported', $where, "unknown warning category `$cat'"
+               if switch_warning $cat;
+           }
+       }
+      else
+       {
+         error ($where, "option `$_' not recognized",
+                uniq_scope => US_GLOBAL);
+         return 1;
+       }
+    }
+  return 0;
+}
+
+sub process_option_list ($@)
+{
+  my ($where, @list) = @_;
+  return _process_option_list (%_options, $where, @list);
+}
+
+sub process_global_option_list ($@)
+{
+  my ($where, @list) = @_;
+  return _process_option_list (%_global_options, $where, @list);
+}
+
+=item C<set_strictness ($name)>
+
+Set the current strictness level.
+C<$name> should be one of C<'foreign'>, C<'gnu'>, or C<'gnits'>.
+
+=cut
+
+# Set strictness.
+sub set_strictness ($)
+{
+  $strictness_name = $_[0];
+
+  Automake::ChannelDefs::set_strictness ($strictness_name);
+
+  if ($strictness_name eq 'gnu')
+    {
+      $strictness = GNU;
+    }
+  elsif ($strictness_name eq 'gnits')
+    {
+      $strictness = GNITS;
+    }
+  elsif ($strictness_name eq 'foreign')
+    {
+      $strictness = FOREIGN;
+    }
+  else
+    {
+      prog_error "level `$strictness_name' not recognized\n";
+    }
+}
+
+1;
+
+### Setup "GNU" style for perl-mode and cperl-mode.
+## Local Variables:
+## perl-indent-level: 2
+## perl-continued-statement-offset: 2
+## perl-continued-brace-offset: 0
+## perl-brace-offset: 0
+## perl-brace-imaginary-offset: 0
+## perl-label-offset: -2
+## cperl-indent-level: 2
+## cperl-brace-offset: 0
+## cperl-continued-brace-offset: 0
+## cperl-label-offset: -2
+## cperl-extra-newline-before-brace: t
+## cperl-merge-trailing-else: nil
+## cperl-continued-statement-offset: 2
+## End:
-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]