xref: /OK3568_Linux_fs/buildroot/support/dependencies/check-host-cmake.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/sh
2
3# prevent shift error
4[ $# -lt 2 ] && exit 1
5
6major_min="${1%.*}"
7minor_min="${1#*.}"
8
9shift
10
11for candidate; do
12
13    # Try to locate the candidate. Discard it if not located.
14    cmake=`which "${candidate}" 2>/dev/null`
15    [ -n "${cmake}" ] || continue
16
17    # Extract version X.Y from versions in the form X.Y or X.Y.Z
18    # with X, Y and Z numbers with one or more digits each, e.g.
19    #   3.2     -> 3.2
20    #   3.2.3   -> 3.2
21    #   3.2.42  -> 3.2
22    #   3.10    -> 3.10
23    #   3.10.4  -> 3.10
24    #   3.10.42 -> 3.10
25    # Discard the candidate if no version can be obtained
26    version="$(${cmake} --version \
27               |sed -r -e '/.* ([[:digit:]]+\.[[:digit:]]+).*$/!d;' \
28                       -e 's//\1/'
29              )"
30    [ -n "${version}" ] || continue
31
32    major="${version%.*}"
33    minor="${version#*.}"
34
35    if [ ${major} -gt ${major_min} ]; then
36        echo "${cmake}"
37        exit
38    elif [ ${major} -eq ${major_min} -a ${minor} -ge ${minor_min} ]; then
39        echo "${cmake}"
40        exit
41    fi
42done
43
44# echo nothing: no suitable cmake found
45exit 1
46