blob: aab4e299d7a2b1ae84afbd92603c2b7ba6241f6c [file] [log] [blame]
Nicolas Pitre23121ca2016-01-26 21:50:18 -05001#!/bin/sh
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02002# SPDX-License-Identifier: GPL-2.0-only
Nicolas Pitre23121ca2016-01-26 21:50:18 -05003
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 Pitre23121ca2016-01-26 21:50:18 -05009
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.
13#
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.
18
19set -e
20
21cur_ksyms_file="include/generated/autoksyms.h"
22new_ksyms_file="include/generated/autoksyms.h.tmpnew"
23
24info() {
25 if [ "$quiet" != "silent_" ]; then
26 printf " %-7s %s\n" "$1" "$2"
27 fi
28}
29
30info "CHK" "$cur_ksyms_file"
31
32# Use "make V=1" to debug this script.
33case "$KBUILD_VERBOSE" in
34*1*)
35 set -x
36 ;;
37esac
38
39# We need access to CONFIG_ symbols
Masahiro Yamada94cf8ac2019-03-08 14:49:10 +090040. include/config/auto.conf
Nicolas Pitre23121ca2016-01-26 21:50:18 -050041
Nicolas Pitre23121ca2016-01-26 21:50:18 -050042# Generate a new ksym list file with symbols needed by the current
43# set of modules.
44cat > "$new_ksyms_file" << EOT
45/*
46 * Automatically generated file; DO NOT EDIT.
47 */
48
49EOT
Nicolas Pitred0734722016-12-08 14:17:03 -050050[ "$(ls -A "$MODVERDIR")" ] &&
Michael Forney1fe7d2b2018-02-06 22:41:17 -080051for mod in "$MODVERDIR"/*.mod; do
52 sed -n -e '3{s/ /\n/g;/^$/!p;}' "$mod"
53done | sort -u |
Nicolas Pitre23121ca2016-01-26 21:50:18 -050054while read sym; do
Nicolas Pitre23121ca2016-01-26 21:50:18 -050055 echo "#define __KSYM_${sym} 1"
56done >> "$new_ksyms_file"
57
58# Special case for modversions (see modpost.c)
59if [ -n "$CONFIG_MODVERSIONS" ]; then
60 echo "#define __KSYM_module_layout 1" >> "$new_ksyms_file"
61fi
62
63# Extract changes between old and new list and touch corresponding
64# dependency files.
65changed=$(
66count=0
67sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
68sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" |
69while read sympath; do
70 if [ -z "$sympath" ]; then continue; fi
Masahiro Yamadafbfa9be2018-03-16 16:37:14 +090071 depfile="include/ksym/${sympath}.h"
Nicolas Pitre23121ca2016-01-26 21:50:18 -050072 mkdir -p "$(dirname "$depfile")"
73 touch "$depfile"
Nicolas Pitre825d4872018-03-15 16:56:20 -040074 # 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
79 touch "$depfile"
80 done
Nicolas Pitre23121ca2016-01-26 21:50:18 -050081 echo $((count += 1))
82done | tail -1 )
83changed=${changed:-0}
84
85if [ $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
93 exec $@
94else
95 rm -f "$new_ksyms_file"
96fi