Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[linux/fpc-iii.git] / scripts / adjust_autoksyms.sh
blob8dc1918b6783dd337590f97b5aa33be5125980ea
1 #!/bin/sh
3 # Script to create/update include/generated/autoksyms.h and dependency files
5 # Copyright: (C) 2016 Linaro Limited
6 # Created by: Nicolas Pitre, January 2016
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.
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.
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.
21 set -e
23 cur_ksyms_file="include/generated/autoksyms.h"
24 new_ksyms_file="include/generated/autoksyms.h.tmpnew"
26 info() {
27 if [ "$quiet" != "silent_" ]; then
28 printf " %-7s %s\n" "$1" "$2"
32 info "CHK" "$cur_ksyms_file"
34 # Use "make V=1" to debug this script.
35 case "$KBUILD_VERBOSE" in
36 *1*)
37 set -x
39 esac
41 # We need access to CONFIG_ symbols
42 case "${KCONFIG_CONFIG}" in
43 */*)
44 . "${KCONFIG_CONFIG}"
47 # Force using a file from the current directory
48 . "./${KCONFIG_CONFIG}"
49 esac
51 # In case it doesn't exist yet...
52 if [ -e "$cur_ksyms_file" ]; then touch "$cur_ksyms_file"; fi
54 # Generate a new ksym list file with symbols needed by the current
55 # set of modules.
56 cat > "$new_ksyms_file" << EOT
58 * Automatically generated file; DO NOT EDIT.
61 EOT
62 sed -ns -e '3{s/ /\n/g;/^$/!p;}' "$MODVERDIR"/*.mod | sort -u |
63 while read sym; do
64 if [ -n "$CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX" ]; then
65 sym="${sym#_}"
67 echo "#define __KSYM_${sym} 1"
68 done >> "$new_ksyms_file"
70 # Special case for modversions (see modpost.c)
71 if [ -n "$CONFIG_MODVERSIONS" ]; then
72 echo "#define __KSYM_module_layout 1" >> "$new_ksyms_file"
75 # Extract changes between old and new list and touch corresponding
76 # dependency files.
77 changed=$(
78 count=0
79 sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
80 sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" |
81 while read sympath; do
82 if [ -z "$sympath" ]; then continue; fi
83 depfile="include/config/ksym/${sympath}.h"
84 mkdir -p "$(dirname "$depfile")"
85 touch "$depfile"
86 echo $((count += 1))
87 done | tail -1 )
88 changed=${changed:-0}
90 if [ $changed -gt 0 ]; then
91 # Replace the old list with tne new one
92 old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true)
93 new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true)
94 info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
95 info "UPD" "$cur_ksyms_file"
96 mv -f "$new_ksyms_file" "$cur_ksyms_file"
97 # Then trigger a rebuild of affected source files
98 exec $@
99 else
100 rm -f "$new_ksyms_file"