1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#!/bin/sh
#
# Copyright 2025 Brad Lanam Pleasant Hill CA
#
CMAKE_REQ_MAJ_VERSION=$1
CMAKE_REQ_MIN_VERSION=$2
export CMAKE_REQ_MAJ_VERSION
export CMAKE_REQ_MIN_VERSION
if [ x"$CMAKE_REQ_MAJ_VERSION" = x ]; then
echo "chkcmake.sh: no max version specified"
exit 1
fi
if [ x"$CMAKE_REQ_MIN_VERSION" = x ]; then
echo "chkcmake.sh: no min version specified"
exit 1
fi
cmvers=`cmake --version 2>/dev/null`
if [ x"$cmvers" = x ]; then
echo "mkc"
exit 0
fi
PATH=/opt/local/bin:/opt/homebrew/bin:/usr/local/bin:/usr/pkg/bin:$PATH
# need a more modern version of awk...
awkcmd=`which gawk 2>/dev/null`
rc=$?
if [ $rc -ne 0 -o "x$awkcmd" = x ]; then
awkcmd=`which nawk 2>/dev/null`
rc=$?
if [ $rc -ne 0 -o "x$awkcmd" = x ]; then
awkcmd=`which awk 2>/dev/null`
rc=$?
if [ $rc -ne 0 -o "x$awkcmd" = x ]; then
# maybe the which command is not there...
# try some common spots
if [ -f /usr/bin/gawk ]; then
awkcmd=gawk
fi
if [ "x$awkcmd" = x -a -f /usr/bin/nawk ]; then
awkcmd=nawk
fi
if [ "x$awkcmd" = x -a -f /usr/bin/awk ]; then
awkcmd=awk
fi
fi
fi
fi
# no good awk, assume cmake is ng as well.
if [ "x$awkcmd" = x ]; then
echo "mkc"
exit 0
fi
echo "$cmvers" | ${awkcmd} '
BEGIN {
reqmaj = ENVIRON["CMAKE_REQ_MAJ_VERSION"];
reqmin = ENVIRON["CMAKE_REQ_MIN_VERSION"];
}
/version/ {
gsub (/^[^0-9]*/, "");
gsub (/[^0-9.].*$/, "");
maj = $0;
min = $0;
gsub (/\..*$/, "", maj);
gsub (/^[0-9]*/, "", min);
gsub (/^\./, "", min);
gsub (/\..*$/, "", min);
rc = 1;
# have to make sure it is a numeric comparison
if ((maj+0 == reqmaj+0 && min+0 >= reqmin+0) ||
maj+0 > reqmaj+0) {
rc = 0;
}
exit rc;
}
'
rc=$?
if [ $rc -eq 0 ]; then
echo "cmake"
else
echo "mkc"
fi
|