core: allow check-host-cmake.sh to try several candidates

This is useful on CentOS 7 whose "cmake" package provides cmake 2.8.12,
which is too old, but the "cmake3" package (from EPEL) provides version
3.6.3, which is satisfactory. Examples:

    $ sh support/dependencies/check-host-cmake.sh 2.8 cmake cmake3
    /usr/bin/cmake

    $ sh support/dependencies/check-host-cmake.sh 3.1 cmake cmake3
    /usr/bin/cmake3

    $ sh support/dependencies/check-host-cmake.sh 3.8 cmake cmake3
    (nothing)

Signed-off-by: Carlos Santos <casantos@datacom.ind.br>
Acked-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
This commit is contained in:
Carlos Santos 2017-05-07 01:32:19 -03:00 committed by Thomas Petazzoni
parent 77a7a15e4c
commit cacc6d0b61

View File

@ -1,16 +1,18 @@
#!/bin/sh #!/bin/sh
version_min="${1}" # prevent shift error
candidate="${2}" [ $# -lt 2 ] && exit 1
major_min="${version_min%.*}" major_min="${1%.*}"
minor_min="${version_min#*.}" minor_min="${1#*.}"
cmake=`which ${candidate}` shift
if [ ! -x "${cmake}" ]; then
# echo nothing: no suitable cmake found for candidate; do
exit 1
fi # Try to locate the candidate. Discard it if not located.
cmake=`which "${candidate}" 2>/dev/null`
[ -n "${cmake}" ] || continue
# Extract version X.Y from versions in the form X.Y or X.Y.Z # Extract version X.Y from versions in the form X.Y or X.Y.Z
# with X, Y and Z numbers with one or more digits each, e.g. # with X, Y and Z numbers with one or more digits each, e.g.
@ -20,20 +22,24 @@ fi
# 3.10 -> 3.10 # 3.10 -> 3.10
# 3.10.4 -> 3.10 # 3.10.4 -> 3.10
# 3.10.42 -> 3.10 # 3.10.42 -> 3.10
# Discard the candidate if no version can be obtained
version="$(${cmake} --version \ version="$(${cmake} --version \
|sed -r -e '/.* ([[:digit:]]+\.[[:digit:]]+).*$/!d;' \ |sed -r -e '/.* ([[:digit:]]+\.[[:digit:]]+).*$/!d;' \
-e 's//\1/' -e 's//\1/'
)" )"
[ -n "${version}" ] || continue
major="${version%.*}" major="${version%.*}"
minor="${version#*.}" minor="${version#*.}"
if [ ${major} -gt ${major_min} ]; then if [ ${major} -gt ${major_min} ]; then
echo "${cmake}" echo "${cmake}"
else exit
if [ ${major} -eq ${major_min} -a ${minor} -ge ${minor_min} ]; then elif [ ${major} -eq ${major_min} -a ${minor} -ge ${minor_min} ]; then
echo "${cmake}" echo "${cmake}"
else exit
fi
done
# echo nothing: no suitable cmake found # echo nothing: no suitable cmake found
exit 1 exit 1
fi
fi