@@ -122,40 +122,53 @@ quiet_cmd_tar = TAR $@
tar-rootdir := $(srctree)
+%.tar: compress-opt :=
+%.tar: .tmp_filelist
+ $(call cmd,tar)
+
%.tar.gz: compress-opt := -I $(KGZIP)
%.tar.gz: .tmp_filelist
$(call cmd,tar)
+%.tar.bz2: compress-opt := -I $(KBZIP2)
+%.tar.bz2: .tmp_filelist
+ $(call cmd,tar)
+
+%.tar.xz: compress-opt := -I $(XZ)
+%.tar.xz: .tmp_filelist
+ $(call cmd,tar)
+
+%.tar.zst: compress-opt := -I $(ZSTD)
+%.tar.zst: .tmp_filelist
+ $(call cmd,tar)
+
# perf-pkg - generate a source tarball with perf source
# ---------------------------------------------------------------------------
-perf-tar=perf-$(KERNELVERSION)
-
-quiet_cmd_perf_tar = TAR
- cmd_perf_tar = \
-git --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/ \
- HEAD^{tree} $$(cd $(srctree); \
- echo $$(cat tools/perf/MANIFEST)) \
- -o $(perf-tar).tar; \
-mkdir -p $(perf-tar); \
-git --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD; \
-(cd $(srctree)/tools/perf; \
-util/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/); \
-tar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \
-rm -r $(perf-tar); \
-$(if $(findstring tar-src,$@),, \
-$(if $(findstring bz2,$@),$(KBZIP2), \
-$(if $(findstring gz,$@),$(KGZIP), \
-$(if $(findstring xz,$@),$(XZ), \
-$(if $(findstring zst,$@),$(ZSTD), \
-$(error unknown target $@))))) \
- -f -9 $(perf-tar).tar)
-
-perf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg \
- perf-tarxz-src-pkg perf-tarzst-src-pkg
-PHONY += $(perf-tar-pkgs)
-$(perf-tar-pkgs):
- $(call cmd,perf_tar)
+perf-tar = perf-$(KERNELVERSION)
+
+perf-tar-phony = perf-$(subst .,,$(1))-src-pkg
+
+.tmp_perf: FORCE
+ $(Q)rm -rf $@
+ $(Q)mkdir $@
+ $(Q)tar -c -f - -C $(srctree) --files-from=$(srctree)/tools/perf/MANIFEST | tar -x -f - -C $@
+ $(Q)if test -z "$(git -C $(srctree) rev-parse --show-cdup 2>/dev/null)" && \
+ head=$$(git -C $(srctree) rev-parse --verify HEAD 2>/dev/null); then \
+ echo $$head > $@/HEAD; \
+ fi
+ $(Q)cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(abspath $@)/
+
+define perf-pkg-rule
+PHONY += $(perf-tar-phony)
+$(perf-tar-phony): $(perf-tar).$(1)
+ @:
+
+$(perf-tar).$(1): private tar-rootdir := .tmp_perf
+$(perf-tar).$(1): | .tmp_perf
+endef
+
+$(foreach x, tar tar.gz tar.bz2 tar.xz tar.zst, $(eval $(call perf-pkg-rule,$(x))))
# Help text displayed when executing 'make help'
# ---------------------------------------------------------------------------
Currently, perf-tar*-src-pkg only uses 'git archive', but it is better to make it work without relying on git. The file, HEAD, which saves the commit hash, will be included in the tarball only when the source tree is managed by git. The git tree is more precisely checked; it has been copied from scripts/setlocalversion. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> --- Changes in v5: - New patch scripts/Makefile.package | 67 ++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 27 deletions(-)