Skip to content

Commit e0ca167

Browse files
committed
kbuild: make perf-tar*-src-pkg work without relying on git
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 <[email protected]>
1 parent e785399 commit e0ca167

File tree

1 file changed

+64
-33
lines changed

1 file changed

+64
-33
lines changed

scripts/Makefile.package

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,25 @@ quiet_cmd_tar = TAR $@
5050

5151
tar-rootdir := $(srctree)
5252

53+
%.tar:
54+
$(call cmd,tar)
55+
5356
%.tar.gz: private tar-compress-opt := -I $(KGZIP)
5457
%.tar.gz:
5558
$(call cmd,tar)
5659

60+
%.tar.bz2: private tar-compress-opt := -I $(KBZIP2)
61+
%.tar.bz2:
62+
$(call cmd,tar)
63+
64+
%.tar.xz: private tar-compress-opt := -I $(XZ)
65+
%.tar.xz:
66+
$(call cmd,tar)
67+
68+
%.tar.zst: private tar-compress-opt := -I $(ZSTD)
69+
%.tar.zst:
70+
$(call cmd,tar)
71+
5772
# Linux source tarball
5873
# ---------------------------------------------------------------------------
5974

@@ -138,36 +153,52 @@ $(tar-pkgs):
138153
$(MAKE) -f $(srctree)/Makefile
139154
+$(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@
140155

141-
# perf-pkg - generate a source tarball with perf source
156+
# perf-tar*-src-pkg - generate a source tarball with perf source
142157
# ---------------------------------------------------------------------------
143158

144-
perf-tar=perf-$(KERNELVERSION)
145-
146-
quiet_cmd_perf_tar = TAR
147-
cmd_perf_tar = \
148-
git --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/ \
149-
HEAD^{tree} $$(cd $(srctree); \
150-
echo $$(cat tools/perf/MANIFEST)) \
151-
-o $(perf-tar).tar; \
152-
mkdir -p $(perf-tar); \
153-
git --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD; \
154-
(cd $(srctree)/tools/perf; \
155-
util/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/); \
156-
tar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \
157-
rm -r $(perf-tar); \
158-
$(if $(findstring tar-src,$@),, \
159-
$(if $(findstring bz2,$@),$(KBZIP2), \
160-
$(if $(findstring gz,$@),$(KGZIP), \
161-
$(if $(findstring xz,$@),$(XZ), \
162-
$(if $(findstring zst,$@),$(ZSTD), \
163-
$(error unknown target $@))))) \
164-
-f -9 $(perf-tar).tar)
165-
166-
perf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg \
167-
perf-tarxz-src-pkg perf-tarzst-src-pkg
168-
PHONY += $(perf-tar-pkgs)
169-
$(perf-tar-pkgs):
170-
$(call cmd,perf_tar)
159+
perf-tar-src-pkg-tarball = perf-$(KERNELVERSION).$(1)
160+
perf-tar-src-pkg-phony = perf-$(subst .,,$(1))-src-pkg
161+
162+
quiet_cmd_stage_perf_src = STAGE $@
163+
cmd_stage_perf_src = \
164+
rm -rf $@; \
165+
mkdir -p $@; \
166+
tar -c -f - --exclude-from=$<_exclude -C $(srctree) --files-from=$(srctree)/tools/perf/MANIFEST | \
167+
tar -x -f - -C $@
168+
169+
.tmp_perf: .tmp_filelist
170+
$(call cmd,stage_perf_src)
171+
172+
filechk_perf_head = \
173+
if test -z "$(git -C $(srctree) rev-parse --show-cdup 2>/dev/null)" && \
174+
head=$$(git -C $(srctree) rev-parse --verify HEAD 2>/dev/null); then \
175+
echo $$head; \
176+
else \
177+
echo "not a git tree"; \
178+
fi
179+
180+
.tmp_perf/HEAD: .tmp_perf FORCE
181+
$(call filechk,perf_head)
182+
183+
quiet_cmd_perf_version_file = GEN $@
184+
cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@))
185+
186+
# PERF-VERSION-FILE and HEAD are independent, but this avoids updating the
187+
# timestamp of PERF-VERSION-FILE.
188+
# The best is to fix tools/perf/util/PERF-VERSION-GEN.
189+
.tmp_perf/PERF-VERSION-FILE: .tmp_perf/HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN
190+
$(call cmd,perf_version_file)
191+
192+
define perf-tar-src-pkg-rule
193+
PHONY += $(perf-tar-src-pkg-phony)
194+
$(perf-tar-src-pkg-phony): $(perf-tar-src-pkg-tarball)
195+
@:
196+
197+
$(perf-tar-src-pkg-tarball): private tar-rootdir := .tmp_perf
198+
$(perf-tar-src-pkg-tarball): .tmp_filelist .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE
199+
endef
200+
201+
$(foreach x, tar tar.gz tar.bz2 tar.xz tar.zst, $(eval $(call perf-tar-src-pkg-rule,$(x))))
171202

172203
# Help text displayed when executing 'make help'
173204
# ---------------------------------------------------------------------------
@@ -186,11 +217,11 @@ help:
186217
@echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
187218
@echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
188219
@echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball'
189-
@echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball'
190-
@echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball'
191-
@echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball'
192-
@echo ' perf-tarxz-src-pkg - Build $(perf-tar).tar.xz source tarball'
193-
@echo ' perf-tarzst-src-pkg - Build $(perf-tar).tar.zst source tarball'
220+
@echo ' perf-tar-src-pkg - Build the perf source tarball with no compression'
221+
@echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression'
222+
@echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression'
223+
@echo ' perf-tarxz-src-pkg - Build the perf source tarball with xz compression'
224+
@echo ' perf-tarzst-src-pkg - Build the perf source tarball with zst compression'
194225

195226
PHONY += FORCE
196227
FORCE:

0 commit comments

Comments
 (0)