#!/bin/bash

# Do a test build of all kernel configs and report errors
# Only works on 2.6 kernel trees

somefailed=

if [ ! -f REPORTING-BUGS ]; then
    echo "You should run this script in the top-level kernel source tree"
    exit 1
fi

[ -e buildlogs ] && rm -rf buildlogs
mkdir buildlogs

echo "Tool chain versions used for test build"
echo "32-bit builds:"
echo "    GCC version: $(gcc -v 2>&1 | grep version)"
echo "    binutils version: $(ld -v)"
echo "64-bit builds:"
echo "    GCC version: $(hppa64-linux-gcc -v 2>&1 | grep version)"
echo "    binutils version: $(hppa64-linux-ld -v)"

echo "Build test started at $(date)"

for f in arch/parisc/configs/*_defconfig
do
    model=$(basename $f)
    model=${model%_defconfig}
    echo Building for $model

    cp $f .config
    echo yes "" | make oldconfig > buildlogs/${model}_config.log
    mv ${f} ${f}.orig
    cp .config ${f}
    diff -u ${f}.orig ${f} > buildlogs/${model}_config.diff
    mv ${f}.orig ${f}
    make clean vmlinux modules > buildlogs/${model}_make.log 2>&1
    if [ $? -ne 0 ]; then
        echo "$model build failed! Check buildlogs/${model}_make.log"
	somefailed="$somefailed $model"
    else
        echo "$model built successfully"
	cp vmlinux buildlogs/vmlinux.${model}
    fi
    grep "warning:" buildlogs/${model}_make.log > buildlogs/${model}_make.warnings
done

if [ -n "$somefailed" ]; then
    echo "The following configs did not build correctly:"
    echo $somefailed
else
    echo "All configs built successfully"
fi

echo "Build test finished at $(date)"
