#!/bin/bash

# This script will set the following shell variables:
#   BUILD_VERSION
#   RELEASE_VERSION
#   BUILD_REVISION
#   HOST_SW_VERSION_STRING
#   PUSH_TOPO
#
# BUILD_VERSION and release VERSION are read from the build_version
# file. BUILD_REVISION is normally set to the svn revision ID of the
# makefile, but this may be overridden in the build_version file.

RELEASE_VERSION=0 ; # defined in build_version file
BUILD_VERSION=0   ; # defined in build_version file
BUILD_REVISION=-1 ; # optionally defined in build_version
source build_version

if [ -e build_version_override ] ; then
  source build_version_override
fi

if [[ $BUILD_REVISION -eq -1 ]] ; then
  if ! [[ $BUILD_VCS_NUMBER -eq 0 ]] ; then
    BUILD_REVISION=$BUILD_VCS_NUMBER
  else
    BUILD_REVISION=`svn info Makefile |grep Revision |cut -d\  -f2`
    echo "BUILD REVISION is $BUILD_REVISION"
    re='^[0-9]+$'
    if ! [[ $BUILD_REVISION =~ $re ]] ; then
      BUILD_REVISION="NoSVN"
    fi
  fi
else
  echo "BUILD_REVISION overridden to $BUILD_REVISION in build_version file."
fi

# PUSH_TOPO is set to 1 when libxrandr version >= 1.2
#   (actually set to 0 if version 1.1, 1 otherwise)
Xmaj=`rpm -q libXrandr | head -n 1 | cut -d - -f 2 | cut -d . -f 1`
Xmin=`rpm -q libXrandr | head -n 1 | cut -d - -f 2 | cut -d . -f 2`
echo "libXrandr version reported as $Xmaj.$Xmin"
if [ $Xmaj == "1" ];
  then
  if [ $Xmin == "1" ];
  then
    export PUSH_TOPO=0
  else
    export PUSH_TOPO=1
  fi
else 
  export PUSH_TOPO=1
fi

export RELEASE_VERSION
export BUILD_VERSION
export BUILD_REVISION
export HOST_SW_VERSION_STRING="$RELEASE_VERSION-$BUILD_VERSION.b$BUILD_REVISION$BUILD_SUFFIX"
echo "HOST_SW_VERSION_STRING is $HOST_SW_VERSION_STRING"

