blob: 59fdb875e81811c54729da50ae9606c6282b16c7 [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
Quentin Perretcd195bc2020-02-28 17:20:14 +00004# Script to update include/generated/autoksyms.h and dependency files
Nicolas Pitre23121ca2016-01-26 21:50:18 -05005#
6# Copyright: (C) 2016 Linaro Limited
7# Created by: Nicolas Pitre, January 2016
8#
Nicolas Pitre23121ca2016-01-26 21:50:18 -05009
Quentin Perretcd195bc2020-02-28 17:20:14 +000010# Update the include/generated/autoksyms.h file.
Nicolas Pitre23121ca2016-01-26 21:50:18 -050011#
12# For each symbol being added or removed, the corresponding dependency
13# file's timestamp is updated to force a rebuild of the affected source
14# file. All arguments passed to this script are assumed to be a command
15# to be exec'd to trigger a rebuild of those files.
16
17set -e
18
19cur_ksyms_file="include/generated/autoksyms.h"
20new_ksyms_file="include/generated/autoksyms.h.tmpnew"
21
22info() {
23 if [ "$quiet" != "silent_" ]; then
24 printf " %-7s %s\n" "$1" "$2"
25 fi
26}
27
28info "CHK" "$cur_ksyms_file"
29
30# Use "make V=1" to debug this script.
31case "$KBUILD_VERBOSE" in
32*1*)
33 set -x
34 ;;
35esac
36
Quentin Perretcd195bc2020-02-28 17:20:14 +000037# Generate a new symbol list file
38$CONFIG_SHELL $srctree/scripts/gen_autoksyms.sh "$new_ksyms_file"
Nicolas Pitre23121ca2016-01-26 21:50:18 -050039
40# Extract changes between old and new list and touch corresponding
41# dependency files.
42changed=$(
43count=0
44sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
Masahiro Yamadabc7cd2d2021-08-30 17:20:33 +090045sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' |
Nicolas Pitre23121ca2016-01-26 21:50:18 -050046while read sympath; do
47 if [ -z "$sympath" ]; then continue; fi
Masahiro Yamadabc7cd2d2021-08-30 17:20:33 +090048 depfile="include/ksym/${sympath}"
Nicolas Pitre23121ca2016-01-26 21:50:18 -050049 mkdir -p "$(dirname "$depfile")"
50 touch "$depfile"
Nicolas Pitre825d4872018-03-15 16:56:20 -040051 # Filesystems with coarse time precision may create timestamps
52 # equal to the one from a file that was very recently built and that
53 # needs to be rebuild. Let's guard against that by making sure our
54 # dep files are always newer than the first file we created here.
55 while [ ! "$depfile" -nt "$new_ksyms_file" ]; do
56 touch "$depfile"
57 done
Nicolas Pitre23121ca2016-01-26 21:50:18 -050058 echo $((count += 1))
59done | tail -1 )
60changed=${changed:-0}
61
62if [ $changed -gt 0 ]; then
63 # Replace the old list with tne new one
64 old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true)
65 new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true)
66 info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
67 info "UPD" "$cur_ksyms_file"
68 mv -f "$new_ksyms_file" "$cur_ksyms_file"
69 # Then trigger a rebuild of affected source files
70 exec $@
71else
72 rm -f "$new_ksyms_file"
73fi