Back to home page

LXR

 
 

    


0001 #!/bin/sh
0002 
0003 # Script to create/update include/generated/autoksyms.h and dependency files
0004 #
0005 # Copyright:    (C) 2016  Linaro Limited
0006 # Created by:   Nicolas Pitre, January 2016
0007 #
0008 # This program is free software; you can redistribute it and/or modify
0009 # it under the terms of the GNU General Public License version 2 as
0010 # published by the Free Software Foundation.
0011 
0012 # Create/update the include/generated/autoksyms.h file from the list
0013 # of all module's needed symbols as recorded on the third line of
0014 # .tmp_versions/*.mod files.
0015 #
0016 # For each symbol being added or removed, the corresponding dependency
0017 # file's timestamp is updated to force a rebuild of the affected source
0018 # file. All arguments passed to this script are assumed to be a command
0019 # to be exec'd to trigger a rebuild of those files.
0020 
0021 set -e
0022 
0023 cur_ksyms_file="include/generated/autoksyms.h"
0024 new_ksyms_file="include/generated/autoksyms.h.tmpnew"
0025 
0026 info() {
0027         if [ "$quiet" != "silent_" ]; then
0028                 printf "  %-7s %s\n" "$1" "$2"
0029         fi
0030 }
0031 
0032 info "CHK" "$cur_ksyms_file"
0033 
0034 # Use "make V=1" to debug this script.
0035 case "$KBUILD_VERBOSE" in
0036 *1*)
0037         set -x
0038         ;;
0039 esac
0040 
0041 # We need access to CONFIG_ symbols
0042 case "${KCONFIG_CONFIG}" in
0043 */*)
0044         . "${KCONFIG_CONFIG}"
0045         ;;
0046 *)
0047         # Force using a file from the current directory
0048         . "./${KCONFIG_CONFIG}"
0049 esac
0050 
0051 # In case it doesn't exist yet...
0052 if [ -e "$cur_ksyms_file" ]; then touch "$cur_ksyms_file"; fi
0053 
0054 # Generate a new ksym list file with symbols needed by the current
0055 # set of modules.
0056 cat > "$new_ksyms_file" << EOT
0057 /*
0058  * Automatically generated file; DO NOT EDIT.
0059  */
0060 
0061 EOT
0062 [ "$(ls -A "$MODVERDIR")" ] &&
0063 sed -ns -e '3{s/ /\n/g;/^$/!p;}' "$MODVERDIR"/*.mod | sort -u |
0064 while read sym; do
0065         if [ -n "$CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX" ]; then
0066                 sym="${sym#_}"
0067         fi
0068         echo "#define __KSYM_${sym} 1"
0069 done >> "$new_ksyms_file"
0070 
0071 # Special case for modversions (see modpost.c)
0072 if [ -n "$CONFIG_MODVERSIONS" ]; then
0073         echo "#define __KSYM_module_layout 1" >> "$new_ksyms_file"
0074 fi
0075 
0076 # Extract changes between old and new list and touch corresponding
0077 # dependency files.
0078 changed=$(
0079 count=0
0080 sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
0081 sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" |
0082 while read sympath; do
0083         if [ -z "$sympath" ]; then continue; fi
0084         depfile="include/config/ksym/${sympath}.h"
0085         mkdir -p "$(dirname "$depfile")"
0086         touch "$depfile"
0087         echo $((count += 1))
0088 done | tail -1 )
0089 changed=${changed:-0}
0090 
0091 if [ $changed -gt 0 ]; then
0092         # Replace the old list with tne new one
0093         old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true)
0094         new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true)
0095         info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
0096         info "UPD" "$cur_ksyms_file"
0097         mv -f "$new_ksyms_file" "$cur_ksyms_file"
0098         # Then trigger a rebuild of affected source files
0099         exec $@
0100 else
0101         rm -f "$new_ksyms_file"
0102 fi