adjust_autoksyms.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. # In case it doesn't exist yet...
  43. if [ -e "$cur_ksyms_file" ]; then touch "$cur_ksyms_file"; fi
  44. # Generate a new ksym list file with symbols needed by the current
  45. # set of modules.
  46. cat > "$new_ksyms_file" << EOT
  47. /*
  48. * Automatically generated file; DO NOT EDIT.
  49. */
  50. EOT
  51. sed -ns -e '3{s/ /\n/g;/^$/!p;}' "$MODVERDIR"/*.mod | sort -u |
  52. while read sym; do
  53. if [ -n "$CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX" ]; then
  54. sym="${sym#_}"
  55. fi
  56. echo "#define __KSYM_${sym} 1"
  57. done >> "$new_ksyms_file"
  58. # Special case for modversions (see modpost.c)
  59. if [ -n "$CONFIG_MODVERSIONS" ]; then
  60. echo "#define __KSYM_module_layout 1" >> "$new_ksyms_file"
  61. fi
  62. # Extract changes between old and new list and touch corresponding
  63. # dependency files.
  64. changed=$(
  65. count=0
  66. sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
  67. sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" |
  68. while read sympath; do
  69. if [ -z "$sympath" ]; then continue; fi
  70. depfile="include/config/ksym/${sympath}.h"
  71. mkdir -p "$(dirname "$depfile")"
  72. touch "$depfile"
  73. # Filesystems with coarse time precision may create timestamps
  74. # equal to the one from a file that was very recently built and that
  75. # needs to be rebuild. Let's guard against that by making sure our
  76. # dep files are always newer than the first file we created here.
  77. while [ ! "$depfile" -nt "$new_ksyms_file" ]; do
  78. touch "$depfile"
  79. done
  80. echo $((count += 1))
  81. done | tail -1 )
  82. changed=${changed:-0}
  83. if [ $changed -gt 0 ]; then
  84. # Replace the old list with tne new one
  85. old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true)
  86. new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true)
  87. info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
  88. info "UPD" "$cur_ksyms_file"
  89. mv -f "$new_ksyms_file" "$cur_ksyms_file"
  90. # Then trigger a rebuild of affected source files
  91. exec $@
  92. else
  93. rm -f "$new_ksyms_file"
  94. fi