Carlos O'Donell 33fde86
#!/bin/bash
Carlos O'Donell 33fde86
# Autogeneries the quilt `series` from the patch order in the spec file.
Carlos O'Donell 33fde86
# We don't use `quilt setup` because it makes a huge mess and doesn't work.
Carlos O'Donell 0cffc9a
component="glibc"
Carlos O'Donell 33fde86
rm -f series.new
Carlos O'Donell e61b8f4
extra_args="--fuzz=0"
Carlos O'Donell 33fde86
count=0
Carlos O'Donell 33fde86
# Filter out the patches, and use `_` as our pseudo-IFS to prevent expansion.
Carlos O'Donell 6e8e9f6
for i in `grep '^%patch' glibc.spec | sed -e 's,%patch,,g' -e 's, ,_,g'`; do
Carlos O'Donell 33fde86
    # Split the patch into number and arguments.
Carlos O'Donell 33fde86
    # 1 - Patch number.
Carlos O'Donell 33fde86
    # 2-N - Patch arguments.
Carlos O'Donell 33fde86
    # Get back our elements by undoing pseudo-IFS change.
Carlos O'Donell 33fde86
    elements=(`echo $i | sed -e 's,_, ,g'`)
Carlos O'Donell 33fde86
    num=${elements[0]}
Carlos O'Donell 33fde86
    args=${elements[@]:1}
Carlos O'Donell 6e8e9f6
    # Find the next patch that applies in order and write it out.
Carlos O'Donell 6e8e9f6
    # This way we transform the patch # list into a patch file list in order.
Carlos O'Donell e61b8f4
    grep "Patch${num}: " glibc.spec \
Carlos O'Donell e61b8f4
	| sed -e 's,Patch.*: ,,g' -e "s,\$, ${args[@]} ${extra_args},g" \
Carlos O'Donell 0cffc9a
	| sed -e "s,%{name},${component},g" \
Carlos O'Donell e61b8f4
	>> series.new
Carlos O'Donell 33fde86
    ((count++))
Carlos O'Donell 33fde86
done
Carlos O'Donell 6e8e9f6
# Double check we processed the correct number of patches.
Carlos O'Donell 33fde86
fcount=`wc -l series.new | sed -e 's, .*$,,g'`
Carlos O'Donell 33fde86
if [ $fcount -ne $count ]; then
Carlos O'Donell 6e8e9f6
    echo "Error! Processed patch count doesn't match spec file count ($fcount != $count)."
Carlos O'Donell 33fde86
    exit 1
Carlos O'Donell 33fde86
fi
Carlos O'Donell 33fde86
echo "Processed $count patches."
Carlos O'Donell 33fde86
mv series.new series
Carlos O'Donell 790a049
echo "Generated quilt ./series file. Please do not commit."
Carlos O'Donell 33fde86
exit 0