[PATCH] kbuild: rpm-pkg: fix rpm-pkg build error

From: jiweisun126
Date: Wed Apr 19 2023 - 02:25:14 EST


From: Jiwei Sun <sunjw10@xxxxxxxxxx>

The following error will trigger when building rpm-pkg
$ make rpm-pkg
SYNC include/config/auto.conf.cmd
HOSTLD scripts/kconfig/conf
UPD include/config/kernel.release
UPD .tmp_HEAD
ARCHIVE linux.tar.gz
sh ./scripts/package/mkspec >./kernel.spec
rpmbuild --target x86_64-linux -bs kernel.spec \
--define='_smp_mflags %{nil}' --define='_sourcedir rpmbuild/SOURCES' --define='_srcrpmdir .'
Building target platforms: x86_64-linux
Building for target x86_64-linux
Wrote: ./kernel-6.3.0_rc7-47.src.rpm
rpmbuild --target x86_64-linux -rb kernel-6.3.0_rc7-47.src.rpm \
--define='_smp_mflags %{nil}'
Installing kernel-6.3.0_rc7-47.src.rpm
Building target platforms: x86_64-linux
Building for target x86_64-linux
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.QtGSXP
+ umask 022
+ cd /mnt/datapart/rpmbuild/BUILD
+ cd /mnt/datapart/rpmbuild/BUILD
+ rm -rf linux
+ /usr/bin/gzip -dc /mnt/datapart/rpmbuild/SOURCES/linux.tar.gz
+ /usr/bin/tar -xof -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd linux
/var/tmp/rpm-tmp.QtGSXP: line 40: cd: linux: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.QtGSXP (%prep)

There is linux.tar, not linux, and the linux.tar.gz is create by the following
quiet_cmd_archive = ARCHIVE $@
cmd_archive = git -C $(srctree) $(git-config-tar$(suffix $@)) archive \
--output=$$(realpath $@) --prefix=$(basename $@)/ $(archive-args)
Here the $@ is linux.tar.gz, and $(basename $@) will be linux.tar,
The above fact is the cause, so use $(basename $(basename $@)) to get the right directory name.

Signed-off-by: Jiwei Sun <sunjw10@xxxxxxxxxx>
---
scripts/Makefile.package | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.package b/scripts/Makefile.package
index 4d90691505b1..3718ecdf9edf 100644
--- a/scripts/Makefile.package
+++ b/scripts/Makefile.package
@@ -49,7 +49,7 @@ git-config-tar.zst = -c tar.tar.zst.command="$(ZSTD)"

quiet_cmd_archive = ARCHIVE $@
cmd_archive = git -C $(srctree) $(git-config-tar$(suffix $@)) archive \
- --output=$$(realpath $@) --prefix=$(basename $@)/ $(archive-args)
+ --output=$$(realpath $@) --prefix=$(basename $(basename $@))/ $(archive-args)

# Linux source tarball
# ---------------------------------------------------------------------------
--
2.27.0