Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0-only
0003 
0004 # Script to update include/generated/autoksyms.h and dependency files
0005 #
0006 # Copyright:    (C) 2016  Linaro Limited
0007 # Created by:   Nicolas Pitre, January 2016
0008 #
0009 
0010 # Update the include/generated/autoksyms.h file.
0011 #
0012 # For each symbol being added or removed, the corresponding dependency
0013 # file's timestamp is updated to force a rebuild of the affected source
0014 # file. All arguments passed to this script are assumed to be a command
0015 # to be exec'd to trigger a rebuild of those files.
0016 
0017 set -e
0018 
0019 cur_ksyms_file="include/generated/autoksyms.h"
0020 new_ksyms_file="include/generated/autoksyms.h.tmpnew"
0021 
0022 info() {
0023         if [ "$quiet" != "silent_" ]; then
0024                 printf "  %-7s %s\n" "$1" "$2"
0025         fi
0026 }
0027 
0028 info "CHK" "$cur_ksyms_file"
0029 
0030 # Use "make V=1" to debug this script.
0031 case "$KBUILD_VERBOSE" in
0032 *1*)
0033         set -x
0034         ;;
0035 esac
0036 
0037 # Generate a new symbol list file
0038 $CONFIG_SHELL $srctree/scripts/gen_autoksyms.sh --modorder "$new_ksyms_file"
0039 
0040 # Extract changes between old and new list and touch corresponding
0041 # dependency files.
0042 changed=$(
0043 count=0
0044 sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
0045 sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' |
0046 while read sympath; do
0047         if [ -z "$sympath" ]; then continue; fi
0048         depfile="include/ksym/${sympath}"
0049         mkdir -p "$(dirname "$depfile")"
0050         touch "$depfile"
0051         # Filesystems with coarse time precision may create timestamps
0052         # equal to the one from a file that was very recently built and that
0053         # needs to be rebuild. Let's guard against that by making sure our
0054         # dep files are always newer than the first file we created here.
0055         while [ ! "$depfile" -nt "$new_ksyms_file" ]; do
0056                 touch "$depfile"
0057         done
0058         echo $((count += 1))
0059 done | tail -1 )
0060 changed=${changed:-0}
0061 
0062 if [ $changed -gt 0 ]; then
0063         # Replace the old list with tne new one
0064         old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true)
0065         new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true)
0066         info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
0067         info "UPD" "$cur_ksyms_file"
0068         mv -f "$new_ksyms_file" "$cur_ksyms_file"
0069         # Then trigger a rebuild of affected source files
0070         exec $@
0071 else
0072         rm -f "$new_ksyms_file"
0073 fi