xref: /OK3568_Linux_fs/kernel/scripts/adjust_autoksyms.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/sh
2*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0-only
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun# Script to update include/generated/autoksyms.h and dependency files
5*4882a593Smuzhiyun#
6*4882a593Smuzhiyun# Copyright:	(C) 2016  Linaro Limited
7*4882a593Smuzhiyun# Created by:	Nicolas Pitre, January 2016
8*4882a593Smuzhiyun#
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun# Update the include/generated/autoksyms.h file.
11*4882a593Smuzhiyun#
12*4882a593Smuzhiyun# For each symbol being added or removed, the corresponding dependency
13*4882a593Smuzhiyun# file's timestamp is updated to force a rebuild of the affected source
14*4882a593Smuzhiyun# file. All arguments passed to this script are assumed to be a command
15*4882a593Smuzhiyun# to be exec'd to trigger a rebuild of those files.
16*4882a593Smuzhiyun
17*4882a593Smuzhiyunset -e
18*4882a593Smuzhiyun
19*4882a593Smuzhiyuncur_ksyms_file="include/generated/autoksyms.h"
20*4882a593Smuzhiyunnew_ksyms_file="include/generated/autoksyms.h.tmpnew"
21*4882a593Smuzhiyun
22*4882a593Smuzhiyuninfo() {
23*4882a593Smuzhiyun	if [ "$quiet" != "silent_" ]; then
24*4882a593Smuzhiyun		printf "  %-7s %s\n" "$1" "$2"
25*4882a593Smuzhiyun	fi
26*4882a593Smuzhiyun}
27*4882a593Smuzhiyun
28*4882a593Smuzhiyuninfo "CHK" "$cur_ksyms_file"
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun# Use "make V=1" to debug this script.
31*4882a593Smuzhiyuncase "$KBUILD_VERBOSE" in
32*4882a593Smuzhiyun*1*)
33*4882a593Smuzhiyun	set -x
34*4882a593Smuzhiyun	;;
35*4882a593Smuzhiyunesac
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun# Generate a new symbol list file
38*4882a593Smuzhiyun$CONFIG_SHELL $srctree/scripts/gen_autoksyms.sh "$new_ksyms_file"
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun# Extract changes between old and new list and touch corresponding
41*4882a593Smuzhiyun# dependency files.
42*4882a593Smuzhiyunchanged=$(
43*4882a593Smuzhiyuncount=0
44*4882a593Smuzhiyunsort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
45*4882a593Smuzhiyunsed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" |
46*4882a593Smuzhiyunwhile read sympath; do
47*4882a593Smuzhiyun	if [ -z "$sympath" ]; then continue; fi
48*4882a593Smuzhiyun	depfile="include/ksym/${sympath}.h"
49*4882a593Smuzhiyun	mkdir -p "$(dirname "$depfile")"
50*4882a593Smuzhiyun	touch "$depfile"
51*4882a593Smuzhiyun	# Filesystems with coarse time precision may create timestamps
52*4882a593Smuzhiyun	# equal to the one from a file that was very recently built and that
53*4882a593Smuzhiyun	# needs to be rebuild. Let's guard against that by making sure our
54*4882a593Smuzhiyun	# dep files are always newer than the first file we created here.
55*4882a593Smuzhiyun	while [ ! "$depfile" -nt "$new_ksyms_file" ]; do
56*4882a593Smuzhiyun		touch "$depfile"
57*4882a593Smuzhiyun	done
58*4882a593Smuzhiyun	echo $((count += 1))
59*4882a593Smuzhiyundone | tail -1 )
60*4882a593Smuzhiyunchanged=${changed:-0}
61*4882a593Smuzhiyun
62*4882a593Smuzhiyunif [ $changed -gt 0 ]; then
63*4882a593Smuzhiyun	# Replace the old list with tne new one
64*4882a593Smuzhiyun	old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true)
65*4882a593Smuzhiyun	new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true)
66*4882a593Smuzhiyun	info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
67*4882a593Smuzhiyun	info "UPD" "$cur_ksyms_file"
68*4882a593Smuzhiyun	mv -f "$new_ksyms_file" "$cur_ksyms_file"
69*4882a593Smuzhiyun	# Then trigger a rebuild of affected source files
70*4882a593Smuzhiyun	exec $@
71*4882a593Smuzhiyunelse
72*4882a593Smuzhiyun	rm -f "$new_ksyms_file"
73*4882a593Smuzhiyunfi
74