]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
[ng] dist: refactor: reduce duplication in the 'dist-*' recipes
authorStefano Lattarini <stefano.lattarini@gmail.com>
Sun, 12 Aug 2012 14:54:52 +0000 (16:54 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 13 Aug 2012 15:32:01 +0000 (17:32 +0200)
* lib/am/distcheck.mk: Here, with heavy refactorings, in particular
introducing ...
(am.dist.all-formats,
am.dist.all-targets,
am.dist.compress-cmd.gzip,
am.dist.uncompress-cmd.gzip,
am.dist.compress-cmd.bzip2,
am.dist.uncompress-cmd.bzip2,
am.dist.compress-cmd.lzip,
am.dist.uncompress-cmd.lzip
am.dist.compress-cmd.xz,
am.dist.uncompress-cmd.xz,
am.dist.create-cmd.zip,
am.dist.extract-cmd.zip): ... these new internal variables ...
(am.dist.create-archive-for-format.aux,
am.dist.create-archive-for-format,
am.dist.extract-archive-for-format.aux,
am.dist.extract-archive-for-format): ... and these new internal
make functions ...
(am.dist-gzip, am.dist-bzip2, am.dist-lzip, am.dist-xz,
am.dist.zip): ... and rewriting these rules as static-pattern
rules sharing the same recipe ...
(distcheck): ... and updating the recipe for this target.
* t/dist-formats.tap: Little adjustments for better usefulness
of verbose output when debugging.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
lib/am/distcheck.mk
t/dist-formats.tap

index 656938749918935b09a4e7ee73758c052f727eca..aec150022b0452071589e29b4199956972bfb1c2 100644 (file)
@@ -16,6 +16,9 @@
 #  Building various distribution flavors.  #
 # ---------------------------------------- #
 
+# ----------------------------------------------------------------------
+# FIXME: how and where are these old comments still relevant?
+# ----------------------------------------------------------------------
 # Note that we don't use GNU tar's '-z' option.  One reason (but
 # not the only reason) is that some versions of tar (e.g., OSF1)
 # interpret '-z' differently.
 # with tar 1.11.2).  We do not do anything specific w.r.t. this
 # incompatibility since packages where empty directories need to be
 # present in the archive are really unusual.
+# ----------------------------------------------------------------------
 
-am.dist.ext.gzip  = tar.gz
-am.dist.ext.bzip2 = tar.bz2
-am.dist.ext.xz    = tar.xz
-am.dist.ext.lzip  = tar.lz
-am.dist.ext.zip   = zip
+# TODO: this definition-oriented interface is almost god enough to offer
+# as a public API allowing the user to define and use new archive formats.
+# However, we must think carefully about possible problems before setting
+# the API in stone.  So, for the moment, we keep this internal and
+# private; there will be time to make it public, once (and if) there's
+# any request from the user base.
 
-DIST_TARGETS  = $(foreach x,$(am.dist.formats),dist-$x)
-DIST_ARCHIVES = $(foreach x,$(am.dist.formats),$(distdir).$(am.dist.ext.$x))
-.PHONY: $(foreach x,$(am.dist.formats),dist-$x)
+am.dist.all-formats =
 
-GZIP_ENV = --best
-dist-gzip: distdir
-       tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
-       $(am.dist.post-remove-distdir)
-
-dist-bzip2: distdir
-       tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2
-       $(am.dist.post-remove-distdir)
+am.dist.all-formats += gzip
+am.dist.ext.gzip = tar.gz
+am.dist.compress-cmd.gzip = GZIP=$(GZIP_ENV) gzip -c
+am.dist.uncompress-cmd.gzip = GZIP=$(GZIP_ENV) gzip -dc
 
-dist-lzip: distdir
-       tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz
-       $(am.dist.post-remove-distdir)
+am.dist.all-formats += bzip2
+am.dist.ext.bzip2 = tar.bz2
+am.dist.compress-cmd.bzip2 = BZIP2=$${BZIP2--9} bzip2 -c
+am.dist.uncompress-cmd.bzip2 = bzip2 -dc
+
+am.dist.all-formats += lzip
+am.dist.ext.lzip = tar.lz
+am.dist.compress-cmd.lzip = lzip -c $${LZIP_OPT--9}
+am.dist.uncompress-cmd.lzip = lzip -dc
+
+am.dist.all-formats += xz
+am.dist.ext.xz = tar.xz
+am.dist.compress-cmd.xz = XZ_OPT=$${XZ_OPT--e} xz -c
+am.dist.uncompress-cmd.xz = xz -dc
+
+am.dist.all-formats += zip
+am.dist.ext.zip = zip
+am.dist.create-cmd.zip = \
+  rm -f $(distdir).zip && zip -rq $(distdir).zip $(distdir)
+am.dist.extract-cmd.zip = \
+  unzip $(distdir).zip
+
+am.dist.all-targets = $(patsubst %,dist-%,$(am.dist.all-formats))
+
+define am.dist.create-archive-for-format.aux
+$(or $(am.dist.create-cmd.$1), \
+  tardir=$(distdir) && $(am__tar) \
+    | $(am.dist.compress-cmd.$1) >$(distdir).$(am.dist.ext.$1))
+endef
+am.dist.create-archive-for-format = $(call $0.aux,$(strip $1))
+
+define am.dist.extract-archive-for-format.aux
+$(or $(am.dist.extract-cmd.$1), \
+  $(am.dist.uncompress-cmd.$1) $(distdir).$(am.dist.ext.$1) \
+    | $(am__untar))
+endef
+am.dist.extract-archive-for-format = $(call $0.aux,$(strip $1))
+
+# The use of this option to pass arguments to the 'gzip' invocation is
+# not only documented in the manual and useful for better compatibility
+# with mainline Automake, but also actively employed by some important
+# makefile fragments (e.g., Gnulib's 'top/maint.mk', at least up to
+# commit v0.0-7569-gec58403).  So keep it.
+GZIP_ENV = --best
 
-dist-xz: distdir
-       tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
-       $(am.dist.post-remove-distdir)
+DIST_TARGETS  = $(foreach x,$(am.dist.formats),dist-$x)
+DIST_ARCHIVES = $(foreach x,$(am.dist.formats),$(distdir).$(am.dist.ext.$x))
 
-dist-zip: distdir
-       rm -f $(distdir).zip
-       zip -rq $(distdir).zip $(distdir)
+.PHONY: $(am.dist.all-targets)
+$(am.dist.all-targets): dist-%: distdir
+       $(call am.dist.create-archive-for-format,$*)
        $(am.dist.post-remove-distdir)
 
 
@@ -87,18 +126,8 @@ endif
 # tarfile.
 .PHONY: distcheck
 distcheck: dist
-       case '$(DIST_ARCHIVES)' in \
-       *.tar.gz*) \
-         GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\
-       *.tar.bz2*) \
-         bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
-       *.tar.lz*) \
-         lzip -dc $(distdir).tar.lz | $(am__untar) ;;\
-       *.tar.xz*) \
-         xz -dc $(distdir).tar.xz | $(am__untar) ;;\
-       *.zip*) \
-         unzip $(distdir).zip ;;\
-       esac
+       $(call am.dist.extract-archive-for-format, \
+         $(firstword $(am.dist.formats)))
 ## Make the new source tree read-only.  Distributions ought to work in
 ## this case.  However, make the top-level directory writable so we
 ## can make our new subdirs.
index 102db68b35bab66d09c18ebad0e7ef2c18115211..ee240aa48000c2e6a118378b0143c247ed14f5c0 100755 (executable)
@@ -167,8 +167,8 @@ can_compress ()
     eval '
       rm -rf *$tarname* \
         && $MAKE dist-$format \
-        && test -f $tarname-1.0.$suffix \
         && ls -l *$tarname* \
+        && test -f $tarname-1.0.$suffix \
         && test "$(echo *$tarname*)" = $tarname-1.0.$suffix'
 
   unset suffix compressor format tarname