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