Re: autoconf macros, portable arithmetic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux