From 4657d8be0d036b5d37374f505791893816c7cdb0 Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Thu, 25 Aug 2022 14:44:43 +0100
Subject: [PATCH] autotools: Require GNU sort
find_lib() uses sort -V, which is a GNU extension. Users of non-GNU
operating systems should either install GNU coreutils (assumed to
provide a gsort executable), or use the CMake build system.
Resolves: https://github.com/libsdl-org/SDL/issues/6106
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry-picked from commit 732e1530e3ef48c225295e81fe84ed282eef3a39)
---
configure | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++-
configure.ac | 5 ++++-
2 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/configure b/configure
index 6a6cf363755d..3ae2706d6330 100755
--- a/configure
+++ b/configure
@@ -723,6 +723,7 @@ ALLOCA
CPP
LIBTOOLLINKERTAG
LINKER
+SORT
PKG_CONFIG_LIBDIR
PKG_CONFIG_PATH
PKG_CONFIG
@@ -17897,6 +17898,59 @@ if test -z "$AWK" ; then
as_fn_error $? "*** awk not found, aborting" "$LINENO" 5
fi
+for ac_prog in gsort sort
+do
+ # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+printf %s "checking for $ac_word... " >&6; }
+if test ${ac_cv_prog_SORT+y}
+then :
+ printf %s "(cached) " >&6
+else $as_nop
+ if test -n "$SORT"; then
+ ac_cv_prog_SORT="$SORT" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ case $as_dir in #(((
+ '') as_dir=./ ;;
+ */) ;;
+ *) as_dir=$as_dir/ ;;
+ esac
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
+ ac_cv_prog_SORT="$ac_prog"
+ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+SORT=$ac_cv_prog_SORT
+if test -n "$SORT"; then
+ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $SORT" >&5
+printf "%s\n" "$SORT" >&6; }
+else
+ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+fi
+
+
+ test -n "$SORT" && break
+done
+test -n "$SORT" || SORT="false"
+
+if ! "$SORT" -V </dev/null >/dev/null
+then :
+ as_fn_error $? "GNU sort(1) is required" "$LINENO" 5
+fi
+
# Check whether --enable-largefile was given.
if test ${enable_largefile+y}
then :
@@ -18226,7 +18280,7 @@ find_lib()
host_lib_path="/usr/$base_libdir /usr/local/$base_libdir"
fi
for path in $env_lib_path $gcc_bin_path $gcc_lib_path $host_lib_path; do
- lib=`ls -- $path/$1 2>/dev/null | sed 's,.*/,,' | sort -V -r | $AWK 'BEGIN{FS="."}{ print NF, $0 }' | sort -n -s | sed 's,[0-9]* ,,' | head -1`
+ lib=`ls -- $path/$1 2>/dev/null | sed 's,.*/,,' | "$SORT" -V -r | $AWK 'BEGIN{FS="."}{ print NF, $0 }' | "$SORT" -n -s | sed 's,[0-9]* ,,' | head -1`
if test x$lib != x; then
echo $lib
return
diff --git a/configure.ac b/configure.ac
index 01b9593d3d4f..4a67ad1597cb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,6 +70,9 @@ if [ test -z "$AWK" ]; then
AC_MSG_ERROR([*** awk not found, aborting])
fi
+AC_CHECK_PROGS([SORT], [gsort sort], [false])
+AS_IF([! "$SORT" -V </dev/null >/dev/null], [AC_MSG_ERROR([GNU sort(1) is required])])
+
dnl 64-bit file offsets if possible unless --disable-largefile is specified
AC_SYS_LARGEFILE
@@ -186,7 +189,7 @@ find_lib()
host_lib_path="/usr/$base_libdir /usr/local/$base_libdir"
fi
for path in $env_lib_path $gcc_bin_path $gcc_lib_path $host_lib_path; do
- lib=[`ls -- $path/$1 2>/dev/null | sed 's,.*/,,' | sort -V -r | $AWK 'BEGIN{FS="."}{ print NF, $0 }' | sort -n -s | sed 's,[0-9]* ,,' | head -1`]
+ lib=[`ls -- $path/$1 2>/dev/null | sed 's,.*/,,' | "$SORT" -V -r | $AWK 'BEGIN{FS="."}{ print NF, $0 }' | "$SORT" -n -s | sed 's,[0-9]* ,,' | head -1`]
if test x$lib != x; then
echo $lib
return