1
0
forked from pool/kernel-source
kernel-source/make-symsets

112 lines
2.6 KiB
Bash

#! /bin/bash
unset LANG ${!LC_*}
# Usage: make-symsets symsets.tar.gz [old-symsets.tar.gz]
# < symvers.gz
#
# symsets.tar.gz
# Create this symbol set tarball.
#
# old-symsets.tar.gz
# Reuse all possible symbol sets from this tarball.
tarball=$1
old_tarball=$2
# Classify all the symbols by the directory they live in
unset ${!class_*}
while read class ignore line; do
class=class_${class//[^a-zA-Z0-9_]/_}
eval "$class[\${#$class[@]}]=\"$line\""
if [ $ignore -gt 0 ]; then
eval "ignore_$class=1"
fi
done < <(
awk '
BEGIN { FS="\t" ; OFS="\t" }
{ class=$3
sub(/\/[^/]+$/, "", class)
ignore=sub(/.*=>/, "", $1)
print class, ignore, $0
}
'
)
tmpdir=$(mktemp -t -d ${0##*/}.XXXXXX)
trap "rm -rf $tmpdir" EXIT
basename=$(basename ${tarball:-.} .tar.gz)
# Save all the new sets, computer and output their hashes
newdir=$tmpdir/new/$basename
mkdir -p $newdir
for class in ${!class_*} ; do
class=${class#class_}
eval "printf \"%s\\n\" \"\${class_$class[@]}\"" \
| sort -k2 \
> $newdir/tmp
set -- $(md5sum $newdir/tmp) ; set -- ${1:0:16}
mv $newdir/tmp $newdir/$class.$1
#echo "Provides: kernel($class) = $1"
done
shopt -s nullglob
if [ -n "$old_tarball" ]; then
# Reuse all sets of symbols from the old tarball that are
# still the same.
old_basename=$(basename $old_tarball .tar.gz)
mkdir -p $tmpdir/old
zcat $old_tarball \
| tar xf - -C $tmpdir/old
set -- $tmpdir/old/*
olddir=$1
if [ ! -d $olddir ]; then
echo "$old_tarball does not contain directory $old_basename"
exit 1
fi
for oldset in $olddir/* ; do
[ -e $newdir/${oldset#$olddir/} ] && continue
class=${oldset##*/} ; class=${class%.*}
set -- $newdir/$class.*
[ $# -eq 1 ] || continue
newset=$1
# '*' doesn't occur in either file.
missing="$(join -t '*' -j 1 -v 1 <(sort "$oldset") <(sort "$newset"))"
if [ -z "$missing" ]; then
keep_oldset[${#keep_oldset[@]}]=$oldset
#echo "Provides: kernel($class) = ${oldset##*.} (old)"
else
set -- $(echo "$missing" | awk '{ print $2 "(" $1 ")" }')
ignore=ignore_class_$class
if [ -n "${!ignore}" ]; then
ignore="; ignoring"
else
ignore=
status=1
fi
echo "No longer provided: kernel($class) = ${oldset##*.} (missing/changed: $@$ignore)" >&2
fi
done
if [ ${#keep_oldset[@]} -gt 0 ]; then
mv "${keep_oldset[@]}" $newdir/
fi
else
echo "No longer provided: previous kernel(...) symbols that may still be" \
"compatible" >&2
fi
# Store the generated sets in $tarball
tar cf - -C $tmpdir/new $basename \
| gzip -9 \
> $tarball \
|| exit 1
exit $status
# vim:shiftwidth=4 softtabstop=4