source: trunk/cf/ax_compare_version.m4

Last change on this file was 1081, checked in by gah, 12 years ago

fix for perl, ruby bindings; visviewer SendBytes? method sends all data at once

File size: 3.4 KB
Line 
1dnl #########################################################################
2AC_DEFUN([AX_COMPARE_VERSION], [
3  AC_PROG_AWK
4
5  # Used to indicate true or false condition
6  ax_compare_version=false
7
8  # Convert the two version strings to be compared into a format that
9  # allows a simple string comparison.  The end result is that a version
10  # string of the form 1.12.5-r617 will be converted to the form
11  # 0001001200050617.  In other words, each number is zero padded to four
12  # digits, and non digits are removed.
13  AS_VAR_PUSHDEF([A],[ax_compare_version_A])
14  A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
15                     -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
16                     -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
17                     -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
18                     -e 's/[[^0-9]]//g'`
19
20  AS_VAR_PUSHDEF([B],[ax_compare_version_B])
21  B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
22                     -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
23                     -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
24                     -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
25                     -e 's/[[^0-9]]//g'`
26
27  dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary
28  dnl # then the first line is used to determine if the condition is true.
29  dnl # The sed right after the echo is to remove any indented white space.
30  m4_case(m4_tolower($2),
31  [lt],[
32    ax_compare_version=`echo "x$A
33x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"`
34  ],
35  [gt],[
36    ax_compare_version=`echo "x$A
37x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"`
38  ],
39  [le],[
40    ax_compare_version=`echo "x$A
41x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"`
42  ],
43  [ge],[
44    ax_compare_version=`echo "x$A
45x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"`
46  ],[
47    dnl Split the operator from the subversion count if present.
48    m4_bmatch(m4_substr($2,2),
49    [0],[
50      # A count of zero means use the length of the shorter version.
51      # Determine the number of characters in A and B.
52      ax_compare_version_len_A=`echo "$A" | $AWK '{print(length)}'`
53      ax_compare_version_len_B=`echo "$B" | $AWK '{print(length)}'`
54
55      # Set A to no more than B's length and B to no more than A's length.
56      A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"`
57      B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"`
58    ],
59    [[0-9]+],[
60      # A count greater than zero means use only that many subversions
61      A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
62      B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
63    ],
64    [.+],[
65      AC_WARNING(
66        [illegal OP numeric parameter: $2])
67    ],[])
68
69    # Pad zeros at end of numbers to make same length.
70    ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`"
71    B="$B`echo $A | sed 's/./0/g'`"
72    A="$ax_compare_version_tmp_A"
73
74    # Check for equality or inequality as necessary.
75    m4_case(m4_tolower(m4_substr($2,0,2)),
76    [eq],[
77      test "x$A" = "x$B" && ax_compare_version=true
78    ],
79    [ne],[
80      test "x$A" != "x$B" && ax_compare_version=true
81    ],[
82      AC_WARNING([illegal OP parameter: $2])
83    ])
84  ])
85
86  AS_VAR_POPDEF([A])dnl
87  AS_VAR_POPDEF([B])dnl
88
89  dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE.
90  if test "$ax_compare_version" = "true" ; then
91    m4_ifvaln([$4],[$4],[:])dnl
92    m4_ifvaln([$5],[else $5])dnl
93  fi
94]) dnl AX_COMPARE_VERSION
Note: See TracBrowser for help on using the repository browser.