adjust_autoksyms.sh 3.1 KB

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