2 # SPDX-License-Identifier: GPL-2.0-only
4 # Script to create/update include/generated/autoksyms.h and dependency files
6 # Copyright: (C) 2016 Linaro Limited
7 # Created by: Nicolas Pitre, January 2016
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.
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.
21 cur_ksyms_file
="include/generated/autoksyms.h"
22 new_ksyms_file
="include/generated/autoksyms.h.tmpnew"
25 if [ "$quiet" != "silent_" ]; then
26 printf " %-7s %s\n" "$1" "$2"
30 info
"CHK" "$cur_ksyms_file"
32 # Use "make V=1" to debug this script.
33 case "$KBUILD_VERBOSE" in
39 # We need access to CONFIG_ symbols
40 . include
/config
/auto.conf
42 # Generate a new ksym list file with symbols needed by the current
44 cat > "$new_ksyms_file" << EOT
46 * Automatically generated file; DO NOT EDIT.
50 [ "$(ls -A "$MODVERDIR")" ] &&
51 for mod
in "$MODVERDIR"/*.mod
; do
52 sed -n -e '3{s/ /\n/g;/^$/!p;}' "$mod"
55 echo "#define __KSYM_${sym} 1"
56 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"
63 # Extract changes between old and new list and touch corresponding
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/ksym/${sympath}.h"
72 mkdir
-p "$(dirname "$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
85 if [ $changed -gt 0 ]; then
86 # Replace the old list with tne new one
87 old
=$
(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true
)
88 new
=$
(grep -c "^#define __KSYM_" "$new_ksyms_file" || true
)
89 info
"KSYMS" "symbols: before=$old, after=$new, changed=$changed"
90 info
"UPD" "$cur_ksyms_file"
91 mv -f "$new_ksyms_file" "$cur_ksyms_file"
92 # Then trigger a rebuild of affected source files
95 rm -f "$new_ksyms_file"