gen_kheaders.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  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. cpio=$KBUILD_SRC/tools/build/cpio
  11. dir_list="
  12. include/
  13. arch/$SRCARCH/include/
  14. "
  15. # Support incremental builds by skipping archive generation
  16. # if timestamps of files being archived are not changed.
  17. # This block is useful for debugging the incremental builds.
  18. # Uncomment it for debugging.
  19. # if [ ! -f /tmp/iter ]; then iter=1; echo 1 > /tmp/iter;
  20. # else iter=$(($(cat /tmp/iter) + 1)); echo $iter > /tmp/iter; fi
  21. # find $src_file_list -name "*.h" | xargs ls -l > /tmp/src-ls-$iter
  22. # find $obj_file_list -name "*.h" | xargs ls -l > /tmp/obj-ls-$iter
  23. # include/generated/compile.h is ignored because it is touched even when none
  24. # of the source files changed. This causes pointless regeneration, so let us
  25. # ignore them for md5 calculation.
  26. pushd $srctree > /dev/null
  27. src_files_md5="$(find $dir_list -name "*.h" |
  28. grep -v "include/generated/compile.h" |
  29. grep -v "include/generated/autoconf.h" |
  30. xargs ls -l | md5sum | cut -d ' ' -f1)"
  31. popd > /dev/null
  32. obj_files_md5="$(find $dir_list -name "*.h" |
  33. grep -v "include/generated/compile.h" |
  34. grep -v "include/generated/autoconf.h" |
  35. xargs ls -l | md5sum | cut -d ' ' -f1)"
  36. # Any changes to this script will also cause a rebuild of the archive.
  37. this_file_md5="$(ls -l $sfile | md5sum | cut -d ' ' -f1)"
  38. if [ -f $tarfile ]; then tarfile_md5="$(md5sum $tarfile | cut -d ' ' -f1)"; fi
  39. if [ -f kernel/kheaders.md5 ] &&
  40. [ "$(cat kernel/kheaders.md5|head -1)" == "$src_files_md5" ] &&
  41. [ "$(cat kernel/kheaders.md5|head -2|tail -1)" == "$obj_files_md5" ] &&
  42. [ "$(cat kernel/kheaders.md5|head -3|tail -1)" == "$this_file_md5" ] &&
  43. [ "$(cat kernel/kheaders.md5|tail -1)" == "$tarfile_md5" ]; then
  44. exit
  45. fi
  46. if [ "${quiet}" != "silent_" ]; then
  47. echo " GEN $tarfile"
  48. fi
  49. rm -rf $cpio_dir
  50. mkdir $cpio_dir
  51. pushd $srctree > /dev/null
  52. for f in $dir_list;
  53. do find "$f" -name "*.h";
  54. done | $cpio --quiet -pd $cpio_dir
  55. popd > /dev/null
  56. # The second CPIO can complain if files already exist which can
  57. # happen with out of tree builds. Just silence CPIO for now.
  58. for f in $dir_list;
  59. do find "$f" -name "*.h";
  60. done | $cpio --quiet -pd $cpio_dir >/dev/null 2>&1
  61. # Remove comments except SDPX lines
  62. find $cpio_dir -type f -print0 |
  63. xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;'
  64. tar -Jcf $tarfile -C $cpio_dir/ . > /dev/null
  65. echo "$src_files_md5" > kernel/kheaders.md5
  66. echo "$obj_files_md5" >> kernel/kheaders.md5
  67. echo "$this_file_md5" >> kernel/kheaders.md5
  68. echo "$(md5sum $tarfile | cut -d ' ' -f1)" >> kernel/kheaders.md5
  69. rm -rf $cpio_dir