adjust_autoksyms.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. # Generate a new symbol list file
  30. $CONFIG_SHELL $srctree/scripts/gen_autoksyms.sh "$new_ksyms_file"
  31. # Extract changes between old and new list and touch corresponding
  32. # dependency files.
  33. changed=$(
  34. count=0
  35. sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
  36. sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" |
  37. while read sympath; do
  38. if [ -z "$sympath" ]; then continue; fi
  39. depfile="include/ksym/${sympath}.h"
  40. mkdir -p "$(dirname "$depfile")"
  41. touch "$depfile"
  42. # Filesystems with coarse time precision may create timestamps
  43. # equal to the one from a file that was very recently built and that
  44. # needs to be rebuild. Let's guard against that by making sure our
  45. # dep files are always newer than the first file we created here.
  46. while [ ! "$depfile" -nt "$new_ksyms_file" ]; do
  47. touch "$depfile"
  48. done
  49. echo $((count += 1))
  50. done | tail -1 )
  51. changed=${changed:-0}
  52. if [ $changed -gt 0 ]; then
  53. # Replace the old list with tne new one
  54. old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true)
  55. new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true)
  56. info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
  57. info "UPD" "$cur_ksyms_file"
  58. mv -f "$new_ksyms_file" "$cur_ksyms_file"
  59. # Then trigger a rebuild of affected source files
  60. exec $@
  61. else
  62. rm -f "$new_ksyms_file"
  63. fi