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