adjust_autoksyms.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/sh
  2. # Script to create/update include/generated/autoksyms.h and dependency files
  3. #
  4. # Copyright: (C) 2016 Linaro Limited
  5. # Created by: Nicolas Pitre, January 2016
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License version 2 as
  9. # published by the Free Software Foundation.
  10. # Create/update the include/generated/autoksyms.h file from the list
  11. # of all module's needed symbols as recorded on the third line of
  12. # .tmp_versions/*.mod files.
  13. #
  14. # For each symbol being added or removed, the corresponding dependency
  15. # file's timestamp is updated to force a rebuild of the affected source
  16. # file. All arguments passed to this script are assumed to be a command
  17. # to be exec'd to trigger a rebuild of those files.
  18. set -e
  19. cur_ksyms_file="include/generated/autoksyms.h"
  20. new_ksyms_file="include/generated/autoksyms.h.tmpnew"
  21. info() {
  22. if [ "$quiet" != "silent_" ]; then
  23. printf " %-7s %s\n" "$1" "$2"
  24. fi
  25. }
  26. info "CHK" "$cur_ksyms_file"
  27. # Use "make V=1" to debug this script.
  28. case "$KBUILD_VERBOSE" in
  29. *1*)
  30. set -x
  31. ;;
  32. esac
  33. # We need access to CONFIG_ symbols
  34. case "${KCONFIG_CONFIG}" in
  35. */*)
  36. . "${KCONFIG_CONFIG}"
  37. ;;
  38. *)
  39. # Force using a file from the current directory
  40. . "./${KCONFIG_CONFIG}"
  41. esac
  42. # Generate a new ksym list file with symbols needed by the current
  43. # set of modules.
  44. cat > "$new_ksyms_file" << EOT
  45. /*
  46. * Automatically generated file; DO NOT EDIT.
  47. */
  48. EOT
  49. [ "$(ls -A "$MODVERDIR")" ] &&
  50. for mod in "$MODVERDIR"/*.mod; do
  51. sed -n -e '3{s/ /\n/g;/^$/!p;}' "$mod"
  52. done | sort -u |
  53. while read sym; do
  54. echo "#define __KSYM_${sym} 1"
  55. done >> "$new_ksyms_file"
  56. # Special case for modversions (see modpost.c)
  57. if [ -n "$CONFIG_MODVERSIONS" ]; then
  58. echo "#define __KSYM_module_layout 1" >> "$new_ksyms_file"
  59. fi
  60. # Extract changes between old and new list and touch corresponding
  61. # dependency files.
  62. changed=$(
  63. count=0
  64. sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
  65. sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" |
  66. while read sympath; do
  67. if [ -z "$sympath" ]; then continue; fi
  68. depfile="include/ksym/${sympath}.h"
  69. mkdir -p "$(dirname "$depfile")"
  70. touch "$depfile"
  71. # Filesystems with coarse time precision may create timestamps
  72. # equal to the one from a file that was very recently built and that
  73. # needs to be rebuild. Let's guard against that by making sure our
  74. # dep files are always newer than the first file we created here.
  75. while [ ! "$depfile" -nt "$new_ksyms_file" ]; do
  76. touch "$depfile"
  77. done
  78. echo $((count += 1))
  79. done | tail -1 )
  80. changed=${changed:-0}
  81. if [ $changed -gt 0 ]; then
  82. # Replace the old list with tne new one
  83. old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true)
  84. new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true)
  85. info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
  86. info "UPD" "$cur_ksyms_file"
  87. mv -f "$new_ksyms_file" "$cur_ksyms_file"
  88. # Then trigger a rebuild of affected source files
  89. exec $@
  90. else
  91. rm -f "$new_ksyms_file"
  92. fi