#!/bin/sh # Script to create/update include/generated/autoksyms.h and dependency files # # Copyright: (C) 2016 Linaro Limited # Created by: Nicolas Pitre, January 2016 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # Create/update the include/generated/autoksyms.h file from the list # of all module's needed symbols as recorded on the third line of # .tmp_versions/*.mod files. # # For each symbol being added or removed, the corresponding dependency # file's timestamp is updated to force a rebuild of the affected source # file. All arguments passed to this script are assumed to be a command # to be exec'd to trigger a rebuild of those files. set -e setglobal cur_ksyms_file = '"include/generated/autoksyms.h'" setglobal new_ksyms_file = '"include/generated/autoksyms.h.tmpnew'" proc info { if test $quiet != "silent_" { printf " %-7s %s\n" $1 $2 } } info "CHK" $cur_ksyms_file # Use "make V=1" to debug this script. match $KBUILD_VERBOSE { with *1* set -x } # We need access to CONFIG_ symbols match $(KCONFIG_CONFIG) { with */* source "${KCONFIG_CONFIG}" with * # Force using a file from the current directory source "./${KCONFIG_CONFIG}" } # In case it doesn't exist yet... if test -e $cur_ksyms_file { touch $cur_ksyms_file; } # Generate a new ksym list file with symbols needed by the current # set of modules. cat > $new_ksyms_file << """ /* * Automatically generated file; DO NOT EDIT. */ """ sed -ns -e '3{s/ /\n/g;/^$/!p;}' "$MODVERDIR"/*.mod | sort -u | while read sym { if test -n $CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX { setglobal sym = $(sym#_) } echo "#define __KSYM_$(sym) 1" } >> "$new_ksyms_file" # Special case for modversions (see modpost.c) if test -n $CONFIG_MODVERSIONS { echo "#define __KSYM_module_layout 1" >> $new_ksyms_file } # Extract changes between old and new list and touch corresponding # dependency files. setglobal changed = $[ setglobal count = '0' sort $cur_ksyms_file $new_ksyms_file | uniq -u | sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" | while read sympath { if test -z $sympath { continue; } setglobal depfile = ""include/config/ksym/$(sympath).h"" mkdir -p $[dirname $depfile] touch $depfile echo $shExpr('count += 1') } | tail -1] setglobal changed = $(changed:-0) if test $changed -gt 0 { # Replace the old list with tne new one setglobal old = $[grep -c "^#define __KSYM_" $cur_ksyms_file || true] setglobal new = $[grep -c "^#define __KSYM_" $new_ksyms_file || true] info "KSYMS" "symbols: before=$old, after=$new, changed=$changed" info "UPD" $cur_ksyms_file mv -f $new_ksyms_file $cur_ksyms_file # Then trigger a rebuild of affected source files exec $ifsjoin(Argv) } else { rm -f $new_ksyms_file }