automake-patches
[Top][All Lists]
Advanced

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

[PATCH 2/4] build: auto-generate perl subroutines prototypes for automak


From: Stefano Lattarini
Subject: [PATCH 2/4] build: auto-generate perl subroutines prototypes for automake and aclocal
Date: Thu, 14 Feb 2013 13:43:21 +0100

This will allow us to avoid either using the '&foo' invocation form when
invoking a subroutine before its definition, or having to maintain the
list of prototypes by hand (with the risk of having it become incomplete
or fall out-of-sync when future edits to the automake and aclocal scripts
are done).

* Makefile.am (automake, aclocal): Automatically generate a list of
prototypes by looking at the subroutines definitions.
* bootstrap.sh: Likewise, when generating the temporary automake and
aclocal scripts used for bootstrapping.
* automake.in: Add a placeholder that will be tracked by the new recipes
and substituted with the computed prototypes.  Remove existing prototypes,
that are now superfluous. Some adjustments required by the new, more
comprehensive prototypes declarations.
* aclocal.in: Likewise.
* maintainer/syntax-checks.mk (sc_diff_automake, sc_diff_aclocal): Adjust.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 Makefile.am                 | 13 +++++++++----
 aclocal.in                  | 22 +---------------------
 automake.in                 | 18 +++++++++---------
 bootstrap.sh                | 11 ++++++-----
 lib/gen-perl-protos         | 36 ++++++++++++++++++++++++++++++++++++
 maintainer/syntax-checks.mk | 19 +++++++++++--------
 6 files changed, 72 insertions(+), 47 deletions(-)
 create mode 100755 lib/gen-perl-protos

diff --git a/Makefile.am b/Makefile.am
index c245369..2e05561 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -96,13 +96,18 @@ uninstall-hook:
 # $(datadir) or other do_subst'ituted variables change.
 automake: automake.in
 aclocal: aclocal.in
-automake aclocal: Makefile
-       $(AM_V_at)rm -f $@ address@hidden
-       $(AM_V_GEN)address@hidden; $(do_subst) <$(srcdir)/address@hidden 
>address@hidden
+automake aclocal: Makefile lib/gen-perl-protos
+       $(AM_V_GEN)rm -f $@ address@hidden address@hidden \
+## Common substitutions.
+         && address@hidden && $(do_subst) <$(srcdir)/$$in >address@hidden \
+## Auto-compute prototypes of perl subroutines.
+         && $(PERL) -w $(srcdir)/lib/gen-perl-protos address@hidden > 
address@hidden \
+         && mv -f address@hidden address@hidden \
 ## We can't use '$(generated_file_finalize)' here, because currently
 ## Automake contains occurrences of unexpanded @substitutions@ in
 ## comments, and that is perfectly legit.
-       $(AM_V_at)chmod a+x,a-w address@hidden && mv -f address@hidden $@
+         && chmod a+x,a-w address@hidden && mv -f address@hidden $@
+EXTRA_DIST += lib/gen-perl-protos
 
 # The master location for INSTALL is lib/INSTALL.
 # This is where "make fetch" will install new versions.
diff --git a/aclocal.in b/aclocal.in
index b51c09d..9e4ab79 100644
--- a/aclocal.in
+++ b/aclocal.in
@@ -169,27 +169,7 @@ my $erase_me;
 
 # Prototypes for all subroutines.
 
-sub unlink_tmp (;$);
-sub xmkdir_p ($);
-sub check_acinclude ();
-sub reset_maps ();
-sub install_file ($$);
-sub list_compare (address@hidden@);
-sub scan_m4_dirs ($$@);
-sub scan_m4_files ();
-sub add_macro ($);
-sub scan_configure_dep ($);
-sub add_file ($);
-sub scan_file ($$$);
-sub strip_redundant_includes (%);
-sub trace_used_macros ();
-sub scan_configure ();
-sub write_aclocal ($@);
-sub usage ($);
-sub version ();
-sub handle_acdir_option ($$);
-sub parse_arguments ();
-sub parse_ACLOCAL_PATH ();
+#! Prototypes here will automatically be generated by the build system.
 
 ################################################################
 
diff --git a/automake.in b/automake.in
index 5b57d3f..3e27843 100644
--- a/automake.in
+++ b/automake.in
@@ -76,6 +76,13 @@ use File::Basename;
 use File::Spec;
 use Carp;
 
+## ----------------------- ##
+## Subroutine prototypes.  ##
+## ----------------------- ##
+
+#! Prototypes here will automatically be generated by the build system.
+
+
 ## ----------- ##
 ## Constants.  ##
 ## ----------- ##
@@ -531,13 +538,6 @@ Automake::Variable::hook ('SUFFIXES', 
\&var_SUFFIXES_trigger);
 
 ################################################################
 
-## --------------------------------- ##
-## Forward subroutine declarations.  ##
-## --------------------------------- ##
-sub register_language (%);
-sub file_contents_internal ($$$%);
-sub define_files_variable (address@hidden);
-
 
 # &initialize_per_input ()
 # ------------------------
@@ -948,7 +948,7 @@ register_language ('name' => 'java',
 # Uncategorized errors about the current Makefile.am.
 sub err_am ($;%)
 {
-  msg_am ('error', @_);
+  msg_am ('error', shift, @_);
 }
 
 # err_ac ($MESSAGE, [%OPTIONS])
@@ -956,7 +956,7 @@ sub err_am ($;%)
 # Uncategorized errors about configure.ac.
 sub err_ac ($;%)
 {
-  msg_ac ('error', @_);
+  msg_ac ('error', shift, @_);
 }
 
 # msg_am ($CHANNEL, $MESSAGE, [%OPTIONS])
diff --git a/bootstrap.sh b/bootstrap.sh
index 93bf3fd..541280e 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -95,14 +95,15 @@ dosubst ()
 dosubst automake-$APIVERSION/Automake/Config.in \
         automake-$APIVERSION/Automake/Config.pm
 
-# Create temporary replacement for aclocal.
-dosubst aclocal.in aclocal.tmp
-
 # Overwrite amversion.m4.
 dosubst m4/amversion.in m4/amversion.m4
 
-# Create temporary replacement for automake.
-dosubst automake.in automake.tmp
+# Create temporary replacement for aclocal and automake.
+for p in aclocal automake; do
+  dosubst $p.in $p.tmp
+  $PERL -w lib/gen-perl-protos $p.tmp > $p.tmp2
+  mv -f $p.tmp2 $p.tmp
+done
 
 # Create required makefile snippets.
 $PERL ./gen-testsuite-part > t/testsuite-part.tmp
diff --git a/lib/gen-perl-protos b/lib/gen-perl-protos
new file mode 100755
index 0000000..9e73d8d
--- /dev/null
+++ b/lib/gen-perl-protos
@@ -0,0 +1,36 @@
+#!/usr/bin/env perl
+#
+# Copyright (C) 2013 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 3, 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, see <http://www.gnu.org/licenses/>.
+
+use warnings;
+use strict;
+
+my @lines = <>;
+my @protos = map { /^(sub \w+\s*\(.*\))/ ? ("$1;") : () } @lines;
+
+while (defined ($_ = shift @lines))
+  {
+    if (/^#!.* prototypes/i)
+      {
+        print "# BEGIN AUTOMATICALLY GENERATED PROTOTYPES\n";
+        print join ("\n", sort @protos) . "\n";
+        print "# END AUTOMATICALLY GENERATED PROTOTYPES\n";
+      }
+    else
+      {
+        print;
+      }
+  }
diff --git a/maintainer/syntax-checks.mk b/maintainer/syntax-checks.mk
index e7e2fc0..878789f 100644
--- a/maintainer/syntax-checks.mk
+++ b/maintainer/syntax-checks.mk
@@ -86,19 +86,22 @@ sc_at_in_texi
 automake_diff_no = 8
 aclocal_diff_no = 9
 sc_diff_automake sc_diff_aclocal: sc_diff_% :
-       @set +e; tmp=$*-diffs.tmp; \
-        diff -u $(srcdir)/$*.in $* > $$tmp; test $$? -eq 1 || exit 1; \
-        added=`grep -v '^+++ ' $$tmp | grep -c '^+'` || exit 1; \
-        removed=`grep -v '^--- ' $$tmp | grep -c '^-'` || exit 1; \
-        test $$added,$$removed = $($*_diff_no),$($*_diff_no) \
+       @set +e; \
+       in=$*-in.tmp out=$*-out.tmp diffs=$*-diffs.tmp \
+         && sed '/^#!.*[pP]rototypes/d' $(srcdir)/$*.in > $$in \
+         && sed '/^# BEGIN.* PROTO/,/^# END.* PROTO/d' $* > $$out \
+         && { diff -u $$in $$out > $$diffs; test $$? -eq 1; } \
+         && added=`grep -v '^+++ ' $$diffs | grep -c '^+'` \
+         && removed=`grep -v '^--- ' $$diffs | grep -c '^-'` \
+         && test $$added,$$removed = $($*_diff_no),$($*_diff_no) \
          || { \
            echo "Found unexpected diffs between $*.in and $*"; \
            echo "Lines added:   $$added"  ; \
            echo "Lines removed: $$removed"; \
-           cat $$tmp >&2; \
+           cat $$diffs; \
            exit 1; \
-         } >&1; \
-       rm -f $$tmp
+         } >&2; \
+       rm -f $$in $$out $$diffs
 
 ## Expect no instances of '${...}'.  However, $${...} is ok, since that
 ## is a shell construct, not a Makefile construct.
-- 
1.8.1.1.662.gaa39828




reply via email to

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