0b43386
#! /bin/bash
0b43386
0b43386
Dir=$1
0b43386
List=$2
0b43386
0b43386
pushd $Dir
0b43386
rm -rf modnames
0b43386
find . -name "*.ko" -type f > modnames
0b43386
# Look through all of the modules, and throw any that have a dependency in
0b43386
# our list into the list as well.
0b43386
rm -rf dep.list dep2.list
0b43386
rm -rf req.list req2.list
0b43386
touch dep.list req.list
0b43386
cp $2 .
0b43386
0b43386
for dep in `cat modnames`
0b43386
do
0b43386
  depends=`modinfo $dep | grep depends| cut -f2 -d":" | sed -e 's/^[ \t]*//'`
0b43386
  [ -z "$depends" ] && continue;
0b43386
  for mod in `echo $depends | sed -e 's/,/ /g'`
0b43386
  do
0b43386
    match=`grep "^$mod.ko" mod-extra.list` ||:
0b43386
    if [ -z "$match" ]
0b43386
    then
0b43386
      continue
0b43386
    else
0b43386
      # check if the module we're looking at is in mod-extra too.  if so
0b43386
      # we don't need to mark the dep as required
0b43386
      mod2=`basename $dep`
0b43386
      match2=`grep "^$mod2" mod-extra.list` ||:
0b43386
      if [ -n "$match2" ]
0b43386
      then
0b43386
        continue
0b43386
          #echo $mod2 >> notreq.list
0b43386
        else
0b43386
          echo $mod.ko >> req.list
0b43386
      fi
0b43386
    fi
0b43386
  done
0b43386
done
0b43386
0b43386
sort -u req.list > req2.list
0b43386
sort -u mod-extra.list > mod-extra2.list
0b43386
join -v 1 mod-extra2.list req2.list > mod-extra3.list
0b43386
0b43386
for mod in `cat mod-extra3.list`
0b43386
do
0b43386
  # get the path for the module
0b43386
  modpath=`grep /$mod modnames` ||:
0b43386
  [ -z "$modpath" ]  && continue;
0b43386
  echo $modpath >> dep.list
0b43386
done
0b43386
0b43386
sort -u dep.list > dep2.list
0b43386
0b43386
# now move the modules into the extra/ directory
0b43386
for mod in `cat dep2.list`
0b43386
do
0b43386
  newpath=`dirname $mod | sed -e 's/kernel\//extra\//'`
0b43386
  mkdir -p $newpath
0b43386
  mv $mod $newpath
0b43386
done
0b43386
7e6e483
popd
7e6e483
7e6e483
# If we're signing modules, we can't leave the .mod files for the .ko files
7e6e483
# we've moved in .tmp_versions/.  Remove them so the Kbuild 'modules_sign'
7e6e483
# target doesn't try to sign a non-existent file.  This is kinda ugly, but
7e6e483
# so is modules-extra.
7e6e483
7e6e483
for mod in `cat ${Dir}/dep2.list`
7e6e483
do
7e6e483
  modfile=`basename $mod | sed -e 's/.ko/.mod/'`
7e6e483
  rm .tmp_versions/$modfile
7e6e483
done
7e6e483
7e6e483
pushd $Dir
0b43386
rm modnames dep.list dep2.list req.list req2.list
0b43386
rm mod-extra.list mod-extra2.list mod-extra3.list
0b43386
popd