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