From: Stefano Lattarini Date: Sun, 12 Aug 2012 14:54:52 +0000 (+0200) Subject: [ng] dist: refactor: reduce duplication in the 'dist-*' recipes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0f51e4b3e7088e89fd64bd3c3af2f7629555b60;p=thirdparty%2Fautomake.git [ng] dist: refactor: reduce duplication in the 'dist-*' recipes * 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 --- diff --git a/lib/am/distcheck.mk b/lib/am/distcheck.mk index 656938749..aec150022 100644 --- a/lib/am/distcheck.mk +++ b/lib/am/distcheck.mk @@ -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. @@ -26,37 +29,73 @@ # 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. diff --git a/t/dist-formats.tap b/t/dist-formats.tap index 102db68b3..ee240aa48 100755 --- a/t/dist-formats.tap +++ b/t/dist-formats.tap @@ -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