Actually, it seems to me there is not enough paragraph rules at all in
automake. Instead of the attrocious
@SUBDIRS@ for subdir in $(@DIST_SUBDIR_NAME@); do \
@SUBDIRS@ if test "$$subdir" = .; then :; else \
@SUBDIRS@ test -d $(distdir)/$$subdir \
@SUBDIRS@ || mkdir $(distdir)/$$subdir \
@SUBDIRS@ || exit 1; \
@SUBDIRS@ (cd $$subdir && \
@SUBDIRS@ $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(@TOP_DISTDIR@)
distdir=../$(distdir)/$$subdir distdir) \
@SUBDIRS@ || exit 1; \
@SUBDIRS@ fi; \
@SUBDIRS@ done
one would want some for of conditional, such as
@if HAS_SUBDIRS@
for subdir in $(@DIST_SUBDIR_NAME@); do \
if test "$$subdir" = .; then :; else \
test -d $(distdir)/$$subdir \
|| mkdir $(distdir)/$$subdir \
|| exit 1; \
(cd $$subdir && \
$(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(@TOP_DISTDIR@)
distdir=../$(distdir)/$$subdir distdir) \
|| exit 1; \
fi; \
done
@fi HAS_SUBDIRS@
or whatever the actual syntax. This means that we want to run the
COMMAND of &file_contents on the *whole* file. Given that we have a
paragraph reading afterwards, it is absolutely possible.
Just my $0.002. Tell me what you think about it.
So the point of this patch is (unofficially, that I continue learning
and feeling about Automake to get an idea of what could be done to
make it easier to understand/extend/migrate to another language) is to
externalize the handling of the dist target. Because it was on my way
to use even more %dependencies.
I'm sorry for the size, one can't do less IMHO.
Note that aside from the new file to distribute (distdir.am), the
changes of the Makefile.ins are limited to a new empty line (of which
we can get rid of but eliminating the leading empty lines in
distdir.am, or, alternatively, decide that &file_contents should
always get rid of leading lines).
Akim
Index: ChangeLog
from Akim Demaille <[EMAIL PROTECTED]>
* distdir.am (distdir): New file, extracted from...
* automake.in (handle_dist_worker): here.
Adjust.
Index: automake.in
--- automake.in Wed, 31 Jan 2001 21:12:00 +0100 akim (am/f/39_automake.i 1.26 755)
+++ automake.in Wed, 31 Jan 2001 22:25:04 +0100 akim (am/f/39_automake.i 1.26 755)
@@ -2613,28 +2613,26 @@ sub handle_multilib
# Worker for handle_dist.
sub handle_dist_worker
{
- local ($makefile) = @_;
-
- $output_rules .= 'distdir: $(DISTFILES)' . "\n";
+ my $makefile = @_;
+ my $xform = '';
# Initialization; only at top level.
if ($relative_dir eq '.')
{
- if (defined $options{'check-news'})
- {
- # For Gnits users, this is pretty handy. Look at 15 lines
- # in case some explanatory text is desirable.
- $output_rules .= ' @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" >
/dev/null; then :; else \\
- echo "NEWS not updated; not releasing" 1>&2; \\
- exit 1; \\
- fi
-';
- }
-
+ $xform .= 's/\@TOPDIR\@//g;';
+ }
+ else
+ {
+ $xform .= 's/\@TOPDIR\@.*//g;';
+ }
- # Create dist directory.
- $output_rules .= ("\t-chmod -R a+w \$(distdir) > /dev/null 2>&1; rm -rf
\$(distdir)\n"
- . "\tmkdir \$(distdir)\n");
+ if (defined $options{'check-news'})
+ {
+ $xform .= 's/\@CK-NEWS\@//g;';
+ }
+ else
+ {
+ $xform .= 's/\@CK-NEWS\@.*//g;';
}
# Scan EXTRA_DIST to see if we need to distribute anything from a
@@ -2674,39 +2672,23 @@ sub handle_dist_worker
# hash lets us ensure that each directory is used only once.
local (%dhash);
grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
- $output_rules .= "\t";
- &pretty_print_rule ('$(mkinstalldirs)', "\t ", sort keys %dhash);
+ $xform .= &transform ('DISTDIRS', join (' ', sort keys %dhash));
+ }
+ else
+ {
+ $xform .= 's/.*\@DISTDIRS\@.*//g;';
}
- # In loop, test for file existence because sometimes a file gets
- # included in DISTFILES twice. For example this happens when a
- # single source file is used in building more than one program.
- # Also, there are situations in which "ln" can fail. For instance
- # a file to distribute could actually be a cross-filesystem
- # symlink -- this can easily happen if "gettextize" was run on the
- # distribution.
- $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
if ($cygnus_mode)
{
- $output_rules .= "\t if test -f \$\$file; then d=.; else d=\$(srcdir); fi;
\\\n";
+ $xform .= 's/\@CYGNUS\@\t*/\t/g;';
+ $xform .= 's/.*\@NCYGNUS\@.*//g;';
}
else
{
- $output_rules .= "\t d=\$(srcdir); \\\n";
+ $xform .= 's/\@NCYGNUS\@\t*/\t/g;';
+ $xform .= 's/.*\@CYGNUS\@.*//g;';
}
- $output_rules .= ("\t if test -d \$\$d/\$\$file; then \\\n"
- # Don't mention $$file in destination argument,
- # since this fails if destination directory
- # already exists. Also, use `-R' and not `-r'.
- # `-r' is almost always incorrect.
- . "\t cp -pR \$\$d/\$\$file \$(distdir) \\\n"
- . "\t || exit 1; \\\n"
- . "\t else \\\n"
- . "\t test -f \$(distdir)/\$\$file \\\n"
- . "\t || cp -p \$\$d/\$\$file \$(distdir)/\$\$file \\\n"
- . "\t || exit 1; \\\n"
- . "\t fi; \\\n"
- . "\tdone\n");
# If we have SUBDIRS, create all dist subdirectories and do
# recursive build.
@@ -2744,29 +2726,20 @@ sub handle_dist_worker
&define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
}
- # Test for directory existence here because previous automake
- # invocation might have created some directories. Note that
- # we explicitly set distdir for the subdir make; that lets us
- # mix-n-match many automake-using packages into one large
- # package, and have "dist" at the top level do the right
- # thing. If we're in the topmost directory, then we use
- # `distdir' instead of `top_distdir'; this lets us work
- # correctly with an enclosing package.
- $output_rules .=
- ("\t" . 'for subdir in $(' . $dist_subdir_name . '); do ' . "\\\n"
- . "\t" . ' if test "$$subdir" = .; then :; else ' . "\\\n"
- . "\t" . ' test -d $(distdir)/$$subdir ' . "\\\n"
- . "\t" . ' || mkdir $(distdir)/$$subdir ' . "\\\n"
- . "\t" . ' || exit 1; ' . "\\\n"
- . "\t" . ' (cd $$subdir'
- . ' && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$('
- . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
- . ') distdir=../$(distdir)/$$subdir distdir) ' . "\\\n"
- . "\t" . ' || exit 1; ' . "\\\n"
- . "\t" . ' fi; ' . "\\\n"
- . "\tdone\n");
+ $xform .= ('s/\@SUBDIRS\@//g;'
+ . &transform ('DIST_SUBDIR_NAME'
+ => $dist_subdir_name,
+ 'TOP_DISTDIR'
+ => (($relative_dir eq '.')
+ ? 'distdir' : 'top_distdir')));
+ }
+ else
+ {
+ $xform .= 's/\@SUBDIRS\@.*//g;';
}
+ $output_rules .= &file_contents ('distdir', $xform);
+
# If the target `dist-hook' exists, make sure it is run. This
# allows users to do random weird things to the distribution
# before it is packaged up.
@@ -2781,8 +2754,6 @@ sub handle_dist_worker
. " top_distdir=\"\$(top_distdir)\""
. " distdir=\"\$(distdir)\" $targ\n");
}
-
- &depend ('.PHONY', 'distdir');
}
# Handle 'dist' target.
@@ -2913,6 +2884,7 @@ sub handle_dist
$xform .= 's/^GETTEXT.*$//;';
}
+ # Arg, this file should have been named `distcheck'.
$output_rules .= &file_contents ('dist', $xform);
local ($dist_all) = ('dist-all: distdir' . "\n"
Index: Makefile.am
--- Makefile.am Sun, 28 Jan 2001 15:27:26 +0100 akim (am/f/46_Makefile.a 1.3 664)
+++ Makefile.am Wed, 31 Jan 2001 22:26:44 +0100 akim (am/f/46_Makefile.a 1.3 664)
@@ -12,9 +12,9 @@
amfiles = check.am clean-hdr.am clean-kr.am clean.am comp-vars.am \
compile.am data-clean.am data.am dejagnu.am depend.am depend2.am \
-dist.am dist-vars.am footer.am header-vars.am header.am java-clean.am \
-java.am kr-extra.am library.am libs-clean.am libs.am libtool.am \
-lisp-clean.am lisp.am ltlib-clean.am ltlib.am ltlibrary.am \
+dist.am distdir.am dist-vars.am footer.am header-vars.am header.am \
+java-clean.am java.am kr-extra.am library.am libs-clean.am libs.am \
+libtool.am lisp-clean.am lisp.am ltlib-clean.am ltlib.am ltlibrary.am \
mans-vars.am mans.am multilib.am program.am progs-clean.am progs.am \
python.am python-clean.am remake-hdr.am remake.am scripts.am \
subdirs.am tags-clean.am tags.am texi-vers.am texinfos.am
Index: tests/Makefile.in
--- tests/Makefile.in Wed, 31 Jan 2001 01:43:58 +0100 akim (am/h/14_Makefile.i 1.2 644)
+++ tests/Makefile.in Wed, 31 Jan 2001 22:26:46 +0100 akim (am/h/14_Makefile.i 1.2 644)
@@ -420,6 +420,7 @@
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
+
distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
Index: m4/Makefile.in
--- m4/Makefile.in Wed, 31 Jan 2001 01:43:58 +0100 akim (am/h/15_Makefile.i 1.2 644)
+++ m4/Makefile.in Wed, 31 Jan 2001 22:26:45 +0100 akim (am/h/15_Makefile.i 1.2 644)
@@ -125,6 +125,7 @@
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
+
distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
Index: Makefile.in
--- Makefile.in Wed, 31 Jan 2001 01:43:58 +0100 akim (am/h/16_Makefile.i 1.2 644)
+++ Makefile.in Wed, 31 Jan 2001 22:26:44 +0100 akim (am/h/16_Makefile.i 1.2 644)
@@ -79,9 +79,9 @@
amfiles = check.am clean-hdr.am clean-kr.am clean.am comp-vars.am \
compile.am data-clean.am data.am dejagnu.am depend.am depend2.am \
-dist.am dist-vars.am footer.am header-vars.am header.am java-clean.am \
-java.am kr-extra.am library.am libs-clean.am libs.am libtool.am \
-lisp-clean.am lisp.am ltlib-clean.am ltlib.am ltlibrary.am \
+dist.am distdir.am dist-vars.am footer.am header-vars.am header.am \
+java-clean.am java.am kr-extra.am library.am libs-clean.am libs.am \
+libtool.am lisp-clean.am lisp.am ltlib-clean.am ltlib.am ltlibrary.am \
mans-vars.am mans.am multilib.am program.am progs-clean.am progs.am \
python.am python-clean.am remake-hdr.am remake.am scripts.am \
subdirs.am tags-clean.am tags.am texi-vers.am texinfos.am
@@ -504,6 +504,7 @@
|| chmod -R a+r $(distdir)
$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).tar.gz
-chmod -R a+w $(distdir) > /dev/null 2>&1; rm -rf $(distdir)
+
distdir: $(DISTFILES)
@if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \
echo "NEWS not updated; not releasing" 1>&2; \
@@ -527,7 +528,8 @@
test -d $(distdir)/$$subdir \
|| mkdir $(distdir)/$$subdir \
|| exit 1; \
- (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(distdir)
distdir=../$(distdir)/$$subdir distdir) \
+ (cd $$subdir && \
+ $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(distdir)
+distdir=../$(distdir)/$$subdir distdir) \
|| exit 1; \
fi; \
done
Index: distdir.am
--- distdir.am Wed, 31 Jan 2001 22:27:46 +0100 akim ()
+++ distdir.am Wed, 31 Jan 2001 22:26:44 +0100 akim (am/h/17_distdir.am 644)
@@ -0,0 +1,82 @@
+## automake - create Makefile.in from Makefile.am
+## Copyright 2001 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.
+
+.PHONY: distdir
+
+distdir: $(DISTFILES)
+##
+## For Gnits users, this is pretty handy. Look at 15 lines
+## in case some explanatory text is desirable.
+##
+@TOPDIR@@CK-NEWS@ @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" >
+/dev/null; then :; else \
+@TOPDIR@@CK-NEWS@ echo "NEWS not updated; not releasing" 1>&2; \
+@TOPDIR@@CK-NEWS@ exit 1; \
+@TOPDIR@@CK-NEWS@ fi
+##
+## Only for the top dir.
+##
+@TOPDIR@ -chmod -R a+w $(distdir) > /dev/null 2>&1; rm -rf $(distdir)
+@TOPDIR@ mkdir $(distdir)
+##
+##
+ $(mkinstalldirs) @DISTDIRS@
+##
+##
+ @for file in $(DISTFILES); do \
+##
+## In loop, test for file existence because sometimes a file gets
+## included in DISTFILES twice. For example this happens when a single
+## source file is used in building more than one program. Also, there
+## are situations in which "ln" can fail. For instance a file to
+## distribute could actually be a cross-filesystem symlink -- this can
+## easily happen if "gettextize" was run on the distribution.
+##
+@CYGNUS@ if test -f $$file; then d=.; else d=$(srcdir); fi; \
+@NCYGNUS@ d=$(srcdir); \
+##
+ if test -d $$d/$$file; then \
+## Don't mention $$file in destination argument, since this fails if
+## destination directory already exists. Also, use `-R' and not `-r'.
+## `-r' is almost always incorrect.
+ cp -pR $$d/$$file $(distdir) \
+ || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+##
+## Test for directory existence here because previous automake
+## invocation might have created some directories. Note that we
+## explicitly set distdir for the subdir make; that lets us mix-n-match
+## many automake-using packages into one large package, and have "dist"
+## at the top level do the right thing. If we're in the topmost
+## directory, then we use `distdir' instead of `top_distdir'; this lets
+## us work correctly with an enclosing package.
+##
+@SUBDIRS@ for subdir in $(@DIST_SUBDIR_NAME@); do \
+@SUBDIRS@ if test "$$subdir" = .; then :; else \
+@SUBDIRS@ test -d $(distdir)/$$subdir \
+@SUBDIRS@ || mkdir $(distdir)/$$subdir \
+@SUBDIRS@ || exit 1; \
+@SUBDIRS@ (cd $$subdir && \
+@SUBDIRS@ $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(@TOP_DISTDIR@)
+distdir=../$(distdir)/$$subdir distdir) \
+@SUBDIRS@ || exit 1; \
+@SUBDIRS@ fi; \
+@SUBDIRS@ done