automake-patches
[Top][All Lists]
Advanced

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

FYI: 2/ move "main" to the end


From: Alexandre Duret-Lutz
Subject: FYI: 2/ move "main" to the end
Date: Thu, 22 May 2003 19:48:21 +0200
User-agent: Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.3 (gnu/linux)

This moves the "main" code to the end of the file.  This has
a few advantages
  - the "main" code is more easily found at the end of the file than in
    the middle
  - using functions after they are declared allows prototype checking
  - we can run some code (initialization of variables local to a
    group of function, hook registration, ...) between functions
    definitions.  In the past I've often be written such code and
    wondered why it wasn't executed, I've only realized these days
    that was because it this code was located after the "main".

(I will register &var_SUFFIXES_trigger as a hook in the variable code.)

This also removes the last `local' from Automake, but I still haven't
understood why I must write 

|  foreach my $file (@input_files)
|    {
|      $am_file = $file;

instead of just

|  foreach $am_file (@input_files)
|    {

:(

2003-05-22  Alexandre Duret-Lutz  <address@hidden>

        * automake.in: Move the "main" code at the end.
        (parse_arguments): Move near the end.
        ($KNOWN_EXTENSIONS_PATTERN, @known_extensions_list,
        accept_extensions, var_SUFFIXES_trigger): Move these definitions
        before any call to register_language.
        (am_file): Move the definition with all other global variables,
        do not use local to define it.
        * Makefile.am (maintainer-check): Expect no `local' in Automake.

Index: Makefile.am
===================================================================
RCS file: /cvs/automake/automake/Makefile.am,v
retrieving revision 1.213
diff -u -r1.213 Makefile.am
--- Makefile.am 19 Mar 2003 21:14:56 -0000      1.213
+++ Makefile.am 22 May 2003 16:25:09 -0000
@@ -159,22 +159,12 @@
          echo "Don't use \`local' with parens: use several \`local' above." 
>&2; \
          exit 1; \
        fi
-## Up to now we manage to limit to 1 use of local, but for `local $_;'.
-       @locals=`grep -v '^[ \t]*local \$$_;' $(srcdir)/automake.in | \
-               grep -c '^[ \t]*local [^*]'`; \
-       case $$locals in \
-         [0] ) \
-           echo "Wow, congrats!  There are no \`local' now!." >&2; \
-           echo "Please update Makefile.am (maintainer-check)." >&2; \
-           exit 1; \
-         ;; \
-         1 ) ;; \
-         * ) \
-           echo "Too many \`local'!  Are you sure you need $$locals of them?" 
>&2; \
-           echo "Up to now 1 was enough." >&2; \
-           exit 1; \
-         ;; \
-       esac
+## Allow only `local $_' in Automake.
+       @if grep -v '^[ \t]*local \$$_;' $(srcdir)/automake.in | \
+               grep '^[ \t]*local [^*]'; then \
+         echo "Please avoid \`local'." 1>&2; \
+         exit 1; \
+       fi
 ## Don't let AMDEP_TRUE substitution appear in automake.in.
        @if grep '@AMDEP''_TRUE@' $(srcdir)/automake.in; then \
          echo "Don't put AMDEP_TRUE substitution in automake.in" 1>&2; \
Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1457
diff -u -r1.1457 automake.in
--- automake.in 21 May 2003 20:30:06 -0000      1.1457
+++ automake.in 22 May 2003 16:25:17 -0000
@@ -487,6 +487,9 @@
 # been checked for.  This variable is local to the "require file"
 # functions.
 my %require_file_found = ();
+
+# The name of the Makefile currently being processed.
+my $am_file = 'BUG';
 
 
 ################################################################
@@ -717,6 +720,41 @@
 # the named of the helper variable used to append to VAR in CONDITIONS.
 my %appendvar = ();
 
+################################################################
+
+# Pattern that matches all know input extensions (i.e. extensions used
+# by the languages supported by Automake).  Using this pattern
+# (instead of `\..*$') to match extensions allows Automake to support
+# dot-less extensions.
+my $KNOWN_EXTENSIONS_PATTERN = "";
+my @known_extensions_list = ();
+
+# accept_extensions (@EXTS)
+# -------------------------
+# Update $KNOWN_EXTENSIONS_PATTERN to recognize the extensions
+# listed @EXTS.  Extensions should contain a dot if needed.
+sub accept_extensions (@)
+{
+    push @known_extensions_list, @_;
+    $KNOWN_EXTENSIONS_PATTERN =
+       '(?:' . join ('|', map (quotemeta, @known_extensions_list)) . ')';
+}
+
+# var_SUFFIXES_trigger ($TYPE, $VALUE)
+# ------------------------------------
+# This is called automagically by macro_define() when SUFFIXES
+# is defined ($TYPE eq '') or appended ($TYPE eq '+').
+# The work here needs to be performed as a side-effect of the
+# macro_define() call because SUFFIXES definitions impact
+# on $KNOWN_EXTENSIONS_PATTERN, and $KNOWN_EXTENSIONS_PATTERN
+# are used when parsing the input am file.
+sub var_SUFFIXES_trigger ($$)
+{
+    my ($type, $value) = @_;
+    accept_extensions (split (' ', $value));
+}
+
+################################################################
 
 ## --------------------------------- ##
 ## Forward subroutine declarations.  ##
@@ -1092,53 +1130,6 @@
 
 ################################################################
 
-# Parse the WARNINGS environment variable.
-&parse_WARNINGS;
-
-# Parse command line.
-&parse_arguments;
-
-# Do configure.ac scan only once.
-&scan_autoconf_files;
-
-&fatal ("no `Makefile.am' found or specified\n")
-  if ! @input_files;
-
-my $automake_has_run = 0;
-
-do
-{
-  if ($automake_has_run)
-    {
-      &verb ('processing Makefiles another time to fix them up.');
-      &prog_error ('running more than two times should never be needed.')
-       if $automake_has_run >= 2;
-    }
-  $automake_needs_to_reprocess_all_files = 0;
-
-  # Now do all the work on each file.
-  # This guy must be local otherwise it's private to the loop.
-  use vars '$am_file';
-  local $am_file;
-  foreach $am_file (@input_files)
-    {
-      if (! -f ($am_file . '.am'))
-       {
-         &error ("`$am_file.am' does not exist");
-       }
-      else
-       {
-         &generate_makefile ($output_files{$am_file}, $am_file);
-       }
-    }
-  ++$automake_has_run;
-}
-while ($automake_needs_to_reprocess_all_files);
-
-exit $exit_code;
-
-################################################################
-
 # Error reporting functions.
 
 # err_var ($VARNAME, $MESSAGE, [%OPTIONS])
@@ -1311,141 +1302,6 @@
 
 ################################################################
 
-# Pattern that matches all know input extensions (i.e. extensions used
-# by the languages supported by Automake).  Using this pattern
-# (instead of `\..*$') to match extensions allows Automake to support
-# dot-less extensions.
-my $KNOWN_EXTENSIONS_PATTERN = "";
-my @known_extensions_list = ();
-
-# accept_extensions (@EXTS)
-# -------------------------
-# Update $KNOWN_EXTENSIONS_PATTERN to recognize the extensions
-# listed @EXTS.  Extensions should contain a dot if needed.
-sub accept_extensions (@)
-{
-    push @known_extensions_list, @_;
-    $KNOWN_EXTENSIONS_PATTERN =
-       '(?:' . join ('|', map (quotemeta, @known_extensions_list)) . ')';
-}
-
-# var_SUFFIXES_trigger ($TYPE, $VALUE)
-# ------------------------------------
-# This is called automagically by macro_define() when SUFFIXES
-# is defined ($TYPE eq '') or appended ($TYPE eq '+').
-# The work here needs to be performed as a side-effect of the
-# macro_define() call because SUFFIXES definitions impact
-# on $KNOWN_EXTENSIONS_PATTERN, and $KNOWN_EXTENSIONS_PATTERN
-# are used when parsing the input am file.
-sub var_SUFFIXES_trigger ($$)
-{
-    my ($type, $value) = @_;
-    accept_extensions (split (' ', $value));
-}
-
-################################################################
-
-
-# Parse command line.
-sub parse_arguments ()
-{
-  # Start off as gnu.
-  &set_strictness ('gnu');
-
-  my %options =
-    (
-     'libdir:s'        => \$libdir,
-     'gnu'             => sub { &set_strictness ('gnu'); },
-     'gnits'           => sub { &set_strictness ('gnits'); },
-     'cygnus'          => \$cygnus_mode,
-     'foreign'                 => sub { &set_strictness ('foreign'); },
-     'include-deps'    => sub { $cmdline_use_dependencies = 1; },
-     'i|ignore-deps'   => sub { $cmdline_use_dependencies = 0; },
-     'no-force'        => sub { $force_generation = 0; },
-     'f|force-missing'  => \$force_missing,
-     'o|output-dir:s'  => \$output_directory,
-     'a|add-missing'   => \$add_missing,
-     'c|copy'          => \$copy_missing,
-     'v|verbose'       => sub { setup_channel 'verb', silent => 0; },
-     'W|warnings:s'     => \&parse_warnings,
-     # These long options (--Werror and --Wno-error) for backward
-     # compatibility.  Use -Werror and -Wno-error today.
-     'Werror'           => sub { parse_warnings 'W', 'error'; },
-     'Wno-error'        => sub { parse_warnings 'W', 'no-error'; },
-     );
-
-  use Getopt::Long;
-  Getopt::Long::config ("bundling", "pass_through");
-
-  # See if --version or --help is used.  We want to process these before
-  # anything else because the GNU Coding Standards require us to
-  # `exit 0' after processing these options, and we can't garanty this
-  # if we treat other options first.  (Handling other options first
-  # could produce error diagnostics, and in this condition it is
-  # confusing if Automake `exit 0'.)
-  my %options_1st_pass =
-    (
-     'version' => \&version,
-     'help'    => \&usage,
-     # Recognize all other options (and their arguments) but do nothing.
-     map { $_ => sub {} } (keys %options)
-     );
-  my @ARGV_backup = @ARGV;
-  Getopt::Long::GetOptions %options_1st_pass
-    or exit 1;
-  @ARGV = @ARGV_backup;
-
-  # Now *really* process the options.  This time we know
-  # that --help and --version are not present.
-  Getopt::Long::GetOptions %options
-    or exit 1;
-
-  if (defined $output_directory)
-    {
-      msg 'obsolete', "`--output-dir' is deprecated\n";
-    }
-  else
-    {
-      # In the next release we'll remove this entirely.
-      $output_directory = '.';
-    }
-
-  foreach my $arg (@ARGV)
-    {
-      if ($arg =~ /^-./)
-       {
-         fatal ("unrecognized option `$arg'\n"
-                . "Try `$0 --help' for more information.");
-       }
-
-      # Handle $local:$input syntax.  Note that we only examine the
-      # first ":" file to see if it is automake input; the rest are
-      # just taken verbatim.  We still keep all the files around for
-      # dependency checking, however.
-      my ($local, $input, @rest) = split (/:/, $arg);
-      if (! $input)
-       {
-         $input = $local;
-       }
-      else
-       {
-         # Strip .in; later on .am is tacked on.  That is how the
-         # automake input file is found.  Maybe not the best way, but
-         # it is easy to explain.
-         $input =~ s/\.in$//
-           or fatal "invalid input file name `$arg'\n.";
-       }
-      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;
-}
-
-################################################################
-
 # Generate a Makefile.in given the name of the corresponding Makefile and
 # the name of the file output by config.status.
 sub generate_makefile
@@ -8833,6 +8689,151 @@
   # --version always returns 0 per GNU standards.
   exit 0;
 }
+
+################################################################
+
+# Parse command line.
+sub parse_arguments ()
+{
+  # Start off as gnu.
+  &set_strictness ('gnu');
+
+  my %options =
+    (
+     'libdir:s'        => \$libdir,
+     'gnu'             => sub { &set_strictness ('gnu'); },
+     'gnits'           => sub { &set_strictness ('gnits'); },
+     'cygnus'          => \$cygnus_mode,
+     'foreign'                 => sub { &set_strictness ('foreign'); },
+     'include-deps'    => sub { $cmdline_use_dependencies = 1; },
+     'i|ignore-deps'   => sub { $cmdline_use_dependencies = 0; },
+     'no-force'        => sub { $force_generation = 0; },
+     'f|force-missing'  => \$force_missing,
+     'o|output-dir:s'  => \$output_directory,
+     'a|add-missing'   => \$add_missing,
+     'c|copy'          => \$copy_missing,
+     'v|verbose'       => sub { setup_channel 'verb', silent => 0; },
+     'W|warnings:s'     => \&parse_warnings,
+     # These long options (--Werror and --Wno-error) for backward
+     # compatibility.  Use -Werror and -Wno-error today.
+     'Werror'           => sub { parse_warnings 'W', 'error'; },
+     'Wno-error'        => sub { parse_warnings 'W', 'no-error'; },
+     );
+  use Getopt::Long;
+  Getopt::Long::config ("bundling", "pass_through");
+
+  # See if --version or --help is used.  We want to process these before
+  # anything else because the GNU Coding Standards require us to
+  # `exit 0' after processing these options, and we can't garanty this
+  # if we treat other options first.  (Handling other options first
+  # could produce error diagnostics, and in this condition it is
+  # confusing if Automake `exit 0'.)
+  my %options_1st_pass =
+    (
+     'version' => \&version,
+     'help'    => \&usage,
+     # Recognize all other options (and their arguments) but do nothing.
+     map { $_ => sub {} } (keys %options)
+     );
+  my @ARGV_backup = @ARGV;
+  Getopt::Long::GetOptions %options_1st_pass
+    or exit 1;
+  @ARGV = @ARGV_backup;
+
+  # Now *really* process the options.  This time we know
+  # that --help and --version are not present.
+  Getopt::Long::GetOptions %options
+    or exit 1;
+
+  if (defined $output_directory)
+    {
+      msg 'obsolete', "`--output-dir' is deprecated\n";
+    }
+  else
+    {
+      # In the next release we'll remove this entirely.
+      $output_directory = '.';
+    }
+
+  foreach my $arg (@ARGV)
+    {
+      if ($arg =~ /^-./)
+       {
+         fatal ("unrecognized option `$arg'\n"
+                . "Try `$0 --help' for more information.");
+       }
+
+      # Handle $local:$input syntax.  Note that we only examine the
+      # first ":" file to see if it is automake input; the rest are
+      # just taken verbatim.  We still keep all the files around for
+      # dependency checking, however.
+      my ($local, $input, @rest) = split (/:/, $arg);
+      if (! $input)
+       {
+         $input = $local;
+       }
+      else
+       {
+         # Strip .in; later on .am is tacked on.  That is how the
+         # automake input file is found.  Maybe not the best way, but
+         # it is easy to explain.
+         $input =~ s/\.in$//
+           or fatal "invalid input file name `$arg'\n.";
+       }
+      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;
+}
+
+################################################################
+
+# Parse the WARNINGS environment variable.
+parse_WARNINGS;
+
+# Parse command line.
+parse_arguments;
+
+# Do configure.ac scan only once.
+scan_autoconf_files;
+
+fatal "no `Makefile.am' found or specified\n"
+  if ! @input_files;
+
+my $automake_has_run = 0;
+
+do
+{
+  if ($automake_has_run)
+    {
+      verb 'processing Makefiles another time to fix them up.';
+      prog_error 'running more than two times should never be needed.'
+       if $automake_has_run >= 2;
+    }
+  $automake_needs_to_reprocess_all_files = 0;
+
+  # Now do all the work on each file.
+  foreach my $file (@input_files)
+    {
+      $am_file = $file;
+      if (! -f ($am_file . '.am'))
+       {
+         error "`$am_file.am' does not exist";
+       }
+      else
+       {
+         generate_makefile ($output_files{$am_file}, $am_file);
+       }
+    }
+  ++$automake_has_run;
+}
+while ($automake_needs_to_reprocess_all_files);
+
+exit $exit_code;
+
 
 ### Setup "GNU" style for perl-mode and cperl-mode.
 ## Local Variables:

-- 
Alexandre Duret-Lutz





reply via email to

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