#!/bin/sh
#
#  This file is part of the Yices SMT Solver.
#  Copyright (C) 2017 SRI International.
# 
#  Yices is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
# 
#  Yices is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
# 
#  You should have received a copy of the GNU General Public License
#  along with Yices.  If not, see .
#
#
# Script to get the Yices version (by calling yices)
#
# Usage:
#   ./yices_version 
#
# - the argument must be the path to the binary or static dist
# - there should be a binary called yices or yices.ext in the bin directory
# - this script call yices --version then extract the GMP version from there
#
usage="Usage: $0 
For example: $0 ./build/x86_64-unknown-linux-gnu-release/dist
"
if test $# -ne 1 ; then
   echo "$usage"
   exit 2
fi
dist=$1
if test ! -d $dist ; then
   echo "Error: can't find directory $dist"
   exit 2
fi
yices=$dist/bin/yices
test -x $yices || yices=$dist/bin/yices.exe
#
# NOTE: we use { printf "%s", $2 } instead of { print $2 }
# because the latter produces an extra '\n' on cygwin.
#
if test -x $yices ; then
   tmp=` $yices --version | awk '/Yices/ { printf "%s", $2 }'`
   case $tmp in
     *.*.* )
       echo $tmp
       ;;
     * )
       echo "Error: Yices version not found or badly formatted"
       echo $tmp
       exit 2
       ;;
   esac
else 
  echo "Error: can't run $dist/bin/yices"
  exit 2
fi