[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: autoconf macros, portable arithmetic
From: |
Paul Eggert |
Subject: |
Re: autoconf macros, portable arithmetic |
Date: |
Thu, 24 Feb 2005 12:39:04 -0800 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) |
Stepan Kasal <address@hidden> writes:
> here is how gnome-common/macros2/gnome-autogen.sh does it (slightly adapted):
That's pretty awkward, and it mishandles letter suffixes: e.g., it
can't tell that 1.2.4a > 1.2.4.
Why not do something like this instead? This suffices for 4-part
version numbers but it's easy to increase this.
# Example inputs
a=3.5.37
b=3.5.371
newline='
'
sorted=`
echo "$a$newline$b" | sed 's/\.0*/./g' | {
# Use POSIX sort first, falling back on traditional sort.
sort -t. -k1,1n -k1,1 -k2,2n -k2,2 -k3,3n -k3,3 -k4,4n -k4,4 2>/dev/null ||
sort -t. +0n -1 +0 -1 +1n -2 +1 -2 +2n -3 +2 -3 +3n -4 +3 -4
}
`
if test "x$a$newline$b" = "x$sorted"; then
echo "$a <= $b"
else
echo "$a > $b"
fi
Perhaps there should be an Autoconf macro for this? Can someone
propose a name, documentation, patch, etc.? Personally I don't like
to check against version numbers -- it's not the Autoconf Way -- but
if it's a common-enough need then it might be useful to have it.