#!/bin/sh

first=$1
second=$2

firstdir=comparison/first
seconddir=comparison/second

# Remember the branch we're on
currentbranch=`git symbolic-ref --short HEAD`

# Make sure the output directory exists
mkdir -p comparison

# Remove any previous builds
rm -fr $firstdir
rm -fr $seconddir

export BREATHE_COMPARE=True

# Checkout the first target
echo git checkout $1
git checkout $1
# Run doxygen for this state
(cd ../examples/specific; make)
(cd ../examples/tinyxml; make)
(cd ../examples/doxygen; make)
# Clean current sphinx build directory
make clean
# Make sure the BUILDDIR variable can be overridden in the Makfile. Required for older commits
sed -i 's/BUILDDIR      = build/BUILDDIR     ?= build/g' Makefile
# Build into our first comparison directory
make html BUILDDIR=$firstdir
# Reset the Makefile to its state for this commit
git checkout Makefile


# Checkout the second target and repeat
echo git checkout $2
git checkout $2
(cd ../examples/specific; make)
(cd ../examples/tinyxml; make)
(cd ../examples/doxygen; make)
make clean
sed -i 's/BUILDDIR      = build/BUILDDIR     ?= build/g' Makefile
make html BUILDDIR=$seconddir
git checkout Makefile

# Return to our current branch
echo git checkout $currentbranch
git checkout $currentbranch

# Launch meld to compare the two html directories
echo meld $firstdir/html $seconddir/html
meld $firstdir/html $seconddir/html

