ignatenkobrain / rpms / kernel

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