#!/bin/sh

# this script looks for the tag corresponding to the version in Makefile.ver
# it then checks each version out between that version and this version in this
# directory and builds each one.

# it uses the directory $BUILDTMP if set, if not then it makes a directory .buildtmp and uses
# that to checkout the code.

[ -x /usr/bin/ccache ] && ccache -z

# get more of the history!
#git fetch --depth 1024
git fetch --unshallow

BUILDTMP=${BUILDTMP-.buildtmp}
mkdir -p ${BUILDTMP}
basecommit=v$(make baseversion)
startingcommit=${1-${basecommit}}
git log --oneline ${startingcommit}.. | tac | \
    while read commit stuff
    do
        echo Working on $commit "(${stuff})"
        rm -rf ${BUILDTMP}/code
        if git clone -q -n --shared . ${BUILDTMP}/code && (cd $BUILDTMP/code && git checkout -q ${commit} && make programs >/dev/null)
        then
            echo success
        else
	    echo ${commit} >BUILD_EVERY_REV_FAILED
            exit 1
        fi
    done

if [ -f BUILD_EVERY_REV_FAILED ]; then
	cat BUILD_EVERY_REV_FAILED
	exit 1
fi

[ -x /usr/bin/ccache ] && ccache -s



