From 91d3cd6f38644ccc65ff4998e9931b84fe4f70de Mon Sep 17 00:00:00 2001 From: Alasdair Date: Thu, 7 Dec 2023 23:51:54 +0000 Subject: [PATCH] Add a Sail version check to Makefile --- Makefile | 9 ++++++++ etc/version_check.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100755 etc/version_check.sh diff --git a/Makefile b/Makefile index 9f284ca24..f30f5c485 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,12 @@ +# Check the current Sail version +SAIL_VERSION := $(shell etc/version_check.sh > /dev/null; echo $$?) +ifeq ($(SAIL_VERSION),1) +ifeq ($(SKIP_SAIL_VERSION_CHECK),) + $(info $(shell etc/version_check.sh)) + $(error 'Sail version check failed. Set SKIP_SAIL_VERSION_CHECK=true to ignore.') +endif +endif + # Select architecture: RV32 or RV64. ARCH ?= RV64 diff --git a/etc/version_check.sh b/etc/version_check.sh new file mode 100755 index 000000000..10eb18f83 --- /dev/null +++ b/etc/version_check.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +req_major="0" +req_minor="17" +req_patch="1" + +function check { + local version=$(sail -v | cut -d ' ' -f 2); + + if [ "$?" -ne 0 ]; then + echo "Could not find Sail version: 'sail -v' command failed" + exit 1 + fi + + local message="Sail version must be at least ${req_major}.${req_minor}.${req_patch}, got ${version}" + + local major=$(echo $version | cut -d '.' -f 1); + local minor=$(echo $version | cut -d '.' -f 2); + local patch=$(echo $version | cut -d '.' -f 3); + + # Sail version string may be two digits without a patch version, + # in which case we treat it as zero. + if [ -z "$patch" ]; then + patch="0" + fi + + if [ "$major" -lt "$req_major" ]; then + echo "${message}" + exit 1 + elif [ "$major" -gt "$req_major" ]; then + exit 0 + fi + + if [ "$minor" -lt "$req_minor" ]; then + echo "${message}" + exit 1 + elif [ "$minor" -gt "$req_minor" ]; then + exit 0 + fi + + if [ "$patch" -lt "$req_patch" ]; then + echo "${message}" + exit 1 + fi + + exit 0 +} + +check