commit d58e226781f7a4546a1a8b5c0736af593297585b
parent 12c83da4c13883e11ed2a198c4b069d467e0a742
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Fri, 23 May 2025 01:10:05 +0200
bootstrap: added portable check for Uncrustify version, added check for git version
Can be backported
Diffstat:
| M | bootstrap | | | 101 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- |
1 file changed, 83 insertions(+), 18 deletions(-)
diff --git a/bootstrap b/bootstrap
@@ -1,23 +1,76 @@
#!/bin/sh
-# This is more portable than `which' but comes with
-# the caveat of not(?) properly working on busybox's ash:
-have_command()
+if command -v "command" >/dev/null 2>&1; then
+have_cmd()
{
- command -v "$1" >/dev/null 2>&1
+ command -v "$1" >/dev/null 2>&1
+}
+elif type "type" >/dev/null 2>&1; then
+have_cmd()
+{
+ type "$1" >/dev/null 2>&1
+}
+else
+have_cmd()
+{
+ : # dummy fallback
+}
+fi
+
+# Extract dotted digits version from stdin and print it to stdout
+ver_filter()
+{
+ ${SED-sed} -n 's/^\(.*[^0-9.]\)\{0,1\}\([0-9][0-9]*\(\.[0-9][0-9]*\)\{0,4\}\).*$/\2/p'
+}
+
+# Compare two version strings
+# Return:
+# * 11 if the first version is greater than the second version
+# * 10 if versions are equal
+# * 9 if the first version is less than the second version
+__helper_ver_cmp()
+{
+ _verA=$1
+ _verB=$2
+ _save_IFS="$IFS"
+ IFS=.
+ set dummy ${_verA}
+ _verA1=${2:-0}; _verA2=${3:-0}; _verA3=${4:-0}; _verA4=${5:-0}; _verA5=${6:-0}
+ set dummy ${_verB}
+ _verB1=${2:-0}; _verB2=${3:-0}; _verB3=${4:-0}; _verB4=${5:-0}; _verB5=${6:-0}
+ IFS="${_save_IFS}"
+ [ "${_verA1}" -gt "${_verB1}" ] && return 11
+ [ "${_verA1}" -lt "${_verB1}" ] && return 9
+ [ "${_verA2}" -gt "${_verB2}" ] && return 11
+ [ "${_verA2}" -lt "${_verB2}" ] && return 9
+ [ "${_verA3}" -gt "${_verB3}" ] && return 11
+ [ "${_verA3}" -lt "${_verB3}" ] && return 9
+ [ "${_verA4}" -gt "${_verB4}" ] && return 11
+ [ "${_verA4}" -lt "${_verB4}" ] && return 9
+ [ "${_verA5}" -gt "${_verB5}" ] && return 11
+ [ "${_verA5}" -lt "${_verB5}" ] && return 9
+ return 10
+}
+
+# Usage: ver_cmp VER1 -gt|-lt|-ge|-le|-eq|-ne VER2
+# For example: ver_cmp 5.10.1 -gt 5.9.1
+ver_cmp()
+{
+ __helper_ver_cmp "$1" "$3"
+ [ $? $2 10 ]
}
-unset bs_srcdir || exit 1
-if test X"`dirname / 2>/dev/null`" = X"/"; then
- bs_scrdir=`dirname $0` || exit 2
+bs_srcdir='' || exit 1
+if have_cmd 'dirname' && test X"`dirname / 2>/dev/null`" = X"/"; then
+ bs_srcdir=`dirname $0` || exit 2
else
case $0 in
- */*) bs_scrdir=`echo $0 | ${SED-sed} -n -e 's|/[^/]*$||p'` || exit 2;;
- *) bs_scrdir='.' ;;
+ */*) bs_srcdir=`echo $0 | ${SED-sed} -n 's|/[^/]*$||p'` || exit 2;;
+ *) bs_srcdir='.' ;;
esac
fi
-test -n "$bs_scrdir" && cd "$bs_scrdir" || echo "Warning: cannot detect sources directory" 1>&2
+test -n "$bs_srcdir" && cd "$bs_srcdir" || echo "Warning: cannot detect sources directory" 1>&2
if test ! -f './configure.ac'; then
echo "Error: no 'configure.ac' found. Wrong sources directory?" 1>&2
@@ -28,31 +81,43 @@ if test ! -f './src/include/microhttpd2.h'; then
exit 2
fi
-if have_command uncrustify; then
+if have_cmd uncrustify; then
+ UNCRUSTIFY_VER=`uncrustify --version | ver_filter`
+ UNCRUSTIFY_VER_NEEDED="0.78.0"
+ if ver_cmp "$UNCRUSTIFY_VER" -ge "$UNCRUSTIFY_VER_NEEDED"; then
if test -f uncrustify.cfg; then
echo "Uncrustify configuration already exists, skipping installation from the upstream file."
else
echo "Installing libmicrohttpd uncrustify configuration"
+ rm -f ./uncrustify.cfg
ln -s contrib/uncrustify.cfg uncrustify.cfg || \
cp contrib/uncrustify.cfg uncrustify.cfg || \
echo "Failed to install uncrustify configuration file" 1>&2
fi
if test -f uncrustify.cfg; then
if test -d '.git' && test -x /bin/bash; then
- if test -f .git/hooks/pre-commit; then
- echo "Pre-commit git hook already exists, skipping installation from the upstream file."
+ if ver_cmp `git --version 2>/dev/null | ver_filter` -lt "1.5.5.2"; then
+ echo "git version 1.5.5.2 (or later) not detected; pre-commit hook not installed."
else
- echo "Installing uncrustify pre-commit git hook"
- ln -s ../../contrib/uncrustify_precommit .git/hooks/pre-commit || \
- cp contrib/uncrustify_precommit .git/hooks/pre-commit || \
- echo "Failed to install pre-commit git hook" 1>&2
+ if test -f .git/hooks/pre-commit; then
+ echo "Pre-commit git hook already exists, skipping installation from the upstream file."
+ else
+ echo "Installing uncrustify pre-commit git hook"
+ rm -f ./.git/hooks/pre-commit
+ ln -s ../../contrib/uncrustify_precommit .git/hooks/pre-commit || \
+ cp contrib/uncrustify_precommit .git/hooks/pre-commit || \
+ echo "Failed to install pre-commit git hook" 1>&2
+ fi
fi
else
echo "No '.git' directory or no bash shell found, skipping installation of pre-commit git hook."
fi
fi
+ else
+ echo "Uncrustify version $UNCRUSTIFY_VER detected, hook not installed. Please install uncrustify $UNCRUSTIFY_VER_NEEDED or newer if you plan to contribute to development."
+ fi
else
- echo "Uncrustify not detected, hook not installed. Please install uncrustify if you plan on doing development."
+ echo "Uncrustify not detected, hook not installed. Please install uncrustify $UNCRUSTIFY_VER_NEEDED or newer if you plan to contribute to development."
fi
WANT_AUTOCONF=latest