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 | |
| 4 | # Script to create/update include/generated/autoksyms.h and dependency files |
| 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 | |
| 10 | # Create/update the include/generated/autoksyms.h file from the list |
Masahiro Yamada | 60ae1b1 | 2019-07-17 15:17:58 +0900 | [diff] [blame] | 11 | # of all module's needed symbols as recorded on the second line of *.mod files. |
Nicolas Pitre | 23121ca | 2016-01-26 21:50:18 -0500 | [diff] [blame] | 12 | # |
| 13 | # For each symbol being added or removed, the corresponding dependency |
| 14 | # file's timestamp is updated to force a rebuild of the affected source |
| 15 | # file. All arguments passed to this script are assumed to be a command |
| 16 | # to be exec'd to trigger a rebuild of those files. |
| 17 | |
| 18 | set -e |
| 19 | |
| 20 | cur_ksyms_file="include/generated/autoksyms.h" |
| 21 | new_ksyms_file="include/generated/autoksyms.h.tmpnew" |
| 22 | |
| 23 | info() { |
| 24 | if [ "$quiet" != "silent_" ]; then |
| 25 | printf " %-7s %s\n" "$1" "$2" |
| 26 | fi |
| 27 | } |
| 28 | |
| 29 | info "CHK" "$cur_ksyms_file" |
| 30 | |
| 31 | # Use "make V=1" to debug this script. |
| 32 | case "$KBUILD_VERBOSE" in |
| 33 | *1*) |
| 34 | set -x |
| 35 | ;; |
| 36 | esac |
| 37 | |
| 38 | # We need access to CONFIG_ symbols |
Masahiro Yamada | 94cf8ac | 2019-03-08 14:49:10 +0900 | [diff] [blame] | 39 | . include/config/auto.conf |
Nicolas Pitre | 23121ca | 2016-01-26 21:50:18 -0500 | [diff] [blame] | 40 | |
Nicolas Pitre | 23121ca | 2016-01-26 21:50:18 -0500 | [diff] [blame] | 41 | # Generate a new ksym list file with symbols needed by the current |
| 42 | # set of modules. |
| 43 | cat > "$new_ksyms_file" << EOT |
| 44 | /* |
| 45 | * Automatically generated file; DO NOT EDIT. |
| 46 | */ |
| 47 | |
| 48 | EOT |
Masahiro Yamada | b7dca6d | 2019-07-17 15:17:57 +0900 | [diff] [blame] | 49 | sed 's/ko$/mod/' modules.order | |
Masahiro Yamada | 60ae1b1 | 2019-07-17 15:17:58 +0900 | [diff] [blame] | 50 | xargs -n1 sed -n -e '2{s/ /\n/g;/^$/!p;}' -- | |
Masahiro Yamada | b7dca6d | 2019-07-17 15:17:57 +0900 | [diff] [blame] | 51 | sort -u | |
| 52 | sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$new_ksyms_file" |
Nicolas Pitre | 23121ca | 2016-01-26 21:50:18 -0500 | [diff] [blame] | 53 | |
| 54 | # Special case for modversions (see modpost.c) |
| 55 | if [ -n "$CONFIG_MODVERSIONS" ]; then |
| 56 | echo "#define __KSYM_module_layout 1" >> "$new_ksyms_file" |
| 57 | fi |
| 58 | |
| 59 | # Extract changes between old and new list and touch corresponding |
| 60 | # dependency files. |
| 61 | changed=$( |
| 62 | count=0 |
| 63 | sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u | |
| 64 | sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" | |
| 65 | while read sympath; do |
| 66 | if [ -z "$sympath" ]; then continue; fi |
Masahiro Yamada | fbfa9be | 2018-03-16 16:37:14 +0900 | [diff] [blame] | 67 | depfile="include/ksym/${sympath}.h" |
Nicolas Pitre | 23121ca | 2016-01-26 21:50:18 -0500 | [diff] [blame] | 68 | mkdir -p "$(dirname "$depfile")" |
| 69 | touch "$depfile" |
Nicolas Pitre | 825d487 | 2018-03-15 16:56:20 -0400 | [diff] [blame] | 70 | # Filesystems with coarse time precision may create timestamps |
| 71 | # equal to the one from a file that was very recently built and that |
| 72 | # needs to be rebuild. Let's guard against that by making sure our |
| 73 | # dep files are always newer than the first file we created here. |
| 74 | while [ ! "$depfile" -nt "$new_ksyms_file" ]; do |
| 75 | touch "$depfile" |
| 76 | done |
Nicolas Pitre | 23121ca | 2016-01-26 21:50:18 -0500 | [diff] [blame] | 77 | echo $((count += 1)) |
| 78 | done | tail -1 ) |
| 79 | changed=${changed:-0} |
| 80 | |
| 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 |