kbuild: deb-pkg: make .orig tarball a hard link if possible
authorMasahiro Yamada <masahiroy@kernel.org>
Wed, 15 Feb 2023 01:20:28 +0000 (10:20 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Sun, 26 Feb 2023 06:20:38 +0000 (15:20 +0900)
If '..' belongs to the same filesystem, create a hard link instead of
a copy. In most cases, you can save disk space.

I do not want to use 'mv' because keeping linux.tar.gz is useful to
avoid unneeded rebuilding of the tarball.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
scripts/Makefile.package

index c207f4e..80a96eb 100644 (file)
@@ -96,7 +96,11 @@ debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
 debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
 debian-orig: private orig-name = $(source)_$(version).orig.tar.gz
 debian-orig: linux.tar.gz debian
-       $(Q)cp $< ../$(orig-name)
+       $(Q)if [ "$(df  --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \
+               ln -f $< ../$(orig-name); \
+       else \
+               cp $< ../$(orig-name); \
+       fi
 
 PHONY += deb-pkg
 deb-pkg: debian-orig