0001
0002
0003
0004
0005
0006 SPATCH_REQ_VERSION="1.0.4"
0007
0008 DIR="$(dirname $(readlink -f $0))/.."
0009 SPATCH="`which ${SPATCH:=spatch}`"
0010 if [ ! -x "$SPATCH" ]; then
0011 echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
0012 exit 1
0013 fi
0014
0015 SPATCH_VERSION=$($SPATCH --version | head -1 | awk '{print $3}')
0016
0017 if ! { echo "$SPATCH_REQ_VERSION"; echo "$SPATCH_VERSION"; } | sort -CV ; then
0018 echo "spatch needs to be version $SPATCH_REQ_VERSION or higher"
0019 exit 1
0020 fi
0021
0022 if [ "$KBUILD_EXTMOD" ]; then
0023 src_prefix=
0024 else
0025 src_prefix=$srctree/
0026 fi
0027
0028 generate_deps_for_ns() {
0029 $SPATCH --very-quiet --in-place --sp-file \
0030 $srctree/scripts/coccinelle/misc/add_namespace.cocci -D nsdeps -D ns=$1 $2
0031 }
0032
0033 generate_deps() {
0034 local mod=${1%.ko:}
0035 shift
0036 local namespaces="$*"
0037 local mod_source_files=$(sed "s|^\(.*\)\.o$|${src_prefix}\1.c|" $mod.mod)
0038
0039 for ns in $namespaces; do
0040 echo "Adding namespace $ns to module $mod.ko."
0041 generate_deps_for_ns $ns "$mod_source_files"
0042
0043 for source_file in $mod_source_files; do
0044 sed '/MODULE_IMPORT_NS/Q' $source_file > ${source_file}.tmp
0045 offset=$(wc -l ${source_file}.tmp | awk '{print $1;}')
0046 cat $source_file | grep MODULE_IMPORT_NS | LC_ALL=C sort -u >> ${source_file}.tmp
0047 tail -n +$((offset +1)) ${source_file} | grep -v MODULE_IMPORT_NS >> ${source_file}.tmp
0048 if ! diff -q ${source_file} ${source_file}.tmp; then
0049 mv ${source_file}.tmp ${source_file}
0050 else
0051 rm ${source_file}.tmp
0052 fi
0053 done
0054 done
0055 }
0056
0057 while read line
0058 do
0059 generate_deps $line
0060 done < $MODULES_NSDEPS