Sort libraries by version and pick the shortest symlink (thanks @jpalus!) Fixes https://github.com/libsdl-org/SDL_image/issues/289
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
diff --git a/configure b/configure
index 41f15cb..312a799 100755
--- a/configure
+++ b/configure
@@ -13073,6 +13073,53 @@ LT_REVISION=$SDL_INTERFACE_AGE
+for ac_prog in gawk mawk nawk awk
+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_AWK+y}
+then :
+ printf %s "(cached) " >&6
+else $as_nop
+ if test -n "$AWK"; then
+ ac_cv_prog_AWK="$AWK" # 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_AWK="$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
+AWK=$ac_cv_prog_AWK
+if test -n "$AWK"; then
+ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5
+printf "%s\n" "$AWK" >&6; }
+else
+ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+fi
+
+
+ test -n "$AWK" && break
+done
+
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -17849,6 +17896,10 @@ printf "%s\n" "no" >&6; }
fi
fi
+if test -z "$AWK" ; then
+ as_fn_error $? "*** awk not found, aborting" "$LINENO" 5
+fi
+
# Check whether --enable-largefile was given.
if test ${enable_largefile+y}
then :
@@ -18178,15 +18229,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 -e '/\.so\..*\./d' -e 's,.*/,,' | sort | tail -1`
- if test x$lib != x; then
- echo $lib
- return
- fi
- done
- # Try again, this time allowing more than one version digit after the .so
- for path in $env_lib_path $gcc_bin_path $gcc_lib_path $host_lib_path; do
- lib=`ls -- $path/$1 2>/dev/null | sed -e 's,.*/,,' | sort | tail -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 0b2c7c7..740ab8b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,6 +58,7 @@ dnl Detect the canonical build and host environments
dnl AC_CANONICAL_HOST
dnl Check for tools
+AC_PROG_AWK
AC_PROG_CC
AC_PROG_CXX
AC_PROG_EGREP
@@ -65,6 +66,10 @@ AC_PROG_INSTALL
AC_PROG_MAKE_SET
PKG_PROG_PKG_CONFIG
+if [ test -z "$AWK" ]; then
+ AC_MSG_ERROR([*** awk not found, aborting])
+fi
+
dnl 64-bit file offsets if possible unless --disable-largefile is specified
AC_SYS_LARGEFILE
@@ -181,15 +186,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 -e '/\.so\..*\./d' -e 's,.*/,,' | sort | tail -1`]
- if test x$lib != x; then
- echo $lib
- return
- fi
- done
- # Try again, this time allowing more than one version digit after the .so
- for path in $env_lib_path $gcc_bin_path $gcc_lib_path $host_lib_path; do
- lib=[`ls -- $path/$1 2>/dev/null | sed -e 's,.*/,,' | sort | tail -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