PageRenderTime 954ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/kernel/gen_kheaders.sh

https://gitlab.com/lszubowi/kernel-ark
Shell | 95 lines | 52 code | 15 blank | 28 comment | 7 complexity | 24092348b0a2f95173cc3f07419d1a3f MD5 | raw file
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. # This script generates an archive consisting of kernel headers
  4. # for CONFIG_IKHEADERS.
  5. set -e
  6. sfile="$(readlink -f "$0")"
  7. outdir="$(pwd)"
  8. tarfile=$1
  9. cpio_dir=$outdir/$tarfile.tmp
  10. dir_list="
  11. include/
  12. arch/$SRCARCH/include/
  13. "
  14. # Support incremental builds by skipping archive generation
  15. # if timestamps of files being archived are not changed.
  16. # This block is useful for debugging the incremental builds.
  17. # Uncomment it for debugging.
  18. # if [ ! -f /tmp/iter ]; then iter=1; echo 1 > /tmp/iter;
  19. # else iter=$(($(cat /tmp/iter) + 1)); echo $iter > /tmp/iter; fi
  20. # find $all_dirs -name "*.h" | xargs ls -l > /tmp/ls-$iter
  21. all_dirs=
  22. if [ "$building_out_of_srctree" ]; then
  23. for d in $dir_list; do
  24. all_dirs="$all_dirs $srctree/$d"
  25. done
  26. fi
  27. all_dirs="$all_dirs $dir_list"
  28. # include/generated/compile.h is ignored because it is touched even when none
  29. # of the source files changed.
  30. #
  31. # When Kconfig regenerates include/generated/autoconf.h, its timestamp is
  32. # updated, but the contents might be still the same. When any CONFIG option is
  33. # changed, Kconfig touches the corresponding timestamp file include/config/*.
  34. # Hence, the md5sum detects the configuration change anyway. We do not need to
  35. # check include/generated/autoconf.h explicitly.
  36. #
  37. # Ignore them for md5 calculation to avoid pointless regeneration.
  38. headers_md5="$(find $all_dirs -name "*.h" |
  39. grep -v "include/generated/compile.h" |
  40. grep -v "include/generated/autoconf.h" |
  41. xargs ls -l | md5sum | cut -d ' ' -f1)"
  42. # Any changes to this script will also cause a rebuild of the archive.
  43. this_file_md5="$(ls -l $sfile | md5sum | cut -d ' ' -f1)"
  44. if [ -f $tarfile ]; then tarfile_md5="$(md5sum $tarfile | cut -d ' ' -f1)"; fi
  45. if [ -f kernel/kheaders.md5 ] &&
  46. [ "$(head -n 1 kernel/kheaders.md5)" = "$headers_md5" ] &&
  47. [ "$(head -n 2 kernel/kheaders.md5 | tail -n 1)" = "$this_file_md5" ] &&
  48. [ "$(tail -n 1 kernel/kheaders.md5)" = "$tarfile_md5" ]; then
  49. exit
  50. fi
  51. echo " GEN $tarfile"
  52. rm -rf $cpio_dir
  53. mkdir $cpio_dir
  54. if [ "$building_out_of_srctree" ]; then
  55. (
  56. cd $srctree
  57. for f in $dir_list
  58. do find "$f" -name "*.h";
  59. done | cpio --quiet -pd $cpio_dir
  60. )
  61. fi
  62. # The second CPIO can complain if files already exist which can happen with out
  63. # of tree builds having stale headers in srctree. Just silence CPIO for now.
  64. for f in $dir_list;
  65. do find "$f" -name "*.h";
  66. done | cpio --quiet -pd $cpio_dir >/dev/null 2>&1
  67. # Remove comments except SDPX lines
  68. find $cpio_dir -type f -print0 |
  69. xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;'
  70. # Create archive and try to normalize metadata for reproducibility.
  71. # For compatibility with older versions of tar, files are fed to tar
  72. # pre-sorted, as --sort=name might not be available.
  73. find $cpio_dir -printf "./%P\n" | LC_ALL=C sort | \
  74. tar "${KBUILD_BUILD_TIMESTAMP:+--mtime=$KBUILD_BUILD_TIMESTAMP}" \
  75. --owner=0 --group=0 --numeric-owner --no-recursion \
  76. -I $XZ -cf $tarfile -C $cpio_dir/ -T - > /dev/null
  77. echo $headers_md5 > kernel/kheaders.md5
  78. echo "$this_file_md5" >> kernel/kheaders.md5
  79. echo "$(md5sum $tarfile | cut -d ' ' -f1)" >> kernel/kheaders.md5
  80. rm -rf $cpio_dir