diff --git a/scripts/Makefile.toolchain.zephyr b/scripts/Makefile.toolchain.zephyr index e2594d13148..a64367279c0 100644 --- a/scripts/Makefile.toolchain.zephyr +++ b/scripts/Makefile.toolchain.zephyr @@ -12,8 +12,18 @@ # ####################################################################### +REQUIRED_SDK_VER=0.8.2 + ifndef ZEPHYR_SDK_INSTALL_DIR + $(error ZEPHYR_SDK_INSTALL_DIR is not set) +else +SDK_VERSION = $(shell cat ${ZEPHYR_SDK_INSTALL_DIR}/sdk_version) +SDK_CHECK = $(shell vercomp $(REQUIRED_SDK_VER) $(SDK_VERSION) || echo $$?) + +ifeq ($(SDK_CHECK),1) +$(error (The SDK version you are using is old, please update your SDK. You need at least SDK version $(REQUIRED_SDK_VER))) +endif endif ifeq ($(HOST_OS),MINGW) diff --git a/scripts/vercomp b/scripts/vercomp new file mode 100755 index 00000000000..1ca1fb614e3 --- /dev/null +++ b/scripts/vercomp @@ -0,0 +1,43 @@ +#!/bin/bash + +# `vercomp()` is copied from: http://stackoverflow.com/a/4025065 + +# Usage: vercomp +# return codes: +# 0: version 1 and version 2 are the same +# 1: version 1 is higher +# 2: version 2 is higher + + +vercomp () { + if [[ $1 == $2 ]] + then + return 0 + fi + local IFS=. + local i ver1=($1) ver2=($2) + # fill empty fields in ver1 with zeros + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) + do + ver1[i]=0 + done + for ((i=0; i<${#ver1[@]}; i++)) + do + if [[ -z ${ver2[i]} ]] + then + # fill empty fields in ver2 with zeros + ver2[i]=0 + fi + if ((10#${ver1[i]} > 10#${ver2[i]})) + then + return 1 + fi + if ((10#${ver1[i]} < 10#${ver2[i]})) + then + return 2 + fi + done + return 0 +} + +vercomp $1 $2