adjust_autoksyms.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-only
  3. # Script to update include/generated/autoksyms.h and dependency files
  4. #
  5. # Copyright: (C) 2016 Linaro Limited
  6. # Created by: Nicolas Pitre, January 2016
  7. #
  8. # Update the include/generated/autoksyms.h file.
  9. #
  10. # For each symbol being added or removed, the corresponding dependency
  11. # file's timestamp is updated to force a rebuild of the affected source
  12. # file. All arguments passed to this script are assumed to be a command
  13. # to be exec'd to trigger a rebuild of those files.
  14. set -e
  15. cur_ksyms_file="include/generated/autoksyms.h"
  16. new_ksyms_file="include/generated/autoksyms.h.tmpnew"
  17. info() {
  18. if [ "$quiet" != "silent_" ]; then
  19. printf " %-7s %s\n" "$1" "$2"
  20. fi
  21. }
  22. info "CHK" "$cur_ksyms_file"
  23. # Use "make V=1" to debug this script.
  24. case "$KBUILD_VERBOSE" in
  25. *1*)
  26. set -x
  27. ;;
  28. esac
  29. # We need access to CONFIG_ symbols
  30. . include/config/auto.conf
  31. # Generate a new symbol list file
  32. $CONFIG_SHELL $srctree/scripts/gen_autoksyms.sh "$new_ksyms_file"
  33. # Extract changes between old and new list and touch corresponding
  34. # dependency files.
  35. changed=$(
  36. count=0
  37. sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
  38. sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" |
  39. while read sympath; do
  40. if [ -z "$sympath" ]; then continue; fi
  41. depfile="include/ksym/${sympath}.h"
  42. mkdir -p "$(dirname "$depfile")"
  43. touch "$depfile"
  44. # Filesystems with coarse time precision may create timestamps
  45. # equal to the one from a file that was very recently built and that
  46. # needs to be rebuild. Let's guard against that by making sure our
  47. # dep files are always newer than the first file we created here.
  48. while [ ! "$depfile" -nt "$new_ksyms_file" ]; do
  49. touch "$depfile"
  50. done
  51. echo $((count += 1))
  52. done | tail -1 )
  53. changed=${changed:-0}
  54. if [ $changed -gt 0 ]; then
  55. # Replace the old list with tne new one
  56. old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true)
  57. new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true)
  58. info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
  59. info "UPD" "$cur_ksyms_file"
  60. mv -f "$new_ksyms_file" "$cur_ksyms_file"
  61. # Then trigger a rebuild of affected source files
  62. exec $@
  63. else
  64. rm -f "$new_ksyms_file"
  65. fi