Skip to content

Commit

Permalink
Add a Sail version check to Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Alasdair committed Dec 7, 2023
1 parent 393e7ed commit 91d3cd6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
49 changes: 49 additions & 0 deletions etc/version_check.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 91d3cd6

Please sign in to comment.