nxt5656 / rpms / kernel

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