0
@@ -175,3 +175,182 @@ AC_SUBST(LTCOMPILE)
0
+# ===========================================================================
0
+# http://autoconf-archive.cryp.to/ax_compare_version.html
0
+# ===========================================================================
0
+# AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
0
+# This macro compares two version strings. Due to the various number of
0
+# minor-version numbers that can exist, and the fact that string
0
+# comparisons are not compatible with numeric comparisons, this is not
0
+# necessarily trivial to do in a autoconf script. This macro makes doing
0
+# these comparisons easy.
0
+# The six basic comparisons are available, as well as checking equality
0
+# limited to a certain number of minor-version levels.
0
+# The operator OP determines what type of comparison to do, and can be one
0
+# eq - equal (test A == B)
0
+# ne - not equal (test A != B)
0
+# le - less than or equal (test A <= B)
0
+# ge - greater than or equal (test A >= B)
0
+# lt - less than (test A < B)
0
+# gt - greater than (test A > B)
0
+# Additionally, the eq and ne operator can have a number after it to limit
0
+# the test to that number of minor versions.
0
+# eq0 - equal up to the length of the shorter version
0
+# ne0 - not equal up to the length of the shorter version
0
+# eqN - equal up to N sub-version levels
0
+# neN - not equal up to N sub-version levels
0
+# When the condition is true, shell commands ACTION-IF-TRUE are run,
0
+# otherwise shell commands ACTION-IF-FALSE are run. The environment
0
+# variable 'ax_compare_version' is always set to either 'true' or 'false'
0
+# AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8])
0
+# AX_COMPARE_VERSION([3.15],[lt],[3.15.8])
0
+# AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8])
0
+# AX_COMPARE_VERSION([3.15],[gt],[3.15.8])
0
+# AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8])
0
+# would be true because it is only comparing two minor versions.
0
+# AX_COMPARE_VERSION([3.15.7],[eq0],[3.15])
0
+# would be true because it is only comparing the lesser number of minor
0
+# versions of the two values.
0
+# Note: The characters that separate the version numbers do not matter. An
0
+# empty string is the same as version 0. OP is evaluated by autoconf, not
0
+# configure, so must be a string, not a variable.
0
+# The author would like to acknowledge Guido Draheim whose advice about
0
+# the m4_case and m4_ifvaln functions make this macro only include the
0
+# portions necessary to perform the specific comparison specified by the
0
+# OP argument in the final configure script.
0
+# Copyright (c) 2008 Tim Toolan <toolan@ele.uri.edu>
0
+# Copying and distribution of this file, with or without modification, are
0
+# permitted in any medium without royalty provided the copyright notice
0
+# and this notice are preserved.
0
+dnl #########################################################################
0
+AC_DEFUN([AX_COMPARE_VERSION], [
0
+ # Used to indicate true or false condition
0
+ ax_compare_version=false
0
+ # Convert the two version strings to be compared into a format that
0
+ # allows a simple string comparison. The end result is that a version
0
+ # string of the form 1.12.5-r617 will be converted to the form
0
+ # 0001001200050617. In other words, each number is zero padded to four
0
+ # digits, and non digits are removed.
0
+ AS_VAR_PUSHDEF([A],[ax_compare_version_A])
0
+ A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
0
+ -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
0
+ -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
0
+ -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
0
+ AS_VAR_PUSHDEF([B],[ax_compare_version_B])
0
+ B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
0
+ -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
0
+ -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
0
+ -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
0
+ dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary
0
+ dnl # then the first line is used to determine if the condition is true.
0
+ dnl # The sed right after the echo is to remove any indented white space.
0
+ m4_case(m4_tolower($2),
0
+ ax_compare_version=`echo "x$A
0
+x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"`
0
+ ax_compare_version=`echo "x$A
0
+x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"`
0
+ ax_compare_version=`echo "x$A
0
+x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"`
0
+ ax_compare_version=`echo "x$A
0
+x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"`
0
+ dnl Split the operator from the subversion count if present.
0
+ m4_bmatch(m4_substr($2,2),
0
+ # A count of zero means use the length of the shorter version.
0
+ # Determine the number of characters in A and B.
0
+ ax_compare_version_len_A=`echo "$A" | $AWK '{print(length)}'`
0
+ ax_compare_version_len_B=`echo "$B" | $AWK '{print(length)}'`
0
+ # Set A to no more than B's length and B to no more than A's length.
0
+ A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"`
0
+ B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"`
0
+ # A count greater than zero means use only that many subversions
0
+ A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
0
+ B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
0
+ [illegal OP numeric parameter: $2])
0
+ # Pad zeros at end of numbers to make same length.
0
+ ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`"
0
+ B="$B`echo $A | sed 's/./0/g'`"
0
+ A="$ax_compare_version_tmp_A"
0
+ # Check for equality or inequality as necessary.
0
+ m4_case(m4_tolower(m4_substr($2,0,2)),
0
+ test "x$A" = "x$B" && ax_compare_version=true
0
+ test "x$A" != "x$B" && ax_compare_version=true
0
+ AC_WARNING([illegal OP parameter: $2])
0
+ dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE.
0
+ if test "$ax_compare_version" = "true" ; then
0
+ m4_ifvaln([$4],[$4],[:])dnl
0
+ m4_ifvaln([$5],[else $5])dnl
0
+]) dnl AX_COMPARE_VERSION
Comments
No one has commented yet.