xuexiaolei / rpms / kernel-rt

Forked from rpms/kernel-rt 4 years ago
Clone

Blame SOURCES/mod-extra.sh

f70460
#! /bin/bash
f70460
f70460
Dir=$1
f70460
List=$2
f70460
Dest="extra"
f70460
f70460
# Destination was specified on the command line
f70460
test -n "$3" && Dest="$3"
f70460
f70460
pushd $Dir
f70460
rm -rf modnames
f70460
find . -name "*.ko" -type f > modnames
f70460
# Look through all of the modules, and throw any that have a dependency in
f70460
# our list into the list as well.
f70460
rm -rf dep.list dep2.list
f70460
rm -rf req.list req2.list
f70460
touch dep.list req.list
f70460
cp "$List" .
f70460
f70460
# This variable needs to be exported because it is used in sub-script
f70460
# executed by xargs
f70460
export ListName=$(basename "$List")
f70460
f70460
# NB: this loop runs 2000+ iterations. Try to be fast.
f70460
NPROC=`nproc`
f70460
[ -z "$NPROC" ] && NPROC=1
f70460
cat modnames | xargs -r -n1 -P $NPROC sh -c '
f70460
  dep=$1
f70460
  depends=`modinfo $dep | sed -n -e "/^depends/ s/^depends:[ \t]*//p"`
f70460
  [ -z "$depends" ] && exit
f70460
  for mod in ${depends//,/ }
f70460
  do
f70460
    match=$(grep "^$mod.ko" "$ListName")
f70460
    [ -z "$match" ] && continue
f70460
    # check if the module we are looking at is in mod-extra too.
f70460
    # if so we do not need to mark the dep as required.
f70460
    mod2=${dep##*/}  # same as `basename $dep`, but faster
f70460
    match2=$(grep "^$mod2" "$ListName")
f70460
    if [ -n "$match2" ]
f70460
    then
f70460
      #echo $mod2 >> notreq.list
f70460
      continue
f70460
    fi
f70460
    echo $mod.ko >> req.list
f70460
  done
f70460
' DUMMYARG0   # xargs appends MODNAME, which becomes $dep in the script above
f70460
f70460
sort -u req.list > req2.list
f70460
sort -u "$ListName" > modules2.list
f70460
join -v 1 modules2.list req2.list > modules3.list
f70460
f70460
for mod in $(cat modules3.list)
f70460
do
f70460
  # get the path for the module
f70460
  modpath=`grep /$mod modnames`
f70460
  [ -z "$modpath" ] && continue
f70460
  echo $modpath >> dep.list
f70460
done
f70460
f70460
sort -u dep.list > dep2.list
f70460
f70460
# now move the modules into the extra/ directory
f70460
for mod in `cat dep2.list`
f70460
do
f70460
  newpath=`dirname $mod | sed -e "s/kernel\\//$Dest\//"`
f70460
  mkdir -p $newpath
f70460
  mv $mod $newpath
f70460
done
f70460
f70460
popd
f70460
f70460
# If we're signing modules, we can't leave the .mod files for the .ko files
f70460
# we've moved in .tmp_versions/.  Remove them so the Kbuild 'modules_sign'
f70460
# target doesn't try to sign a non-existent file.  This is kinda ugly, but
f70460
# so is modules-extra.
f70460
f70460
for mod in `cat ${Dir}/dep2.list`
f70460
do
f70460
  modfile=`basename $mod | sed -e 's/.ko/.mod/'`
f70460
  rm .tmp_versions/$modfile
f70460
done
f70460
f70460
pushd $Dir
f70460
rm modnames dep.list dep2.list req.list req2.list
f70460
rm "$ListName" modules2.list modules3.list
f70460
popd