kheaders: substituting --sort in archive creation

The option --sort=ORDER was only introduced in tar 1.28 (2014), which
is rather new and might not be available in some setups.

This patch tries to replicate the previous behaviour as closely as
possible to fix the kheaders build for older environments. It does
not produce identical archives compared to the previous version due
to minor sorting differences but produces reproducible results itself
in my tests.

Reported-by: Andreas Schwab <schwab@suse.de>
Signed-off-by: Dmitry Goldin <dgoldin+lkml@protonmail.ch>
Tested-by: Andreas Schwab <schwab@suse.de>
Tested-by: Quentin Perret <qperret@google.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

authored by Dmitry Goldin and committed by Masahiro Yamada 700dea5a 991b78fb

Changed files
+7 -4
kernel
+7 -4
kernel/gen_kheaders.sh
··· 71 71 find $cpio_dir -type f -print0 | 72 72 xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;' 73 73 74 - # Create archive and try to normalize metadata for reproducibility 75 - tar "${KBUILD_BUILD_TIMESTAMP:+--mtime=$KBUILD_BUILD_TIMESTAMP}" \ 76 - --owner=0 --group=0 --sort=name --numeric-owner \ 77 - -Jcf $tarfile -C $cpio_dir/ . > /dev/null 74 + # Create archive and try to normalize metadata for reproducibility. 75 + # For compatibility with older versions of tar, files are fed to tar 76 + # pre-sorted, as --sort=name might not be available. 77 + find $cpio_dir -printf "./%P\n" | LC_ALL=C sort | \ 78 + tar "${KBUILD_BUILD_TIMESTAMP:+--mtime=$KBUILD_BUILD_TIMESTAMP}" \ 79 + --owner=0 --group=0 --numeric-owner --no-recursion \ 80 + -Jcf $tarfile -C $cpio_dir/ -T - > /dev/null 78 81 79 82 echo "$src_files_md5" > kernel/kheaders.md5 80 83 echo "$obj_files_md5" >> kernel/kheaders.md5