automake-patches
[Top][All Lists]
Advanced

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

[PATCH 8/8] maint: simplify generation of files with @substed@ stuff


From: Stefano Lattarini
Subject: [PATCH 8/8] maint: simplify generation of files with @substed@ stuff
Date: Sun, 8 Apr 2012 14:55:29 +0200

Use a proper "config.status --file=-" idiom to do most substitutions
in our generated files, to avoid too much duplications between the
various $(do_subst) commands in Makefile.am and the (explicit or
implicit AC_SUBST) invocation in configure.ac.

>From a suggestion by Eric Blake and Federico Simoncelli:
<http://lists.gnu.org/archive/html/automake/2012-01/msg00011.html>

* Makefile.am (do_subst): Rewrite to take advantage of the
"config.status --file=-" idiom.
(generated_file_finalize): New, to help checking that generated
files don't contain unexpanded '@substitutions@', and are made
read-only.
(automake, aclocal): Take advantage of the improved $(do_subst).
Improve comments.
(lib/Automake/Config.pm): Likewise, and of the new variable
$(generated_file_finalize) as well.
($(top_srcdir)/m4/amversion.m4): Likewise.
(defs-static): Likewise, and depend explicitly on 'Makefile'.
(do_subst_t): Remove as obsolete.
* THANKS: Update.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 Makefile.am |  144 +++++++++++++++++------------------------------------------
 THANKS      |    1 +
 2 files changed, 42 insertions(+), 103 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 5fa11e0..8bf9200 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,6 +27,32 @@ EXTRA_DIST =
 ##  Top level.  ##
 ## ------------ ##
 
+# We want a handful of substitutions to be fully-expanded by make;
+# then use config.status to substitute the remainder where a single
+# expansion is sufficient.  We use a funny notation here to avoid
+# configure substitutions in our text.
+do_subst = ( sed \
+  -e "s,address@hidden@],Generated from $$in; do not edit by hand.,g" \
+  -e 's,address@hidden@],$(datadir),g' \
+  -e 's,address@hidden@],$(amdir),g' \
+  -e 's,address@hidden@],$(bindir),g' \
+  -e 's,address@hidden@],$(docdir),g' \
+  -e 's,address@hidden@],$(pkgvdatadir),g' \
+  -e 's,address@hidden@],$(scriptdir),g' \
+  -e 's,address@hidden@],$(automake_acdir),g' \
+  -e 's,address@hidden@],$(system_acdir),g' \
+  | $(SHELL) ./config.status --file=- )
+
+# Generated  files shouldn't contain unexpanded '@substitutions@', and
+# should be made read-only, to prevent them from being edited by mistake
+# instead of the file the are generated from.
+generated_file_finalize = $(AM_V_at) \
+  if LC_ALL=C grep '@[a-zA-Z0-9_][a-zA-Z0-9_]*@' address@hidden; then \
+    echo "$@ contains unexpanded substitution (see lines above)"; \
+    exit 1; \
+  fi; \
+  chmod a-w address@hidden && mv -f address@hidden $@
+
 bin_SCRIPTS = automake aclocal
 
 CLEANFILES += $(bin_SCRIPTS)
@@ -61,32 +87,16 @@ uninstall-hook:
          rm -f "$(DESTDIR)$(bindir)/$$fv"; \
        done
 
-## We can't use configure to do the substitution here; we must do it
-## by hand.  We use a funny notation here to avoid configure
-## substitutions in our text.
-do_subst = sed \
-  -e 's,address@hidden@],$(APIVERSION),g' \
-  -e 's,address@hidden@],$(PACKAGE),g' \
-  -e 's,address@hidden@],$(PACKAGE_BUGREPORT),g' \
-  -e 's,address@hidden@],$(PACKAGE_URL),g' \
-  -e 's,address@hidden@],$(PATH_SEPARATOR),g' \
-  -e 's,address@hidden@],$(PERL),g' \
-  -e 's,address@hidden@],$(PERL_THREADS),g' \
-  -e 's,address@hidden@],$(SHELL),g' \
-  -e 's,address@hidden@],$(am_AUTOCONF),g' \
-  -e 's,address@hidden@],$(am_AUTOM4TE),g' \
-  -e 's,address@hidden@],$(VERSION),g' \
-  -e 's,address@hidden@],Generated from address@hidden; do not edit by 
hand.,g' \
-  -e 's,address@hidden@],$(datadir),g'
-
 ## These files depend on Makefile so they are rebuilt if $(VERSION),
 ## $(datadir) or other do_subst'ituted variables change.
-## Use chmod a-w to prevent people from editing the wrong file by accident.
 automake: automake.in
 aclocal: aclocal.in
 automake aclocal: Makefile
        $(AM_V_at)rm -f $@ address@hidden
-       $(AM_V_GEN)$(do_subst) $(srcdir)/address@hidden >address@hidden
+       $(AM_V_GEN)address@hidden; $(do_subst) <$(srcdir)/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 $@
 
 ## The master location for INSTALL is lib/INSTALL.
@@ -182,23 +192,12 @@ dist_perllib_DATA = \
 nodist_perllib_DATA = lib/Automake/Config.pm
 CLEANFILES += $(nodist_perllib_DATA)
 
-## This file depends on Makefile so it is rebuilt if $(VERSION),
-## $(datadir) or other do_subst'ituted variables change.
-## Use chmod a-w to prevent people from editing the wrong file by accident.
 lib/Automake/Config.pm: lib/Automake/Config.in Makefile
        $(AM_V_at)rm -f $@ address@hidden
        $(AM_V_at)test -d lib/Automake || $(MKDIR_P) lib/Automake
-       $(AM_V_GEN)sed <$(srcdir)/lib/Automake/Config.in >address@hidden \
-         -e 's,address@hidden@],$(APIVERSION),g' \
-         -e 's,address@hidden@],$(PACKAGE),g' \
-         -e 's,address@hidden@],$(PACKAGE_BUGREPORT),g' \
-         -e 's,address@hidden@],$(PERL),g' \
-         -e 's,address@hidden@],$(PERL_THREADS),g' \
-         -e 's,address@hidden@],$(SHELL),g' \
-         -e 's,address@hidden@],$(VERSION),g' \
-         -e "s,address@hidden@],Generated from Config.in; do not edit by 
hand.,g" \
-         -e 's,address@hidden@],$(datadir),g'
-       $(AM_V_at)chmod a-w address@hidden && mv -f address@hidden $@
+       $(AM_V_GEN)in=Config.in \
+         && $(do_subst) <$(srcdir)/lib/Automake/Config.in >address@hidden
+       $(generated_file_finalize)
 EXTRA_DIST += lib/Automake/Config.in
 
 
@@ -300,12 +299,10 @@ dist_system_ac_DATA = m4/acdir/README
 # Use '$(top_srcdir)/m4' for the benefit of non-GNU makes: this is
 # how amversion.m4 appears in our dependencies.
 $(top_srcdir)/m4/amversion.m4: $(srcdir)/configure.ac $(srcdir)/m4/amversion.in
-       $(AM_V_at)sed \
-           -e 's,address@hidden@],$(VERSION),g' \
-           -e 's,address@hidden@],$(APIVERSION),g' \
-           -e "s,address@hidden@],Generated from amversion.in; do not edit by 
hand.,g" \
-           $(srcdir)/m4/amversion.in > address@hidden
-       $(AM_V_at)chmod a-w address@hidden && mv -f address@hidden $@
+       $(AM_V_at)rm -f address@hidden $@
+       $(AM_V_GEN)in=amversion.in \
+         && $(do_subst) <$(srcdir)/m4/amversion.in >address@hidden
+       $(generated_file_finalize)
 EXTRA_DIST += m4/amversion.in
 
 
@@ -393,70 +390,11 @@ t/distcheck-missing-m4.log: t/ax/distcheck-hook-m4.am
 t/distcheck-outdated-m4.log: t/ax/distcheck-hook-m4.am
 EXTRA_DIST += t/ax/distcheck-hook-m4.am
 
-# Keep in sync with AC_SUBST'd stuff in defs-static.in.
-do_subst_t = sed \
-  -e 's|@address@hidden|$(abs_srcdir)|g' \
-  -e 's|@address@hidden|$(abs_top_srcdir)|g' \
-  -e 's|@address@hidden|$(abs_builddir)|g' \
-  -e 's|@address@hidden|$(abs_top_builddir)|g' \
-  -e 's|@address@hidden|$(prefix)|g' \
-  -e 's|@address@hidden|$(amdir)|g' \
-  -e 's|@address@hidden|$(bindir)|g' \
-  -e 's|@address@hidden|$(datadir)|g' \
-  -e 's|@address@hidden|$(docdir)|g' \
-  -e 's|@address@hidden|$(automake_acdir)|g' \
-  -e 's|@address@hidden|$(system_acdir)|g' \
-  -e 's|@address@hidden|$(scriptdir)|g' \
-  -e 's|@address@hidden|$(pkgvdatadir)|g' \
-  -e 's|@address@hidden|$(host_alias)|g' \
-  -e 's|@address@hidden|$(build_alias)|g' \
-  -e 's|@address@hidden|$(APIVERSION)|g' \
-  -e 's|@address@hidden|$(PATH_SEPARATOR)|g' \
-  -e 's|@address@hidden|$(SHELL)|g' \
-  -e 's|@address@hidden|$(AWK)|g' \
-  -e 's|@address@hidden|$(PERL)|g' \
-  -e 's|@address@hidden|$(EGREP)|g' \
-  -e 's|@address@hidden|$(FGREP)|g' \
-  -e 's|@address@hidden|$(CPPFLAGS)|g' \
-  -e 's|@address@hidden|$(CC)|g' \
-  -e 's|@address@hidden|$(CFLAGS)|g' \
-  -e 's|@address@hidden|$(CXX)|g' \
-  -e 's|@address@hidden|$(CXXFLAGS)|g' \
-  -e 's|@address@hidden|$(F77)|g' \
-  -e 's|@address@hidden|$(FFLAGS)|g' \
-  -e 's|@address@hidden|$(FC)|g' \
-  -e 's|@address@hidden|$(FCFLAGS)|g' \
-  -e 's|@address@hidden|$(GNU_CC)|g' \
-  -e 's|@address@hidden|$(GNU_CFLAGS)|g' \
-  -e 's|@address@hidden|$(GNU_CXX)|g' \
-  -e 's|@address@hidden|$(GNU_CXXFLAGS)|g' \
-  -e 's|@address@hidden|$(GNU_F77)|g' \
-  -e 's|@address@hidden|$(GNU_FFLAGS)|g' \
-  -e 's|@address@hidden|$(GNU_FC)|g' \
-  -e 's|@address@hidden|$(GNU_FCFLAGS)|g' \
-  -e 's|@address@hidden|$(GNU_GCJ)|g' \
-  -e 's|@address@hidden|$(GNU_GCJFLAGS)|g' \
-  -e 's|@address@hidden|$(YACC)|g' \
-  -e 's|@address@hidden|$(LEX)|g' \
-  -e 's|@address@hidden|$(TEX)|g' \
-  -e 's|@address@hidden|$(MODIFICATION_DELAY)|g' \
-  -e 's|@address@hidden|$(am_AUTOCONF)|g' \
-  -e 's|@address@hidden|$(am_AUTOM4TE)|g' \
-  -e 's|@address@hidden|$(am_AUTORECONF)|g' \
-  -e 's|@address@hidden|$(am_AUTOHEADER)|g' \
-  -e 's|@address@hidden|$(am_AUTOUPDATE)|g' \
-  -e 's|@address@hidden|$(sh_errexit_works)|g' \
-  -e 's|@address@hidden|Generated from address@hidden  DO NOT EDIT BY HAND!|'
-
-defs-static: defs-static.in
+defs-static: defs-static.in Makefile
        $(AM_V_at)rm -f $@ address@hidden
-       $(AM_V_GEN)$(do_subst_t) $(srcdir)/defs-static.in >address@hidden
-       $(AM_V_at) : Sanity check on the substitutions; \
-       if LC_ALL=C grep '@[a-zA-Z0-9_][a-zA-Z0-9_]*@' address@hidden; then \
-         echo "$@ contains unexpanded substitution (see lines above)"; \
-         exit 1; \
-       fi
-       $(AM_V_at)chmod a-w address@hidden && mv -f address@hidden $@
+       $(AM_V_GEN)in=defs-static.in\
+         && $(do_subst) <$(srcdir)/defs-static.in >address@hidden
+       $(generated_file_finalize)
 EXTRA_DIST += defs-static.in
 CLEANFILES += defs-static
 
diff --git a/THANKS b/THANKS
index 2f91ee7..f66bcba 100644
--- a/THANKS
+++ b/THANKS
@@ -112,6 +112,7 @@ Erik Lindahl                address@hidden
 Esben Haabendal Soerensen address@hidden
 Ezra Peisach           address@hidden
 Fabian Alenius         address@hidden
+Federico Simoncelli    address@hidden
 Flavien Astraud                address@hidden
 Florian Briegel                address@hidden
 Francesco Salvestrini  address@hidden
-- 
1.7.9




reply via email to

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