thirdwheel - 2008-07-13

Hey,

I wrote a small script that parses the errata page and the patches to build a Makefile.  It's far from perfect as it couldn't possibly account for every possibility, but I think it can handle most.

Here is the script in full.  Note that you will need to have wget installed for this to work.

#!/bin/sh

wget -O .errata-$$ -o /dev/null http://www.openbsd.org/errata\`uname -r | sed 's/\.//'`.html

urls=$(grep "\.patch" .errata-$$ | sed -e 's/.*a href="//' -e 's/".*//')
files=$(grep "\.patch" .errata-$$ | sed -e 's/.*patches\///' -e 's/.patch.*//')

head -16 Makefile > Makefile.old

common=""
i386=""
for i in $urls; do
        file=$(echo $i | sed -e 's/.*patches\///' -e 's/.patch.*//')
        type=`echo $file | cut -d / -f 2`
        name=`echo $file | cut -d / -f 3`

        if [ "$type" == "common" ]; then
                common="$name $common"
        fi

        if [ "$type" == "i386" ]; then
                i386="$i386 $name"
        fi

        pf=.patch-$$

        wget -O $pf -o /dev/null $i
        buildstr=""
        start=0

        prereq=""

        while read line; do

                [ "$(echo $line | grep "Index")" ] && start=0
                [ "$(echo $line | grep "kernel")" ] && prereq="$prereq _kernel"

                if [ "$start" == "1" ]; then
                        #let's strip any excess whitespace
                        str=$(echo $line);
                        case $str in
                                cd*)            buildstr="$buildstr && cd \"\${WRKSRC}/`echo $str | cut -d " " -f 2-`\""
                                                ;;
                                "make obj")     buildstr="$buildstr && \${_obj}"
                                                ;;
                                "make cleandir")        buildstr="$buildstr && \${_cleandir}"
                                                ;;
                                "make depend")  buildstr="$buildstr && \${_depend}"
                                                ;;
                                make)           buildstr="$buildstr && \${_build}"
                                                ;;
                                "make install"|"")
                                                ;;
                                *)              buildstr="$buildstr && ($str)"
                        esac
                fi

                [ "$(echo $line | grep "rebuild")" ] && start=1
        done < $pf

        echo "$name:" $prereq
        echo -n "       "
        echo $buildstr | sed 's/\&amp;\&amp; //'
        echo
done >> Makefile.old

cat >> Makefile.old <<EOF

.include "bsd.binpatch.mk"
EOF

echo "Common: $common"
echo "i386: $i386"

sed -e "/PATCH_COMMON/s/.*/PATCH_COMMON=$common/" -e "/PATCH_I386/s/.*/PATCH_I386=$i386/" Makefile.old > Makefile

rm .errata-$$
rm .patch-$$