[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: autoconf macros, portable arithmetic
From: |
Stepan Kasal |
Subject: |
Re: autoconf macros, portable arithmetic |
Date: |
Thu, 24 Feb 2005 14:18:55 +0100 |
User-agent: |
Mutt/1.4.1i |
Hi,
On Thu, Feb 24, 2005 at 06:02:47AM -0700, Eric Blake wrote:
> I think there may already be version comparison macros out there, ...
here is how gnome-common/macros2/gnome-autogen.sh does it (slightly adapted):
# Usage:
# compare_versions MIN_VERSION ACTUAL_VERSION
# returns true if ACTUAL_VERSION >= MIN_VERSION
compare_versions() {
ch_min_version=$1
ch_actual_version=$2
ch_status=0
ch_save_IFS="${IFS- }"; IFS="."
set $ch_actual_version
for ch_min in $ch_min_version; do
IFS="$ch_save_IFS"
ch_cur=`echo $1 | sed 's/[^0-9].*$//'` # remove letter suffixes
shift
if [ -z "$ch_min" ]; then break; fi
if [ -z "$ch_cur" ]; then ch_status=1; break; fi
if [ $ch_cur -gt $ch_min ]; then break; fi
if [ $ch_cur -lt $ch_min ]; then ch_status=1; break; fi
done
return $ch_status
}
Have a nice day,
Stepan Kasal