1#!/bin/sh 2 3# 4# This file is part of the Yices SMT Solver. 5# Copyright (C) 2017 SRI International. 6# 7# Yices is free software: you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation, either version 3 of the License, or 10# (at your option) any later version. 11# 12# Yices is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with Yices. If not, see <http://www.gnu.org/licenses/>. 19# 20 21 22# 23# Construct a README file from a template 24# 25# Usage: 26# ./mkreadme <dist> <template> 27# 28# <dist> must be a distribution directory like 29# build/x86_64-unknown-linux-gnu-release/static_dist 30# 31# The template must be an appropriate text file for the distribution 32# (e.g. etc/README.static.linux) 33# 34# This scripts replaces 35# __YICES__ by the Yices version number 36# __GMP__ by the GMP version 37# __DYLIB__ by the name of the dynamic library 38# __OS_VERSION__ by the build OS 39# in the template 40# 41# NOTE: For cross-compilation on cygwin, this script may not work for 42# the mingw32 or mingw64 non-static distribution (can't run yices.exe 43# from cygwin because the libgmp.xx.dll is not found). It should work 44# for the static mingw32 and mingw64 distributions. 45# 46 47usage="Usage: $0 <distribution directory> <template>\n 48\n 49 For example\n 50\n 51 $0 ./build/x86_64-unknown-linux-gnu-release/dist ./etc/README.linux\n 52" 53 54if test $# != 2 ; then 55 echo "$usage" 56 exit 1 57fi 58 59dist=$1 60template=$2 61libdir=$dist/lib 62 63if test ! -d $dist ; then 64 echo "Error: $dist not found or not a directory" 65 exit 1 66fi 67 68if test ! -f $template ; then 69 echo "Error: $template not found" 70 exit 1 71fi 72 73if test ! -d $libdir ; then 74 echo "Error: $libdir not found or not a directory" 75 exit 1 76fi 77 78 79if test -x $dist/bin/yices ; then 80 yices=$dist/bin/yices 81else 82 if test -x $dist/bin/yices.exe ; then 83 yices=$dist/bin/yices.exe 84 else 85 echo "Error: can't find yices or yices.exe in $dist/bin" 86 exit 1 87 fi 88fi 89 90 91# 92# Check whether we can execute $yices --version 93# 94{ $yices --version > /dev/null 2>&1 ; } || { echo "Error: can't run $yices" ; exit 1 ; } 95 96 97# 98# Get GMP version 99# 100tmp=` $yices --version | awk '/GMP/ { print $4 }' | tr -d '\015' ` 101case $tmp in 102 *.*.* ) 103 gmp_version=$tmp 104 ;; 105 106 * ) 107 echo "Error: invalid GMP version (got $tmp)" 108 exit 1 109 ;; 110esac 111 112# 113# Get Yices version 114# 115tmp=` $yices --version | awk '/Yices/ { print $2 }' | tr -d '\015' ` 116case $tmp in 117 *.*.* ) 118 yices_version=$tmp 119 ;; 120 121 * ) 122 echo "Error: invalid Yices version (got $tmp)" 123 exit 1 124 ;; 125esac 126 127 128# 129# Get the dynamic library name 130# 131libname="none" 132alllibs=`ls $libdir` 133for lib in $alllibs; do 134 case $lib in 135 libyices.so.* | libyices.*.dylib ) 136 if test $libname = "none" ; then 137 libname=$lib 138 else 139 echo "Error: found two dymanic libraries: $libname and $lib in $dist/lib" 140 exit 1 141 fi 142 ;; 143 esac 144done 145 146 147# 148# Get os name and release 149# 150os_name=`uname 2>/dev/null` || os_name=unknown 151os_release=`(uname -r) 2>/dev/null` || os_release=unknown 152case "${os_name}:${os_release}" in 153 unknown:* | *:unknown ) 154 echo "Error: failed to get OS version\n" 155 exit 1 156 ;; 157 158 *Linux* | *linux* ) 159 # 160 # Try to get the distribution (via lsb_release) 161 # 162 linux_dist=`(lsb_release -d -s) 2>/dev/null` || linux_dist=unknown 163 case $linux_dist in 164 unknown ) 165 os_version="${os_name} ${os_release}" 166 ;; 167 168 * ) 169 os_version="${linux_dist} (${os_name} ${os_release})" 170 ;; 171 esac 172 ;; 173 174 * ) 175 os_version="${os_name} ${os_release}" 176 ;; 177esac 178 179# 180# On cygwin and possibly other systems, the os_release contains '/' 181# so we can't do sed -e "s/__OS_VERSION__/${os_version}/g". Instead, 182# we use sed -e "s,__OS_VERSION__,${os_version},g". 183# 184# To make sure this command works, we remove any ',' from the os_version. 185# 186clean_os_version=` echo $os_version | sed -e 's/,/ /g' ` 187 188# 189# Apply the substitution 190# 191sed -e "s/__YICES__/${yices_version}/g" -e "s/__GMP__/${gmp_version}/g" \ 192 -e "s/__DYLIB__/${libname}/g" -e "s,__OS_VERSION__,${clean_os_version},g" $template 193 194