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